登录相关mock

This commit is contained in:
xuziqiang
2024-05-20 16:42:40 +08:00
parent 7cb6d585b4
commit e6c8c78308
4 changed files with 4428 additions and 80 deletions

View File

@@ -1,5 +1,7 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { http } from '/nerv-lib/saas'; import { http } from '/nerv-lib/saas';
import { useApi, HttpRequestConfig } from '/nerv-lib/use/use-api';
interface AppConfig { interface AppConfig {
projectType: string; projectType: string;
baseApi: string; baseApi: string;
@@ -36,6 +38,10 @@ interface resourceInfoModul {
api: string; api: string;
dealReosurceList?: Function; dealReosurceList?: Function;
} }
const { httpRequest } = useApi();
const requestConfig: HttpRequestConfig = { method: 'POST' };
export const appConfigStore = defineStore({ export const appConfigStore = defineStore({
id: 'appConfig', id: 'appConfig',
state(): AppConfig { state(): AppConfig {
@@ -102,32 +108,39 @@ export const appConfigStore = defineStore({
}, },
userLogin(data: loginData) { userLogin(data: loginData) {
if (this.userLoginApi) { if (this.userLoginApi) {
return http.post(this.userLoginApi, data, { return httpRequest({ api: this.userLoginApi, params: data, pathParams: {}, requestConfig });
transformRequest: [
(mode, headers) => { // return http.post(this.userLoginApi, data, {
if (headers.qsToken) { // transformRequest: [
delete headers.qsToken; // (mode, headers) => {
} // if (headers.qsToken) {
return JSON.stringify(mode); // delete headers.qsToken;
}, // }
], // return JSON.stringify(mode);
}); // },
// ],
// });
} else { } else {
return null; return null;
} }
}, },
userInfo() { userInfo() {
if (this.userInfoApi) { if (this.userInfoApi) {
return http.get(this.userInfoApi); return httpRequest({ api: this.userInfoApi, params: {}, pathParams: {}, requestConfig });
} else { } else {
return null; return { data: {} };
} }
}, },
userResource() { userResource() {
if (this.userResourceApi) { if (this.userResourceApi) {
return http.get(this.userResourceApi); return httpRequest({
api: this.userResourceApi,
params: {},
pathParams: {},
requestConfig,
});
} else { } else {
return null; return { data: [] };
} }
}, },
}, },

View File

@@ -86,67 +86,67 @@
if (userName.value !== '' && password.value !== '') { if (userName.value !== '' && password.value !== '') {
errorShow.value = false; errorShow.value = false;
let data = JSON.stringify({ userName: userName.value, password: password.value }); let data = JSON.stringify({ userName: userName.value, password: password.value });
Cookies.set('nervsid', 'mockdata'); // Cookies.set('nervsid', 'mockdata');
router.replace({ name: 'root' });
// loading.value = true;
// async function logins() {
// try {
// const res = await configStore.userLogin(JSON.parse(data));
// if (res.success) {
// if (res.data?.userToken) {
// Cookies.set('nervsid', res.data?.userToken);
// }
// const info = await configStore.userInfo();
// info.success
// ? window.sessionStorage.setItem('userInfo', JSON.stringify(info.data))
// : '';
// loading.value = false;
// if (configStore.enablePermissions) {
// const res = await configStore.userResource();
// if (configStore.customApplication) {
// await useAuthorization.initMenuResource();
// }
// initUrl.value = '';
// const dealInitUrl = (item) => {
// if (item.type === 'menus' && item.menus && item.menus?.length !== 0) {
// dealInitUrl(item.menus[0]);
// } else {
// // if (item.type === 'noChildrenMenu') {
// initUrl.value = configStore.resourceName
// ? item.code.replace(configStore.resourceName, '')
// : item.code;
// // }
// }
// };
// if (configStore.resourceName) {
// const initResource = [];
// res.data.forEach((item) => {
// if (item.code.includes(configStore.resourceName)) {
// initResource.push(item);
// }
// });
// dealInitUrl(initResource[0]);
// } else {
// dealInitUrl(res.data[0]);
// }
// // dealInitUrl(res.data[0]);
// useAuthorization.updateUserResource(res.data);
// const initRouterList = useAuthorization.getInitRouterList;
// router.push({
// name: initRouterList.length === 0 ? 'error403' : initUrl.value,
// });
// } else {
// router.replace({ name: 'root' }); // router.replace({ name: 'root' });
loading.value = true;
async function logins() {
try {
const res = await configStore.userLogin(JSON.parse(data));
if (res.success) {
if (res.data?.userToken) {
Cookies.set('nervsid', res.data?.userToken);
}
const info = await configStore.userInfo();
info.success
? window.sessionStorage.setItem('userInfo', JSON.stringify(info.data))
: '';
loading.value = false;
if (configStore.enablePermissions) {
const res = await configStore.userResource();
if (configStore.customApplication) {
await useAuthorization.initMenuResource();
}
initUrl.value = '';
const dealInitUrl = (item) => {
if (item.type === 'menus' && item.menus && item.menus?.length !== 0) {
dealInitUrl(item.menus[0]);
} else {
// if (item.type === 'noChildrenMenu') {
initUrl.value = configStore.resourceName
? item.code.replace(configStore.resourceName, '')
: item.code;
// } // }
// } }
// } catch (err) { };
// loading.value = false; if (configStore.resourceName) {
// } const initResource = [];
// } res.data.forEach((item) => {
// logins(); if (item.code.includes(configStore.resourceName)) {
initResource.push(item);
}
});
dealInitUrl(initResource[0]);
} else {
dealInitUrl(res.data[0]);
}
// dealInitUrl(res.data[0]);
useAuthorization.updateUserResource(res.data);
const initRouterList = useAuthorization.getInitRouterList;
router.push({
name: initRouterList.length === 0 ? 'error403' : initUrl.value,
});
} else {
router.replace({ name: 'root' });
}
}
} catch (err) {
loading.value = false;
}
}
logins();
} }
}; };
const checkoutLogo = (): void => { const checkoutLogo = (): void => {

View File

@@ -1,22 +1,48 @@
/** @format */ /** @format */
import { dateUtil } from '/nerv-lib/util/date-util'; import { dateUtil } from '/nerv-lib/util/date-util';
import mockResource from './resource.json';
console.log(mockResource.menus);
export const appConfig = { export const appConfig = {
projectType: 'web', projectType: 'web',
baseApi: '/api', baseApi: '/api',
enablePermissions: false, enablePermissions: true,
// siderPosition: 'left', // siderPosition: 'left',
baseHeader: '/parkingManage', baseHeader: '/parkingManage',
baseRouter: '/parkingManage/parkingLotManage', baseRouter: '/parkingManage/parkingLotManage',
userCustomRouterGuard: (to, from, next, whiteNameList, authorizationStore, appConfig) => { // userCustomRouterGuard: (to, from, next, whiteNameList, authorizationStore, appConfig) => {
console.log({ to, from, next, whiteNameList, authorizationStore, appConfig }, 'routeConfig'); // console.log({ to, from, next, whiteNameList, authorizationStore, appConfig }, 'routeConfig');
next(); // next();
}, // },
customUpdatePwd: () => import('/@/view/updatePassword/updatePassword.vue'), customUpdatePwd: () => import('/@/view/updatePassword/updatePassword.vue'),
timeout: 60 * 1000, timeout: 60 * 1000,
userLoginApi: 'api/web/objs/Login', userLoginApi: () => {
// userResourceApi: '/api/web/objs/User/Resource', return {
// userInfoApi: 'api/web/objs/CurrentUser', code: 200,
success: true,
data: { userToken: 123123123 },
};
},
userResourceApi: () => {
return { data: mockResource.menus };
},
userInfoApi: () => {
return {
code: 200,
success: true,
data: {
accountCode: '1305107806187376793',
accountName: 'adm*n',
accountType: 'admin',
accountStatus: 1,
accountRealName: 'admin',
organizationCode: 'dingcloud',
authConfigList: [],
organizeResCode: [],
leadDepartmentUuidList: [],
},
};
},
useHistoryTag: false, useHistoryTag: false,
// 修改密码配置 // 修改密码配置
updatePassWordInfo: { updatePassWordInfo: {

File diff suppressed because it is too large Load Diff