jufubao-base 1.0.145-beta14 → 1.0.145-beta21

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,6 +1,6 @@
1
1
  {
2
2
  "name": "jufubao-base",
3
- "version": "1.0.145-beta14",
3
+ "version": "1.0.145-beta21",
4
4
  "private": false,
5
5
  "description": "聚福宝业务组件基础插件包",
6
6
  "main": "index.js",
@@ -4,11 +4,15 @@
4
4
  import cookie from "@/common/cookie";
5
5
  //#endif
6
6
  import storage from "@/common/storage";
7
+
7
8
  const settings = require('./../../settings');
8
9
  import Vue from 'vue';
10
+
9
11
  let __jfbAuthorize = null;
10
12
  import store from "@/store";
11
13
 
14
+ import {Base64} from 'js-base64';
15
+
12
16
  class JfbAuthorize {
13
17
  /**
14
18
  * @description 构造函数
@@ -18,20 +22,27 @@ class JfbAuthorize {
18
22
  * @param options.cardPath {String} 购物登录地址 【选填】
19
23
  * @param options.LoginPath {String} 用户登录地址 【选填】
20
24
  */
21
- constructor(options){
25
+ constructor(options) {
22
26
  this.siteId = options.siteId;
23
27
  this.xSite = options.xSite;
24
28
  this.cardPath = options.cardPath;
25
29
  this.LoginPath = options.LoginPath;
30
+ this.jumpToTimer = null;
31
+ this.maxTime = 10;
26
32
 
27
- this.config = Object.assign({},{
33
+ this.config = Object.assign({}, {
28
34
  'user': 'JFB-CSRF-TOKEN-{siteID}',
29
35
  'card': 'JFB-CARD-TOKEN-{siteID}',
30
36
  'refresh': 'JFB-REFRESH-TOKEN-{siteID}',
31
37
  'access': 'JFB-ACCESS-TOKEN',
32
- }, settings.token? settings.token: {});
38
+ 'bizCode': 'JFB-CARD-CODE-{siteID}',
39
+ 'userAll':'JFB-USER-ALL-{siteID}',
40
+ }, settings.token ? settings.token : {});
33
41
  }
34
42
 
43
+ doMain() {
44
+ return [''].concat(window.location.host.split('.').slice(-2)).join('.');
45
+ }
35
46
 
36
47
 
37
48
  /**
@@ -39,10 +50,10 @@ class JfbAuthorize {
39
50
  * @param key {String} {String} 设置cookie/storage键值,其值:card|user|refresh|access, 默认:user,【选填】
40
51
  * @returns {string|*}
41
52
  */
42
- getTokenKeyword(key){
53
+ getTokenKeyword(key) {
43
54
  if (!this.config[key]) key = 'user';
44
- if(key === 'access') return this.config.access;
45
- else{
55
+ if (key === 'access') return this.config.access;
56
+ else {
46
57
  return `${this.config[key].replace("{siteID}", this.siteId)}`;
47
58
  }
48
59
  }
@@ -82,13 +93,16 @@ class JfbAuthorize {
82
93
  * @param options {Object} 可选项,{expires: 1, domain: ''}, 过期时间单位:小时
83
94
  */
84
95
  removeToken(key, options = {}) {
96
+ let codeKey = this.getTokenKeyword('bizCode');
85
97
  key = this.getTokenKeyword(key);
86
98
  //#ifdef H5
87
99
  cookie.remove(key, options);
88
- console.warn(`cookie.key=${key}`);
100
+ cookie.remove(codeKey, options);
101
+ cookie.remove(key, {domain: this.doMain()});
102
+ cookie.remove(codeKey, {domain: this.doMain()});
89
103
  //#endif
90
- console.warn(`storage.key=${key}`);
91
104
  storage.remove(key);
105
+ storage.remove(codeKey);
92
106
  }
93
107
 
94
108
  /**
@@ -113,10 +127,10 @@ class JfbAuthorize {
113
127
  * @description h5中获取base
114
128
  * @param $vm {Vue}
115
129
  */
116
- getBasePath($vm){
130
+ getBasePath($vm) {
117
131
  let base = '';
118
132
  //#ifdef H5
119
- base = $vm.$router.history.base;
133
+ base = $vm.$router.history.base;
120
134
  //#endif
121
135
  return base;
122
136
  }
@@ -124,8 +138,10 @@ class JfbAuthorize {
124
138
  /**
125
139
  * @description 跳转到卡登陆页面
126
140
  * @param $vm {Vue}
141
+ * @param callbackUrl {String} 返回参数
127
142
  */
128
- jumpToCardLogin($vm){
143
+
144
+ jumpToCardLogin($vm, callbackUrl) {
129
145
  let redirect_url = '';
130
146
  if (store.state.configProject.platform === 'mp.weixin') {
131
147
  redirect_url = $vm['$xdUniHelper'].parseURL().source;
@@ -133,25 +149,87 @@ class JfbAuthorize {
133
149
  if (store.state.configProject.platform === 'h5') {
134
150
  redirect_url = $vm.$route.fullPath;
135
151
  }
152
+
153
+
154
+ //登陆地址与当前项目不再同一个app中处理
155
+ //#ifdef H5
156
+ if (!this.checkUrlIsCameDir(this.cardPath)) {
157
+ redirect_url = `@site_domain@/${store.state.brandInfo.deploy_dir}${redirect_url}`
158
+ }
159
+ //#endif
160
+
161
+ if (callbackUrl) redirect_url = callbackUrl;
162
+
163
+ if (!this.cardPath) {
164
+ console.error(this.cardPath);
165
+ $vm.$xdAlert({
166
+ content: "请设置卡登陆页面地址"
167
+ })
168
+ throw new Error('请设置卡登陆页面地址');
169
+ }
170
+
171
+ //设置页面过滤卡
172
+ let business_code = '';
173
+ if(store.state.pageBusinessCode) {
174
+ business_code = `&jfb_business_code=${store.state.pageBusinessCode}`;
175
+ }
176
+
136
177
  $vm['$xdUniHelper'].redirectTo({
137
- url: this.cardPath + `?inCallback=${encodeURIComponent(redirect_url)}`,
178
+ url: this.cardPath + `?inCallback=${Base64.encodeURI(redirect_url)}${business_code}`,
138
179
  });
139
180
  }
140
181
 
182
+ checkUrlIsCameDir(url) {
183
+ url = url.replace('@site_domain@', '').split('/');
184
+ console.log('checkUrlIsCameDir', url)
185
+ console.log('checkUrlIsCameDir', store.state.brandInfo)
186
+ return url.length === 5 && url[1] === store.state.brandInfo.deploy_dir;
187
+ }
188
+
141
189
  /**
142
190
  * @description 跳转到用户登陆页面
143
191
  * @param $vm {Vue}
192
+ * @param isRedirect {boolean}
144
193
  */
145
- jumpToUserLogin($vm) {
194
+ jumpToUserLogin($vm,isRedirect = true) {
146
195
  let redirect_url = '';
147
- if(store.state.configProject.platform === 'mp.weixin') {
196
+ if (store.state.configProject.platform === 'mp.weixin') {
148
197
  redirect_url = $vm['$xdUniHelper'].parseURL().source;
149
198
  }
150
199
  if (store.state.configProject.platform === 'h5') {
151
200
  redirect_url = $vm.$route.fullPath;
152
201
  }
202
+ if(!isRedirect) redirect_url = '';
203
+
204
+ //#ifdef H5
205
+ //登陆地址与当前项目不再同一个app中处理
206
+ if(!this.checkUrlIsCameDir(this.LoginPath)) {
207
+ if(redirect_url) {
208
+ redirect_url = `@site_domain@/${store.state.brandInfo.deploy_dir}${redirect_url}`;
209
+ }
210
+ else {
211
+ redirect_url = `@site_domain@/${store.state.brandInfo.deploy_dir}/`;
212
+ }
213
+ }
214
+ //#endif
215
+
216
+ //判断是否有登陆地址
217
+ let LoginPath = redirect_url;
218
+ if (LoginPath.indexOf(this.LoginPath) === -1) {
219
+ LoginPath = this.LoginPath + `?redirect_url=${Base64.encodeURI(redirect_url)}`;
220
+ }
221
+
222
+ if (!this.LoginPath) {
223
+ console.error(this.LoginPath);
224
+ $vm.$xdAlert({
225
+ content: "请设置用户登陆页面地址"
226
+ })
227
+ throw new Error('请设置用户登陆页面地址');
228
+ }
229
+
230
+ console.warn(`jumpToUserLogin.redirect.url: ${redirect_url} , login: ${LoginPath}`)
153
231
  $vm['$xdUniHelper'].redirectTo({
154
- url: this.LoginPath + `?redirect_url=${encodeURIComponent(redirect_url)}`,
232
+ url: LoginPath,
155
233
  });
156
234
  }
157
235
 
@@ -162,17 +240,55 @@ class JfbAuthorize {
162
240
  * @param isAutoJump {Boolean} 是否自己跳转 默认值:true
163
241
  * @return {boolean} true 已登陆或者免登 false 未登陆
164
242
  */
165
- checkCardLogin(canCard = false, $vm, isAutoJump=true){
166
- if(!canCard) return true;
243
+ checkCardLogin(canCard = false, $vm, isAutoJump = true) {
244
+ let isSpecialPages = $vm['isSpecialPages'];
245
+
246
+ //免卡登陆
247
+ if (!canCard) {
248
+ return true;
249
+ }
250
+
251
+
167
252
  if (!this.getToken('card')) {
168
- if(isAutoJump) {
169
- this.jumpToCardLogin($vm);
253
+ $vm.isCardLogined = false;
254
+ if (isAutoJump) {
255
+ //需要特殊处理,在设置强制卡的时候需要也可以免卡登陆模式,但是需要进行卡检查
256
+ if(isSpecialPages) return true;
257
+ else this.jumpToCardLogin($vm);
170
258
  }
171
259
  return false;
172
260
  }
261
+
262
+ //已登陆卡
263
+ $vm.isCardLogined = true;
173
264
  return true;
174
265
  }
175
266
 
267
+ checkLoginCardSupportBizCode(canCard = false, $vm, isAutoJump = true){
268
+ if (!canCard) return true;
269
+
270
+ //未获取业务线直接跳回卡登陆页面
271
+ let bizCode = this.getToken('bizCode')
272
+ if (!bizCode) {
273
+ if (isAutoJump) {
274
+ this.jumpToCardLogin($vm);
275
+ }
276
+ return false;
277
+ }
278
+ //
279
+ else{
280
+ let bizCodeArr = bizCode.split(',');
281
+ let currentBizCode = store.state.xnamespace;
282
+ if(bizCodeArr.includes(currentBizCode)) {
283
+ return true
284
+ }
285
+ if (isAutoJump) {
286
+ this.jumpToCardLogin($vm);
287
+ }
288
+ return false;
289
+ }
290
+ }
291
+
176
292
  /**
177
293
  * @description 用户已登录信息
178
294
  * @param canSign {Boolean} 检查是否用登录信息 默认:false
@@ -180,21 +296,34 @@ class JfbAuthorize {
180
296
  * @param isAutoJump {Boolean} 是否自己跳转 默认值:true
181
297
  * @return {Promise} true: 已登陆或者未启用,false:未登陆或刷新token已过期获取(从新交换token)
182
298
  */
183
- checkUserLogin(canSign, $vm, isAutoJump=true) {
184
- return new Promise((resolve, reject)=>{
299
+ checkUserLogin(canSign, $vm, isAutoJump = true) {
300
+ return new Promise((resolve, reject) => {
301
+ let isSpecialPages = $vm['isSpecialPages'];
302
+
185
303
  //免登陆操作
186
304
  if (!canSign) resolve(true);
187
305
 
188
- //用户登陆判断
306
+ //用户登陆判断crf
189
307
  let userToken = this.getToken('user');
190
308
  //用户刷新token
191
309
  let refreshToken = this.getToken('refresh');
192
310
 
193
311
  //用户未登陆
194
- if(!userToken && !refreshToken) {
312
+ if (!userToken && !refreshToken) {
313
+ $vm.isLogined = false;
314
+
315
+ //需要自动跳转到登陆页面
195
316
  if (isAutoJump) {
317
+ //需要特殊处理,在设置强制登陆的时候需要也可以免登陆模式,但是需要进行登陆检查
318
+ if(isSpecialPages){
319
+ resolve(true);
320
+ return
321
+ }
322
+
196
323
  this.jumpToUserLogin($vm);
324
+ return;
197
325
  }
326
+
198
327
  resolve(false);
199
328
  return
200
329
  }
@@ -202,31 +331,58 @@ class JfbAuthorize {
202
331
  //去刷新token
203
332
  if (!userToken) store.dispatch('userRefreshToken')
204
333
  .then(res => {
334
+ $vm.isLogined = true;
205
335
  resolve(true);
206
336
  })
207
- .catch(error=>{
337
+ .catch(error => {
338
+ $vm.isLogined = false;
339
+
208
340
  if (isAutoJump) {
341
+ //需要特殊处理,在设置强制登陆的时候需要也可以免登陆模式,但是需要进行登陆检查
342
+ if(isSpecialPages){
343
+ resolve(true);
344
+ return
345
+ }
346
+
209
347
  this.jumpToUserLogin($vm);
348
+ return;
210
349
  }
350
+
211
351
  resolve(false);
212
352
  });
213
- else{
353
+
354
+ //已登陆
355
+ else {
356
+ $vm.isLogined = true;
214
357
  resolve(true);
215
358
  }
216
359
  });
217
360
  }
218
361
 
362
+
363
+
219
364
  /**
220
365
  * @description 客户端设置所有token
221
366
  * @param result
222
367
  * @param cb {Function|null}
223
368
  */
224
- setAllToken(result,cb = null){
369
+ setAllToken(result, cb = null) {
370
+
225
371
  //#ifdef MP-WEIXIN
226
- this.setToken('user', result['csrf_token'], {expires: result['csrf_token_expire_in']/60/60});
372
+ if(result['csrf_token_expire_in']) result['csrf_token_expire_in'] = Number(result['csrf_token_expire_in']);
373
+ if(result['access_token_expire_in']) result['access_token_expire_in'] = Number(result['access_token_expire_in']);
374
+ if(result['refresh_token_expire_in']) result['refresh_token_expire_in'] = Number(result['refresh_token_expire_in']);
375
+ this.setToken('user', result['csrf_token'], {expires: result['csrf_token_expire_in'] / 60 / 60});
227
376
  this.setToken('access', result['access_token'], {expires: result['access_token_expire_in'] / 60 / 60})
228
377
  this.setToken('refresh', result['refresh_token'], {expires: result['refresh_token_expire_in'] / 60 / 60})
229
- if(typeof cb === 'function') cb();
378
+ this.setToken('userAll',result,{expires: result['csrf_token_expire_in'] / 60 / 60})
379
+ if (typeof cb === 'function') cb();
380
+ //#endif
381
+ }
382
+
383
+ setCardToken(result,cb){
384
+ //#ifdef MP-WEIXIN
385
+ if (typeof cb === 'function') cb();
230
386
  //#endif
231
387
  }
232
388
 
@@ -234,14 +390,12 @@ class JfbAuthorize {
234
390
  * @description 客户端删除所有token
235
391
  * @param cb {Function|null}
236
392
  */
237
- removeAllToken(cb=null){
393
+ removeAllToken(cb = null) {
238
394
  //#ifdef MP-WEIXIN
239
395
  this.removeToken('user');
240
396
  this.removeToken('access');
241
397
  this.removeToken('refresh');
242
- if (store.state.jfbAuthorize !== null) {
243
- store.state.jfbAuthorize.setAllToken(res)
244
- }
398
+ this.removeToken('userAll');
245
399
  //#endif
246
400
  }
247
401
  }
@@ -254,7 +408,7 @@ class JfbAuthorize {
254
408
  * @param options.LoginPath {String} 用户登录地址 【选填】
255
409
  */
256
410
  export default function (options) {
257
- if(__jfbAuthorize !== null) return __jfbAuthorize;
411
+ if (__jfbAuthorize !== null) return __jfbAuthorize;
258
412
  return __jfbAuthorize = new JfbAuthorize(options);
259
413
  }
260
414
 
@@ -490,9 +490,10 @@ export default {
490
490
  this.$xdHideLoading();
491
491
  //#ifdef MP-WEIXIN
492
492
  if (this.jfbAuthorize !== null) {
493
- this.jfbAuthorize.setToken("card", res["card_token"], {
494
- expires: res["card_expire_in"] / 60 / 60,
495
- });
493
+ this.jfbAuthorize.setCardToken(res);
494
+ // this.jfbAuthorize.setToken("card", res["card_token"], {
495
+ // expires: res["card_expire_in"] / 60 / 60,
496
+ // });
496
497
  }
497
498
  //#endif
498
499
 
@@ -367,9 +367,7 @@ export default {
367
367
  this.$xdHideLoading();
368
368
  //#ifdef MP-WEIXIN
369
369
  if (this.jfbAuthorize !== null) {
370
- this.jfbAuthorize.setToken("card", res["card_token"], {
371
- expires: res["card_expire_in"] / 60 / 60,
372
- });
370
+ this.jfbAuthorize.setCardToken(res);
373
371
  this.handleToApp(entry);
374
372
  }
375
373
  //#endif
@@ -592,9 +592,7 @@ export default {
592
592
  this.$xdHideLoading();
593
593
  //#ifdef MP-WEIXIN
594
594
  if (this.jfbAuthorize !== null) {
595
- this.jfbAuthorize.setToken("card", res["card_token"], {
596
- expires: res["card_expire_in"] / 60 / 60,
597
- });
595
+ this.jfbAuthorize.setCardToken(res);
598
596
  this.handleToApp(entry);
599
597
  }
600
598
  //#endif
@@ -226,9 +226,7 @@
226
226
  this.$xdHideLoading();
227
227
  //#ifdef MP-WEIXIN
228
228
  if (this.jfbAuthorize !== null) {
229
- this.jfbAuthorize.setToken("card", res["card_token"], {
230
- expires: res["card_expire_in"] / 60 / 60,
231
- });
229
+ this.jfbAuthorize.setCardToken(res);
232
230
  }
233
231
  //#endif
234
232
 
@@ -175,9 +175,7 @@
175
175
  this.$xdHideLoading();
176
176
  //#ifdef MP-WEIXIN
177
177
  if (this.jfbAuthorize !== null) {
178
- this.jfbAuthorize.setToken("card", res["card_token"], {
179
- expires: res["card_expire_in"] / 60 / 60,
180
- });
178
+ this.jfbAuthorize.setCardToken(res);
181
179
  }
182
180
  //#endif
183
181
 
@@ -477,11 +477,8 @@ export default {
477
477
  })
478
478
  .then((res) => {
479
479
  let { redirect_url, callback_url } = this;
480
- if (redirect_url)
481
- redirect_url = redirect_url;
482
- let url = Base64.encodeURI(
483
- redirect_url || callback_url || this.settings.index
484
- );
480
+ //if (redirect_url) redirect_url = redirect_url;
481
+ let url = Base64.encodeURI(redirect_url || callback_url || this.settings.index);
485
482
  //需要授权操作
486
483
  if (res.auth_code) {
487
484
  this.$xdUniHelper.navigateTo({
@@ -490,15 +487,15 @@ export default {
490
487
  }
491
488
  //无需授权直接进行登录
492
489
  else {
493
-
494
490
  if (this.jfbAuthorize !== null) {
495
491
  this.jfbAuthorize.setAllToken(res["login_info"], () => {
496
492
  //需要收集手机号码
497
- if(res.is_collect_phone_number === 'Y'){
493
+ if(res['is_collect_phone_number'] === 'Y'){
498
494
  this.$xdUniHelper.navigateTo({
499
495
  url: `${this.mpAuthPhoneUrl}?provider_id=${this.quickLogin.provider_id}&url=${url}`,
500
496
  });
501
- }else{
497
+ }
498
+ else{
502
499
  this.toHomeAfterLogin();
503
500
  }
504
501
  });
@@ -759,7 +756,6 @@ export default {
759
756
 
760
757
  toHomeAfterLogin() {
761
758
  let { redirect_url, callback_url } = this;
762
- if (redirect_url) redirect_url = redirect_url;
763
759
  this.$xdUniHelper.redirectTo({
764
760
  url: redirect_url || callback_url || this.settings.index,
765
761
  });
@@ -100,10 +100,7 @@
100
100
  <view class="remain_pay" v-if="payInfo.channel_amount > 0">
101
101
  <view style="border-bottom: 2rpx solid #eee;" class="column-group">
102
102
  <view class="column-item" style="padding: 30rpx 60rpx">
103
- <view class="column_label">
104
- 仍需支付
105
- <view class="label_sub">(可使用多张票券支付)</view>
106
- </view>
103
+ <view class="column_label">仍需支付<text class="label_sub">(可使用多张票券支付)</text></view>
107
104
  <view class="column_value text-primary">
108
105
  <xd-unit
109
106
  :price="payInfo.channel_amount"
@@ -135,31 +132,25 @@
135
132
  class="pay_item"
136
133
  >
137
134
  <view class="icon">
138
- <xd-font-icon
139
- v-if="item.channel_code == 'wxpay'"
140
- icon="iconwx"
141
- size="64"
142
- color="#25bc46"
143
- ></xd-font-icon>
135
+ <image mode="scaleToFill" :src="item['channel_logo']" style="height:64rpx; width: 64rpx" />
144
136
  </view>
145
137
  <view class="pay_name">{{ item.channel_provider_name }}</view>
146
138
  <xd-radio
147
139
  @change="(flat) => handlerPayCheck(item.channel_provider_id, flat)"
148
- :value="channel_provider_id == item.channel_provider_id"
140
+ :value="channel_provider_id === item.channel_provider_id"
149
141
  size="mini"
150
142
  ></xd-radio>
151
143
  </view>
152
144
  </view>
153
145
  </view>
154
146
  <view class="bottom_btn-mask"></view>
155
- <view v-if="is_can_pay=='Y'" class="bottom_btn" :style="prod_bottom">
147
+ <view v-if="is_can_pay==='Y'" class="bottom_btn" :style="prod_bottom">
156
148
  <xd-button
157
149
  width="360rpx"
158
150
  type="primary"
159
151
  radius="50rpx"
160
152
  @click="doThirdPay"
161
- >确认支付</xd-button
162
- >
153
+ >确认支付</xd-button>
163
154
  </view>
164
155
  </view>
165
156
  </view>
@@ -336,7 +327,6 @@ export default {
336
327
  item["end_time"] = this.getTimeFormat(item.end_time);
337
328
  return item;
338
329
  });
339
- //this.cardList = [...this.cardList,...this.cardList,...this.cardList,...this.cardList,...this.cardList]
340
330
  });
341
331
  },
342
332
  p_getListUserPayChannel() {
@@ -590,7 +580,7 @@ export default {
590
580
  .remain_header {
591
581
  display: flex;
592
582
  justify-content: space-between;
593
- padding: 16rpx 60rpx 0;
583
+ padding: 30rpx 60rpx 0;
594
584
  color: #999999;
595
585
  font-size: 24rpx;
596
586
  }
@@ -607,8 +597,8 @@ export default {
607
597
  width: 64rpx;
608
598
  height: 64rpx;
609
599
  border-radius: 32rpx;
610
- // background: #DDD;
611
600
  margin-right: 30rpx;
601
+ overflow: hidden;
612
602
  }
613
603
  .pay_name {
614
604
  flex: 1;