提交 b37eff8c authored 作者: lidongxu's avatar lidongxu

refactor(router): 修改:勤策移动端_促销菜单跳转修复

上级 42ae05d6
......@@ -42,6 +42,7 @@ router.beforeEach((to, from, next) => {
useVersionStore().getVersion().then((res) => {
// 生成可访问路由表
accessRoutes.forEach(route => {
console.log('挂载路由', route)
if (!isHttp(route.path) ) {
router.addRoute(route)
}
......
......@@ -3,6 +3,7 @@ import router, { constantRoutes, dynamicRoutes } from '@/router'
import { getRouters } from '@/api'
import Layout from '@/layout/index'
import ParentView from '@/components/ParentView'
import MobileIndex from '@/views/mobile/index'
import InnerLink from '@/layout/components/InnerLink'
import useUserStore from '@/store/modules/user'
import useAppStore from '@/store/modules/app'
......@@ -44,7 +45,7 @@ const usePermissionStore = defineStore(
res.data = res.data.filter(item => item.belongSys == 0)
} else {
// 勤策
res.data = res.data.filter(item => item.belongSys == 1)
res.data = res.data.filter(item => item.belongSys == 1)[0].children
}
const sdata = JSON.parse(JSON.stringify(res.data))
const rdata = JSON.parse(JSON.stringify(res.data))
......@@ -84,7 +85,12 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
if (route.component === 'Layout') {
route.component = Layout
} else if (route.component === 'ParentView') {
route.component = ParentView
// 勤策移动端
if (useAppStore().belongSys == 1) {
route.component = MobileIndex
} else {
route.component = ParentView
}
} else if (route.component === 'InnerLink') {
route.component = InnerLink
} else {
......
......@@ -7,13 +7,29 @@
</template>
<script setup>
import { constantMobileRoutes } from '@/views/mobile/router'
import usePermissionStore from '@/store/modules/permission';
const permissionStore = usePermissionStore();
// 递归判断有 children 往里走找到所有路由对象 meta 的 keepAlive 是 true 的然后返回 meta 同级的 name 名字的值,组成一个数组
const cachedViews = []
watch(
() => permissionStore.sidebarRouters,
(newRoutes) => {
if (newRoutes.length > 0) {
// 路由加载完成后转换格式
// 把 hidden: true 的筛选掉
getKeepAliveName(newRoutes)
}
},
{ immediate: true, deep: true }
);
function getKeepAliveName(routes) {
console.log('routes', routes)
routes.forEach((item) => {
if (item.meta?.keepAlive) {
console.log('1', item)
if (!item.meta?.noCache && item.name) { // 是否缓存
cachedViews.push(item.name)
}
if (item.children) {
......@@ -21,5 +37,5 @@ function getKeepAliveName(routes) {
}
})
}
getKeepAliveName(constantMobileRoutes)
</script>
......@@ -211,6 +211,11 @@ getPlanDetail()
// 点击稽查按钮
const clickExamine = async () => {
if (examined.value) {
router.push({ path: `/examine/${examined.value}` })
return
}
// 确认是否开始稽查
showConfirmDialog({
title: '系统提示',
......@@ -234,7 +239,7 @@ const clickExamine = async () => {
}
newExamined.value = result.data.id
}
router.push({ path: `/m/examine/${examined?.value || newExamined.value}` })
router.push({ path: `/examine/${examined?.value || newExamined.value}` })
})
}
......
......@@ -11,7 +11,7 @@
@load="onLoad">
<van-cell-group inset
v-if="planList?.length > 0">
<van-cell v-for="item, index in planList.concat(planList)"
<van-cell v-for="item, index in planList"
:key="item.id">
<template #title>
<p class="cell-info">
......
......@@ -84,7 +84,7 @@
<script setup>
// 指定当前组件的名字
defineOptions({
name: 'm_promotion_plan'
name: 'Promotion_plan'
})
import userStore from '@/store/modules/user'
import { parseTime } from '@/utils'
......@@ -105,7 +105,8 @@ const showSearch = ref(false)
// 从新增页面跳转回来需要刷新列表
watch(() => route.path, (newPath, oldPath) => {
if (oldPath.includes('/promotion_plan_editing') && newPath === '/m/promotion_plan') {
if (oldPath.includes('/promotion_plan_editing') && newPath === '/promotion_plan') {
console.log('刷新页面?')
planSearch.value.resetFn()
}
});
......@@ -184,7 +185,8 @@ const onRefresh = () => {
const clickDetail = (row) => {
// 当前处于长按状态 / 查看已删除列表,点击详情不做任何操作
if (showSelect.value || query.isDeleted) return
router.push(`/m/promotion_plan_detail/${row.id}?isDeleted=${query.isDeleted}`)
// router.push(`/promotion_plan_detail/${row.id}?isDeleted=${query.isDeleted}`)
router.push(`/promotion_plan_detail/${row.id}`)
}
// 搜索表单
......@@ -203,7 +205,7 @@ const editPlan = (row) => {
if (!checkPlanChangeExpire(row)) {
return showNotify({ type: 'warning', message: '无法变更,日期小于等于今日' })
}
router.push(`/m/promotion_plan_editing/${row.id}`)
router.push(`/promotion_plan_editing/${row.id}`)
}
// 删除计划
......@@ -327,7 +329,7 @@ onUnmounted(() => {
const addNewPlan = () => {
// 后台设置按钮权限分配就能新增
if (proxy.checkPermi(['promotion:plan:create'])) {
router.push('/m/promotion_plan_editing')
router.push('/promotion_plan_editing')
} else {
showNotify({ type: 'warning', message: '规定日期内_无法新增计划' })
}
......
......@@ -44,26 +44,26 @@ const modules = ref([]); // 替换原有的静态modules
// 格式化路由为菜单所需结构
const formatRoutesToModules = (routes) => {
// 根据实际路由结构转换,这里假设需要提取一级路由作为模块
modules.value = routes[0].children.map(o => {
modules.value = routes.map(o => {
return {
title: o.meta.title,
icons: o.children?.map(child => ({
name: child.meta.title,
iconName: child.meta.icon || 'default',
iconColor: child.meta.color || '#5aaeec',
to: child.path
to: o.path + '/' + child.path
})) || []
}
})
// .map(route => ({
// title: route.meta.title,
// icons: route.children?.map(child => ({
// name: child.meta.title,
// iconName: child.meta.icon || 'default',
// iconColor: child.meta.color || '#5aaeec',
// to: child.path
// })) || []
// }))
// .map(route => ({
// title: route.meta.title,
// icons: route.children?.map(child => ({
// name: child.meta.title,
// iconName: child.meta.icon || 'default',
// iconColor: child.meta.color || '#5aaeec',
// to: child.path
// })) || []
// }))
}
// 监听路由变化
watch(
......
// 移动端 静态路由
export const constantMobileRoutes = [
{
......@@ -7,49 +8,34 @@ export const constantMobileRoutes = [
},
{
path: '/',
redirect: '/m'
},
{
path: '/m',
redirect: '/m/menu',
component: () => import('@/views/mobile/index'),
hidden: true,
redirect: '/menu',
children: [
// 菜单页
{
path: 'menu',
component: () => import('@/views/mobile/views/menu'),
name: 'm_menu',
},
// 促销计划
{
path: 'promotion_plan', // 列表
component: () => import('@/views/mobile/views/cp_activity/promotion/plan/index'),
name: 'm_promotion_plan',
meta: { keepAlive: true } // 标记该路由需要缓存
path: 'menu',// 菜单页
component: () => import('@/views/mobile/pages/menu'),
name: 'm_menu'
},
{
path: 'promotion_plan_detail/:planId', // 详情
component: () => import('@/views/mobile/views/cp_activity/promotion/plan/detail'),
component: () => import('@/views/mobile/pages/cp_activity/promotion/plan/detail'),
name: 'm_promotion_detail',
},
{
path: 'promotion_plan_editing/:planId?', // 增改
component: () => import('@/views/mobile/views/cp_activity/promotion/plan/editing'),
component: () => import('@/views/mobile/pages/cp_activity/promotion/plan/editing'),
name: 'm_promotion_editing',
},
// 稽查
{
path: 'examine/:examineId',
component: () => import('@/views/mobile/views/cp_activity/examine'),
path: 'examine/:examineId', // 促销内稽查
component: () => import('@/views/mobile/pages/cp_activity/examine'),
name: 'm_promotion_examine',
},
{
path: 'logistics', // 物流信息页面
component: () => import('@/views/mobile/pages/other/logistics'),
name: 'logistics'
}
]
},
// 物流信息页面
{
path: '/logistics',
component: () => import('@/views/mobile/views/other/logistics'),
name: 'logistics'
}
]
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论