92 lines
2.3 KiB
TypeScript
92 lines
2.3 KiB
TypeScript
import { NDM_SETTING_STORE_ID } from '@/constants';
|
|
import { darkTheme, lightTheme } from 'naive-ui';
|
|
import { defineStore } from 'pinia';
|
|
import { computed, ref, watch } from 'vue';
|
|
import { useUserStore } from './user';
|
|
import router from '@/router';
|
|
|
|
export const useSettingStore = defineStore(
|
|
NDM_SETTING_STORE_ID,
|
|
() => {
|
|
const darkThemeEnabled = ref(true);
|
|
const themeMode = computed(() => {
|
|
return darkThemeEnabled.value ? darkTheme : lightTheme;
|
|
});
|
|
|
|
const menuCollpased = ref(false);
|
|
|
|
const stationGridCols = ref(6);
|
|
|
|
const debugModeEnabled = ref(false);
|
|
const enableDebugMode = () => {
|
|
debugModeEnabled.value = true;
|
|
};
|
|
const disableDebugMode = () => {
|
|
debugModeEnabled.value = false;
|
|
};
|
|
|
|
// 离线开发模式
|
|
// 控制 版本轮询 stomp连接 app-layout中的自动getUserInfo
|
|
const offlineDev = ref(false);
|
|
watch(offlineDev, (newValue, oldValue) => {
|
|
// 如果启用离线开发模式且当前未登录 自动填写token以绕过路由守卫并跳过登录页
|
|
if (!oldValue && newValue) {
|
|
const userStore = useUserStore();
|
|
if (!userStore.userLoginResult) {
|
|
userStore.userLoginResult = {
|
|
tenantId: '',
|
|
uuid: '',
|
|
token: 'test',
|
|
refreshToken: '',
|
|
expire: '',
|
|
expiration: '',
|
|
};
|
|
}
|
|
if (!userStore.userLoginResult.token) {
|
|
userStore.userLoginResult.token = 'test';
|
|
}
|
|
if (!userStore.userInfo) {
|
|
userStore.userInfo = {
|
|
id: '2',
|
|
username: 'lamp',
|
|
nickName: '内置超管',
|
|
mobile: '15211111110',
|
|
employeeId: '2',
|
|
tenantId: '1',
|
|
};
|
|
}
|
|
if (router.currentRoute.value.path === '/login') {
|
|
router.push({ path: '/' });
|
|
}
|
|
}
|
|
});
|
|
|
|
return {
|
|
darkThemeEnabled,
|
|
themeMode,
|
|
|
|
menuCollpased,
|
|
|
|
stationGridCols,
|
|
|
|
debugModeEnabled,
|
|
enableDebugMode,
|
|
disableDebugMode,
|
|
|
|
offlineDev,
|
|
};
|
|
},
|
|
{
|
|
persist: [
|
|
{
|
|
omit: ['debugModeEnabled'],
|
|
storage: window.localStorage,
|
|
},
|
|
{
|
|
pick: ['debugModeEnabled'],
|
|
storage: window.sessionStorage,
|
|
},
|
|
],
|
|
},
|
|
);
|