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.

148 lines
3.9 KiB

7 months ago
import { defineStore } from 'pinia';
import { http } from '/nerv-lib/saas';
6 months ago
import { useApi, HttpRequestConfig } from '/nerv-lib/use/use-api';
7 months ago
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;
}
6 months ago
const { httpRequest } = useApi();
const requestConfig: HttpRequestConfig = { method: 'POST' };
7 months ago
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) {
6 months ago
return httpRequest({ api: this.userLoginApi, params: data, pathParams: {}, requestConfig });
// return http.post(this.userLoginApi, data, {
// transformRequest: [
// (mode, headers) => {
// if (headers.qsToken) {
// delete headers.qsToken;
// }
// return JSON.stringify(mode);
// },
// ],
// });
7 months ago
} else {
return null;
}
},
userInfo() {
if (this.userInfoApi) {
6 months ago
return httpRequest({ api: this.userInfoApi, params: {}, pathParams: {}, requestConfig });
7 months ago
} else {
6 months ago
return { data: {} };
7 months ago
}
},
userResource() {
if (this.userResourceApi) {
6 months ago
return httpRequest({
api: this.userResourceApi,
params: {},
pathParams: {},
requestConfig,
});
7 months ago
} else {
6 months ago
return { data: [] };
7 months ago
}
},
},
});