统一授权前端类库
yarn add kst-auth
- 安装依赖
-
yarn add jquery bootstrap js-cookie moment
-
下载
font-awesome4.7
- 配置依赖
转到angular.json
,添加配置
"styles": [
"src/assets/font-awesome-4.7.0/css/font-awesome.min.css",
"node_modules\\bootstrap\\dist\\css\\bootstrap.min.css",
],
"scripts": [
"node_modules\\jquery\\dist\\jquery.slim.min.js",
"node_modules\\bootstrap\\dist\\js\\bootstrap.min.js"
]
- 引入类库
- 在跟模块(一般为
AppModule
)中:
import { AccountModule, AppAccountSession } from 'kst-auth';
- 在应用初始化中(依然在跟模块):
export function appInitializerFactory(injector: Injector) {
const appSession = injector.get(AppAccountSession);
return () => {
return new Promise((reslove, reject) => {
// 应用初始化
// 此处必须条用getCurrentLoginInfo
appSession.getCurrentLoginInfo(() => {
reslove();
});
});
};
}
// ------------------------
providers: [{
provide: APP_INITIALIZER,
useFactory: appInitializerFactory,
deps: [Injector],
multi: true
}]
- 在根路由模块
AppRoutingModule
:
{ path: 'account', loadChildren: () => import('kst-auth').then(mod => mod.AccountModule) }
- 启动查看效果