73 lines
1.7 KiB
TypeScript
Raw Normal View History

import zhCN from 'element-plus/es/locale/lang/zh-cn';
import enUS from 'element-plus/es/locale/lang/en';
2023-04-02 01:01:56 +08:00
export const useAppStore = defineStore('app', () => {
const sidebarStatus = useStorage('sidebarStatus', '1');
2023-04-03 00:05:09 +08:00
const sidebar = reactive({
opened: sidebarStatus.value ? !!+sidebarStatus.value : true,
2023-04-03 00:05:09 +08:00
withoutAnimation: false,
hide: false
});
const device = ref<string>('desktop');
const size = useStorage<'large' | 'default' | 'small'>('size', 'default');
2023-04-03 00:05:09 +08:00
// 语言
const language = useStorage('language', 'zh_CN');
const languageObj: any = {
en_US: enUS,
zh_CN: zhCN
};
2023-04-03 00:05:09 +08:00
const locale = computed(() => {
return languageObj[language.value];
2023-04-03 00:05:09 +08:00
});
2023-04-02 01:01:56 +08:00
const toggleSideBar = (withoutAnimation: boolean) => {
2023-04-03 00:05:09 +08:00
if (sidebar.hide) {
return false;
}
2023-04-02 01:01:56 +08:00
2023-04-03 00:05:09 +08:00
sidebar.opened = !sidebar.opened;
sidebar.withoutAnimation = withoutAnimation;
2023-04-03 00:05:09 +08:00
if (sidebar.opened) {
sidebarStatus.value = '1';
2023-04-03 00:05:09 +08:00
} else {
sidebarStatus.value = '0';
2023-04-03 00:05:09 +08:00
}
};
2023-04-02 01:01:56 +08:00
2023-04-03 00:05:09 +08:00
const closeSideBar = ({ withoutAnimation }: any): void => {
sidebarStatus.value = '0';
2023-04-03 00:05:09 +08:00
sidebar.opened = false;
sidebar.withoutAnimation = withoutAnimation;
};
const toggleDevice = (d: string): void => {
device.value = d;
};
const setSize = (s: 'large' | 'default' | 'small'): void => {
2023-04-03 00:05:09 +08:00
size.value = s;
};
const toggleSideBarHide = (status: boolean): void => {
sidebar.hide = status;
};
2023-04-02 01:01:56 +08:00
2023-04-03 00:05:09 +08:00
const changeLanguage = (val: string): void => {
language.value = val;
};
2023-04-02 01:01:56 +08:00
2023-04-03 00:05:09 +08:00
return {
device,
sidebar,
language,
locale,
size,
changeLanguage,
toggleSideBar,
closeSideBar,
toggleDevice,
setSize,
toggleSideBarHide
};
2023-04-02 01:01:56 +08:00
});
export default useAppStore;