登录相关mock
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { http } from '/nerv-lib/saas';
|
||||
import { useApi, HttpRequestConfig } from '/nerv-lib/use/use-api';
|
||||
|
||||
interface AppConfig {
|
||||
projectType: string;
|
||||
baseApi: string;
|
||||
@@ -36,6 +38,10 @@ interface resourceInfoModul {
|
||||
api: string;
|
||||
dealReosurceList?: Function;
|
||||
}
|
||||
|
||||
const { httpRequest } = useApi();
|
||||
const requestConfig: HttpRequestConfig = { method: 'POST' };
|
||||
|
||||
export const appConfigStore = defineStore({
|
||||
id: 'appConfig',
|
||||
state(): AppConfig {
|
||||
@@ -102,32 +108,39 @@ export const appConfigStore = defineStore({
|
||||
},
|
||||
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);
|
||||
},
|
||||
],
|
||||
});
|
||||
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);
|
||||
// },
|
||||
// ],
|
||||
// });
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
userInfo() {
|
||||
if (this.userInfoApi) {
|
||||
return http.get(this.userInfoApi);
|
||||
return httpRequest({ api: this.userInfoApi, params: {}, pathParams: {}, requestConfig });
|
||||
} else {
|
||||
return null;
|
||||
return { data: {} };
|
||||
}
|
||||
},
|
||||
userResource() {
|
||||
if (this.userResourceApi) {
|
||||
return http.get(this.userResourceApi);
|
||||
return httpRequest({
|
||||
api: this.userResourceApi,
|
||||
params: {},
|
||||
pathParams: {},
|
||||
requestConfig,
|
||||
});
|
||||
} else {
|
||||
return null;
|
||||
return { data: [] };
|
||||
}
|
||||
},
|
||||
},
|
||||
|
@@ -86,67 +86,67 @@
|
||||
if (userName.value !== '' && password.value !== '') {
|
||||
errorShow.value = false;
|
||||
let data = JSON.stringify({ userName: userName.value, password: password.value });
|
||||
Cookies.set('nervsid', 'mockdata');
|
||||
router.replace({ name: 'root' });
|
||||
// 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();
|
||||
// }
|
||||
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;
|
||||
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' });
|
||||
// }
|
||||
// }
|
||||
// } catch (err) {
|
||||
// loading.value = false;
|
||||
// }
|
||||
// }
|
||||
// logins();
|
||||
router.push({
|
||||
name: initRouterList.length === 0 ? 'error403' : initUrl.value,
|
||||
});
|
||||
} else {
|
||||
router.replace({ name: 'root' });
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
logins();
|
||||
}
|
||||
};
|
||||
const checkoutLogo = (): void => {
|
||||
|
Reference in New Issue
Block a user