焊接首页
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import {
|
||||
defineStore
|
||||
} from 'pinia'
|
||||
import {
|
||||
ref,
|
||||
computed
|
||||
} from 'vue'
|
||||
import {reqHJIndexData} from '@/api/hj.js'
|
||||
|
||||
export const useLargeStore = defineStore('large', () => {
|
||||
const hjIndexData = ref(null)
|
||||
|
||||
/**
|
||||
* 获取焊接首页数据
|
||||
*/
|
||||
const fetchHJIndex = (projectId)=>{
|
||||
reqHJIndexData(projectId).then(res=>{
|
||||
hjIndexData.value = res.data
|
||||
})
|
||||
}
|
||||
return {
|
||||
hjIndexData,
|
||||
fetchHJIndex
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,102 @@
|
||||
import {
|
||||
defineStore
|
||||
} from 'pinia'
|
||||
import {
|
||||
ref,
|
||||
computed
|
||||
} from 'vue'
|
||||
import {pastelColors,defaultApps} from '@/utils/constant.js'
|
||||
import {reqMenuPowerList} from '@/api/auth.js'
|
||||
|
||||
export const useMenuStore = defineStore('menu', () => {
|
||||
// 应用列表(默认配置 + 持久化)
|
||||
const appsList = ref([...defaultApps])
|
||||
// 编辑时的临时缓存
|
||||
const editCache = ref([])
|
||||
// 菜单的权限列表(后端返回的有权限的菜单 code 数组)
|
||||
const menuProwerList = ref([])
|
||||
|
||||
// 快捷应用列表(已选择的)
|
||||
const quickApps = computed(() => appsList.value.filter(app => app.selected&&hasMenuPermission(app.menuId)))
|
||||
|
||||
// 业务查询列表(未选择的)
|
||||
const queryApps = computed(() => appsList.value.filter(app => !app.selected&&hasMenuPermission(app.menuId)))
|
||||
|
||||
/**
|
||||
* 打开编辑弹窗(备份当前状态)
|
||||
*/
|
||||
const openEdit = () => {
|
||||
editCache.value = appsList.value.filter(app => hasMenuPermission(app.menuId))
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换应用选择状态
|
||||
*/
|
||||
const toggleSelect = (item) => {
|
||||
item.selected = !item.selected
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认编辑(保存更改)
|
||||
*/
|
||||
const confirmEdit = () => {
|
||||
appsList.value = editCache.value.map(app => ({ ...app }))
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求菜单权限列表
|
||||
*/
|
||||
const fetchMenuPowerList = async (userId, projectId) => {
|
||||
if (!userId || !projectId) return
|
||||
try {
|
||||
const res = await reqMenuPowerList(userId, projectId)
|
||||
menuProwerList.value = res.data || []
|
||||
} catch (err) {
|
||||
console.error('获取菜单权限失败:', err)
|
||||
menuProwerList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断菜单是否有权限打开
|
||||
* @param {string} menuCode - 菜单编码/标识
|
||||
* @returns {boolean} 是否有权限
|
||||
*/
|
||||
const hasMenuPermission = (menuCode) => {
|
||||
if (!menuCode) return true
|
||||
return menuProwerList.value.includes(menuCode)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据权限过滤快捷应用
|
||||
*/
|
||||
const quickAppsWithPermission = computed(() => {
|
||||
if (menuProwerList.value.length === 0) return quickApps.value
|
||||
return quickApps.value.filter(app => {
|
||||
return hasMenuPermission(app.permissionCode)
|
||||
})
|
||||
})
|
||||
|
||||
return {
|
||||
appsList,
|
||||
editCache,
|
||||
quickApps,
|
||||
quickAppsWithPermission,
|
||||
queryApps,
|
||||
menuProwerList,
|
||||
pastelColors,
|
||||
openEdit,
|
||||
toggleSelect,
|
||||
confirmEdit,
|
||||
fetchMenuPowerList,
|
||||
hasMenuPermission
|
||||
}
|
||||
}, {
|
||||
persist: {
|
||||
enabled: true,
|
||||
strategies: [{
|
||||
key: 'menu',
|
||||
paths: [],
|
||||
}]
|
||||
},
|
||||
})
|
||||
+24
-8
@@ -2,12 +2,13 @@ import {
|
||||
defineStore
|
||||
} from 'pinia'
|
||||
import {
|
||||
ref
|
||||
ref,
|
||||
watch
|
||||
} from 'vue'
|
||||
import {
|
||||
reqLogin
|
||||
} from '@/api/auth.js'
|
||||
|
||||
import { useMenuStore, useLargeStore } from '@/store'
|
||||
export const useUserStore = defineStore('user', () => {
|
||||
const token = ref("")
|
||||
const userInfo = ref(null)
|
||||
@@ -20,6 +21,20 @@ export const useUserStore = defineStore('user', () => {
|
||||
const projectList = ref([])
|
||||
const currentProject = ref(null)
|
||||
|
||||
// 监听 currentProject 变化,获取菜单权限
|
||||
watch(() => currentProject.value?.ProjectId, (newId) => {
|
||||
if (newId) {
|
||||
// 项目变化 请求菜单权限
|
||||
const menuStore = useMenuStore()
|
||||
const userId = userInfo.value?.PersonId
|
||||
menuStore.fetchMenuPowerList(userId, newId)
|
||||
// 项目变化 请求焊接首页数据
|
||||
const largeStore = useLargeStore()
|
||||
largeStore.fetchHJIndex(newId)
|
||||
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
|
||||
/**
|
||||
* 登出
|
||||
@@ -27,11 +42,11 @@ export const useUserStore = defineStore('user', () => {
|
||||
const logout = () => {
|
||||
token.value = ""
|
||||
userInfo.value = null
|
||||
loginForm.value = {
|
||||
account: '',
|
||||
password: '',
|
||||
Telephone: '',
|
||||
}
|
||||
// loginForm.value = {
|
||||
// account: '',
|
||||
// password: '',
|
||||
// Telephone: '',
|
||||
// }
|
||||
currentProject.value = null
|
||||
}
|
||||
|
||||
@@ -79,7 +94,8 @@ export const useUserStore = defineStore('user', () => {
|
||||
projectList,
|
||||
currentProject,
|
||||
setProjectList,
|
||||
setCurrentProject
|
||||
setCurrentProject,
|
||||
logout
|
||||
}
|
||||
}, {
|
||||
persist: {
|
||||
|
||||
Reference in New Issue
Block a user