From 70d1c9162365c1ad21ea2c39f0f4cc83742c5bf1 Mon Sep 17 00:00:00 2001 From: wangzenghua <1048523306@qq.com> Date: Sat, 25 Jan 2025 02:44:29 +0000 Subject: [PATCH] =?UTF-8?q?feat:=E4=B8=BB=E5=BA=94=E7=94=A8=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/.env.development | 3 +- main/.env.production | 1 + main/src/App.vue | 24 +- .../components/custom-table-operate/index.vue | 46 ++++ main/src/components/index.js | 3 +- main/src/hooks/useBreakpoint.js | 6 +- main/src/hooks/useEcharts.js | 2 +- main/src/hooks/useWrapComponents.js | 2 +- main/src/layouts/Link.vue | 44 ---- main/src/layouts/index-bak.vue | 223 ++++++++++++++++++ main/src/layouts/index.vue | 207 +--------------- main/src/main.js | 2 + main/src/micro/app.js | 6 +- main/src/micro/index.js | 21 +- main/src/router/index.js | 27 +-- main/src/store/modules/permission.js | 3 +- main/src/utils/permission.js | 39 +-- main/src/views/home.vue | 7 - .../layouts/component/Breadcrumb/index.vue | 8 +- .../src/layouts/component/Header/index.vue | 4 +- .../src/layouts/component/Size/index.vue | 40 ---- .../src/config/index.js | 19 ++ .../src/layouts/component/Header/index.vue | 4 +- .../src/layouts/component/Size/index.vue | 40 ---- .../src/router/modules/plantingAndBreeding.js | 6 +- .../src/styles/common/define.scss | 13 + .../src/views/resource/land/index.vue | 47 ++-- .../src/views/trace/planting/archives.vue | 86 +++++-- .../src/views/trace/planting/seed.vue | 213 +++++++++++++++++ 29 files changed, 669 insertions(+), 477 deletions(-) create mode 100644 main/src/components/custom-table-operate/index.vue delete mode 100644 main/src/layouts/Link.vue create mode 100644 main/src/layouts/index-bak.vue delete mode 100644 main/src/views/home.vue delete mode 100644 sub-admin/src/layouts/component/Size/index.vue delete mode 100644 sub-government-affairs-service/src/layouts/component/Size/index.vue create mode 100644 sub-government-affairs-service/src/views/trace/planting/seed.vue diff --git a/main/.env.development b/main/.env.development index eeee949..c23115e 100644 --- a/main/.env.development +++ b/main/.env.development @@ -1,9 +1,10 @@ # 开发环境 VITE_PORT = 9000 VITE_APP_NAME = 'daimp-front-main' +VITE_APP_TITLE = '数字农业产业管理平台' VITE_APP_BASE_API = "https://mock.mengxuegu.com/mock/664ef7fee45d2156fa209ee4/api-qiankun" VITE_APP_BASE_URL = 'http://192.168.18.158:9080' -VITE_APP_SUB_VUE = '//localhost:9526/sub-vue/' +VITE_APP_SUB_VUE = '//localhost:9526/sub-operation-service/' VITE_APP_SUB_ADMIN = '//localhost:9527/sub-admin/' VITE_APP_SUB_GAS = '//localhost:9528/suv-government-affairs-service/' diff --git a/main/.env.production b/main/.env.production index acc3426..0e98be6 100644 --- a/main/.env.production +++ b/main/.env.production @@ -1,5 +1,6 @@ # 正式环境 VITE_APP_NAME = 'daimp-front-main' +VITE_APP_TITLE = '数字农业产业管理平台' VITE_APP_BASE_API = "" VITE_APP_BASE_URL = '' VITE_APP_SUB_VUE = '//localhost:9526/sub-vue/' diff --git a/main/src/App.vue b/main/src/App.vue index 7032c14..7c2462b 100644 --- a/main/src/App.vue +++ b/main/src/App.vue @@ -1,34 +1,16 @@ + diff --git a/main/src/components/index.js b/main/src/components/index.js index 019eefa..e0d4830 100644 --- a/main/src/components/index.js +++ b/main/src/components/index.js @@ -1,5 +1,6 @@ import SvgIcon from './svg-icon'; +import CustomTableOperate from './custom-table-operate'; import CustomRichEditor from './custom-rich-editor'; import CustomEchartBar from './custom-echart-bar'; -export { SvgIcon, CustomEchartBar, CustomRichEditor }; +export { SvgIcon, CustomTableOperate, CustomEchartBar, CustomRichEditor }; diff --git a/main/src/hooks/useBreakpoint.js b/main/src/hooks/useBreakpoint.js index cf0e081..32311f2 100644 --- a/main/src/hooks/useBreakpoint.js +++ b/main/src/hooks/useBreakpoint.js @@ -1,9 +1,9 @@ import { ref, computed, unref } from 'vue'; import { useEventListener } from './useEventListener'; -let globalScreenRef; -let globalWidthRef; -let globalRealWidthRef; +let globalScreenRef = 0; +let globalWidthRef = 0; +let globalRealWidthRef = 0; const screenMap = new Map(); screenMap.set('XS', 480); diff --git a/main/src/hooks/useEcharts.js b/main/src/hooks/useEcharts.js index 8d14d5d..19c989f 100644 --- a/main/src/hooks/useEcharts.js +++ b/main/src/hooks/useEcharts.js @@ -12,7 +12,7 @@ export const useEcharts = (elRef, theme = 'default') => { let chartInstance = null; let resizeFn = resize; const cacheOptions = ref({}); - let removeResizeFn = () => {}; + let removeResizeFn = null; resizeFn = useDebounceFn(resize, 200); diff --git a/main/src/hooks/useWrapComponents.js b/main/src/hooks/useWrapComponents.js index 7862e73..0be12f0 100644 --- a/main/src/hooks/useWrapComponents.js +++ b/main/src/hooks/useWrapComponents.js @@ -12,7 +12,7 @@ export const useWrapComponents = (Component, route) => { wrapper = { name: wrapperName, render() { - return h('div', { className: 'layout-main' }, Component); + return h('div', { className: 'layout' }, Component); }, }; wrapperMap.set(wrapperName, wrapper); diff --git a/main/src/layouts/Link.vue b/main/src/layouts/Link.vue deleted file mode 100644 index 257ed94..0000000 --- a/main/src/layouts/Link.vue +++ /dev/null @@ -1,44 +0,0 @@ - - - - diff --git a/main/src/layouts/index-bak.vue b/main/src/layouts/index-bak.vue new file mode 100644 index 0000000..37a1d4d --- /dev/null +++ b/main/src/layouts/index-bak.vue @@ -0,0 +1,223 @@ + + + + + + diff --git a/main/src/layouts/index.vue b/main/src/layouts/index.vue index dbbecbe..8fd1567 100644 --- a/main/src/layouts/index.vue +++ b/main/src/layouts/index.vue @@ -2,113 +2,29 @@ * @Description: * @Author: zenghua.wang * @Date: 2023-06-20 14:29:45 - * @LastEditors: zenghua.wang “1048523306@qq.com” - * @LastEditTime: 2025-01-17 16:36:25 + * @LastEditors: zenghua.wang + * @LastEditTime: 2025-01-25 09:28:53 --> diff --git a/main/src/main.js b/main/src/main.js index 7ac7581..9105699 100644 --- a/main/src/main.js +++ b/main/src/main.js @@ -5,9 +5,11 @@ import router from './router'; import pinia from './store'; import ElementPlus from 'element-plus'; import 'element-plus/dist/index.css'; +import { registerGlobalMicroApps } from './micro'; import { registerElIcons } from './plugins/icon'; import './utils/permission'; const app = createApp(App); app.use(pinia).use(router).use(ElementPlus).mount('#root'); registerElIcons(app); +registerGlobalMicroApps(); diff --git a/main/src/micro/app.js b/main/src/micro/app.js index 0a7bf91..18c6793 100644 --- a/main/src/micro/app.js +++ b/main/src/micro/app.js @@ -4,9 +4,9 @@ const { VITE_APP_SUB_VUE, VITE_APP_SUB_ADMIN, VITE_APP_SUB_GAS } = import.meta.e export const leftApps = [ { - name: 'sub-vue', + name: 'sub-operation-service', entry: VITE_APP_SUB_VUE, - activeRule: '/sub-vue/', + activeRule: '/sub-operation-service/', title: '运营服务', icon: 'platform/icon-home.png', }, @@ -69,7 +69,7 @@ export const microApps = [...leftApps, ...rightApps]; const apps = microApps.map((item) => { return { ...item, - container: '#sub-app', + container: '#app', props: { routerBase: item.activeRule, getGlobalState: actions.getGlobalState, diff --git a/main/src/micro/index.js b/main/src/micro/index.js index 2e71ae1..dc1cf12 100644 --- a/main/src/micro/index.js +++ b/main/src/micro/index.js @@ -2,9 +2,7 @@ import { registerMicroApps, setDefaultMountApp, start, addGlobalUncaughtErrorHan import microApps from './app'; const registerGlobalMicroApps = () => { - // 给子应用配置加上loader方法 const apps = microApps.map((item) => { - // console.log('registerGlobalMicroApps==', item); return { ...item, }; @@ -12,25 +10,22 @@ const registerGlobalMicroApps = () => { registerMicroApps(apps, { beforeLoad: (app) => { - console.log('before load', app); - switch (app.name) { - case 'sub-vue': - document.title = 'sub-vue'; - break; - case 'sub-admin': - document.title = 'sub-admin'; - break; - } + console.log('before load=', app); }, beforeMount: [ (app) => { - console.log('before mount', app.name); + console.log('before mount=', app); + }, + ], + afterUnmount: [ + (app) => { + console.log('after unmount=', app); }, ], }); start({ - prefetch: false, // 取消预加载 + prefetch: true, // 取消预加载 sandbox: { experimentalStyleIsolation: true }, }); diff --git a/main/src/router/index.js b/main/src/router/index.js index 323502d..0ec93ba 100644 --- a/main/src/router/index.js +++ b/main/src/router/index.js @@ -1,4 +1,4 @@ -import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'; +import { createRouter, createWebHistory } from 'vue-router'; import Layout from '@/layouts/index.vue'; export const constantRoutes = [ @@ -12,12 +12,6 @@ export const constantRoutes = [ icon: 'Login', }, }, - { - path: '/platform', - component: () => import('@/views/index.vue'), - name: 'platform', - meta: { title: '平台入口', icon: 'House' }, - }, { path: '/', name: 'layout', @@ -26,28 +20,15 @@ export const constantRoutes = [ meta: { title: '平台入口', icon: 'House' }, children: [ { - path: '/home', - component: () => import('@/views/home.vue'), - name: 'home', + path: '/platform', + component: () => import('@/views/index.vue'), + name: 'platform', meta: { title: '平台入口', icon: 'House' }, }, - { - path: '/sub-admin/:pathMatch(.*)*', - component: () => import('@/views/subApp.vue'), - name: 'sub-admin', - hidden: true, - meta: { title: '子应用入口', icon: 'House' }, - }, ], }, ]; -export const notFoundRouter = { - path: '/:pathMatch(.*)', - name: 'notFound', - redirect: '/404', -}; - const router = createRouter({ history: createWebHistory(), routes: constantRoutes, diff --git a/main/src/store/modules/permission.js b/main/src/store/modules/permission.js index 6691180..9d95a93 100644 --- a/main/src/store/modules/permission.js +++ b/main/src/store/modules/permission.js @@ -1,5 +1,5 @@ import { defineStore } from 'pinia'; -import { constantRoutes, notFoundRouter } from '@/router'; +import { constantRoutes } from '@/router'; import { createAsyncRoutes, filterAsyncRoutes, filterKeepAlive } from '@/utils/router'; import { useUserStore } from '@/store/modules/user'; import { getTree } from '@/utils'; @@ -34,7 +34,6 @@ export const usePermissionStore = defineStore({ } else { accessedRoutes = this.asyncRoutes || []; } - accessedRoutes = accessedRoutes.concat(notFoundRouter); this.routes = constantRoutes.concat(accessedRoutes); resolve(accessedRoutes); }); diff --git a/main/src/utils/permission.js b/main/src/utils/permission.js index 2bb80bf..8501768 100644 --- a/main/src/utils/permission.js +++ b/main/src/utils/permission.js @@ -13,23 +13,13 @@ import { usePermissionStore } from '@/store/modules/permission'; NProgress.configure({ showSpinner: false }); -const { VITE_APP_NAME } = import.meta.env; +const { VITE_APP_TITLE } = import.meta.env; const whiteList = ['/login']; router.beforeEach(async (to, from, next) => { - // 解决三级菜单页面缓存问题 - // if (to.matched && to.matched.length > 1) { - // for (let i = 0; i < to.matched.length; i++) { - // const element = to.matched[i]; - // if (element.components.default.name === 'ViewBox') { - // to.matched.splice(i, 1); - // } - // } - // } - NProgress.start(); if (typeof to.meta.title === 'string') { - document.title = VITE_APP_NAME + ' | ' + to.meta.title; + document.title = VITE_APP_TITLE + ' | ' + to.meta.title; } const userStore = useUserStore(); @@ -46,6 +36,11 @@ router.beforeEach(async (to, from, next) => { accessRoutes.forEach((item) => router.addRoute(item)); next({ ...to, replace: true }); } else { + // 子应用跳转回主应用时判断#app是否还有渲染的子应用,如若没有则重新渲染主应用 + if (from.path.includes('/sub') && !to.path.includes('/sub')) { + window.location.reload(); + return; + } next(); } } catch (error) { @@ -59,26 +54,8 @@ router.beforeEach(async (to, from, next) => { next(`/login?redirect=${to.path}`); } } - - // const PermissionStore = usePermissionStore(); - // console.log('===', PermissionStore.routes); - // if (!PermissionStore.routes.length) { - // const accessRoutes = await PermissionStore.getRoutes(); - // accessRoutes.forEach((item) => router.addRoute(item)); - // next({ ...to, replace: true }); - // } else { - // next(); - // } }); -router.afterEach((to) => { - // qiankun子应用跳转回主应用时判断#app是否还有渲染的子应用,如若没有则重新渲染主应用 - // setTimeout(() => { - // if (to.path === '/') { - // if (window.wocwin_qiankun) { - // window.wocwin_qiankun = null; - // } - // } - // }, 300); +router.afterEach(() => { NProgress.done(); }); diff --git a/main/src/views/home.vue b/main/src/views/home.vue deleted file mode 100644 index 312b8bb..0000000 --- a/main/src/views/home.vue +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/sub-admin/src/layouts/component/Breadcrumb/index.vue b/sub-admin/src/layouts/component/Breadcrumb/index.vue index c01ea2e..2a42b29 100644 --- a/sub-admin/src/layouts/component/Breadcrumb/index.vue +++ b/sub-admin/src/layouts/component/Breadcrumb/index.vue @@ -3,7 +3,7 @@ * @Author: zenghua.wang * @Date: 2023-06-20 14:29:45 * @LastEditors: zenghua.wang - * @LastEditTime: 2024-01-26 23:04:14 + * @LastEditTime: 2025-01-24 15:13:25 -->