login-authorization-v2 2.0.0-beta.1 → 2.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +45 -47
  2. package/dist/index.d.ts +14 -4
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.esm.js +405 -497
  5. package/dist/index.umd.js +424 -537
  6. package/dist/src/request.d.ts.map +1 -1
  7. package/package.json +29 -25
  8. package/babel.config.js +0 -6
  9. package/coverage/clover.xml +0 -140
  10. package/coverage/coverage-final.json +0 -8
  11. package/coverage/lcov-report/base.css +0 -224
  12. package/coverage/lcov-report/block-navigation.js +0 -87
  13. package/coverage/lcov-report/common-authorization-v2/index.html +0 -116
  14. package/coverage/lcov-report/common-authorization-v2/index.ts.html +0 -547
  15. package/coverage/lcov-report/common-authorization-v2/src/compatible.ts.html +0 -223
  16. package/coverage/lcov-report/common-authorization-v2/src/constance.ts.html +0 -106
  17. package/coverage/lcov-report/common-authorization-v2/src/cookie.ts.html +0 -346
  18. package/coverage/lcov-report/common-authorization-v2/src/dom.ts.html +0 -262
  19. package/coverage/lcov-report/common-authorization-v2/src/index.html +0 -206
  20. package/coverage/lcov-report/common-authorization-v2/src/request.ts.html +0 -361
  21. package/coverage/lcov-report/common-authorization-v2/src/shares.ts.html +0 -163
  22. package/coverage/lcov-report/common-authorization-v2/src/types.ts.html +0 -412
  23. package/coverage/lcov-report/common-authorization-v2/src/utils.ts.html +0 -145
  24. package/coverage/lcov-report/compatible.ts.html +0 -223
  25. package/coverage/lcov-report/constance.ts.html +0 -106
  26. package/coverage/lcov-report/cookie.ts.html +0 -310
  27. package/coverage/lcov-report/dom.ts.html +0 -262
  28. package/coverage/lcov-report/favicon.png +0 -0
  29. package/coverage/lcov-report/index.html +0 -206
  30. package/coverage/lcov-report/prettify.css +0 -1
  31. package/coverage/lcov-report/prettify.js +0 -2
  32. package/coverage/lcov-report/shares.ts.html +0 -163
  33. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  34. package/coverage/lcov-report/sorter.js +0 -210
  35. package/coverage/lcov-report/types.ts.html +0 -412
  36. package/coverage/lcov-report/utils.ts.html +0 -145
  37. package/coverage/lcov.info +0 -268
  38. package/dist/compatible.d.ts +0 -10
  39. package/dist/compatible.d.ts.map +0 -1
  40. package/dist/constance.d.ts +0 -6
  41. package/dist/constance.d.ts.map +0 -1
  42. package/dist/cookie.d.ts +0 -8
  43. package/dist/cookie.d.ts.map +0 -1
  44. package/dist/dom.d.ts +0 -2
  45. package/dist/dom.d.ts.map +0 -1
  46. package/dist/index.js.LICENSE.txt +0 -1
  47. package/dist/request.d.ts +0 -36
  48. package/dist/request.d.ts.map +0 -1
  49. package/dist/shares.d.ts +0 -10
  50. package/dist/shares.d.ts.map +0 -1
  51. package/dist/test/cookie.test.d.ts +0 -2
  52. package/dist/test/cookie.test.d.ts.map +0 -1
  53. package/dist/test/shares.test.d.ts +0 -2
  54. package/dist/test/shares.test.d.ts.map +0 -1
  55. package/dist/types.d.ts +0 -89
  56. package/dist/types.d.ts.map +0 -1
  57. package/dist/utils.d.ts +0 -2
  58. package/dist/utils.d.ts.map +0 -1
  59. package/index.html +0 -28
  60. package/index.ts +0 -154
  61. package/jest.config.js +0 -6
  62. package/src/compatible.ts +0 -46
  63. package/src/constance.ts +0 -7
  64. package/src/cookie.ts +0 -75
  65. package/src/dom.ts +0 -59
  66. package/src/request.ts +0 -99
  67. package/src/shares.ts +0 -26
  68. package/src/types.ts +0 -109
  69. package/src/utils.ts +0 -20
  70. package/tests/compatible.test.ts +0 -420
  71. package/tests/cookie.test.ts +0 -78
  72. package/tests/dom.test.ts +0 -95
  73. package/tests/index.test.ts +0 -126
  74. package/tests/shares.test.ts +0 -52
  75. package/tests/utils.test.ts +0 -79
  76. package/tsconfig.json +0 -49
  77. package/webpack.config.mjs +0 -47
package/README.md CHANGED
@@ -1,55 +1,53 @@
1
- # login-authorization
1
+ # login-authorization-v2
2
2
 
3
- > 登录验证
4
- ## 安装依赖
3
+ ## 安装
4
+ ```bash
5
+ #npm
6
+ npm install login-authorization-v2
5
7
 
6
- ``` bash
7
- # install dependencies
8
- npm install login-authorization --save
9
- # or with yarn
10
- yarn add login-authorization
8
+ #yarn
9
+ yarn add login-authorization-v2
11
10
  ```
12
- ## 方法使用说明
13
- ### 初始化:init(requestUrl, loginUrl, systemName) 此方法必须在入口文件中调用
14
- ```bash
15
- import { init } from 'login-authorization';
16
-
17
- init('http://127.0.0.1','http://127.0.0.1/#/login?systemName=Finance', 'Finance').then(res => {
18
- if (res) {
19
- // true 已登录
20
- } else {
21
- // false 未登录
22
- }
23
- })
24
11
 
