jufubao-third 1.0.0-beta1

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,500 @@
1
+ 'use strict';
2
+
3
+ import { mapState, mapActions} from 'vuex';
4
+ import {JfbEvent} from "@/utils/xd.event";
5
+
6
+ import {
7
+ AttrToTargetValues,
8
+ getContainerPropsValue,
9
+ baseCloneDeep,
10
+ } from "@/utils/xd.base";
11
+ import getServiceUrl from "@/common/getServiceUrl";
12
+
13
+ export default {
14
+ computed: {
15
+ ...mapState(['siteInfo', 'jfbAuthorize', 'webThemes', 'xnamespace']),
16
+ },
17
+ watch: {
18
+ webThemes: {
19
+ immediate: true,
20
+ handler(value) {
21
+ if (value) this.themesList = value
22
+ },
23
+ }
24
+ },
25
+ data(){
26
+ return {
27
+ themesList: {}, //保存所有业务组件使用风格列表
28
+ titleDefaultCount: 0, //设置标题时候计数器,最大查找uni-page-head__title样式名称次数
29
+ }
30
+ },
31
+ methods: {
32
+ ...mapActions(['loginCardMock']),
33
+ getMockCard(){
34
+ let pagae = this.$xdUniHelper.parseURL();
35
+ let card = pagae.params['x-test'];
36
+ if (card) {
37
+ let reg = /^(card_)[a-zA-Z0-9\-_]{8,}$/;
38
+ if (reg.test(card)) {
39
+ return card.split('_')[1];
40
+ }
41
+ }
42
+ return ''
43
+ },
44
+ checkMockCard(){
45
+ // #ifdef H5
46
+ let pagae = this.$xdUniHelper.parseURL();
47
+ let userLogin = `/${this.projectAttr.deploy_dir}${this.$configProject.login_entry}`;
48
+ let cardLogin = `/${this.projectAttr.deploy_dir}${this.$configProject.card_entry}`;
49
+
50
+ //登陆页面和卡登陆页面不启用
51
+ if(pagae.path === userLogin || pagae.path === cardLogin) {
52
+ return false
53
+ }
54
+
55
+ let card = pagae.params['x-test'];
56
+ if(card) {
57
+ let reg = /^(card_)[a-zA-Z0-9\-_]+$/;
58
+ if(reg.test(card)) return true
59
+ }
60
+ // #endif
61
+ return false;
62
+ },
63
+
64
+ init(){
65
+ this.settings = this.$settings;
66
+ this.site_id = this.brandInfo.site_id;
67
+ this.projectAttr = this.brandInfo;
68
+
69
+ //第一次上班日志
70
+ this.$xdLog.setProject('pages.init', {
71
+ projectAttr: this.brandInfo,
72
+ site_id: this.site_id
73
+ });
74
+
75
+ //预览模式设置页面ID
76
+ if (this.$configProject.isPreview === true) {
77
+ let {page_id} = this.$xdUniHelper.parseURL().params;
78
+ if (!page_id) throw new Error('请设置页面ID');
79
+ this.pageAttr['page_id'] = page_id;
80
+ }
81
+
82
+ //获取用户信息
83
+ this.getPageAttr(this.page_id)
84
+ .then(async (res) => {
85
+
86
+ //设置页面信息
87
+ this.pageAttr = {...this.pageAttr, ...this.parsePageConfig(res)};
88
+ if (this.pageAttr['config']) this.pageAttr['configs'] = this.pageAttr['config'];
89
+
90
+ //预览模式设置topBar属性
91
+ if (this.$configProject.isPreview) {
92
+ this.setPreviewSetPageConfig(this.pageAttr.is_bar_custom === 'custom');
93
+ } else this.setPageConfig(this.pageAttr);
94
+
95
+ //计算页面插件信息
96
+ this.containers = this.getContainerGroup(res['containers']);
97
+
98
+ //保存页面headers变量
99
+ if (res['headers']) this.setPagesHeader(res['headers']);
100
+ else this.setPagesHeader(null);
101
+
102
+ //保存页面权限
103
+ if (res['permission']) this.setPagesPermission(res['permission']);
104
+ else this.setPagesPermission({can_card: false, can_sign: false});
105
+ this.loadStatus = true;
106
+
107
+ //检查用户是否登录
108
+ if (!await this.checkLoginAndCardLogin(res.permission['can_sign'])) {
109
+ return;
110
+ }
111
+
112
+ //登陆测试卡
113
+ if(this.checkMockCard()) {
114
+ if(this.getMockCard()){
115
+ if (!await this.loginCardMock({card_number: this.getMockCard()})) {
116
+ this.$xdAlert({
117
+ content: '当前登陆的卡券或服务不可用,请重试!',
118
+ width: '60vw',
119
+ time: 3000
120
+ })
121
+ return
122
+ }
123
+ }
124
+ else{
125
+ this.$xdAlert({
126
+ content: '请输入正确券号,请重试!',
127
+ width: '60vw',
128
+ time: 3000
129
+ })
130
+ return
131
+ }
132
+ }
133
+
134
+ //正常卡登陆
135
+ else{
136
+ //检查用户卡是否登录
137
+ if (!await this.checkLoginAndCardLogin(res.permission['can_card'], 'card')) {
138
+ return;
139
+ }
140
+ }
141
+
142
+
143
+
144
+ //用户状态已经检查完成
145
+ this.isCheckAuth = true;
146
+
147
+
148
+ //设置标题
149
+
150
+ // #ifdef MP-WEIXIN
151
+ uni.setNavigationBarTitle({
152
+ title: '首页'
153
+ });
154
+
155
+ // #endif
156
+
157
+ // #ifdef H5
158
+ if (this.$configProject.type === 'food') {
159
+ let xd = getApp().globalData.$xd;
160
+ if (xd && xd.brandInfo && xd.brandInfo.name) {
161
+ document.title = xd.brandInfo.name;
162
+ this.setH5Title('首页');
163
+ }
164
+ } else {
165
+ if (this.projectAttr['site_name'] || this.projectAttr['seo_title']) {
166
+ document.title = this.projectAttr['seo_title'] || this.projectAttr['site_name'];
167
+ }
168
+ this.setH5Title('首页');
169
+ }
170
+
171
+ // #endif
172
+
173
+ //执行onload事件
174
+ if (this.isOnLoad) {
175
+ console.log('exec.created', new Date().getTime() - this.time, 'ms');
176
+ new JfbEvent('onJfbLoad', {
177
+ vm: this,
178
+ data: this.options,
179
+ });
180
+ }
181
+ })
182
+ .catch();
183
+
184
+ // #ifdef H5
185
+ if (this.$configProject.viewType === 'preview') {
186
+ XdBus.addEvent('onDelPackage', (data) => {
187
+ this.deleteComponent(data);
188
+ });
189
+
190
+ //注册事件
191
+ this.regAddComponent();
192
+ this.editComponent();
193
+ this.regMoveComponent()
194
+ }
195
+ // #endif
196
+ },
197
+
198
+ /**
199
+ * @description 检查页面强制卡登陆(废弃)
200
+ * @param can_card
201
+ */
202
+ checkNameSpace(can_card) {
203
+ return true;
204
+ if (!can_card) {
205
+ console.warn('not-card-login:非强制卡登陆')
206
+ return new Promise((resolve)=>{
207
+ resolve(true)
208
+ });
209
+ }
210
+
211
+ let maxNTime = 30;
212
+ let timer = null;
213
+ let nTime = 0;
214
+ return new Promise((resolve)=>{
215
+ console.warn('card-login:强制卡登陆');
216
+ timer = setInterval(async ()=>{
217
+ if(nTime > maxNTime){
218
+ console.warn(`card-login-to-max-time:${nTime}`)
219
+ clearInterval(timer);
220
+ }
221
+ else{
222
+ if (this.xnamespace) {
223
+ console.warn(`card-login-get-to-namespace:${this.xnamespace}`)
224
+ let status = await this.jfbAuthorize.checkLoginCardSupportBizCode(can_card, this);
225
+ resolve(status);
226
+ clearInterval(timer)
227
+ }
228
+ else nTime++;
229
+ }
230
+ }, 50)
231
+ });
232
+
233
+ },
234
+
235
+ /**
236
+ * @description 获取页面信息
237
+ * @returns {{pageAttr: *, projectAttr: *, pagePackConfig: *}}
238
+ */
239
+ getPageAllInfo(){
240
+ return {
241
+ pageAttr: this.pageAttr,
242
+ projectAttr: this.projectAttr,
243
+ pagePackConfig: this.pagePackConfig
244
+ }
245
+ },
246
+
247
+ /**
248
+ * @description 预览模式设置页面属性
249
+ * @param type {Object} 导航模式 (false|true)false=>系统 true => 自定义
250
+ */
251
+ setPreviewSetPageConfig(type) {
252
+ console.log('navigationStyle', this.$configProject.extras)
253
+
254
+ if (type) {
255
+ this.pageAttr['showBar'] = this.pageAttr['is_bar'] || false;
256
+ this.pageAttr['backgroundImage'] = this.pageAttr.configs['background_image'] || 'none';
257
+ this.pageAttr['showBack'] = this.pageAttr['is_back'] || false;
258
+ this.pageAttr['isUseBgImage'] = !(this.pageAttr['is_use_bar_show_bg'] || false);
259
+ } else {
260
+ this.pageAttr['showBar'] = true;
261
+ this.pageAttr['backgroundImage'] = this.pageAttr.configs['background_image'] || 'none';
262
+ this.pageAttr.isUseBgImage = false;
263
+ this.pageAttr.showBack = false;
264
+ }
265
+ this.pageAttr['navigationStyleIsCustom'] = type;
266
+
267
+ //导航颜色
268
+ if(!type) this.pageAttr['barColor'] = this.pageAttr['is_bar_default_tc'] || this.$configProject.extras['top_bar_text_color'] || 'black';
269
+ else this.pageAttr['barColor'] = this.pageAttr['is_bar_custom_tc'] || this.$configProject.extras['top_bar_text_color'] || 'black';
270
+ this.pageAttr['background'] = this.pageAttr.configs['background_color'] || this.$configProject.extras.bgc || 'none';
271
+ this.pageAttr['barBgColor'] = '';
272
+
273
+
274
+ //h5使用渐变色
275
+ let templateBgcGradient = '';
276
+ let pageBgcGradient = '';
277
+
278
+
279
+ //#ifdef H5
280
+ if(type) {
281
+ if (this.$configProject.extras['bgc_gradient']) {
282
+ templateBgcGradient = this.$configProject.extras['bgc_gradient']
283
+ }
284
+ if (this.pageAttr['is_bar_bgc_gradient']) {
285
+ pageBgcGradient = this.pageAttr['is_bar_bgc_gradient']
286
+ }
287
+ }
288
+ //#endif
289
+
290
+ this.pageAttr['barBackground'] = templateBgcGradient || pageBgcGradient ||
291
+ this.pageAttr.is_bar_bgc || this.$configProject.extras.top_bar_color
292
+ || '#f8f8f8';
293
+
294
+ },
295
+
296
+ /**
297
+ * @description 解析页面configs数据
298
+ * @param res {Object} 页面数据
299
+ */
300
+ parsePageConfig(res) {
301
+ if (res.configs.background_image) res.configs.background_image = getServiceUrl(res.configs.background_image);
302
+ if (res.configs.parameters &&
303
+ this.$xdUniHelper.checkVarType(res.configs.parameters) === 'array'
304
+ ) {
305
+ res.configs.parameters = AttrToTargetValues(res.configs['parameters']);
306
+ res.configs.parameters.map(item => {
307
+ res[item['key']] = item.value
308
+ })
309
+ } else res.configs.parameters = {};
310
+ return res;
311
+ },
312
+
313
+ /**
314
+ * @description 设置标题
315
+ */
316
+
317
+ setH5Title(title) {
318
+ if (this.titleDefaultCount > 20) return;
319
+ let titleElx = document.getElementsByClassName('uni-page-head__title').item(0);
320
+ if (titleElx) {
321
+ titleElx.innerHTML = title;
322
+ } else setTimeout(() => {
323
+ this.titleDefaultCount++;
324
+ this.setH5Title(title);
325
+ }, 50);
326
+ },
327
+
328
+ /**
329
+ * @description 获取站点信息
330
+ */
331
+ getSiteAttr() {
332
+ return this.siteInfo;
333
+ },
334
+
335
+ /**
336
+ * @description 检查是否登陆
337
+ * @param permission {Boolean} 是否检查登陆
338
+ * @param type {String} 检查类型 login=用户登陆 card=>正常用户卡登陆 card_mock=>自动卡登陆
339
+ * @param isAutoJump {Boolean} 是否启动自动跳转到登陆或者卡登陆页面
340
+ */
341
+ checkLoginAndCardLogin(permission, type = 'login', isAutoJump = true) {
342
+ return new Promise((resolve) => {
343
+
344
+ //检查用户是否已经登录
345
+ if (type === 'login') {
346
+ if (permission) {
347
+
348
+ //status=true 免登或者已登陆 status=false 未登陆
349
+ this.jfbAuthorize.checkUserLogin(permission, this, isAutoJump)
350
+ .then(status => {
351
+ resolve(status)
352
+ })
353
+ .catch(status => {
354
+ console.error(status)
355
+ resolve(false)
356
+ });
357
+ }
358
+
359
+ //用户免登陆
360
+ else resolve(true)
361
+ }
362
+
363
+ //检查用户是否已经登录消费卡
364
+ if (type === 'card') {
365
+ if (permission) {
366
+
367
+ //已登陆卡
368
+ if (this.jfbAuthorize.checkCardLogin(permission, this, isAutoJump)) {
369
+ resolve(true)
370
+ }
371
+
372
+ //未登陆卡
373
+ else resolve(false)
374
+ }
375
+
376
+ //免登陆卡
377
+ else resolve(true)
378
+ }
379
+
380
+ //自动卡登陆
381
+ if (type === 'card_mock') {
382
+ if (this.jfbAuthorize.checkCardLogin(permission, this, false)) {
383
+ resolve(true)
384
+ }
385
+
386
+ //未登陆卡
387
+ else resolve(false)
388
+ }
389
+
390
+ })
391
+ },
392
+
393
+
394
+ /**
395
+ * @description 获取业务插件风格配置
396
+ * @param appid {String} 业务插件所在插件应用id
397
+ */
398
+ getStyles(appid) {
399
+ function getGradient(data){
400
+ try{
401
+ let {list,deg} = JSON.parse(data);
402
+ if (list.length === 0) return '';
403
+ if (list.length === 1) return list[0].color;
404
+ let color = list.map(item => {
405
+ return `${item.color} ${item.percentage}%`;
406
+ });
407
+ return `linear-gradient(${deg}deg,${color.join(',')})`;
408
+ }
409
+ catch (e) {
410
+ return ''
411
+ }
412
+ }
413
+
414
+ let theme = {};
415
+ (this.themesList[appid] || this.$webSetting.defaultTheme).map(item => {
416
+ if(item['key'] === '$mainGradient' || item['key'] === '$subGradient' ) {
417
+ theme[item['key']] = getGradient(item.value)
418
+ }else{
419
+ theme[item['key']] = item.value;
420
+ }
421
+ });
422
+
423
+ //设置默认值
424
+ if (!theme['$mainGradient']) theme['$mainGradient'] = theme['$mainColor'];
425
+ if (!theme['$subGradient']) theme['$subGradient'] = theme['$subMainColor'] || theme['$mainColor'];
426
+
427
+ return theme;
428
+ },
429
+
430
+ /**
431
+ * @description
432
+ * @param page {Object} 页面对象
433
+ */
434
+ setPageConfig(page = {}) {
435
+ const handle = (data, key) => {
436
+ if (this.$xdUniHelper.isEmpty(data)) return null;
437
+ let temp = {};
438
+ data.map(item => {
439
+ temp[item['key']] = item['value'];
440
+ });
441
+
442
+ if (temp[key] !== undefined) return temp[key];
443
+ else return null;
444
+ };
445
+
446
+ let pageTemp = {};
447
+ const configs = page['configs'];
448
+ let parameters = {};
449
+ if (configs['parameters']) parameters = configs['parameters'];
450
+
451
+ //页面名称
452
+ if (page['title']) pageTemp['title'] = page['title'];
453
+
454
+ //是否显示返回按钮
455
+ if (handle(parameters, "is_back") !== null) pageTemp['showBack'] = handle(parameters, "is_back");
456
+
457
+ //背景是否仅仅顶部导航显示
458
+ if (handle(parameters, "is_use_bar_show_bg") !== null) pageTemp['isUseBgImage'] = !handle(parameters, "is_use_bar_show_bg");
459
+
460
+ //是否显示顶部导航
461
+ if (handle(parameters, "is_bar") !== null) pageTemp['showBar'] = handle(parameters, "is_bar");
462
+
463
+ //背景图片
464
+ if (configs['background_image']) {
465
+ pageTemp['backgroundImage'] = getServiceUrl(configs['background_image']);
466
+ }
467
+
468
+ //背景颜色
469
+ if (configs['background_color']) pageTemp['background'] = configs['background_color'];
470
+
471
+ //非自定义模式直接隐藏自定义topBar
472
+ if (this.pagePackConfig.navigationStyle === 'default') {
473
+ pageTemp['showBar'] = false
474
+ }
475
+ this.pageAttr = Object.assign({}, this.$xdUniHelper.cloneDeep(this.pageAttr), page, pageTemp);
476
+
477
+ //设置自定义导航导航背景色
478
+ if(this.pageAttr['is_bar_custom'] === 'custom') {
479
+ let templateBgcGradient = '', pageBgcGradient='';
480
+
481
+ //#ifdef H5
482
+ if (this.$configProject.extras['bgc_gradient']) {
483
+ templateBgcGradient = this.$configProject.extras['bgc_gradient']
484
+ }
485
+ if (this.pageAttr['is_bar_bgc_gradient']) {
486
+ pageBgcGradient = this.pageAttr['is_bar_bgc_gradient']
487
+ }
488
+ //#endif
489
+ this.pageAttr['barBackground'] = templateBgcGradient || pageBgcGradient
490
+ || this.pageAttr.is_bar_bgc || this.$configProject.extras.top_bar_color
491
+ || '#f8f8f8';
492
+ this.pageAttr['barColor'] = this.pageAttr['is_bar_custom_tc'] || this.$configProject.extras['top_bar_text_color'] || 'black';
493
+ }
494
+ this.pageAttr['navigationStyleIsCustom'] = this.pageAttr['is_bar_custom'] === 'custom';
495
+ },
496
+
497
+ }
498
+ }
499
+
500
+
package/src/mocks.js ADDED
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ export default {}
4
+