初始化
This commit is contained in:
322
src/store/modules/app.ts
Normal file
322
src/store/modules/app.ts
Normal file
@@ -0,0 +1,322 @@
|
||||
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
||||
import { ElementPlusSize } from '@/types/elementPlus'
|
||||
import { LayoutType } from '@/types/layout'
|
||||
import { ThemeTypes } from '@/types/theme'
|
||||
import { humpToUnderline, setCssVar } from '@/utils'
|
||||
import { getCssColorVariable, hexToRGB, mix } from '@/utils/color'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { defineStore } from 'pinia'
|
||||
import { store } from '../index'
|
||||
|
||||
const { wsCache } = useCache()
|
||||
|
||||
interface AppState {
|
||||
breadcrumb: boolean
|
||||
breadcrumbIcon: boolean
|
||||
collapse: boolean
|
||||
uniqueOpened: boolean
|
||||
hamburger: boolean
|
||||
screenfull: boolean
|
||||
search: boolean
|
||||
size: boolean
|
||||
locale: boolean
|
||||
message: boolean
|
||||
tagsView: boolean
|
||||
tagsViewImmerse: boolean
|
||||
tagsViewIcon: boolean
|
||||
logo: boolean
|
||||
fixedHeader: boolean
|
||||
greyMode: boolean
|
||||
pageLoading: boolean
|
||||
layout: LayoutType
|
||||
title: string
|
||||
userInfo: string
|
||||
isDark: boolean
|
||||
currentSize: ElementPlusSize
|
||||
sizeMap: ElementPlusSize[]
|
||||
mobile: boolean
|
||||
footer: boolean
|
||||
theme: ThemeTypes
|
||||
fixedMenu: boolean
|
||||
}
|
||||
|
||||
export const useAppStore = defineStore('app', {
|
||||
state: (): AppState => {
|
||||
return {
|
||||
userInfo: 'userInfo', // 登录信息存储字段-建议每个项目换一个字段,避免与其他项目冲突
|
||||
sizeMap: ['default', 'large', 'small'],
|
||||
mobile: false, // 是否是移动端
|
||||
title: import.meta.env.VITE_APP_TITLE, // 标题
|
||||
pageLoading: false, // 路由跳转loading
|
||||
|
||||
breadcrumb: true, // 面包屑
|
||||
breadcrumbIcon: true, // 面包屑图标
|
||||
collapse: false, // 折叠菜单
|
||||
uniqueOpened: true, // 是否只保持一个子菜单的展开
|
||||
hamburger: true, // 折叠图标
|
||||
screenfull: true, // 全屏图标
|
||||
search: true, // 搜索图标
|
||||
size: true, // 尺寸图标
|
||||
locale: true, // 多语言图标
|
||||
message: true, // 消息图标
|
||||
tagsView: true, // 标签页
|
||||
tagsViewImmerse: false, // 标签页沉浸
|
||||
tagsViewIcon: true, // 是否显示标签图标
|
||||
logo: true, // logo
|
||||
fixedHeader: true, // 固定toolheader
|
||||
footer: true, // 显示页脚
|
||||
greyMode: false, // 是否开始灰色模式,用于特殊悼念日
|
||||
fixedMenu: wsCache.get('fixedMenu') || false, // 是否固定菜单
|
||||
|
||||
layout: wsCache.get(CACHE_KEY.LAYOUT) || 'classic', // layout布局
|
||||
isDark: wsCache.get(CACHE_KEY.IS_DARK) || false, // 是否是暗黑模式
|
||||
currentSize: wsCache.get('default') || 'default', // 组件尺寸
|
||||
theme: wsCache.get(CACHE_KEY.THEME) || {
|
||||
// 主题色
|
||||
elColorPrimary: '#409eff',
|
||||
// 左侧菜单边框颜色
|
||||
leftMenuBorderColor: 'inherit',
|
||||
// 左侧菜单背景颜色
|
||||
leftMenuBgColor: '#001529',
|
||||
// 左侧菜单浅色背景颜色
|
||||
leftMenuBgLightColor: '#0f2438',
|
||||
// 左侧菜单选中背景颜色
|
||||
leftMenuBgActiveColor: 'var(--el-color-primary)',
|
||||
// 左侧菜单收起选中背景颜色
|
||||
leftMenuCollapseBgActiveColor: 'var(--el-color-primary)',
|
||||
// 左侧菜单字体颜色
|
||||
leftMenuTextColor: '#bfcbd9',
|
||||
// 左侧菜单选中字体颜色
|
||||
leftMenuTextActiveColor: '#fff',
|
||||
// logo字体颜色
|
||||
logoTitleTextColor: '#fff',
|
||||
// logo边框颜色
|
||||
logoBorderColor: 'inherit',
|
||||
// 头部背景颜色
|
||||
topHeaderBgColor: '#fff',
|
||||
// 头部字体颜色
|
||||
topHeaderTextColor: 'inherit',
|
||||
// 头部悬停颜色
|
||||
topHeaderHoverColor: '#f6f6f6',
|
||||
// 头部边框颜色
|
||||
topToolBorderColor: '#eee'
|
||||
}
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
getBreadcrumb(): boolean {
|
||||
return this.breadcrumb
|
||||
},
|
||||
getBreadcrumbIcon(): boolean {
|
||||
return this.breadcrumbIcon
|
||||
},
|
||||
getCollapse(): boolean {
|
||||
return this.collapse
|
||||
},
|
||||
getUniqueOpened(): boolean {
|
||||
return this.uniqueOpened
|
||||
},
|
||||
getHamburger(): boolean {
|
||||
return this.hamburger
|
||||
},
|
||||
getScreenfull(): boolean {
|
||||
return this.screenfull
|
||||
},
|
||||
getSize(): boolean {
|
||||
return this.size
|
||||
},
|
||||
getLocale(): boolean {
|
||||
return this.locale
|
||||
},
|
||||
getMessage(): boolean {
|
||||
return this.message
|
||||
},
|
||||
getTagsView(): boolean {
|
||||
return this.tagsView
|
||||
},
|
||||
getTagsViewImmerse(): boolean {
|
||||
return this.tagsViewImmerse
|
||||
},
|
||||
getTagsViewIcon(): boolean {
|
||||
return this.tagsViewIcon
|
||||
},
|
||||
getLogo(): boolean {
|
||||
return this.logo
|
||||
},
|
||||
getFixedHeader(): boolean {
|
||||
return this.fixedHeader
|
||||
},
|
||||
getGreyMode(): boolean {
|
||||
return this.greyMode
|
||||
},
|
||||
getFixedMenu(): boolean {
|
||||
return this.fixedMenu
|
||||
},
|
||||
getPageLoading(): boolean {
|
||||
return this.pageLoading
|
||||
},
|
||||
getLayout(): LayoutType {
|
||||
return this.layout
|
||||
},
|
||||
getTitle(): string {
|
||||
return this.title
|
||||
},
|
||||
getUserInfo(): string {
|
||||
return this.userInfo
|
||||
},
|
||||
getIsDark(): boolean {
|
||||
return this.isDark
|
||||
},
|
||||
getCurrentSize(): ElementPlusSize {
|
||||
return this.currentSize
|
||||
},
|
||||
getSizeMap(): ElementPlusSize[] {
|
||||
return this.sizeMap
|
||||
},
|
||||
getMobile(): boolean {
|
||||
return this.mobile
|
||||
},
|
||||
getTheme(): ThemeTypes {
|
||||
return this.theme
|
||||
},
|
||||
getFooter(): boolean {
|
||||
return this.footer
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setPrimaryLight() {
|
||||
if (this.theme.elColorPrimary) {
|
||||
const elColorPrimary = this.theme.elColorPrimary
|
||||
const color = this.isDark ? '#000000' : '#ffffff'
|
||||
const lightList = [3, 5, 7, 8, 9]
|
||||
lightList.forEach((v) => {
|
||||
setCssVar(`--el-color-primary-light-${v}`, mix(color, elColorPrimary, v / 10))
|
||||
})
|
||||
setCssVar(`--el-color-primary-dark-2`, mix(color, elColorPrimary, 0.2))
|
||||
|
||||
this.setAllColorRgbVars()
|
||||
}
|
||||
},
|
||||
|
||||
// 处理element自带的主题色和辅助色的-rgb切换主题变化,如:--el-color-primary-rgb
|
||||
setAllColorRgbVars() {
|
||||
// 需要处理的颜色类型列表
|
||||
const colorTypes = ['primary', 'success', 'warning', 'danger', 'error', 'info']
|
||||
|
||||
colorTypes.forEach((type) => {
|
||||
// 获取当前颜色值
|
||||
const colorValue = getCssColorVariable(`--el-color-${type}`)
|
||||
if (colorValue) {
|
||||
// 转换为rgba并提取RGB部分
|
||||
const rgbaString = hexToRGB(colorValue, 1)
|
||||
const rgbValues = rgbaString.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/i)
|
||||
if (rgbValues) {
|
||||
const [, r, g, b] = rgbValues
|
||||
// 设置对应的RGB变量
|
||||
setCssVar(`--el-color-${type}-rgb`, `${r}, ${g}, ${b}`)
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
setBreadcrumb(breadcrumb: boolean) {
|
||||
this.breadcrumb = breadcrumb
|
||||
},
|
||||
setBreadcrumbIcon(breadcrumbIcon: boolean) {
|
||||
this.breadcrumbIcon = breadcrumbIcon
|
||||
},
|
||||
setCollapse(collapse: boolean) {
|
||||
this.collapse = collapse
|
||||
},
|
||||
setUniqueOpened(uniqueOpened: boolean) {
|
||||
this.uniqueOpened = uniqueOpened
|
||||
},
|
||||
setHamburger(hamburger: boolean) {
|
||||
this.hamburger = hamburger
|
||||
},
|
||||
setScreenfull(screenfull: boolean) {
|
||||
this.screenfull = screenfull
|
||||
},
|
||||
setSize(size: boolean) {
|
||||
this.size = size
|
||||
},
|
||||
setLocale(locale: boolean) {
|
||||
this.locale = locale
|
||||
},
|
||||
setMessage(message: boolean) {
|
||||
this.message = message
|
||||
},
|
||||
setTagsView(tagsView: boolean) {
|
||||
this.tagsView = tagsView
|
||||
},
|
||||
setTagsViewImmerse(tagsViewImmerse: boolean) {
|
||||
this.tagsViewImmerse = tagsViewImmerse
|
||||
},
|
||||
setTagsViewIcon(tagsViewIcon: boolean) {
|
||||
this.tagsViewIcon = tagsViewIcon
|
||||
},
|
||||
setLogo(logo: boolean) {
|
||||
this.logo = logo
|
||||
},
|
||||
setFixedHeader(fixedHeader: boolean) {
|
||||
this.fixedHeader = fixedHeader
|
||||
},
|
||||
setGreyMode(greyMode: boolean) {
|
||||
this.greyMode = greyMode
|
||||
},
|
||||
setFixedMenu(fixedMenu: boolean) {
|
||||
wsCache.set('fixedMenu', fixedMenu)
|
||||
this.fixedMenu = fixedMenu
|
||||
},
|
||||
setPageLoading(pageLoading: boolean) {
|
||||
this.pageLoading = pageLoading
|
||||
},
|
||||
setLayout(layout: LayoutType) {
|
||||
if (this.mobile && layout !== 'classic') {
|
||||
ElMessage.warning('移动端模式下不支持切换其他布局')
|
||||
return
|
||||
}
|
||||
this.layout = layout
|
||||
wsCache.set(CACHE_KEY.LAYOUT, this.layout)
|
||||
},
|
||||
setTitle(title: string) {
|
||||
this.title = title
|
||||
},
|
||||
setIsDark(isDark: boolean) {
|
||||
this.isDark = isDark
|
||||
if (this.isDark) {
|
||||
document.documentElement.classList.add('dark')
|
||||
document.documentElement.classList.remove('light')
|
||||
} else {
|
||||
document.documentElement.classList.add('light')
|
||||
document.documentElement.classList.remove('dark')
|
||||
}
|
||||
wsCache.set(CACHE_KEY.IS_DARK, this.isDark)
|
||||
this.setPrimaryLight()
|
||||
},
|
||||
setCurrentSize(currentSize: ElementPlusSize) {
|
||||
this.currentSize = currentSize
|
||||
wsCache.set('currentSize', this.currentSize)
|
||||
},
|
||||
setMobile(mobile: boolean) {
|
||||
this.mobile = mobile
|
||||
},
|
||||
setTheme(theme: ThemeTypes) {
|
||||
this.theme = Object.assign(this.theme, theme)
|
||||
wsCache.set(CACHE_KEY.THEME, this.theme)
|
||||
},
|
||||
setCssVarTheme() {
|
||||
for (const key in this.theme) {
|
||||
setCssVar(`--${humpToUnderline(key)}`, this.theme[key])
|
||||
}
|
||||
this.setPrimaryLight()
|
||||
},
|
||||
setFooter(footer: boolean) {
|
||||
this.footer = footer
|
||||
}
|
||||
},
|
||||
persist: false
|
||||
})
|
||||
|
||||
export const useAppStoreWithOut = () => {
|
||||
return useAppStore(store)
|
||||
}
|
||||
55
src/store/modules/bpm/simpleWorkflow.ts
Normal file
55
src/store/modules/bpm/simpleWorkflow.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { store } from '../../index'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useWorkFlowStore = defineStore('simpleWorkflow', {
|
||||
state: () => ({
|
||||
tableId: '',
|
||||
isTried: false,
|
||||
promoterDrawer: false,
|
||||
approverDrawer: false,
|
||||
approverConfig1: {},
|
||||
copyerDrawer: false,
|
||||
copyerConfig: {},
|
||||
conditionDrawer: false,
|
||||
conditionsConfig1: {
|
||||
conditionNodes: []
|
||||
},
|
||||
userTaskConfig: {}
|
||||
}),
|
||||
actions: {
|
||||
setTableId(payload) {
|
||||
this.tableId = payload
|
||||
},
|
||||
setIsTried(payload) {
|
||||
this.isTried = payload
|
||||
},
|
||||
setPromoter(payload) {
|
||||
this.promoterDrawer = payload
|
||||
},
|
||||
setApproverDrawer(payload) {
|
||||
this.approverDrawer = payload
|
||||
},
|
||||
setApproverConfig(payload) {
|
||||
this.approverConfig1 = payload
|
||||
},
|
||||
setCopyerDrawer(payload) {
|
||||
this.copyerDrawer = payload
|
||||
},
|
||||
setCopyerConfig(payload) {
|
||||
this.copyerConfig = payload
|
||||
},
|
||||
setCondition(payload) {
|
||||
this.conditionDrawer = payload
|
||||
},
|
||||
setConditionsConfig(payload) {
|
||||
this.conditionsConfig1 = payload
|
||||
},
|
||||
setUserTaskConfig(payload) {
|
||||
this.userTaskConfig = payload
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export const useWorkFlowStoreWithOut = () => {
|
||||
return useWorkFlowStore(store)
|
||||
}
|
||||
104
src/store/modules/dict.ts
Normal file
104
src/store/modules/dict.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { store } from '../index'
|
||||
// @ts-ignore
|
||||
import { DictDataVO } from '@/api/system/dict/types'
|
||||
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
||||
const { wsCache } = useCache('sessionStorage')
|
||||
import { getSimpleDictDataList } from '@/api/system/dict/dict.data'
|
||||
|
||||
export interface DictValueType {
|
||||
value: any
|
||||
label: string
|
||||
clorType?: string
|
||||
cssClass?: string
|
||||
}
|
||||
export interface DictTypeType {
|
||||
dictType: string
|
||||
dictValue: DictValueType[]
|
||||
}
|
||||
export interface DictState {
|
||||
dictMap: Map<string, any>
|
||||
isSetDict: boolean
|
||||
}
|
||||
|
||||
export const useDictStore = defineStore('dict', {
|
||||
state: (): DictState => ({
|
||||
dictMap: new Map<string, any>(),
|
||||
isSetDict: false
|
||||
}),
|
||||
getters: {
|
||||
getDictMap(): Recordable {
|
||||
const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE)
|
||||
if (dictMap) {
|
||||
this.dictMap = dictMap
|
||||
}
|
||||
return this.dictMap
|
||||
},
|
||||
getIsSetDict(): boolean {
|
||||
return this.isSetDict
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async setDictMap() {
|
||||
const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE)
|
||||
if (dictMap) {
|
||||
this.dictMap = dictMap
|
||||
this.isSetDict = true
|
||||
} else {
|
||||
const res = await getSimpleDictDataList()
|
||||
// 设置数据
|
||||
const dictDataMap = new Map<string, any>()
|
||||
res.forEach((dictData: DictDataVO) => {
|
||||
// 获得 dictType 层级
|
||||
const enumValueObj = dictDataMap[dictData.dictType]
|
||||
if (!enumValueObj) {
|
||||
dictDataMap[dictData.dictType] = []
|
||||
}
|
||||
// 处理 dictValue 层级
|
||||
dictDataMap[dictData.dictType].push({
|
||||
value: dictData.value,
|
||||
label: dictData.label,
|
||||
colorType: dictData.colorType,
|
||||
cssClass: dictData.cssClass
|
||||
})
|
||||
})
|
||||
this.dictMap = dictDataMap
|
||||
this.isSetDict = true
|
||||
wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 秒 过期
|
||||
}
|
||||
},
|
||||
getDictByType(type: string) {
|
||||
if (!this.isSetDict) {
|
||||
this.setDictMap()
|
||||
}
|
||||
return this.dictMap[type]
|
||||
},
|
||||
async resetDict() {
|
||||
wsCache.delete(CACHE_KEY.DICT_CACHE)
|
||||
const res = await getSimpleDictDataList()
|
||||
// 设置数据
|
||||
const dictDataMap = new Map<string, any>()
|
||||
res.forEach((dictData: DictDataVO) => {
|
||||
// 获得 dictType 层级
|
||||
const enumValueObj = dictDataMap[dictData.dictType]
|
||||
if (!enumValueObj) {
|
||||
dictDataMap[dictData.dictType] = []
|
||||
}
|
||||
// 处理 dictValue 层级
|
||||
dictDataMap[dictData.dictType].push({
|
||||
value: dictData.value,
|
||||
label: dictData.label,
|
||||
colorType: dictData.colorType,
|
||||
cssClass: dictData.cssClass
|
||||
})
|
||||
})
|
||||
this.dictMap = dictDataMap
|
||||
this.isSetDict = true
|
||||
wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 秒 过期
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export const useDictStoreWithOut = () => {
|
||||
return useDictStore(store)
|
||||
}
|
||||
59
src/store/modules/locale.ts
Normal file
59
src/store/modules/locale.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { store } from '../index'
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||
import en from 'element-plus/es/locale/lang/en'
|
||||
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
||||
import { LocaleDropdownType } from '@/types/localeDropdown'
|
||||
|
||||
const { wsCache } = useCache()
|
||||
|
||||
const elLocaleMap = {
|
||||
'zh-CN': zhCn,
|
||||
en: en
|
||||
}
|
||||
interface LocaleState {
|
||||
currentLocale: LocaleDropdownType
|
||||
localeMap: LocaleDropdownType[]
|
||||
}
|
||||
|
||||
export const useLocaleStore = defineStore('locales', {
|
||||
state: (): LocaleState => {
|
||||
return {
|
||||
currentLocale: {
|
||||
lang: wsCache.get(CACHE_KEY.LANG) || 'zh-CN',
|
||||
elLocale: elLocaleMap[wsCache.get(CACHE_KEY.LANG) || 'zh-CN']
|
||||
},
|
||||
// 多语言
|
||||
localeMap: [
|
||||
{
|
||||
lang: 'zh-CN',
|
||||
name: '简体中文'
|
||||
},
|
||||
{
|
||||
lang: 'en',
|
||||
name: 'English'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
getCurrentLocale(): LocaleDropdownType {
|
||||
return this.currentLocale
|
||||
},
|
||||
getLocaleMap(): LocaleDropdownType[] {
|
||||
return this.localeMap
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setCurrentLocale(localeMap: LocaleDropdownType) {
|
||||
// this.locale = Object.assign(this.locale, localeMap)
|
||||
this.currentLocale.lang = localeMap?.lang
|
||||
this.currentLocale.elLocale = elLocaleMap[localeMap?.lang]
|
||||
wsCache.set(CACHE_KEY.LANG, localeMap?.lang)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export const useLocaleStoreWithOut = () => {
|
||||
return useLocaleStore(store)
|
||||
}
|
||||
48
src/store/modules/lock.ts
Normal file
48
src/store/modules/lock.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { store } from '@/store'
|
||||
|
||||
interface lockInfo {
|
||||
isLock?: boolean
|
||||
password?: string
|
||||
}
|
||||
|
||||
interface LockState {
|
||||
lockInfo: lockInfo
|
||||
}
|
||||
|
||||
export const useLockStore = defineStore('lock', {
|
||||
state: (): LockState => {
|
||||
return {
|
||||
lockInfo: {
|
||||
// isLock: false, // 是否锁定屏幕
|
||||
// password: '' // 锁屏密码
|
||||
}
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
getLockInfo(): lockInfo {
|
||||
return this.lockInfo
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setLockInfo(lockInfo: lockInfo) {
|
||||
this.lockInfo = lockInfo
|
||||
},
|
||||
resetLockInfo() {
|
||||
this.lockInfo = {}
|
||||
},
|
||||
unLock(password: string) {
|
||||
if (this.lockInfo?.password === password) {
|
||||
this.resetLockInfo()
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
},
|
||||
persist: true
|
||||
})
|
||||
|
||||
export const useLockStoreWithOut = () => {
|
||||
return useLockStore(store)
|
||||
}
|
||||
81
src/store/modules/mall/kefu.ts
Normal file
81
src/store/modules/mall/kefu.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { store } from '@/store'
|
||||
import { defineStore } from 'pinia'
|
||||
import { KeFuConversationApi, KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation'
|
||||
import { KeFuMessageRespVO } from '@/api/mall/promotion/kefu/message'
|
||||
import { isEmpty } from '@/utils/is'
|
||||
|
||||
interface MallKefuInfoVO {
|
||||
conversationList: KeFuConversationRespVO[] // 会话列表
|
||||
conversationMessageList: Map<number, KeFuMessageRespVO[]> // 会话消息
|
||||
}
|
||||
|
||||
export const useMallKefuStore = defineStore('mall-kefu', {
|
||||
state: (): MallKefuInfoVO => ({
|
||||
conversationList: [],
|
||||
conversationMessageList: new Map<number, KeFuMessageRespVO[]>() // key 会话,value 会话消息列表
|
||||
}),
|
||||
getters: {
|
||||
getConversationList(): KeFuConversationRespVO[] {
|
||||
return this.conversationList
|
||||
},
|
||||
getConversationMessageList(): (conversationId: number) => KeFuMessageRespVO[] | undefined {
|
||||
return (conversationId: number) => this.conversationMessageList.get(conversationId)
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
// ======================= 会话消息相关 =======================
|
||||
/** 缓存历史消息 */
|
||||
saveMessageList(conversationId: number, messageList: KeFuMessageRespVO[]) {
|
||||
this.conversationMessageList.set(conversationId, messageList)
|
||||
},
|
||||
|
||||
// ======================= 会话相关 =======================
|
||||
/** 加载会话缓存列表 */
|
||||
async setConversationList() {
|
||||
this.conversationList = await KeFuConversationApi.getConversationList()
|
||||
this.conversationSort()
|
||||
},
|
||||
/** 更新会话缓存已读 */
|
||||
async updateConversationStatus(conversationId: number) {
|
||||
if (isEmpty(this.conversationList)) {
|
||||
return
|
||||
}
|
||||
const conversation = this.conversationList.find((item) => item.id === conversationId)
|
||||
conversation && (conversation.adminUnreadMessageCount = 0)
|
||||
},
|
||||
/** 更新会话缓存 */
|
||||
async updateConversation(conversationId: number) {
|
||||
if (isEmpty(this.conversationList)) {
|
||||
return
|
||||
}
|
||||
|
||||
const conversation = await KeFuConversationApi.getConversation(conversationId)
|
||||
this.deleteConversation(conversationId)
|
||||
conversation && this.conversationList.push(conversation)
|
||||
this.conversationSort()
|
||||
},
|
||||
/** 删除会话缓存 */
|
||||
deleteConversation(conversationId: number) {
|
||||
const index = this.conversationList.findIndex((item) => item.id === conversationId)
|
||||
// 存在则删除
|
||||
if (index > -1) {
|
||||
this.conversationList.splice(index, 1)
|
||||
}
|
||||
},
|
||||
conversationSort() {
|
||||
// 按置顶属性和最后消息时间排序
|
||||
this.conversationList.sort((a, b) => {
|
||||
// 按照置顶排序,置顶的会在前面
|
||||
if (a.adminPinned !== b.adminPinned) {
|
||||
return a.adminPinned ? -1 : 1
|
||||
}
|
||||
// 按照最后消息时间排序,最近的会在前面
|
||||
return (b.lastMessageTime as unknown as number) - (a.lastMessageTime as unknown as number)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export const useMallKefuStoreWithOut = () => {
|
||||
return useMallKefuStore(store)
|
||||
}
|
||||
71
src/store/modules/permission.ts
Normal file
71
src/store/modules/permission.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { store } from '@/store'
|
||||
import { cloneDeep } from 'lodash-es'
|
||||
import remainingRouter from '@/router/modules/remaining'
|
||||
import { flatMultiLevelRoutes, generateRoute } from '@/utils/routerHelper'
|
||||
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
||||
|
||||
const { wsCache } = useCache()
|
||||
|
||||
export interface PermissionState {
|
||||
routers: AppRouteRecordRaw[]
|
||||
addRouters: AppRouteRecordRaw[]
|
||||
menuTabRouters: AppRouteRecordRaw[]
|
||||
}
|
||||
|
||||
export const usePermissionStore = defineStore('permission', {
|
||||
state: (): PermissionState => ({
|
||||
routers: [],
|
||||
addRouters: [],
|
||||
menuTabRouters: []
|
||||
}),
|
||||
getters: {
|
||||
getRouters(): AppRouteRecordRaw[] {
|
||||
return this.routers
|
||||
},
|
||||
getAddRouters(): AppRouteRecordRaw[] {
|
||||
return flatMultiLevelRoutes(cloneDeep(this.addRouters))
|
||||
},
|
||||
getMenuTabRouters(): AppRouteRecordRaw[] {
|
||||
return this.menuTabRouters
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async generateRoutes(): Promise<unknown> {
|
||||
return new Promise<void>(async (resolve) => {
|
||||
// 获得菜单列表,它在登录的时候,setUserInfoAction 方法中已经进行获取
|
||||
let res: AppCustomRouteRecordRaw[] = []
|
||||
const roleRouters = wsCache.get(CACHE_KEY.ROLE_ROUTERS)
|
||||
if (roleRouters) {
|
||||
res = roleRouters as AppCustomRouteRecordRaw[]
|
||||
}
|
||||
const routerMap: AppRouteRecordRaw[] = generateRoute(res)
|
||||
// 动态路由,404一定要放到最后面
|
||||
// preschooler:vue-router@4以后已支持静态404路由,此处可不再追加
|
||||
this.addRouters = routerMap.concat([
|
||||
{
|
||||
path: '/:path(.*)*',
|
||||
// redirect: '/404',
|
||||
component: () => import('@/views/Error/404.vue'),
|
||||
name: '404Page',
|
||||
meta: {
|
||||
hidden: true,
|
||||
breadcrumb: false
|
||||
}
|
||||
}
|
||||
])
|
||||
// 渲染菜单的所有路由
|
||||
this.routers = cloneDeep(remainingRouter).concat(routerMap)
|
||||
resolve()
|
||||
})
|
||||
},
|
||||
setMenuTabRouters(routers: AppRouteRecordRaw[]): void {
|
||||
this.menuTabRouters = routers
|
||||
}
|
||||
},
|
||||
persist: false
|
||||
})
|
||||
|
||||
export const usePermissionStoreWithOut = () => {
|
||||
return usePermissionStore(store)
|
||||
}
|
||||
177
src/store/modules/tagsView.ts
Normal file
177
src/store/modules/tagsView.ts
Normal file
@@ -0,0 +1,177 @@
|
||||
import router from '@/router'
|
||||
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
||||
import { getRawRoute } from '@/utils/routerHelper'
|
||||
import { defineStore } from 'pinia'
|
||||
import { store } from '../index'
|
||||
import { findIndex } from '@/utils'
|
||||
import { useUserStoreWithOut } from './user'
|
||||
|
||||
export interface TagsViewState {
|
||||
visitedViews: RouteLocationNormalizedLoaded[]
|
||||
cachedViews: Set<string>
|
||||
selectedTag?: RouteLocationNormalizedLoaded
|
||||
}
|
||||
|
||||
export const useTagsViewStore = defineStore('tagsView', {
|
||||
state: (): TagsViewState => ({
|
||||
visitedViews: [],
|
||||
cachedViews: new Set(),
|
||||
selectedTag: undefined
|
||||
}),
|
||||
getters: {
|
||||
getVisitedViews(): RouteLocationNormalizedLoaded[] {
|
||||
return this.visitedViews
|
||||
},
|
||||
getCachedViews(): string[] {
|
||||
return Array.from(this.cachedViews)
|
||||
},
|
||||
getSelectedTag(): RouteLocationNormalizedLoaded | undefined {
|
||||
return this.selectedTag
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
// 新增缓存和tag
|
||||
addView(view: RouteLocationNormalizedLoaded): void {
|
||||
this.addVisitedView(view)
|
||||
this.addCachedView()
|
||||
},
|
||||
// 新增tag
|
||||
addVisitedView(view: RouteLocationNormalizedLoaded) {
|
||||
if (this.visitedViews.some((v) => v.fullPath === view.fullPath)) return
|
||||
if (view.meta?.noTagsView) return
|
||||
const visitedView = Object.assign({}, view, { title: view.meta?.title || 'no-name' })
|
||||
|
||||
if (visitedView.meta) {
|
||||
const titleSuffixList: string[] = []
|
||||
this.visitedViews.forEach((v) => {
|
||||
if (v.path === visitedView.path && v.meta?.title === visitedView.meta?.title) {
|
||||
titleSuffixList.push(v.meta?.titleSuffix || '1')
|
||||
}
|
||||
})
|
||||
if (titleSuffixList.length) {
|
||||
let titleSuffix = 1
|
||||
while (titleSuffixList.includes(`${titleSuffix}`)) {
|
||||
titleSuffix += 1
|
||||
}
|
||||
visitedView.meta.titleSuffix = titleSuffix === 1 ? undefined : `${titleSuffix}`
|
||||
}
|
||||
}
|
||||
|
||||
this.visitedViews.push(visitedView)
|
||||
},
|
||||
// 新增缓存
|
||||
addCachedView() {
|
||||
const cacheMap: Set<string> = new Set()
|
||||
for (const v of this.visitedViews) {
|
||||
const item = getRawRoute(v)
|
||||
const needCache = !item.meta?.noCache
|
||||
if (!needCache) {
|
||||
continue
|
||||
}
|
||||
const name = item.name as string
|
||||
cacheMap.add(name)
|
||||
}
|
||||
if (Array.from(this.cachedViews).sort().toString() === Array.from(cacheMap).sort().toString())
|
||||
return
|
||||
this.cachedViews = cacheMap
|
||||
},
|
||||
// 删除某个
|
||||
delView(view: RouteLocationNormalizedLoaded) {
|
||||
this.delVisitedView(view)
|
||||
this.delCachedView()
|
||||
},
|
||||
// 删除tag
|
||||
delVisitedView(view: RouteLocationNormalizedLoaded) {
|
||||
for (const [i, v] of this.visitedViews.entries()) {
|
||||
if (v.fullPath === view.fullPath) {
|
||||
this.visitedViews.splice(i, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
// 删除缓存
|
||||
delCachedView() {
|
||||
const route = router.currentRoute.value
|
||||
const index = findIndex<string>(this.getCachedViews, (v) => v === route.name)
|
||||
if (index > -1) {
|
||||
this.cachedViews.delete(this.getCachedViews[index])
|
||||
}
|
||||
},
|
||||
// 删除所有缓存和tag
|
||||
delAllViews() {
|
||||
this.delAllVisitedViews()
|
||||
this.delCachedView()
|
||||
},
|
||||
// 删除所有tag
|
||||
delAllVisitedViews() {
|
||||
const userStore = useUserStoreWithOut()
|
||||
|
||||
// const affixTags = this.visitedViews.filter((tag) => tag.meta.affix)
|
||||
this.visitedViews = userStore.getUser
|
||||
? this.visitedViews.filter((tag) => tag?.meta?.affix)
|
||||
: []
|
||||
},
|
||||
// 删除其他
|
||||
delOthersViews(view: RouteLocationNormalizedLoaded) {
|
||||
this.delOthersVisitedViews(view)
|
||||
this.addCachedView()
|
||||
},
|
||||
// 删除其他tag
|
||||
delOthersVisitedViews(view: RouteLocationNormalizedLoaded) {
|
||||
this.visitedViews = this.visitedViews.filter((v) => {
|
||||
return v?.meta?.affix || v.fullPath === view.fullPath
|
||||
})
|
||||
},
|
||||
// 删除左侧
|
||||
delLeftViews(view: RouteLocationNormalizedLoaded) {
|
||||
const index = findIndex<RouteLocationNormalizedLoaded>(
|
||||
this.visitedViews,
|
||||
(v) => v.fullPath === view.fullPath
|
||||
)
|
||||
if (index > -1) {
|
||||
this.visitedViews = this.visitedViews.filter((v, i) => {
|
||||
return v?.meta?.affix || v.fullPath === view.fullPath || i > index
|
||||
})
|
||||
this.addCachedView()
|
||||
}
|
||||
},
|
||||
// 删除右侧
|
||||
delRightViews(view: RouteLocationNormalizedLoaded) {
|
||||
const index = findIndex<RouteLocationNormalizedLoaded>(
|
||||
this.visitedViews,
|
||||
(v) => v.fullPath === view.fullPath
|
||||
)
|
||||
if (index > -1) {
|
||||
this.visitedViews = this.visitedViews.filter((v, i) => {
|
||||
return v?.meta?.affix || v.fullPath === view.fullPath || i < index
|
||||
})
|
||||
this.addCachedView()
|
||||
}
|
||||
},
|
||||
updateVisitedView(view: RouteLocationNormalizedLoaded) {
|
||||
for (let v of this.visitedViews) {
|
||||
if (v.fullPath === view.fullPath) {
|
||||
v = Object.assign(v, view)
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
// 设置当前选中的 tag
|
||||
setSelectedTag(tag: RouteLocationNormalizedLoaded) {
|
||||
this.selectedTag = tag
|
||||
},
|
||||
setTitle(title: string, path?: string) {
|
||||
for (const v of this.visitedViews) {
|
||||
if (v.path === (path ?? this.selectedTag?.path)) {
|
||||
v.meta.title = title
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
persist: false
|
||||
})
|
||||
|
||||
export const useTagsViewStoreWithOut = () => {
|
||||
return useTagsViewStore(store)
|
||||
}
|
||||
108
src/store/modules/user.ts
Normal file
108
src/store/modules/user.ts
Normal file
@@ -0,0 +1,108 @@
|
||||
import { store } from '@/store'
|
||||
import { defineStore } from 'pinia'
|
||||
import { getAccessToken, removeToken } from '@/utils/auth'
|
||||
import { CACHE_KEY, useCache, deleteUserCache } from '@/hooks/web/useCache'
|
||||
import { getInfo, loginOut } from '@/api/login'
|
||||
|
||||
const { wsCache } = useCache()
|
||||
|
||||
interface UserVO {
|
||||
id: number
|
||||
avatar: string
|
||||
nickname: string
|
||||
deptId: number
|
||||
}
|
||||
|
||||
interface UserInfoVO {
|
||||
// USER 缓存
|
||||
permissions: Set<string>
|
||||
roles: string[]
|
||||
isSetUser: boolean
|
||||
user: UserVO
|
||||
}
|
||||
|
||||
export const useUserStore = defineStore('admin-user', {
|
||||
state: (): UserInfoVO => ({
|
||||
permissions: new Set<string>(),
|
||||
roles: [],
|
||||
isSetUser: false,
|
||||
user: {
|
||||
id: 0,
|
||||
avatar: '',
|
||||
nickname: '',
|
||||
deptId: 0
|
||||
}
|
||||
}),
|
||||
getters: {
|
||||
getPermissions(): Set<string> {
|
||||
return this.permissions
|
||||
},
|
||||
getRoles(): string[] {
|
||||
return this.roles
|
||||
},
|
||||
getIsSetUser(): boolean {
|
||||
return this.isSetUser
|
||||
},
|
||||
getUser(): UserVO {
|
||||
return this.user
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async setUserInfoAction() {
|
||||
if (!getAccessToken()) {
|
||||
this.resetState()
|
||||
return null
|
||||
}
|
||||
let userInfo = wsCache.get(CACHE_KEY.USER)
|
||||
if (!userInfo) {
|
||||
userInfo = await getInfo()
|
||||
} else {
|
||||
// 特殊:在有缓存的情况下,进行加载。但是即使加载失败,也不影响后续的操作,保证可以进入系统
|
||||
try {
|
||||
userInfo = await getInfo()
|
||||
} catch (error) {}
|
||||
}
|
||||
this.permissions = new Set(userInfo.permissions)
|
||||
this.roles = userInfo.roles
|
||||
this.user = userInfo.user
|
||||
this.isSetUser = true
|
||||
wsCache.set(CACHE_KEY.USER, userInfo)
|
||||
wsCache.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus)
|
||||
},
|
||||
async setUserAvatarAction(avatar: string) {
|
||||
const userInfo = wsCache.get(CACHE_KEY.USER)
|
||||
// NOTE: 是否需要像`setUserInfoAction`一样判断`userInfo != null`
|
||||
this.user.avatar = avatar
|
||||
userInfo.user.avatar = avatar
|
||||
wsCache.set(CACHE_KEY.USER, userInfo)
|
||||
},
|
||||
async setUserNicknameAction(nickname: string) {
|
||||
const userInfo = wsCache.get(CACHE_KEY.USER)
|
||||
// NOTE: 是否需要像`setUserInfoAction`一样判断`userInfo != null`
|
||||
this.user.nickname = nickname
|
||||
userInfo.user.nickname = nickname
|
||||
wsCache.set(CACHE_KEY.USER, userInfo)
|
||||
},
|
||||
async loginOut() {
|
||||
await loginOut()
|
||||
removeToken()
|
||||
deleteUserCache() // 删除用户缓存
|
||||
this.resetState()
|
||||
},
|
||||
resetState() {
|
||||
this.permissions = new Set<string>()
|
||||
this.roles = []
|
||||
this.isSetUser = false
|
||||
this.user = {
|
||||
id: 0,
|
||||
avatar: '',
|
||||
nickname: '',
|
||||
deptId: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export const useUserStoreWithOut = () => {
|
||||
return useUserStore(store)
|
||||
}
|
||||
Reference in New Issue
Block a user