提交 2a78f8d8 authored 作者: 王鹏飞's avatar 王鹏飞

feat: 修改菜单通过接口控制显示隐藏

上级 db1cfddf
...@@ -151,3 +151,8 @@ export function getCategoryList(params?: { name?: string }) { ...@@ -151,3 +151,8 @@ export function getCategoryList(params?: { name?: string }) {
export function getProductList(params?: { name?: string }) { export function getProductList(params?: { name?: string }) {
return httpRequest.get('/api/lab/v1/experiment/live-commodity/list', { params }) return httpRequest.get('/api/lab/v1/experiment/live-commodity/list', { params })
} }
// 获取当前实验下的所有权限 (实验营销配置)
export function getAuth() {
return httpRequest.get('/api/lab/v1/experiment/auth/all')
}
...@@ -15,6 +15,11 @@ const routes: RouteRecordRaw[] = [ ...@@ -15,6 +15,11 @@ const routes: RouteRecordRaw[] = [
{ path: 'view', component: () => import('./views/Demo.vue'), props: { isView: true } }, { path: 'view', component: () => import('./views/Demo.vue'), props: { isView: true } },
], ],
}, },
{
path: '/one/live/test/view',
component: () => import('./views/Demo.vue'),
props: { isView: true },
},
] ]
export { routes } export { routes }
...@@ -3,11 +3,11 @@ import { useUserStore } from '@/stores/user' ...@@ -3,11 +3,11 @@ import { useUserStore } from '@/stores/user'
const router = createRouter({ const router = createRouter({
history: createWebHistory(), history: createWebHistory(),
routes: [{ path: '/:pathMatch(.*)*', redirect: '/' }] routes: [{ path: '/:pathMatch(.*)*', redirect: '/' }],
}) })
router.beforeEach(async (to, from, next) => { router.beforeEach(async (to, from, next) => {
const whiteList = ['/401'] const whiteList = ['/401', '/one/live/test/view']
const user = useUserStore() const user = useUserStore()
if (!user.isLogin && !whiteList.includes(to.path)) { if (!user.isLogin && !whiteList.includes(to.path)) {
try { try {
...@@ -27,8 +27,8 @@ router.beforeEach(async (to, from, next) => { ...@@ -27,8 +27,8 @@ router.beforeEach(async (to, from, next) => {
...to.query, ...to.query,
experiment_id: from.query.experiment_id || '7028276368903241728', experiment_id: from.query.experiment_id || '7028276368903241728',
student_id: from.query.student_id, student_id: from.query.student_id,
force_tgc: from.query.force_tgc force_tgc: from.query.force_tgc,
} },
}) })
} else { } else {
next() next()
......
...@@ -37,292 +37,347 @@ interface State { ...@@ -37,292 +37,347 @@ interface State {
// 学生菜单 // 学生菜单
const studentMenus: IMenuItem[] = [ const studentMenus: IMenuItem[] = [
{ {
id: 1,
name: '基础配置', name: '基础配置',
path: '/connect', path: '/connect',
icon: markRaw(IconMetadata), icon: markRaw(IconMetadata),
children: [ children: [
{ {
id: 2,
name: '连接管理', name: '连接管理',
path: '/connect', path: '/connect',
icon: markRaw(IconConnect) icon: markRaw(IconConnect),
} },
] ],
}, },
{ {
id: 5,
name: '营销策划', name: '营销策划',
path: '/market/my', path: '/market/my',
icon: markRaw(IconMarket) icon: markRaw(IconMarket),
}, },
{ {
id: 6,
name: '用户画像', name: '用户画像',
path: '/user', path: '/user',
icon: markRaw(IconUser) icon: markRaw(IconUser),
}, },
{ {
id: 7,
name: '用户识别', name: '用户识别',
path: '/label', path: '/label',
icon: markRaw(IconGroup2), icon: markRaw(IconGroup2),
children: [ children: [
{ {
id: 8,
name: '标签管理', name: '标签管理',
path: '/label', path: '/label',
icon: markRaw(IconLabel) icon: markRaw(IconLabel),
}, },
{ {
id: 9,
name: '群组管理', name: '群组管理',
path: '/group', path: '/group',
icon: markRaw(IconGroup) icon: markRaw(IconGroup),
} },
] ],
}, },
{ {
id: 10,
name: '营销内容设计', name: '营销内容设计',
path: '/material', path: '/material',
icon: markRaw(IconMaterial), icon: markRaw(IconMaterial),
children: [ children: [
{ {
id: 11,
name: '文本资料管理', name: '文本资料管理',
path: '/material?type=1', path: '/material?type=1',
icon: markRaw(IconText), icon: markRaw(IconText),
// tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list'
tag: '' tag: '',
}, },
{ {
id: 12,
name: '图片资料管理', name: '图片资料管理',
path: '/material?type=2', path: '/material?type=2',
icon: markRaw(IconImage), icon: markRaw(IconImage),
// tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list'
tag: '' tag: '',
}, },
{ {
id: 13,
name: '卡券资料管理', name: '卡券资料管理',
path: '/material?type=8', path: '/material?type=8',
icon: markRaw(IconCard), icon: markRaw(IconCard),
// tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list'
tag: '' tag: '',
}, },
{ {
id: 17,
name: '语音资料管理', name: '语音资料管理',
path: '/material?type=3', path: '/material?type=3',
icon: markRaw(IconAudio), icon: markRaw(IconAudio),
// tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list'
tag: '' tag: '',
}, },
{ {
id: 14,
name: '视频资料管理', name: '视频资料管理',
path: '/material?type=4', path: '/material?type=4',
icon: markRaw(IconVideo), icon: markRaw(IconVideo),
// tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list'
tag: '' tag: '',
}, },
{ {
id: 15,
name: 'H5资料管理', name: 'H5资料管理',
path: '/material?type=5', path: '/material?type=5',
icon: markRaw(IconH5), icon: markRaw(IconH5),
tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list',
}, },
{ {
id: 16,
name: '二维码资料管理', name: '二维码资料管理',
path: '/material?type=6', path: '/material?type=6',
icon: markRaw(IconQrcode), icon: markRaw(IconQrcode),
// tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list'
tag: '' tag: '',
}, },
{ {
id: 18,
name: '小程序资料管理', name: '小程序资料管理',
path: '/material?type=7', path: '/material?type=7',
icon: markRaw(IconMiniProgram), icon: markRaw(IconMiniProgram),
// tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list'
tag: '' tag: '',
} },
] ],
}, },
{ {
id: 19,
name: '自动化营销', name: '自动化营销',
path: '/trip/my', path: '/trip/my',
icon: markRaw(IconTrip) icon: markRaw(IconTrip),
}, },
{ {
id: 20,
name: '直播带货', name: '直播带货',
path: '/live', path: '/live',
icon: markRaw(IconLive), icon: markRaw(IconLive),
children: [ children: [
{ name: '商品管理', path: '/live/product/management', icon: markRaw(IconLiveProductManagement) }, {
{ name: '直播话术管理', path: '/live/talk', icon: markRaw(IconLiveTalk) }, id: 23,
{ name: '直播练习', path: '/live/test', icon: markRaw(IconLiveTest) } name: '商品管理',
] path: '/live/product/management',
icon: markRaw(IconLiveProductManagement),
},
{ id: 24, name: '直播话术管理', path: '/live/talk', icon: markRaw(IconLiveTalk) },
{ id: 25, name: '直播练习', path: '/live/test', icon: markRaw(IconLiveTest) },
],
}, },
{ {
id: 26,
name: '数据分析', name: '数据分析',
path: '/analyze', path: '/analyze',
icon: markRaw(IconAnalyze), icon: markRaw(IconAnalyze),
children: [ children: [
{ name: '用户分析', path: '/analyze/user' }, { id: 27, name: '用户分析', path: '/analyze/user' },
{ name: '标签群组分析', path: '/analyze/label' }, { id: 28, name: '标签群组分析', path: '/analyze/label' },
{ name: '事件分析', path: '/analyze/event' }, { id: 29, name: '事件分析', path: '/analyze/event' },
{ name: '营销分析', path: '/analyze/marketing' } { id: 30, name: '营销分析', path: '/analyze/marketing' },
] ],
} },
] ]
const adminMenus: IMenuItem[] = [ const adminMenus: IMenuItem[] = [
{ {
id: 1,
name: '基础配置', name: '基础配置',
path: '/connect', path: '/connect',
icon: markRaw(IconMetadata), icon: markRaw(IconMetadata),
children: [ children: [
{ {
id: 2,
name: '连接管理', name: '连接管理',
path: '/connect', path: '/connect',
icon: markRaw(IconConnect), icon: markRaw(IconConnect),
tag: 'v1-experiment-connection' // tag: 'v1-experiment-connection',
}, },
{ {
id: 3,
name: '用户属性管理', name: '用户属性管理',
path: '/metadata/user', path: '/metadata/user',
icon: markRaw(IconUser2), icon: markRaw(IconUser2),
tag: 'v1-experiment-meta-member' // tag: 'v1-experiment-meta-member',
}, },
{ {
id: 4,
name: '事件属性管理', name: '事件属性管理',
path: '/metadata/event', path: '/metadata/event',
icon: markRaw(IconEvent), icon: markRaw(IconEvent),
tag: 'v1-experiment-meta-event' // tag: 'v1-experiment-meta-event',
} },
] ],
}, },
{ {
id: 5,
name: '营销策划', name: '营销策划',
path: '/market/review', path: '/market/review',
icon: markRaw(IconMarket) studentPath: '/market/my',
icon: markRaw(IconMarket),
}, },
{ {
id: 6,
name: '用户画像', name: '用户画像',
path: '/user', path: '/user',
icon: markRaw(IconUser), icon: markRaw(IconUser),
tag: 'v1-experiment-member' // tag: 'v1-experiment-member',
}, },
{ {
id: 7,
name: '用户识别', name: '用户识别',
path: '/label', path: '/label',
icon: markRaw(IconGroup2), icon: markRaw(IconGroup2),
children: [ children: [
{ {
id: 8,
name: '标签管理', name: '标签管理',
path: '/label', path: '/label',
icon: markRaw(IconLabel), icon: markRaw(IconLabel),
tag: 'experiment_tags' // tag: 'experiment_tags',
}, },
{ {
id: 9,
name: '群组管理', name: '群组管理',
path: '/group', path: '/group',
icon: markRaw(IconGroup), icon: markRaw(IconGroup),
tag: 'experiment_groups' // tag: 'experiment_groups',
} },
] ],
}, },
{ {
id: 10,
name: '营销内容设计', name: '营销内容设计',
path: '/material', path: '/material',
icon: markRaw(IconMaterial), icon: markRaw(IconMaterial),
tag: 'v1-experiment-marketing-material', // tag: 'v1-experiment-marketing-material',
children: [ children: [
{ {
id: 11,
name: '文本资料管理', name: '文本资料管理',
path: '/material?type=1', path: '/material?type=1',
icon: markRaw(IconText), icon: markRaw(IconText),
tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list',
}, },
{ {
id: 12,
name: '图片资料管理', name: '图片资料管理',
path: '/material?type=2', path: '/material?type=2',
icon: markRaw(IconImage), icon: markRaw(IconImage),
tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list',
}, },
{ {
id: 13,
name: '卡券资料管理', name: '卡券资料管理',
path: '/material?type=8', path: '/material?type=8',
icon: markRaw(IconCard), icon: markRaw(IconCard),
tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list',
}, },
{ {
id: 17,
name: '语音资料管理', name: '语音资料管理',
path: '/material?type=3', path: '/material?type=3',
icon: markRaw(IconAudio), icon: markRaw(IconAudio),
tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list',
}, },
{ {
id: 14,
name: '视频资料管理', name: '视频资料管理',
path: '/material?type=4', path: '/material?type=4',
icon: markRaw(IconVideo), icon: markRaw(IconVideo),
tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list',
}, },
{ {
id: 15,
name: 'H5资料管理', name: 'H5资料管理',
path: '/material?type=5', path: '/material?type=5',
icon: markRaw(IconH5), icon: markRaw(IconH5),
tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list',
}, },
{ {
id: 16,
name: '二维码资料管理', name: '二维码资料管理',
path: '/material?type=6', path: '/material?type=6',
icon: markRaw(IconQrcode), icon: markRaw(IconQrcode),
tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list',
}, },
{ {
id: 18,
name: '小程序资料管理', name: '小程序资料管理',
path: '/material?type=7', path: '/material?type=7',
icon: markRaw(IconMiniProgram), icon: markRaw(IconMiniProgram),
tag: 'v1-experiment-marketing-material-list' // tag: 'v1-experiment-marketing-material-list',
} },
] ],
}, },
{ {
id: 19,
name: '自动化营销', name: '自动化营销',
path: '/trip', path: '/trip',
studentPath: '/trip/my',
icon: markRaw(IconTrip), icon: markRaw(IconTrip),
tag: 'experiment_itinerary' // tag: 'experiment_itinerary',
// children: [{ name: '旅程模板管理', path: '/trip/template', tag: 'experiment_itinerary_list' }] // children: [{ name: '旅程模板管理', path: '/trip/template', tag: 'experiment_itinerary_list' }]
}, },
{ {
id: 20,
name: '直播带货', name: '直播带货',
path: '/live', path: '/live',
icon: markRaw(IconLive), icon: markRaw(IconLive),
children: [ children: [
{ name: '商品品类管理', path: '/live/product/category', icon: markRaw(IconLiveProductCategory) }, { id: 21, name: '商品品类管理', path: '/live/product/category', icon: markRaw(IconLiveProductCategory) },
{ name: '商品属性管理', path: '/live/product/attr', icon: markRaw(IconLiveProductAttr) }, { id: 22, name: '商品属性管理', path: '/live/product/attr', icon: markRaw(IconLiveProductAttr) },
{ name: '商品管理', path: '/live/product/management', icon: markRaw(IconLiveProductManagement) }, { id: 23, name: '商品管理', path: '/live/product/management', icon: markRaw(IconLiveProductManagement) },
{ name: '直播话术管理', path: '/live/talk', icon: markRaw(IconLiveTalk) }, { id: 24, name: '直播话术管理', path: '/live/talk', icon: markRaw(IconLiveTalk) },
{ name: '直播练习', path: '/live/test', icon: markRaw(IconLiveTest) } { id: 25, name: '直播练习', path: '/live/test', icon: markRaw(IconLiveTest) },
] ],
}, },
{ {
id: 26,
name: '数据分析', name: '数据分析',
path: '/analyze', path: '/analyze',
icon: markRaw(IconAnalyze), icon: markRaw(IconAnalyze),
children: [ children: [
{ name: '用户分析', path: '/analyze/user' }, { id: 27, name: '用户分析', path: '/analyze/user' },
{ name: '标签群组分析', path: '/analyze/label' }, { id: 28, name: '标签群组分析', path: '/analyze/label' },
{ name: '事件分析', path: '/analyze/event' }, { id: 29, name: '事件分析', path: '/analyze/event' },
{ name: '营销分析', path: '/analyze/marketing' } { id: 30, name: '营销分析', path: '/analyze/marketing' },
] ],
} },
] ]
export const useMenuStore = defineStore({ export const useMenuStore = defineStore({
id: 'menu', id: 'menu',
state: (): State => ({ state: (): State => ({
studentMenus, studentMenus,
adminMenus adminMenus,
}), }),
getters: { getters: {
menus: state => { menus: (state) => {
const userStore = useUserStore() const userStore = useUserStore()
if (userStore.role?.id === 1) { // const menus = userStore.role?.id === 1 ? state.studentMenus : state.adminMenus
return state.studentMenus
} else {
return state.adminMenus return state.adminMenus
.filter((item) => {
// 过滤有权限的菜单
return userStore.menus.find((menu) => menu.id == item.id)
})
.map((item) => {
// 如果当前角色是学生,则使用学生的路径
if (userStore.role?.id === 1 && item.studentPath) {
item.path = item.studentPath
} }
} return item
} })
},
},
}) })
import type { UserType, ProjectType, OrganizationType, RoleType, PermissionType } from '@/types' import type { UserType, ProjectType, OrganizationType, RoleType, PermissionType } from '@/types'
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { getUser, logout, checkDataStatus } from '@/api/base' import { getUser, logout, checkDataStatus, getAuth } from '@/api/base'
import { useMapStore } from '@/stores/map' import { useMapStore } from '@/stores/map'
// 角色信息(1学员;5教师; 6管理员) // 角色信息(1学员;5教师; 6管理员)
...@@ -16,6 +16,13 @@ interface State { ...@@ -16,6 +16,13 @@ interface State {
roles: RoleType[] roles: RoleType[]
permissions: PermissionType[] permissions: PermissionType[]
status: any status: any
menus: Menu[]
}
interface Menu {
id: number
name: string
pid: number
} }
export const useUserStore = defineStore({ export const useUserStore = defineStore({
...@@ -27,10 +34,11 @@ export const useUserStore = defineStore({ ...@@ -27,10 +34,11 @@ export const useUserStore = defineStore({
project: null, project: null,
roles: [], roles: [],
permissions: [], permissions: [],
status: {} status: {},
menus: [],
}), }),
getters: { getters: {
isLogin: state => !!state.user isLogin: (state) => !!state.user,
}, },
actions: { actions: {
async getUser() { async getUser() {
...@@ -44,13 +52,16 @@ export const useUserStore = defineStore({ ...@@ -44,13 +52,16 @@ export const useUserStore = defineStore({
this.roles = roles this.roles = roles
this.permissions = permissions this.permissions = permissions
await useMapStore().getMapList() await useMapStore().getMapList()
await checkDataStatus().then(res => { await checkDataStatus().then((res) => {
this.status = res.data this.status = res.data
}) })
await getAuth().then((res) => {
this.menus = res.data.items || []
})
}, },
async logout() { async logout() {
await logout() await logout()
this.user = null this.user = null
} },
} },
}) })
import type { Component } from 'vue' import type { Component } from 'vue'
export interface IMenuItem { export interface IMenuItem {
id?: number
tag?: string | string[] tag?: string | string[]
name: string name: string
path: string path: string
studentPath?: string
icon?: Component icon?: Component
children?: IMenuItem[] children?: IMenuItem[]
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论