w-web-perm 1.0.36 → 1.0.37

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.
@@ -0,0 +1,100 @@
1
+ import axios from 'axios'
2
+ import get from 'lodash-es/get.js'
3
+ import isestr from 'wsemi/src/isestr.mjs'
4
+ import iseobj from 'wsemi/src/iseobj.mjs'
5
+ import isfun from 'wsemi/src/isfun.mjs'
6
+ import ispm from 'wsemi/src/ispm.mjs'
7
+
8
+
9
+ async function getPermUserInfor(url, tokenSelf, userIdTar, opt = {}) {
10
+ //url: http://localhost:11006/api/getPermUserInfor?token={sysToken}&userId={userId}
11
+ let errTemp = null
12
+
13
+ //check
14
+ if (!isestr(url)) {
15
+ return Promise.reject('invalid url')
16
+ }
17
+ if (!isestr(tokenSelf)) {
18
+ return Promise.reject('invalid tokenSelf')
19
+ }
20
+ if (!isestr(userIdTar)) {
21
+ return Promise.reject('invalid userIdTar')
22
+ }
23
+
24
+ //funConvertPerm
25
+ let funConvertPerm = get(opt, 'funConvertPerm')
26
+
27
+ //url
28
+ if (url.indexOf('token={sysToken}') < 0 && url.indexOf('userId={userId}') < 0) {
29
+ return Promise.reject(`no 'token={sysToken}', 'userId={userId}' in url`)
30
+ }
31
+ url = url.replaceAll('{sysToken}', tokenSelf) //系統介接用permToken
32
+ url = url.replaceAll('{userId}', userIdTar)
33
+ // console.log('getPermUserInfor: url', url)
34
+
35
+ //get
36
+ let res = await axios.get(url)
37
+ .catch((err) => {
38
+ errTemp = err.toString()
39
+ })
40
+
41
+ //check
42
+ if (errTemp !== null) {
43
+ console.log('res', res)
44
+ console.log('errTemp', errTemp)
45
+ console.log(`can not get user by url[${url}]`)
46
+ return Promise.reject(`can not get user by url[${url}]`) //由SSO取得使用者資訊錯誤
47
+ }
48
+
49
+ //data
50
+ let data = get(res, 'data')
51
+
52
+ //state
53
+ let state = get(data, 'state', '')
54
+
55
+ //msg
56
+ let msg = get(data, 'msg')
57
+
58
+ //check
59
+ if (state !== 'success') {
60
+ console.log('res', res)
61
+ console.log('data', data)
62
+ console.log('state', state)
63
+ console.log('errTemp', msg)
64
+ console.log(`can not get user data by url[${url}]`)
65
+ return Promise.reject(`can not get user data by url[${url}]`) //取得使用者資訊失敗
66
+ }
67
+
68
+ //ur
69
+ let ur = msg
70
+ // console.log('getPermUserInfor ur(msg)', ur)
71
+
72
+ //check
73
+ if (!iseobj(ur)) {
74
+ console.log(`no user data by url[${url}]`)
75
+ return Promise.reject(`no user data by url[${url}]`)
76
+ }
77
+
78
+ //check
79
+ if (isfun(funConvertPerm)) {
80
+
81
+ //funConvertPerm
82
+ ur = funConvertPerm(ur)
83
+ if (ispm(ur)) {
84
+ ur = await ur
85
+ }
86
+ // console.log('getPermUserInfor ur(funConvertPerm)', ur)
87
+
88
+ //check
89
+ if (!iseobj(ur)) {
90
+ console.log(`no user data after funConvertPerm`)
91
+ return Promise.reject(`no user data after funConvertPerm`)
92
+ }
93
+
94
+ }
95
+
96
+ return ur
97
+ }
98
+
99
+
100
+ export default getPermUserInfor
package/tableTags.json CHANGED
@@ -1 +1 @@
1
- {"grups":"2025-07-21T14:54:33+08:00|5dbjYM","pemis":"2025-07-21T14:53:48+08:00|yiHNP7","targets":"2025-07-21T14:51:12+08:00|wIhPNL","users":"2025-07-21T14:54:43+08:00|r0HM32"}
1
+ {"grups":"2025-07-24T23:53:43+08:00|kqQUfj","pemis":"2025-07-24T23:53:43+08:00|JIx6QG","targets":"2025-07-24T23:53:43+08:00|DLziCS","users":"2025-07-24T23:53:43+08:00|qBeZwW"}