diff --git a/.env.production b/.env.production index dc93818..7393827 100644 --- a/.env.production +++ b/.env.production @@ -7,6 +7,3 @@ VITE_APP_ENV='production' # 生产环境 VITE_API_BASE='https://dev.api.leapy.cn/merchant/' VITE_WS_URL='wss://dev.api.leapy.cn/mms' - -# 是否在打包时开启压缩,支持 gzip 和 brotli -VITE_BUILD_COMPRESS=gzip diff --git a/package.json b/package.json index db0c257..174f025 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,7 @@ "vue": "^3.5.14", "vue-i18n": "^11.1.5", "vue-router": "^4.5.1", - "vuedraggable": "^2.24.3", - "vuex": "^4.1.0" + "vuedraggable": "^2.24.3" }, "devDependencies": { "@types/node": "^22.15.21", diff --git a/src/layout/components/iframeView.vue b/src/layout/components/iframeView.vue index 09cf7ff..0e9141c 100644 --- a/src/layout/components/iframeView.vue +++ b/src/layout/components/iframeView.vue @@ -8,12 +8,16 @@ diff --git a/src/main.ts b/src/main.ts index c961d5c..74d9a91 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,13 +5,13 @@ import 'element-plus/theme-chalk/display.css' import i18n from './locales' import App from './App.vue' +import pinia from './store' import router from './router' -import store from './store' import pi from './pi' const app = createApp(App); -app.use(store); +app.use(pinia); app.use(router); app.use(ElementPlus); app.use(i18n); diff --git a/src/router/index.ts b/src/router/index.ts index 7fa9bf4..de926f3 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -84,7 +84,7 @@ router.beforeEach(async (to, from, next) => { }); router.afterEach((to, from) => { - // afterEach(to) + afterEach(to) NProgress.done() }); diff --git a/src/store/global.ts b/src/store/global.ts new file mode 100644 index 0000000..3951bfc --- /dev/null +++ b/src/store/global.ts @@ -0,0 +1,33 @@ +import tools from "@/utils/tools"; +import config from "@/config"; +import {defineStore} from "pinia"; + +const globalStore = defineStore('global', { + state: () => ({ + //移动端布局 + ismobile: false, + //布局 + layout: tools.data.get('APP_LAYOUT') || config.APP_LAYOUT || 'header', + //菜单是否折叠 toggle + menuIsCollapse: false, + //多标签栏 + layoutTags: true + }), + actions: { + SET_ismobile(key) { + this.ismobile = key + }, + SET_layout(key) { + this.layout = key + }, + TOGGLE_menuIsCollapse() { + this.menuIsCollapse = !this.menuIsCollapse + }, + TOGGLE_layoutTags() { + this.layoutTags = !this.layoutTags + } + }, + persist: true +}) + +export default globalStore diff --git a/src/store/iframe.ts b/src/store/iframe.ts new file mode 100644 index 0000000..9253ed7 --- /dev/null +++ b/src/store/iframe.ts @@ -0,0 +1,43 @@ +import {defineStore} from "pinia"; + +const iframeStore = defineStore("iframe", { + state: () => ({ + iframeList: [] + }), + actions: { + setIframeList(route){ + this.iframeList = [] + this.iframeList.push(route) + }, + pushIframeList(route){ + let target = this.iframeList.find((item) => item.path === route.path) + if(!target){ + this.iframeList.push(route) + } + }, + removeIframeList(route){ + this.iframeList.forEach((item, index) => { + if (item.path === route.path){ + this.iframeList.splice(index, 1) + } + }) + }, + refreshIframe(route){ + this.iframeList.forEach((item) => { + if (item.path == route.path){ + var url = route.meta.url; + item.meta.url = ''; + setTimeout(function() { + item.meta.url = url + }, 200); + } + }) + }, + clearIframeList(){ + this.iframeList = [] + } + }, + persist: true +}) + +export default iframeStore diff --git a/src/store/index.ts b/src/store/index.ts index 74319fa..8ee91b5 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,7 +1,7 @@ import { createPinia } from "pinia" import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' -const store = createPinia() -store.use(piniaPluginPersistedstate) +const pinia = createPinia() +pinia.use(piniaPluginPersistedstate) -export default store +export default pinia diff --git a/src/store/keepAlive.ts b/src/store/keepAlive.ts new file mode 100644 index 0000000..2e33f4d --- /dev/null +++ b/src/store/keepAlive.ts @@ -0,0 +1,34 @@ +import {defineStore} from "pinia"; + +const keepAliveStore = defineStore("keepAlive", { + state: () => ({ + keepLiveRoute: [], + routeKey: null, + routeShow: true + }), + actions: { + pushKeepLive(component) { + if (!this.keepLiveRoute.includes(component)) { + this.keepLiveRoute.push(component) + } + }, + removeKeepLive(component) { + var index = this.keepLiveRoute.indexOf(component); + if (index !== -1) { + this.keepLiveRoute.splice(index, 1); + } + }, + clearKeepLive() { + this.keepLiveRoute = [] + }, + setRouteKey(key) { + this.routeKey = key + }, + setRouteShow(key) { + this.routeShow = key + } + }, + persist: true +}) + +export default keepAliveStore diff --git a/src/store/model/global.ts b/src/store/model/global.ts deleted file mode 100644 index 080e777..0000000 --- a/src/store/model/global.ts +++ /dev/null @@ -1,36 +0,0 @@ -import tools from "@/utils/tools"; -import config from "@/config"; -import {defineStore} from "pinia"; - -// const globalStore = defineStore('global', { -// state: () => { -// -// } -// }) - -export default { - state: { - //移动端布局 - ismobile: false, - //布局 - layout: tools.data.get('APP_LAYOUT') || config.APP_LAYOUT || 'header', - //菜单是否折叠 toggle - menuIsCollapse: false, - //多标签栏 - layoutTags: true - }, - mutations: { - SET_ismobile(state, key) { - state.ismobile = key - }, - SET_layout(state, key) { - state.layout = key - }, - TOGGLE_menuIsCollapse(state) { - state.menuIsCollapse = !state.menuIsCollapse - }, - TOGGLE_layoutTags(state) { - state.layoutTags = !state.layoutTags - } - } -} diff --git a/src/store/model/iframe.ts b/src/store/model/iframe.ts deleted file mode 100644 index f139578..0000000 --- a/src/store/model/iframe.ts +++ /dev/null @@ -1,38 +0,0 @@ -export default { - state: { - iframeList: [] - }, - mutations: { - setIframeList(state, route){ - state.iframeList = [] - state.iframeList.push(route) - }, - pushIframeList(state, route){ - let target = state.iframeList.find((item) => item.path === route.path) - if(!target){ - state.iframeList.push(route) - } - }, - removeIframeList(state, route){ - state.iframeList.forEach((item, index) => { - if (item.path === route.path){ - state.iframeList.splice(index, 1) - } - }) - }, - refreshIframe(state, route){ - state.iframeList.forEach((item) => { - if (item.path == route.path){ - var url = route.meta.url; - item.meta.url = ''; - setTimeout(function() { - item.meta.url = url - }, 200); - } - }) - }, - clearIframeList(state){ - state.iframeList = [] - } - } -} diff --git a/src/store/model/keepAlive.ts b/src/store/model/keepAlive.ts deleted file mode 100644 index c143cf5..0000000 --- a/src/store/model/keepAlive.ts +++ /dev/null @@ -1,34 +0,0 @@ -export default { - state: { - keepLiveRoute: [], - routeKey: null, - routeShow: true - }, - mutations: { - pushKeepLive(state, component){ - if(!state.keepLiveRoute.includes(component)){ - state.keepLiveRoute.push(component) - } - }, - removeKeepLive(state, component){ - var index = state.keepLiveRoute.indexOf(component); - if(index !== -1){ - state.keepLiveRoute.splice(index, 1); - } - }, - clearKeepLive(state){ - state.keepLiveRoute = [] - }, - setRouteKey(state, key){ - state.routeKey = key - }, - setRouteShow(state, key){ - state.routeShow = key - } - }, - actions: { - setRouteKey({ commit }, key) { - commit('setRouteKey', key); - } - } -} diff --git a/src/store/model/viewTags.ts b/src/store/model/viewTags.ts deleted file mode 100644 index 7d0d2fd..0000000 --- a/src/store/model/viewTags.ts +++ /dev/null @@ -1,47 +0,0 @@ -import router from '@/router' - -export default { - state: { - viewTags: [] - }, - mutations: { - pushViewTags(state, route){ - let backPathIndex = state.viewTags.findIndex(item => item.fullPath == router.options.history.state.back) - let target = state.viewTags.find((item) => item.fullPath === route.fullPath) - let isName = route.name - if(!target && isName){ - if(backPathIndex == -1){ - state.viewTags.push(Object.assign({}, route)) - }else{ - state.viewTags.splice(backPathIndex+1, 0, Object.assign({}, route)) - } - } - }, - removeViewTags(state, route){ - state.viewTags.forEach((item, index) => { - if (item.fullPath === route.fullPath){ - state.viewTags.splice(index, 1) - } - }) - }, - updateViewTags(state, route){ - state.viewTags.forEach((item) => { - if (item.fullPath == route.fullPath){ - // 追加数据 - item = Object.assign(item, route) - } - }) - }, - updateViewTagsTitle(state, title=''){ - const nowFullPath = location.hash.substring(1) - state.viewTags.forEach((item) => { - if (item.fullPath == nowFullPath){ - item.meta.title = title - } - }) - }, - clearViewTags(state){ - state.viewTags = [] - } - } -} diff --git a/src/store/viewTags.ts b/src/store/viewTags.ts new file mode 100644 index 0000000..86e4d79 --- /dev/null +++ b/src/store/viewTags.ts @@ -0,0 +1,68 @@ +import {defineStore} from "pinia"; +import router from '@/router' + +const viewTagsStore = defineStore("viewTags", { + state: () => ({ + viewTags: [] + }), + actions: { + pushViewTags(route){ + let backPathIndex = this.viewTags.findIndex(item => item.fullPath == router.options.history.state.back) + let target = this.viewTags.find((item) => item.fullPath === route.fullPath) + let isName = route.name + if(!target && isName){ + const _route = { + name: route.name, + fullPath: route.fullPath, + component: route.component, + path: route.path, + scrollTop: route.scrollTop, + meta: { + hidden: route?.meta?.hidden, + icon: route?.meta?.icon, + affix: route?.meta?.affix, + type: route?.meta?.type, + title: route?.meta?.title, + }, + query: route.query, + params: route.params, + hash: route.hash + } + if(backPathIndex == -1){ + this.viewTags.push(_route) + }else{ + this.viewTags.splice(backPathIndex+1, 0, _route) + } + } + }, + removeViewTags(route){ + this.viewTags.forEach((item, index) => { + if (item.fullPath === route.fullPath){ + this.viewTags.splice(index, 1) + } + }) + }, + updateViewTags(route){ + this.viewTags.forEach((item) => { + if (item.fullPath == route.fullPath){ + // 追加数据 + item = Object.assign(item, route) + } + }) + }, + updateViewTagsTitle(title=''){ + const nowFullPath = location.hash.substring(1) + this.viewTags.forEach((item) => { + if (item.fullPath == nowFullPath){ + item.meta.title = title + } + }) + }, + clearViewTags(){ + this.viewTags = [] + } + }, + persist: true +}) + +export default viewTagsStore diff --git a/src/utils/route.ts b/src/utils/route.ts index 41b9291..13e1145 100644 --- a/src/utils/route.ts +++ b/src/utils/route.ts @@ -1,4 +1,4 @@ -import store from '@/store' +import viewTagsStore from "@/store/viewTags"; import {nextTick} from 'vue' import {RouteLocationNormalized, RouteLocationNormalizedLoaded} from "vue-router"; import tools from "@/utils/tools"; @@ -8,10 +8,11 @@ const notFound = () => import('/src/layout/404.vue') export function beforeEach(to: RouteLocationNormalized, from: RouteLocationNormalizedLoaded) { const piMain = document.querySelector('#pi-main'); + const viewTags = viewTagsStore() if (!piMain) { return false } - store.commit("updateViewTags", { + viewTags.updateViewTags({ fullPath: from.fullPath, scrollTop: piMain.scrollTop }) @@ -19,12 +20,13 @@ export function beforeEach(to: RouteLocationNormalized, from: RouteLocationNorma export function afterEach(to: RouteLocationNormalized) { const piMain = document.querySelector('#pi-main'); + const viewTags = viewTagsStore() if (!piMain) { return false } nextTick(() => { // @ts-ignore - const beforeRoute = store.state.viewTags.viewTags.filter(v => v.fullPath == to.fullPath)[0]; + const beforeRoute = viewTags.viewTags.filter(v => v.fullPath == to.fullPath)[0]; if (beforeRoute) { piMain.scrollTop = beforeRoute.scrollTop || 0 }