You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.4 KiB

4 months ago
import { defineStore } from 'pinia';
import { http } from '/nerv-lib/saas';
interface AppConfig {
projectType: string;
baseApi: string;
timeout: number;
pagePermission: boolean;
actionPermission: boolean;
showProject: boolean;
resourceName: string;
useHistoryTag: boolean;
siderPosition: string; //菜单位置
userLoginApi: string; //登录接口
userCustomRouterGuard?: Function; //使用自己的路由守卫
userResourceApi: string; //获取资源接口
userInfoApi: string; //登录详情接口
enablePermissions: boolean; //是否开启权限
updatePassWordInfo?: object; //修改密码配置
headerBellInfo?: object;
customInitMessageCount?: Function; // 自定义消息数量获取事件
iframe?: false;
dropOut?: Function; //退出登录
defaultResource?: object; //默认权限
resourceInfo?: resourceInfoModul; //权限提交配置
strategyInfoApi?: string; // 获取系统密码策略
themeConfig?: object;
initThemeCoinfig?: boolean;
}
interface loginData {
userName: string;
password: string;
}
interface resourceInfoModul {
application: object;
token: string;
api: string;
dealReosurceList?: Function;
}
export const appConfigStore = defineStore({
id: 'appConfig',
state(): AppConfig {
return {
projectType: 'web',
baseApi: '/api',
timeout: 15 * 1000,
pagePermission: true,
actionPermission: true,
userLoginApi: '',
siderPosition: 'top',
userResourceApi: '',
userInfoApi: '',
resourceName: '',
showProject: false,
useHistoryTag: false,
enablePermissions: false,
updatePassWordInfo: {},
dropOut: undefined,
iframe: false,
userCustomRouterGuard: undefined,
defaultResource: undefined,
headerBellInfo: {
isShow: false,
api: '',
toRouterName: '',
},
themeConfig: {},
initThemeCoinfig: false,
resourceInfo: {
application: {},
api: '',
token: '',
},
};
},
getters: {
getThemeConfig: (state: any) => state.themeConfig,
getHeaderBellInfo: (state: any) => state.headerBellInfo,
getInitThemeCoinfig: (state: any) => state.initThemeCoinfig,
},
actions: {
setInitThemeCoinfig(val: boolean) {
this.initThemeCoinfig = val;
},
setUserInfo(val: any) {
this.userBasicInfo = val;
},
setThemeConfig(val: any) {
this.themeConfig = val;
},
setConfig(config: AppConfig) {
Object.keys(config).forEach((key) => {
this[key] = config[key];
});
},
initDefaultResource(data: any) {
this.defaultResource = data;
},
setParams(config: Object) {
Object.keys(config).forEach((key) => {
this[key] = config[key];
});
},
userLogin(data: loginData) {
if (this.userLoginApi) {
return http.post(this.userLoginApi, data, {
transformRequest: [
(mode, headers) => {
if (headers.qsToken) {
delete headers.qsToken;
}
return JSON.stringify(mode);
},
],
});
} else {
return null;
}
},
userInfo() {
if (this.userInfoApi) {
return http.get(this.userInfoApi);
} else {
return null;
}
},
userResource() {
if (this.userResourceApi) {
return http.get(this.userResourceApi);
} else {
return null;
}
},
},
});