| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import { updatePreferences } from '@vben/preferences';
- import { acceptHMRUpdate, defineStore } from 'pinia';
- import { ConfigApi } from '#/api';
- interface AccessState {
- /**
- * 配置信息
- */
- appInfo: ConfigApi.AppInfo | null;
- exitUrl: string;
- }
- /**
- * @zh_CN 配置信息相关
- */
- export const useAppStore = defineStore('web-info', {
- actions: {
- setAppInfo(appInfo: ConfigApi.AppInfo | null) {
- this.appInfo = appInfo;
- updatePreferences({
- app: {
- watermark: appInfo?.openWatermark,
- name: appInfo?.webTitle,
- layout: 'header-nav',
- },
- tabbar: {
- enable: false,
- },
- theme: {
- builtinType: 'custom',
- colorPrimary: 'hsl(300 64% 31%)',
- mode: 'auto',
- },
- });
- },
- async loadAppInfo() {
- const appInfo = await ConfigApi.getWebInfo();
- this.setAppInfo(appInfo);
- return appInfo;
- },
- setExitUrl(url: string) {
- this.exitUrl = url;
- },
- getExitUrl() {
- return this.exitUrl;
- },
- },
- state: (): AccessState => ({
- appInfo: null,
- exitUrl: '',
- }),
- persist: {
- // 持久化
- pick: ['appInfo.webWatermark'],
- },
- });
- // 解决热更新问题
- const hot = import.meta.hot;
- if (hot) {
- hot.accept(acceptHMRUpdate(useAppStore, hot));
- }
|