@smart100/spu-web-plugin 0.0.7 → 0.0.9

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.
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@smart100/spu-web-plugin",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "rollup -c -w",
7
7
  "build": "rollup -c && npm run build:types",
8
- "build:types": "node script/build-types.js"
8
+ "build:types": "node script/build-types.js",
9
+ "docs": "cd ./docs && npm run docs"
9
10
  },
10
11
  "author": "tarymee <tarymee@qq.com>",
11
12
  "type": "module",
package/src/cloudServ.ts CHANGED
@@ -84,6 +84,10 @@ class CloudServ {
84
84
  lsProxy.setItem(this.CLOUD_SERVE_KEY, storage)
85
85
  }
86
86
 
87
+ public remove () {
88
+ lsProxy.removeItem(this.CLOUD_SERVE_KEY)
89
+ }
90
+
87
91
  private getProvider (sign: StorageType = 'storage') {
88
92
  const storage: NormalizedCloudServItem | null = this.get(sign)
89
93
  if (!storage) {
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@ import { getLocation, getDistance } from './location'
5
5
  import { spuAxios, apaasAxios } from './axios'
6
6
  import { spuConfig } from './spuConfig'
7
7
  import { downloadService, uploadService } from './oss'
8
- import { getUniqueid } from './utils'
8
+ import { getUniqueid, functionCheck } from './utils'
9
9
  import AMapLoader from './AMapLoader'
10
10
  import login from './login'
11
11
  import { v4 as getUuid } from 'uuid'
@@ -44,6 +44,7 @@ export {
44
44
  uploadService,
45
45
  getUniqueid,
46
46
  getUuid,
47
+ functionCheck,
47
48
  AMapLoader,
48
49
  getToken,
49
50
  getTokenExpires,
package/src/install.ts CHANGED
@@ -27,9 +27,6 @@ const install = (app: any, options: SPUWebPluginOptions) => {
27
27
  urlquery.init()
28
28
  login.startRefreshtoken()
29
29
 
30
-
31
-
32
-
33
30
  // setTimeout(async () => {
34
31
  // const a = await downloadService.getUrl({
35
32
  // // source: 'a1b9954a-fb39-4bb2-aa0b-501f4af0d99e.jpeg',
@@ -55,6 +52,7 @@ const install = (app: any, options: SPUWebPluginOptions) => {
55
52
  // console.log(to)
56
53
  // const isInitVisit = from.path === '/' && from.name === undefined // 路由初始化访问
57
54
  // console.log('isInitVisit', isInitVisit)
55
+ // console.error(444444)
58
56
 
59
57
  // 自动登录
60
58
  if (to.query.token) {
package/src/login.ts CHANGED
@@ -3,6 +3,7 @@ import jwtDecode from 'jwt-decode'
3
3
  import { apaasAxios } from './axios'
4
4
  import tenantInfo from './tenantInfo'
5
5
  import { lsProxy } from './storageProxy'
6
+ // import { functionCheck } from './utils'
6
7
 
7
8
  type JwtResult = {
8
9
  LoginUser: IAny
@@ -191,6 +192,45 @@ class Login {
191
192
  return haslogged
192
193
  }
193
194
 
195
+ // 接口请求回来的 userInfo 有 functioncodes 以便做权限校验
196
+ async getAndSetUserInfo () {
197
+ // return apaasAxios.post('/api/teapi/rolepermission/account/getaccountinfo', {
198
+ // positionid: this.getUser('positioncode'),
199
+ // deviceinfo: '',
200
+ // sysversion: '',
201
+ // clientversion: ''
202
+ // }).then((res: any) => {
203
+ // // console.log(res)
204
+ // // debugger
205
+ // if (res.code === 200 && res.data) {
206
+ // this.setUser(res.data)
207
+ // }
208
+ // }).catch((err: Error) => {
209
+ // console.error(22)
210
+ // console.error(err)
211
+ // })
212
+
213
+ try {
214
+ const accountinfo: null | any = await apaasAxios.post('/api/teapi/rolepermission/account/getaccountinfo', {
215
+ positionid: this.getUser('positioncode'),
216
+ deviceinfo: '',
217
+ sysversion: '',
218
+ clientversion: ''
219
+ }).then((res: any) => {
220
+ if (res.code === 200 && res.data) {
221
+ return res.data
222
+ } else {
223
+ return null
224
+ }
225
+ })
226
+ if (accountinfo) {
227
+ this.setUser(accountinfo)
228
+ }
229
+ } catch (e) {
230
+ console.error(e)
231
+ }
232
+ }
233
+
194
234
  // 单点登录
195
235
  async singleLogin (query: IAny) {
196
236
  // 自动登录
@@ -205,11 +245,14 @@ class Login {
205
245
  const tokenexpires = query.tokenexpires
206
246
  if (refreshtoken) {
207
247
  this.setRefreshToken(refreshtoken)
248
+ } else {
249
+ this.removeRefreshToken()
208
250
  }
209
251
  if (tokenexpires) {
210
252
  this.setTokenExpires(tokenexpires)
253
+ } else {
254
+ this.removeTokenExpires()
211
255
  }
212
- // debugger
213
256
 
214
257
  // context 上下文字段 产品运营中心安装 卸载 配置 和 产品配置中心业务配置 页面需要用到
215
258
  let context = query.context
@@ -219,18 +262,11 @@ class Login {
219
262
  delete query.context
220
263
  }
221
264
 
222
- // const tenant = await apassRequest.get('/api/auth/tenantlist', {}).then((res) => {
223
- // return res?.data?.tenants?.[0]
224
- // })
225
- // if (tenant) {
226
- // lsProxy.setItem('tenant', JSON.stringify(tenant))
227
- // const normalizedTenant = tenantInfoApi.format(tenant as Tenant)
228
- // normalizedTenant && tenantInfoApi.save(normalizedTenant)
229
- // }
230
- // console.log(tenant)
231
-
232
265
  await tenantInfo.getAndSave()
233
- // debugger
266
+ await this.getAndSetUserInfo()
267
+
268
+ // const ischeck = functionCheck('1429379220684842752')
269
+ // console.log(ischeck)
234
270
  } else {
235
271
  console.error('query 中没有 token,无法单点登录。')
236
272
  }
@@ -238,7 +274,7 @@ class Login {
238
274
  delete query.token
239
275
  delete query.refreshtoken
240
276
  delete query.tokenexpires
241
- delete query.context
277
+ // debugger
242
278
  return {
243
279
  query
244
280
  }
package/src/tenantInfo.ts CHANGED
@@ -30,13 +30,6 @@ class TenantInfo {
30
30
  }
31
31
  }
32
32
 
33
- save (tenant: NormalizedCloudServ) {
34
- if (!tenant) {
35
- return
36
- }
37
- cloudServ.set(tenant)
38
- }
39
-
40
33
  format (tenant: ITenantInfo) {
41
34
  if (!tenant) {
42
35
  return null
@@ -65,11 +58,16 @@ class TenantInfo {
65
58
  async getAndSave (tenantCode?: string) {
66
59
  const tenant: ITenantInfo | null = await this.get(tenantCode)
67
60
  if (!tenant) {
61
+ lsProxy.removeItem('tenant')
62
+ cloudServ.remove()
68
63
  return
69
64
  }
65
+
70
66
  lsProxy.setItem('tenant', JSON.stringify(tenant))
71
67
  const normalizedTenant = this.format(tenant)
72
- normalizedTenant && this.save(normalizedTenant)
68
+ if (normalizedTenant) {
69
+ cloudServ.set(normalizedTenant)
70
+ }
73
71
  }
74
72
  }
75
73
 
package/src/utils.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import login from './login'
2
+
1
3
  const isIOS = () => {
2
4
  const ua = navigator.userAgent
3
5
  return /(iPhone|iPad|iPod|IOS)/i.test(ua)
@@ -27,10 +29,20 @@ const getUniqueid = () => {
27
29
  }
28
30
 
29
31
 
32
+ const functionCheck = (functioncode?: string): boolean => {
33
+ if (!functioncode) return false
34
+ const functioncodes = login.getUser('functioncodes') || []
35
+ // console.log(functioncodes)
36
+ // debugger
37
+ const check = functioncodes.includes(functioncode)
38
+ return !!check
39
+ }
40
+
30
41
  export {
31
42
  isIOS,
32
43
  isInWxwork,
33
44
  isInPcWxwork,
34
45
  isInAppWxwork,
35
- getUniqueid
46
+ getUniqueid,
47
+ functionCheck
36
48
  }