wl-design-mobile 0.8.0 → 0.8.1

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 (2) hide show
  1. package/package.json +1 -1
  2. package/util/jssdk-sczy.js +16 -89
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wl-design-mobile",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "finch",
@@ -2,48 +2,6 @@ import wx from "weixin-js-sdk";
2
2
  import config from '../config/config'
3
3
  import {axios} from '../util/axios'
4
4
 
5
- const SIGNATURE_CACHE_KEY = 'sczy_js_signature_cache'
6
- const SIGNATURE_CACHE_TTL = 5 * 60 * 1000
7
- let configPromise = null
8
-
9
- function getCacheKey(url) {
10
- return `${SIGNATURE_CACHE_KEY}:${url}`
11
- }
12
-
13
- function getCachedSignature(url) {
14
- try {
15
- const raw = sessionStorage.getItem(getCacheKey(url))
16
- if (!raw) {
17
- return null
18
- }
19
- const cached = JSON.parse(raw)
20
- if (!cached || !cached.data || !cached.expireAt || Date.now() > cached.expireAt) {
21
- sessionStorage.removeItem(getCacheKey(url))
22
- return null
23
- }
24
- return cached.data
25
- } catch (e) {
26
- sessionStorage.removeItem(getCacheKey(url))
27
- return null
28
- }
29
- }
30
-
31
- function setCachedSignature(url, data) {
32
- try {
33
- sessionStorage.setItem(getCacheKey(url), JSON.stringify({
34
- expireAt: Date.now() + SIGNATURE_CACHE_TTL,
35
- data,
36
- }))
37
- } catch (e) {
38
- // ignore storage failures
39
- }
40
- }
41
-
42
-
43
- /**
44
- * 判断ios系统版本号是否大于14
45
- * @returns {boolean}
46
- */
47
5
  const isIos14AndMore = () => {
48
6
  try {
49
7
  const str = navigator.userAgent.toLowerCase()
@@ -59,42 +17,32 @@ const isIos14AndMore = () => {
59
17
  }
60
18
 
61
19
  async function getSczyJsConfig() {
62
- let url = window.location.href.split('#')[0]
20
+ let url = window.location.href.split('#')[0].toString()
63
21
  if (isIos14AndMore()) {
64
- const storedUrl = sessionStorage.getItem('ios14ConfigUrl')
65
- if (storedUrl) {
66
- url = storedUrl
67
- }
68
- }
69
-
70
- const cached = getCachedSignature(url)
71
- if (cached) {
72
- return cached
22
+ console.log('[jssdk-sczy] iOS 14+,使用当前页面 URL 参与签名', url)
73
23
  }
74
24
 
75
25
  const resp = await axios.get(config.platformServerContext + '/api/weixin/js/signature', {
76
26
  params: { url }
77
27
  })
78
- const data = resp && resp.data ? resp.data : {}
79
- const signatureData = data && data.data ? data.data : null
80
- const errcode = data && data.errcode
81
- if (errcode !== 0 || !signatureData) {
82
- throw new Error((data && data.errmsg) ? data.errmsg : '获取签名失败')
28
+
29
+ const signatureData = resp.data
30
+ const errcode = resp.errcode
31
+ const errmsg = resp.errmsg || resp.message
32
+
33
+ if (errcode !== 0) {
34
+ throw new Error(errmsg)
83
35
  }
84
- setCachedSignature(url, signatureData)
36
+
85
37
  return signatureData
86
38
  }
87
39
 
88
40
  function configWx() {
89
- if (configPromise) {
90
- return configPromise
91
- }
92
-
93
- configPromise = getSczyJsConfig().then((resp) => {
94
- return new Promise((resolve, reject) => {
41
+ return new Promise((resolve, reject) => {
42
+ getSczyJsConfig().then((resp) => {
95
43
  wx.config({
96
44
  beta: true,
97
- debug: false,
45
+ debug: true,
98
46
  appId: resp.appId,
99
47
  timestamp: resp.timestamp,
100
48
  nonceStr: resp.nonceStr,
@@ -102,38 +50,17 @@ function configWx() {
102
50
  jsApiList: ['scanQRCode']
103
51
  })
104
52
 
105
- const timeout = setTimeout(() => {
106
- configPromise = null
107
- reject('企业微信初始化js-sdk超时')
108
- }, 15000)
109
-
110
53
  wx.ready(() => {
111
- clearTimeout(timeout)
112
54
  resolve()
113
55
  })
114
56
 
115
57
  wx.error((res) => {
116
- clearTimeout(timeout)
117
- configPromise = null
118
58
  reject('企业微信初始化js-sdk失败' + (res && res.errMsg ? res.errMsg : ''))
119
59
  })
60
+ }).catch((error) => {
61
+ reject('请求服务端jssdk签名失败:'+error)
120
62
  })
121
- }).catch((error) => {
122
- configPromise = null
123
- throw new Error('请求服务端jssdk签名失败:' + error)
124
63
  })
125
-
126
- return configPromise
127
- }
128
-
129
- function extractScanText(res) {
130
- if (!res) {
131
- return ''
132
- }
133
- if (typeof res === 'string') {
134
- return res
135
- }
136
- return res.resultStr || res.result || res.text || res.code || ''
137
64
  }
138
65
 
139
66
  function scanQRCode() {
@@ -149,7 +76,7 @@ function scanQRCode() {
149
76
  needResult: 1,
150
77
  scanType: ['qrCode', 'barCode'],
151
78
  success: function (res) {
152
- resolve(extractScanText(res))
79
+ resolve(res)
153
80
  },
154
81
  fail: function (res) {
155
82
  if (res && res.errMsg && res.errMsg.indexOf('function_not_exist') > -1) {