fix:router

This commit is contained in:
wangzenghua 2025-02-28 06:28:54 +00:00
parent 1b2b03352a
commit 75491c9448
19 changed files with 71 additions and 204 deletions

View File

@ -1,5 +1,4 @@
# 开发环境
VITE_PORT = 9000
VITE_APP_NAME = 'daimp-front-main'
VITE_APP_TITLE = '数字农业产业管理平台'
VITE_APP_SUB_OS = '//localhost:8090/sub-operation-service/'

View File

@ -18,9 +18,6 @@ actions.onGlobalStateChange((newState, prev) => {
}
});
// 有key表示取globalState下的某个子级对象
// 无key表示取全部
actions.getGlobalState = (key) => {
return key ? initialState[key] : initialState;
};

View File

@ -25,7 +25,6 @@ export const usePermissionStore = defineStore({
actions: {
generateRoutes(roles) {
return new Promise((resolve) => {
// 在这判断是否有权限,哪些角色拥有哪些权限
const UserStore = useUserStore();
this.asyncRoutes = createAsyncRoutes(getTree(UserStore.getMenus()));
let accessedRoutes;

View File

@ -1,64 +1,12 @@
import { defineStore } from 'pinia';
import { CONSTANTS } from '@/config';
export const useSettingStore = defineStore({
id: 'settingStore',
state: () => ({
// menu 是否收缩
isCollapse: true,
//
withoutAnimation: false,
device: 'desktop',
// 刷新当前页
isReload: true,
// 主题设置
themeConfig: {
// 显示设置
showSetting: false,
// 菜单展示模式 默认 vertical horizontal / vertical /columns
mode: 'vertical',
// tagsView 是否展示 默认展示
showTag: true,
// 页脚
footer: true,
// 深色模式 切换暗黑模式
isDark: false,
// 显示侧边栏Logo
showLogo: true,
// 主题颜色
primary: CONSTANTS.PRIMARY,
// element组件大小
globalComSize: 'default',
// 是否只保持一个子菜单的展开
uniqueOpened: true,
// 固定header
fixedHeader: true,
// 灰色模式
gray: false,
// 色弱模式
weak: false,
},
}),
getters: {},
actions: {
// 设置主题
setThemeConfig({ key, val }) {
this.themeConfig[key] = val;
},
// 切换 Collapse
setCollapse(value) {
this.isCollapse = value;
this.withoutAnimation = false;
},
// 关闭侧边栏
closeSideBar({ withoutAnimation }) {
this.isCollapse = false;
this.withoutAnimation = withoutAnimation;
},
toggleDevice(device) {
this.device = device;
},
// 刷新
setReload() {
this.isReload = false;
setTimeout(() => {

View File

@ -34,9 +34,10 @@ router.beforeEach(async (to, from, next) => {
if (!PermissionStore.routes.length) {
const accessRoutes = await PermissionStore.generateRoutes(userStore.roles);
accessRoutes.forEach((item) => router.addRoute(item));
next({ ...to, replace: true });
return next({ ...to, replace: true });
} else {
if (from.path.includes('/sub') && !to.path.includes('/sub')) {
if (from.path.includes('/sub') && (!to.path.includes('/sub') || to.path.includes('/platform'))) {
NProgress.done();
window.location.reload();
return;
}

View File

@ -36,22 +36,15 @@ import actions from '@/micro/actions';
import { getAssetsFile } from '@/utils';
const gotoPage = (row) => {
// const curentApp = microApps.find((item) => row.name === item.name);
// actions.setGlobalState({
// curentApp,
// });
// console.log('===', actions.getGlobalState('user'));
// if (row.name !== 'sub-government-affairs-service') return;
window.history.pushState({}, row.name, row.activeRule);
};
</script>
<style lang="scss" scoped>
.platform {
width: 100%;
height: 100%;
min-height: 100%;
background-image: url('@/assets/images/platform/bg.png');
background-size: cover;
// background-position: center;
&-title {
width: 1200px;

View File

@ -21,30 +21,6 @@ export default defineConfig(({ command, mode }) => {
target: 'ESNext',
outDir: 'dist',
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
pure_funcs: ['console.log'],
},
output: {
comments: true,
},
},
reportCompressedSize: false,
chunkSizeWarningLimit: 2000,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
return id.toString().split('node_modules/')[1].split('/')[1].toString();
}
},
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
},
},
},
server: {
host: '0.0.0.0',
@ -119,5 +95,13 @@ export default defineConfig(({ command, mode }) => {
}),
],
};
if (mode === 'production') {
config.build.terserOptions = {
compress: {
drop_console: true,
drop_debugger: true,
},
};
}
return config;
});

View File

@ -7,7 +7,7 @@
<title>政务服务</title>
</head>
<body>
<div id="sub-app"></div>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

View File

@ -3,7 +3,7 @@
* @Author: zenghua.wang
* @Date: 2024-01-24 18:54:01
* @LastEditors: zenghua.wang
* @LastEditTime: 2024-01-26 22:57:34
* @LastEditTime: 2025-02-28 11:31:12
-->
<template>
<el-config-provider :size="size" :locale="zhCn">

View File

@ -2,7 +2,7 @@ import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper';
const { VITE_APP_MIAN, VITE_APP_NAME } = import.meta.env;
export const GenKey = (key, prefix = VITE_APP_NAME) => {
prefix = qiankunWindow.__POWERED_BY_QIANKUN__ ? VITE_APP_MIAN : VITE_APP_NAME;
prefix = qiankunWindow.__POWERED_BY_QIANKUN__ ? VITE_APP_MIAN : VITE_APP_MIAN;
return prefix ? `${prefix}_` + key : key;
};

View File

@ -7,7 +7,7 @@
*/
import 'virtual:svg-icons-register';
import { createApp } from 'vue';
import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper';
import VueAMap, { initAMapApiLoader } from '@vuemap/vue-amap';
import App from './App.vue';
import router from './router';
import pinia from './store';
@ -15,11 +15,12 @@ import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import Avue from '@smallwei/avue';
import '@smallwei/avue/lib/index.css';
import './utils/permission';
import { registerDirective } from './directives';
import { registerGlobalComponents } from './plugins/globalComponents';
import { registerElIcons } from './plugins/icon';
import './utils/permission';
import VueAMap, { initAMapApiLoader } from '@vuemap/vue-amap';
import { registerMicroApps } from './plugins/micro';
initAMapApiLoader({
key: 'c843a50db7157faf295c6fa37c48719f',
securityJsCode: 'f09302d3ed65110614bdb26e44717ddf', // 新版key需要配合安全密钥使用
@ -27,37 +28,10 @@ initAMapApiLoader({
// version: '2.0.0'
//} // 如果需要使用loca组件库需要加载Loca
});
const registerMicroApps = () => {
let app = null;
const initQiankun = () => {
renderWithQiankun({
bootstrap() {
console.log('bootstrap');
},
mount(props) {
console.log('mount', props);
render(props);
},
update(props) {
console.log('update', props);
},
unmount(props) {
console.log('unmount', props);
app = null;
},
});
};
const render = async ({ container }) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
app = createApp(App);
app.use(pinia).use(router).use(ElementPlus).use(Avue).use(VueAMap);
registerGlobalComponents(app);
registerElIcons(app);
registerDirective(app);
registerMicroApps(app);
app.mount(container.querySelector('#sub-app') || '#sub-app');
};
qiankunWindow.__POWERED_BY_QIANKUN__ ? initQiankun() : render({});
};
registerMicroApps();
const app = createApp(App);
app.use(pinia).use(router).use(ElementPlus).use(Avue).use(VueAMap);
registerGlobalComponents(app);
registerElIcons(app);
registerDirective(app);
registerMicroApps(app);

View File

@ -1,6 +1,6 @@
import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper';
export const registerMicroApps = (app) => {
export const registerMicroApps = async (app) => {
const initQiankun = () => {
renderWithQiankun({
bootstrap() {
@ -20,11 +20,7 @@ export const registerMicroApps = (app) => {
};
const render = async ({ container }) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
if (!container) {
console.error('挂载容器不存在');
return;
}
app.mount(container.querySelector('#sub-app') || '#sub-app');
app.mount(container ? container.querySelector('#app') : '#app');
};
qiankunWindow.__POWERED_BY_QIANKUN__ ? initQiankun() : render({});
};

View File

@ -3,50 +3,37 @@
* @Author: zenghua.wang
* @Date: 2023-06-20 11:48:41
* @LastEditors: zenghua.wang
* @LastEditTime: 2025-02-18 11:22:07
* @LastEditTime: 2025-02-28 13:50:00
*/
import { createRouter, createWebHistory } from 'vue-router';
import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper';
import Layout from '@/layouts/index.vue';
import resourceRouter from './modules/resource';
import plantingAndBreedingRouter from './modules/plantingAndBreeding';
import landsRoutes from './modules/lands';
const { VITE_APP_NAME } = import.meta.env;
export const constantRoutes = [
{
path: '/404',
path: '/sub-government-affairs-service/404',
name: '404',
component: () => import('@/views/error/404.vue'),
hidden: true,
},
{
path: '/403',
path: '/sub-government-affairs-service/403',
name: '403',
component: () => import('@/views/error/403.vue'),
hidden: true,
},
// {
// path: '/login',
// name: 'login',
// component: () => import('@/views/error/404.vue'),
// hidden: true,
// meta: {
// title: '登录',
// icon: 'Login',
// },
// },
{
path: '/',
path: '/sub-government-affairs-service',
name: 'layout',
component: Layout,
redirect: '/home',
redirect: '/sub-government-affairs-service/home',
meta: { title: '政务服务', icon: 'House' },
children: [
{
path: '/home',
path: '/sub-government-affairs-service/home',
component: () => import('@/views/home/index.vue'),
name: 'home',
meta: { title: '首页', icon: 'House' },
@ -62,13 +49,13 @@ export const constantRoutes = [
* @Title notFoundRouter(找不到路由)
*/
export const notFoundRouter = {
path: '/:pathMatch(.*)',
path: '/sub-government-affairs-service/:pathMatch(.*)',
name: 'notFound',
redirect: '/404',
redirect: '/sub-government-affairs-service/404',
};
const router = createRouter({
history: createWebHistory(qiankunWindow.__POWERED_BY_QIANKUN__ ? `/${VITE_APP_NAME}/` : '/'), // history
history: createWebHistory(),
routes: constantRoutes,
});

View File

@ -3,27 +3,27 @@ import Views from '@/layouts/Views.vue';
export default [
{
path: '/plantingAndBreeding',
path: '/sub-government-affairs-service/plantingAndBreeding',
name: 'plantingAndBreeding',
component: Layout,
redirect: '/breeding',
redirect: '/sub-government-affairs-service/breeding',
meta: { title: '种养殖管理', icon: 'Document' },
children: [
{
path: '/planting',
path: '/sub-government-affairs-service/planting',
name: 'planting',
component: Views,
meta: { title: '种植档案', icon: 'Document' },
redirect: '/planting-base',
redirect: '/sub-government-affairs-service/planting-base',
children: [
{
path: '/planting-base',
path: '/sub-government-affairs-service/planting-base',
component: () => import('@/views/trace/planting/base/index.vue'),
name: 'planting-base',
meta: { title: '基地档案', icon: 'Document' },
},
{
path: '/planting-seed',
path: '/sub-government-affairs-service/planting-seed',
component: () => import('@/views/trace/planting/seed/index.vue'),
name: 'planting-seed',
meta: { title: '种子档案', icon: 'Document' },
@ -31,20 +31,20 @@ export default [
],
},
{
path: '/breeding',
path: '/sub-government-affairs-service/breeding',
name: 'breeding',
component: Views,
meta: { title: '农事管理', icon: 'Document' },
redirect: '/breeding-coding',
redirect: '/sub-government-affairs-service/breeding-coding',
children: [
{
path: '/breeding-coding',
path: '/sub-government-affairs-service/breeding-coding',
component: () => import('@/views/trace/breeding/coding/index.vue'),
name: 'breeding-coding',
meta: { title: '采收与赋码管理', icon: 'Document' },
},
{
path: '/breeding-quality',
path: '/sub-government-affairs-service/breeding-quality',
component: () => import('@/views/trace/breeding/quality/index.vue'),
name: 'breeding-quality',
meta: { title: '产品质检管理', icon: 'Document' },
@ -54,20 +54,20 @@ export default [
],
},
{
path: '/trace',
path: '/sub-government-affairs-service/trace',
name: 'trace',
component: Layout,
redirect: '/trace-search',
redirect: '/sub-government-affairs-service/trace-search',
meta: { title: '溯源查询', icon: 'Document' },
children: [
{
path: '/trace-search',
path: '/sub-government-affairs-service/trace-search',
name: 'trace-search',
component: () => import('@/views/trace/search/index.vue'),
meta: { title: '溯源查询', icon: 'Document' },
},
{
path: '/trace-info',
path: '/sub-government-affairs-service/trace-info',
name: 'trace-info',
component: () => import('@/views/trace/search/info.vue'),
meta: { title: '溯源详情', icon: 'Document' },

View File

@ -3,14 +3,14 @@ import Views from '@/layouts/Views.vue';
export default [
{
path: '/resource',
path: '/sub-government-affairs-service/resource',
name: 'resource',
component: Layout,
redirect: '/grid',
redirect: '/sub-government-affairs-service/grid',
meta: { title: '土地资源管理', icon: 'icon-test' },
children: [
{
path: '/grid',
path: '/sub-government-affairs-service/grid',
component: () => import('@/views/resource/grid/index.vue'),
name: 'grid',
meta: { title: '网格化管理', icon: 'Document' },

View File

@ -1,8 +1,9 @@
import { defineStore } from 'pinia';
import { CONSTANTS } from '@/config';
import { GenKey } from '@/config';
export const useSettingStore = defineStore({
id: 'settingStore',
id: GenKey('settingStore'),
state: () => ({
// menu 是否收缩
isCollapse: true,

View File

@ -34,8 +34,12 @@ router.beforeEach(async (to, from, next) => {
if (!PermissionStore.routes.length) {
const accessRoutes = await PermissionStore.generateRoutes(userStore.roles);
accessRoutes.forEach((item) => router.addRoute(item));
next({ ...to, replace: true });
return next({ ...to, replace: true });
} else {
if (from.path.includes('/sub') && to.path.includes('/platform')) {
window.location.reload();
return;
}
next();
}
} catch (error) {

View File

@ -24,9 +24,9 @@
<el-button type="success" icon="download" @click="onExport">导出</el-button>
</template>
<template #id="{ row }">
<!-- <template #id="{ row }">
<el-image style="width: 50px; height: 50px; cursor: pointer" :src="row.orCodeUrl" fit="cover" lazy @click="onViewCode(row)" />
</template>
</template> -->
<template #productUrl-form="{ column }">
<el-upload class="custom-form__uploader" action="#" :show-file-list="false" accept="image/*" :limit="1" :http-request="rowUploadPicture">

View File

@ -3,7 +3,7 @@
* @Author: zenghua.wang
* @Date: 2022-09-18 21:24:29
* @LastEditors: zenghua.wang
* @LastEditTime: 2025-02-27 09:16:00
* @LastEditTime: 2025-02-28 11:04:41
*/
import { defineConfig, loadEnv } from 'vite';
@ -30,30 +30,6 @@ export default defineConfig(({ command, mode }) => {
target: 'ESNext',
outDir: 'dist',
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
pure_funcs: ['console.log'],
},
output: {
comments: true,
},
},
reportCompressedSize: false,
chunkSizeWarningLimit: 2000,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
return id.toString().split('node_modules/')[1].split('/')[1].toString();
}
},
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
},
},
},
server: {
host: '0.0.0.0',
@ -128,5 +104,13 @@ export default defineConfig(({ command, mode }) => {
}),
],
};
if (mode === 'production') {
config.build.terserOptions = {
compress: {
drop_console: true,
drop_debugger: true,
},
};
}
return config;
});