first commit
This commit is contained in:
69
滴滴淘/houtaiguanli/src/core/annotation/operationalComponent.ts
Normal file
69
滴滴淘/houtaiguanli/src/core/annotation/operationalComponent.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { dynamic, history } from 'umi';
|
||||
import { Component } from 'react';
|
||||
// import UeroModel from '@/models/user';
|
||||
|
||||
function listen() {
|
||||
return new Promise((resolve, reject) => {
|
||||
history.listen(res => {
|
||||
resolve(res)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 对外导出2种用法
|
||||
* 函数用法和装饰器用法
|
||||
*/
|
||||
|
||||
export class OperationalComponent {
|
||||
/**
|
||||
* 在正常对外高阶组件中必须调用此方法
|
||||
* 并使用此方法返回的组件进行再处理
|
||||
* 接收一个组件并返回处理后的组件
|
||||
* @param model 组件
|
||||
*/
|
||||
private static componentHoc<T extends typeof Component>(model: T): T {
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面权限控制
|
||||
* @param model
|
||||
*/
|
||||
public static routerHoc<T extends typeof Component>(model: T): T {
|
||||
let hoc: T = this.componentHoc(model);
|
||||
// let router = JSON.stringify(UeroModel.state.routerConfig)
|
||||
let hashname: string = window.location.hash.slice(1)
|
||||
// if (router.indexOf(hashname) < 0) {
|
||||
// // @ts-ignore
|
||||
// let el: T = LimitedAuthority;
|
||||
// return el;
|
||||
// }
|
||||
return hoc
|
||||
}
|
||||
|
||||
/**
|
||||
* 组件加载动画
|
||||
* @param el
|
||||
*/
|
||||
public static LoadDemand<T>(el: T): React.ComponentClass<{}, T> | T {
|
||||
return dynamic({
|
||||
loader: async () => {
|
||||
// 需要等待的时间
|
||||
await new Promise(resolve => {
|
||||
setTimeout(resolve, 500);
|
||||
});
|
||||
return el;
|
||||
},
|
||||
// 动画组件必须使用require动态加载模块
|
||||
loading: require('../../components/loading/index.tsx').default,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function routerHoc(target: any) {
|
||||
return (target = OperationalComponent.routerHoc(target));
|
||||
}
|
||||
export function LoadDemand(target: any) {
|
||||
return (target = OperationalComponent.LoadDemand(target));
|
||||
}
|
||||
Reference in New Issue
Block a user