25
- 注意:systemName必须和Cognito中配置的系统组名保持一致。
12
+ ## 使用文档
13
+ ### 基本使用
14
+ ```javascript
15
+ import { make } from 'login-authorization-v2'
26
16
 
27
- ```
28
- <font color=#ff0000 size=24>注意:凡是涉及到统一登录系统的loginUrl后面必须将你的系统名称带上,且参数名称为systemName,如果未涉及则不用。</font>
29
- ### 登录成功时需要设置idToken和refreshToken初始值
30
- setIdToken(value)
31
- setRefreshToken(value)
32
- ### 获取idToken:getIdToken()
33
- ```bash
34
- import { getIdToken } from 'login-authorization';
17
+ const { init, logout } = make({
18
+ moduleName: 'Portal', // 当前模块名称
19
+ moduleBaseUrl: 'https://servers-api.gztest.net:8107', // 后端的 module_base 服务地址
20
+ loginPageUrl: 'http://huangcheng.ddmarketinghub.com:8080', // 如果未登录,跳转的登录页地址
21
+ })
35
22
 
36
- let idToken = getIdToken(); // 'xxxxxx',如果未登录则为null
37
- ```
38
- ### 获取用户信息:getUserInfo()
39
- ```bash
40
- import { getUserInfo } from 'login-authorization';
23
+ init({ brand: 1, tenantId: 1 }).then(menus => {
24
+ // menus 即为当前用户的菜单权限数据
25
+ }).catch(err => {
26
+ // 任何不能正常登陆的情况都会进入这里
27
+ })
41
28
 
42
- let userInfo = getUserInfo(); //{email: 'xxx', name: 'xxx',...},如果未登录则为null
43
- ```
44
- ### 登出:logout()
45
- ```bash
46
- import { logout } from 'login-authorization';
47
-
48
- logout().then(res => {
49
- if (res) {
50
- // true 登出成功,会自动跳转到登录页面
51
- } else {
52
- // false 登出失败
53
- }
29
+ logout().then(() => {
30
+ // 退出登陆成功
31
+ }).catch(() => {
32
+ // 可以不用管
54
33
  })
55
- ```
34
+ ```
35
+ > tenantId、brand、moduleName 枚举值可以在 login-authorization-v2 包内的 `./dist/src/types.d.ts` 文件中查看
36
+
37
+ ### 新增方法
38
+ #### main
39
+ 1. make(options: MakeFnParams): { init, logout }
40
+ 2. init(params: InitParams): Promise<MenuItem[]>
41
+ 3. logout(): Promise<void>
42
+
43
+ #### cookie 相关方法
44
+ 1. setAccessToken(string | null): void
45
+ 2. getAccessToken(): string | undefined
46
+ 3. setRefreshToken(string | null): void
47
+ 4. getRefreshToken(): string | undefined
48
+ 5. setSystemType(string | null): void
49
+ 6. getSystemType(): string | undefined
50
+
51
+ #### 工具函数
52
+ 1. isMobile(): boolean // 判断当前环境是否为移动端
53
+ 2. getUserInfo(): Promise<UserInfo | null> // 获取当前用户信息
package/dist/index.d.ts CHANGED
@@ -1,15 +1,25 @@
1
1
  export * from './src/cookie';
2
2
  export * from './src/compatible';
3
- import { type ModuleName, type Tenant, type Brand } from './src/types';
3
+ export * from './src/utils';
4
+ import { Brand, type ModuleName, Tenant } from './src/types';
4
5
  type MakeFnParams = {
5
- brand: Brand;
6
- tenantId: Tenant;
7
6
  moduleName: ModuleName;
8
7
  moduleBaseUrl: string;
9
8
  loginPageUrl: string;
10
9
  };
10
+ type InitFnParams = {
11
+ brand?: Brand;
12
+ tenantId: Tenant;
13
+ };
11
14
  export declare const make: (config: MakeFnParams) => {
12
- init: () => Promise<void>;
15
+ init: (initConfig: InitFnParams) => Promise<{
16
+ groupName: ModuleName;
17
+ icon: string;
18
+ id: number;
19
+ label: string;
20
+ staffEndpoint: boolean;
21
+ url: string;
22
+ }[]>;
13
23
  logout: () => Promise<import("axios").AxiosResponse<any, any>>;
14
24
  };
15
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAOhC,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,MAAM,EAAE,KAAK,KAAK,EAAiB,MAAM,aAAa,CAAA;AAIrF,KAAK,YAAY,GAAG;IAClB,KAAK,EAAE,KAAK,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,UAAU,CAAA;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,QAAQ,YAAY;;;CAqIxC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAO3B,OAAO,EAAE,KAAK,EAAE,KAAK,UAAU,EAAc,MAAM,EAAiB,MAAM,aAAa,CAAA;AAGvF,KAAK,YAAY,GAAG;IAClB,UAAU,EAAE,UAAU,CAAA;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,KAAK,YAAY,GAAG;IAClB,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,QAAQ,YAAY;uBAUb,YAAY;;;;;;;;;CAmIvC,CAAA"}