提交 efb12ebe 编写于 作者: zcdtk's avatar zcdtk

对象处理

上级 220f81ae
...@@ -62,40 +62,35 @@ export class AuthGuard { ...@@ -62,40 +62,35 @@ export class AuthGuard {
} }
/** /**
* post请求 * 权限认证
* *
* @param {string} url * @param {string} url
* @param {*} [params={}] * @param {*} [params={}]
* @param {Store<any>} store * @param {Store<any>} store
* @returns {Promise<boolean>} * @returns {Promise<any>}
* @memberof AuthGuard * @memberof AuthGuard
*/ */
public async authGuard(url: string, params: any = {}, store: Store<any>): Promise<any> { public async authGuard(url: string, params: any = {}, store: Store<any>): Promise<any> {
this.loadDictionaryDatas(store); const response: any = await Http.getInstance().get(url);
try{ if (response && response.status === 200) {
let response = await Http.getInstance().get(url); let { data }: { data: any } = response;
if (response && response.status === 200) { if (data) {
let { data }: { data: any } = response; // token认证把用户信息放入应用级数据
if (data) { if (localStorage.getItem('user')) {
// token认证把用户信息放入应用级数据 let user: any = JSON.parse(localStorage.getItem('user') as string);
if(localStorage.getItem('user')){ let localAppData: any = {};
let user:any = JSON.parse(localStorage.getItem('user') as string); if (user.sessionParams) {
let localAppData:any = {}; localAppData = { context: user.sessionParams };
if(user.sessionParams){ Object.assign(localAppData, data);
localAppData = {context:user.sessionParams};
Object.assign(localAppData,data);
}
data = JSON.parse(JSON.stringify(localAppData));
} }
store.commit('addAppData', data); data = JSON.parse(JSON.stringify(localAppData));
// 提交统一资源数据
store.dispatch('authresource/commitAuthData', data);
} }
return true; store.commit('addAppData', data);
// 提交统一资源数据
store.dispatch('authresource/commitAuthData', data);
} }
}catch (error) {
console.error("获取应用数据出现异常");
} }
return await this.loadDictionaryDatas(store);
} }
/** /**
...@@ -115,7 +110,7 @@ export class AuthGuard { ...@@ -115,7 +110,7 @@ export class AuthGuard {
if (response && response.status === 200 && response.data && Array.isArray(response.data)) { if (response && response.status === 200 && response.data && Array.isArray(response.data)) {
const datas: any[] = [...response.data]; const datas: any[] = [...response.data];
datas.forEach((item: any) => { datas.forEach((item: any) => {
if (!item.items) { if (item && !item.items) {
item.items = []; item.items = [];
} }
}); });
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册