ai_images/portal-ui/src/store/modules/main.js

272 lines
5.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Cookies from 'js-cookie'
import {
getDimension,
setDimension
} from '../../utils/auth'
import $storage from 'good-storage'
import {
switchPoint,
getUnreadMessageCount
} from '../../api/user.js'
import {
isMobile
} from '../../utils/base.js'
const state = {
sidebar: {
opened: isMobile() ? false : true,
withoutAnimation: false,
// 左侧导航默认适中宽度(用户若需更窄/宽可本地调小范围会写 cookie
width: Cookies.get('sidebarWidth') || '268px'
},
topMenu: Cookies.get('topMenu'),
// 当前语言
// 多语言切换已禁用全站固定繁体中文zh_HK
language: 'zh_HK',
// 主题 '':亮色 / dark:暗黑
theme: $storage.get('theme') || '',
// 系统端
system: $storage.get('system') || '',
// 当前系统的所有多语言数据
i18nMessages: {},
// 组件全局尺寸
dimension: getDimension(),
// 字体尺寸
size: Cookies.get('size') || 'medium',
reloginVisible: false,
// 面包屑
breadcrumbList: [],
// 菜单打开项
openedKeys: [],
showMessage: false,
messageData: {},
messageCount: 0,
// 是否显示18禁弹窗默认不拦截直接进入首页等主页面
showForbidden: false,
// 阻止页面切换
showPrevent: false,
showLogin: false
}
const mutations = {
// 切换菜单显示隐藏
TOGGLE_SIDEBAR: (state) => {
state.sidebar.opened = !state.sidebar.opened
state.sidebar.withoutAnimation = false
if (state.sidebar.opened) {
Cookies.set('sidebarStatus', 1)
} else {
Cookies.set('sidebarStatus', 0)
}
},
CLOSE_SIDEBAR: (state) => {
Cookies.set('sidebarStatus', 0)
state.sidebar.opened = false
},
// 设置一级菜单值
SET_TOP_MENU: (state, value) => {
Cookies.set('topMenu', value)
state.topMenu = value
},
// 设置菜单宽度
SET_SIDEBAR_WIDTH: (state, width) => {
state.sidebar.width = width
Cookies.set('sidebarWidth', width)
},
SET_LANGUAGE: (state, language) => {
state.language = language
Cookies.set('language', language)
},
SET_SIZE: (state, size) => {
state.size = size
Cookies.set('size', size)
},
SET_DIMENSION: (state, value) => {
state.dimension = value
setDimension(value)
},
SET_I18N_MESSAGES: (state, value) => {
state.i18nMessages = value
},
SET_BREADCRUMB: (state, value) => {
state.breadcrumbList = value
},
SET_BREADCRUMB_NAME: (state, value) => {
if (!Array.isArray(value)) return
value.map((i) => {
state.breadcrumbList
.filter((bread) => bread?.meta?.title === i.currTitle)
.map((bread) => {
bread.meta.title = i.newTitle
bread.meta.i18n = false
if (i.redirect) bread.redirect = i.redirect
})
})
},
// 设置主题
SET_THEME(state, value) {
state.theme = value
$storage.set('theme', value)
},
// 设置系统端
SET_SYSTEM(state, value) {
state.system = value
$storage.set('system', value)
},
SET_OPENED_KEYS(state, value) {
state.openedKeys = value;
},
SHOW_MESSAGE(state, {
show,
source,
id,
orderid
}) {
state.showMessage = show;
state.messageData = {
source,
id,
orderid
}
},
SET_UNREAD_MESSAGE(state, value) {
state.messageCount = value;
},
SET_FORBIDDEN(state, value) {
state.showForbidden = value;
$storage.set('showForbidden', value)
},
SET_PREVENT(state, value) {
state.showPrevent = value;
},
SET_SHOW_LOGIN(state, value) {
state.showLogin = value;
}
}
const actions = {
setPrevent({
commit
}, value) {
commit('SET_PREVENT', value);
},
setShowLogin({
commit
}, value) {
commit('SET_SHOW_LOGIN', value);
},
toggleSideBar({
commit
}) {
commit('TOGGLE_SIDEBAR')
},
closeSideBar({
commit
}) {
commit('CLOSE_SIDEBAR')
},
setTopMenu({
commit
}, value) {
commit('SET_TOP_MENU', value)
},
setLanguage({
commit
}, language) {
commit('SET_LANGUAGE', language)
},
setSize({
commit
}, size) {
commit('SET_SIZE', size)
},
setDimension({
commit
}, value) {
commit('SET_DIMENSION', value)
},
setI18nMessages({
commit
}, messages) {
commit('SET_I18N_MESSAGES', messages)
},
// 设置面包屑
setBreadcrumb({
commit
}, value) {
commit('SET_BREADCRUMB', value)
},
// 设置面包屑名称
setBreadcrumbName({
commit
}, value) {
commit('SET_BREADCRUMB_NAME', value)
},
// 设置主题
setTheme({
commit
}, value) {
commit('SET_THEME', value)
},
// 设置当前系统端
setSystem({
commit
}, value) {
commit('SET_SYSTEM', value)
},
// 设置菜单展开项
setOpenedKeys({
commit
}, value) {
commit('SET_OPENED_KEYS', value)
},
// 显示消息提示
showMessage({
commit,
dispatch
}, value) {
return new Promise((resolve, reject) => {
let {
mid
} = value;
if (mid) {
dispatch('main/switchSystem', 'service', {
root: true
}).then((_) => {
dispatch('user/swichUser', mid, {
root: true
}).then((_) => {
commit('SHOW_MESSAGE', value)
resolve()
})
})
} else {
commit('SHOW_MESSAGE', value)
resolve()
}
})
},
// 读取未读消息数量
getUnreadMessage({
commit
}) {
getUnreadMessageCount().then(res => {
commit('SET_UNREAD_MESSAGE', parseInt(res))
})
},
// 设置是否显示18禁弹窗
setForbidden({
commit
}, value) {
commit('SET_FORBIDDEN', value)
},
}
export default {
namespaced: true,
state,
mutations,
actions
}