|
@@ -1,6 +1,5 @@
|
|
|
import { inject, onMounted, onUnmounted } from "vue";
|
|
|
import { useRoute, useRouter } from "vue-router";
|
|
|
-import { LockBill, UnLockBill } from "@/api/modules/common";
|
|
|
|
|
|
/**
|
|
|
* @description 路由器跳转封装
|
|
@@ -18,55 +17,24 @@ export const usePageRouter = () => {
|
|
|
* @param path 路由地址
|
|
|
* @param title K3显示的标题
|
|
|
*/
|
|
|
- const pageOpen = (path: string, title?: string) => {
|
|
|
- let pageid = window.location.href.split("pageid=")[1];
|
|
|
- if (pageid) {
|
|
|
- // let poststr = JSON.stringify({
|
|
|
- // pageid: pageid,
|
|
|
- // putdata: {
|
|
|
- // url: path,
|
|
|
- // title: getRouteTitle(path, title),
|
|
|
- // showType: "MainNewTabPage"
|
|
|
- // }
|
|
|
- // });
|
|
|
- // let _window = window as any;
|
|
|
- // if (_window?.chrome?.webview) {
|
|
|
- // // 客户端
|
|
|
- // console.log("_window.chrome.webview.postMessage ", poststr, ";_window ", _window);
|
|
|
- // _window.chrome.webview.postMessage(poststr);
|
|
|
- // } else if (window.top) {
|
|
|
- // // 浏览器
|
|
|
- // console.log("window.top.postMessage ", poststr, ";window ", window);
|
|
|
- // window.top.postMessage(poststr, "*");
|
|
|
- // } else if (window.parent) {
|
|
|
- // // 一般不使用
|
|
|
- // console.log("window.parent.postMessage ", poststr, ";window ", window);
|
|
|
- // window.parent.postMessage(poststr, "*");
|
|
|
- // } else {
|
|
|
- // // 一般不使用
|
|
|
- // console.log("window.postMessage ", poststr, ";window ", window);
|
|
|
- // window.postMessage(poststr, "*");
|
|
|
- // }
|
|
|
+ const pageOpen = (
|
|
|
+ arg:
|
|
|
+ | string
|
|
|
+ | {
|
|
|
+ name: string;
|
|
|
+ params?: Record<string, any>;
|
|
|
+ query?: Record<string, any>;
|
|
|
+ replace?: boolean;
|
|
|
+ }
|
|
|
+ ) => {
|
|
|
+ if (typeof arg === "string") {
|
|
|
+ return router.push(arg);
|
|
|
} else {
|
|
|
- router.push(path);
|
|
|
+ const { name, params = {}, query = {} } = arg;
|
|
|
+ return router.push({ name, params, query });
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- const pageLockOpen = async (path: string, keyword: string, billid: number, billcode: string) => {
|
|
|
- await LockBill({ keyword, billid, billcode });
|
|
|
- router.push(path);
|
|
|
- };
|
|
|
-
|
|
|
- const pageLockRefresh = async (path: string, keyword: string, billid: number, billcode: string) => {
|
|
|
- await LockBill({ keyword, billid, billcode });
|
|
|
- router.replace(path);
|
|
|
- };
|
|
|
-
|
|
|
- const pageUnLockRefresh = async (path: string, keyword: string, billid: number, billcode: string) => {
|
|
|
- await UnLockBill({ keyword, billid, billcode });
|
|
|
- router.replace(path);
|
|
|
- };
|
|
|
-
|
|
|
/**
|
|
|
* @description 页面关闭, 兼容:如果有pageid参数就postMessage给K3,由K3关闭
|
|
|
* */
|
|
@@ -98,46 +66,21 @@ export const usePageRouter = () => {
|
|
|
* @param path 路由地址
|
|
|
* @param title K3显示的标题
|
|
|
*/
|
|
|
- const pageRefresh = (path: string, title?: string) => {
|
|
|
- let pageid = window.location.href.split("pageid=")[1];
|
|
|
- if (pageid) {
|
|
|
- // let poststr = JSON.stringify({
|
|
|
- // pageid: pageid,
|
|
|
- // putdata: {
|
|
|
- // url: path,
|
|
|
- // title: getRouteTitle(path, title),
|
|
|
- // showType: "InCurrentForm"
|
|
|
- // }
|
|
|
- // });
|
|
|
- // let _window = window as any;
|
|
|
- // if (_window?.chrome?.webview) {
|
|
|
- // _window.chrome.webview.postMessage(poststr);
|
|
|
- // } else {
|
|
|
- // window.top?.postMessage(poststr, "*");
|
|
|
- // }
|
|
|
+ const pageRefresh = (
|
|
|
+ arg:
|
|
|
+ | string
|
|
|
+ | {
|
|
|
+ name: string;
|
|
|
+ params?: Record<string, any>;
|
|
|
+ query?: Record<string, any>;
|
|
|
+ replace?: boolean;
|
|
|
+ }
|
|
|
+ ) => {
|
|
|
+ if (typeof arg === "string") {
|
|
|
+ return router.replace(arg);
|
|
|
} else {
|
|
|
- router.replace(path);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- /**
|
|
|
- * @description 获取路由标题
|
|
|
- * @param path 路由地址
|
|
|
- * @param title 标题
|
|
|
- */
|
|
|
- const getRouteTitle = (path: string, title?: string) => {
|
|
|
- if (title) return title;
|
|
|
- const basePath = path.split("?")[0];
|
|
|
- try {
|
|
|
- const resolved = router.resolve(basePath);
|
|
|
- if (resolved.matched.length === 0) return "";
|
|
|
-
|
|
|
- // 获取最深层级的路由记录(支持嵌套路由)
|
|
|
- const matchedRoute = resolved.matched[resolved.matched.length - 1];
|
|
|
- return matchedRoute.meta?.title || "";
|
|
|
- } catch (e) {
|
|
|
- console.error("路由解析失败:", e);
|
|
|
- return "";
|
|
|
+ const { name, params = {}, query = {} } = arg;
|
|
|
+ return router.replace({ name, params, query });
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -182,9 +125,6 @@ export const usePageRouter = () => {
|
|
|
pageOpen,
|
|
|
pageClose,
|
|
|
pageRefresh,
|
|
|
- pageLockOpen,
|
|
|
- pageLockRefresh,
|
|
|
- pageUnLockRefresh,
|
|
|
useAutoMessageHandler
|
|
|
};
|
|
|
};
|