jufubao-third 1.0.8 → 1.0.9-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.
@@ -1,10 +1,22 @@
1
1
  'use strict';
2
- import {mapActions} from 'vuex';
2
+ import {mapActions, mapMutations} from 'vuex';
3
+ import storage from "@/common/storage";
3
4
 
4
5
  export default {
5
6
  data() {
6
7
  return {
7
- locationStatus: false
8
+ locationStatus: false,
9
+ currentLocationCity: 'jfb_current_ajax_location_city',
10
+ useSelectCity: 'xd_user_current_access_city',
11
+ timeoutLocationTime: null,
12
+ timeoutLocationStatus: false,
13
+ }
14
+ },
15
+
16
+ destroyed() {
17
+ if(this.timeoutLocationTime) {
18
+ clearTimeout(this.timeoutLocationTime)
19
+ this.timeoutLocationTime = null;
8
20
  }
9
21
  },
10
22
 
@@ -13,23 +25,95 @@ export default {
13
25
  ...mapActions('wxAuthorize', [
14
26
  'getLoadingCityInfoByLocationLv4'
15
27
  ]),
28
+ ...mapMutations(['setCityInfo']),
16
29
 
17
- //==开启定位============
18
30
  async getCityInfoByLocation(options, cb) {
19
31
  try {
32
+ this.$xdLog.setProject('Layout.getCity.start.open.in', {
33
+ time: new Date().getTime(),
34
+ timeString: new Date().toLocaleString(),
35
+ ...options
36
+ });
20
37
  let locationInfo = await this.getLoadingCityInfoByLocationLv4(options);
21
- this.$xdLog.setProject('location.getCity.success', locationInfo);
38
+ storage.set('console_Layout.getCity.done',locationInfo)
39
+ this.$xdLog.setProject('Layout.getCity.done', {
40
+ time: new Date().getTime(),
41
+ timeString: new Date().toLocaleString(),
42
+ ...locationInfo
43
+ });
22
44
  cb(locationInfo);
23
45
  } catch (e) {
24
- this.$xdLog.setARMSCustomError('get_city_info_by_location_loading', this.$runtime.getErrorInfo(e));
25
- this.$xdLog.setProject('location.getCity.fail', {data: this.$settings.defaultCity});
46
+ storage.set('aaa_Layout.getCity.fail',1)
47
+ this.$xdLog.setProject('Layout.getCity.fail', {
48
+ time: new Date().getTime(),
49
+ timeString: new Date().toLocaleString(),
50
+ ...this.$settings.defaultCity
51
+ });
26
52
  cb({data: this.$settings.defaultCity})
27
53
  }
28
54
  },
29
55
 
30
- handleLocationDone(info) {
31
- this.$xdLog.setProject('location.done', info);
32
- this.locationStatus = true;
56
+ setDefaultCityData(defaultCity, local){
57
+ if(!defaultCity.isDefault){
58
+ storage.set(this.currentLocationCity, defaultCity, .5);
59
+ }
60
+ //用户首次定位成功设置系统自动给用户选中一个城市
61
+ if (!storage.get(this.useSelectCity)) {
62
+ this.setCityInfo(defaultCity)
63
+ }
64
+ },
65
+
66
+ timeoutLocation(location){
67
+ this.timeoutLocationTime = setTimeout(()=>{
68
+ this.setDefaultCityData(this.$settings.defaultCity);
69
+ this.$xdLog.setProject('Layout.getCity.timeout.5s', {
70
+ time: new Date().getTime(),
71
+ timeString: new Date().toLocaleString(),
72
+ ...this.$settings.defaultCity,
73
+ ...location
74
+ });
75
+ this.locationStatus = true;
76
+ this.timeoutLocationStatus = true;
77
+ }, 3000)
78
+ },
79
+
80
+ handleLocationDone(location) {
81
+ this.$xdLog.setProject('Layout.getCity.start', {
82
+ time: new Date().getTime(),
83
+ timeString: new Date().toLocaleString(),
84
+ statue:this.locationStatus,
85
+ ...location
86
+ });
87
+
88
+ //从缓存定位到的城市
89
+ if(storage.get(this.currentLocationCity)) {
90
+ this.locationStatus = true;
91
+ return;
92
+ }
93
+
94
+ //通过接口获取定位城市信息
95
+ this.$xdLog.setProject('Layout.getCity.start.send', {
96
+ time: new Date().getTime(),
97
+ timeString: new Date().toLocaleString(),
98
+ });
99
+
100
+ this.getCityInfoByLocation(location, (res)=>{
101
+ if (this.timeoutLocationStatus) return;
102
+ this.setDefaultCityData(res.data);
103
+ this.$xdLog.setProject('Layout.location.done', {
104
+ time: new Date().getTime(),
105
+ timeString: new Date().toLocaleString(),
106
+ });
107
+ if(this.timeoutLocationTime) {
108
+ clearTimeout(this.timeoutLocationTime);
109
+ this.timeoutLocationTime = null;
110
+ this.timeoutLocationStatus = false;
111
+ }
112
+
113
+ this.locationStatus = true;
114
+ });
115
+
116
+ this.timeoutLocation(location);
33
117
  },
34
118
  }
35
119
  }
@@ -4,6 +4,7 @@ import {
4
4
  getContainerPropsValue,
5
5
  baseCloneDeep,
6
6
  } from "@/utils/xd.base";
7
+ import {JfbEvent} from "@/utils/xd.event";
7
8
 
8
9
 
9
10
  export default {
@@ -15,77 +16,83 @@ export default {
15
16
  },
16
17
 
17
18
  created(){
18
- //注册预览模式删除插件事件
19
- XdBus.addEvent('onDelPackage', (data) => {
20
- this.deleteComponent(data);
21
- });
19
+ // #ifdef H5
20
+ if (this.$configProject.viewType === 'preview') {
21
+ //注册预览模式删除插件事件
22
+ XdBus.addEvent('onDelPackage', (data) => {
23
+ this.deleteComponent(data);
24
+ });
25
+
22
26
 
23
- //注册预览模式新增插件事件
24
- this.regAddComponent();
27
+ //注册预览模式新增插件事件
28
+ this.regAddComponent();
25
29
 
26
- //注册预览模式编辑插件面板事件
27
- this.editComponent();
30
+ //注册预览模式编辑插件面板事件
31
+ this.editComponent();
28
32
 
29
- //注册预览模式移动插件面板事件
30
- this.regMoveComponent()
33
+ //注册预览模式移动插件面板事件
34
+ this.regMoveComponent()
35
+ }
36
+ // #endif
31
37
  },
32
38
 
33
39
  methods: {
40
+ // #ifdef H5
34
41
  //==移动插件相关=================================
35
- regMoveComponent() {
42
+ /**
43
+ * @description 绑定监听插件移动事件
44
+ */
45
+ regMoveComponent(){
36
46
  XdBus.addEvent('onMoveComponents', ({container, type}) => {
37
47
  let temp = baseCloneDeep(this.containers);
38
-
39
48
  //先计算当前移动的插件在那个组中
40
49
  let fixed = this.getFixedValue(container);
41
50
  let containers = temp[fixed];
42
-
43
51
  //数组为0或者为1个长度不处理
44
- if (containers.length <= 1) {
52
+ if(containers.length <= 1){
45
53
  alert('当前区域只有一个组件,无需排序操作');
46
54
  return;
47
55
  }
48
56
  let index = this.getItemToContainerIndex(containers, container.containerId);
49
-
50
57
  //向上并且已经是第一个
51
- if (type === 'up' && index === 0) {
58
+ if (type === 'up' && index === 0){
52
59
  alert('已经是第一个,无需排序操作');
53
60
  return;
54
61
  }
55
-
56
62
  //向下并且已经是最后一个
57
- if (type === 'down' && index === (containers.length - 1)) {
63
+ if (type === 'down' && index === (containers.length - 1)){
58
64
  alert('已经是最后个,无需排序操作');
59
65
  return;
60
66
  }
61
-
62
67
  let item = baseCloneDeep(containers[index]);
63
- let newIndex = type === 'up' ? (index - 1) : (index + 1);
64
- containers.splice(index, 1);
68
+ let newIndex = type === 'up' ? (index - 1): (index + 1);
69
+ containers.splice(index,1);
65
70
  containers.splice(newIndex, 0, item);
66
71
  temp[fixed] = containers;
67
- let newContainers = baseCloneDeep([].concat(temp.tops, temp.bodys, temp.bottoms));
72
+ let newContainers = baseCloneDeep([].concat(temp.tops, temp.bodys, temp.bottoms,temp.footers));
73
+ this.containers = baseCloneDeep(temp);
68
74
 
69
- this.containers = baseCloneDeep.cloneDeep(temp);
70
75
  let indexObj = {};
71
76
  newContainers.map((it, i) => {
72
77
  indexObj[it['container_id']] = i;
73
- });
78
+ })
74
79
  XdBus.send('onMoveComponentsIndex', indexObj);
75
80
  });
76
81
  },
77
- getItemToContainerIndex(container, containerId) {
82
+
83
+ getItemToContainerIndex(container, containerId){
78
84
  let index = null;
79
- container.map((item, idx) => {
80
- if (containerId === item['container_id']) index = idx
85
+ container.map((item,idx) =>{
86
+ if(containerId === item['container_id']) index = idx
81
87
  })
82
88
  return index;
83
89
  },
84
- getFixedValue(value) {
90
+
91
+ getFixedValue(value){
85
92
  let fixed = 'bodys';
86
93
  let attr = value['container']['component']['attrs'];
87
- attr.map(item => {
88
- if (item['key'] === 'fixed') {
94
+ attr.map(item=>{
95
+ if(item['key'] ==='fixed') {
89
96
  if (item['value'] === 'top') fixed = 'tops';
90
97
  if (item['value'] === 'bottom') fixed = 'bottoms';
91
98
  if (item['value'] === 'footer') fixed = 'footers';
@@ -101,13 +108,24 @@ export default {
101
108
  * @description 删除插件
102
109
  */
103
110
  deleteComponent(data) {
104
- let temp = this.$xdUniHelper.cloneDeep(this.containers);
111
+ let temp = baseCloneDeep(this.containers);
105
112
  temp['refreshKey'] = this.$xdUniHelper.randomChar(20);
106
- this.refs = this.refs.filter(item => {
113
+ let fixed = 'body';
114
+ let height = 0;
115
+ data['container']['component']['attrs'].map(it => {
116
+ if (it['key'] === 'fixed') {
117
+ fixed = it['value'];
118
+ }
119
+ if (it['key'] === 'height') {
120
+ height = it['value'];
121
+ }
122
+ });
123
+
124
+ //重置refs
125
+ this.refs = this.refs.filter(item=>{
107
126
  return item !== data.containerId
108
127
  });
109
128
 
110
- let {fixed, height} = this.getFixedKey(data, false);
111
129
  switch (fixed) {
112
130
  case 'top':
113
131
  temp.tops = temp.tops.filter(item => {
@@ -133,34 +151,31 @@ export default {
133
151
  });
134
152
  }
135
153
  this.containers = temp;
136
-
137
154
  this.$nextTick(() => {
138
155
  setTimeout(() => {
139
156
  this.setIframeHeigth(false);
140
157
  XdBus.send('onDelViewUpdateBoard', {});
141
158
  this.dataListRefreshKey = this.$xdUniHelper.randomChar(20);
142
- }, this.time)
159
+ }, 100)
143
160
  })
144
161
  },
145
162
 
146
- /**
147
- * @description 接受点击加入插件操作
148
- */
149
- regAddComponent() {
150
- XdBus.addEvent('onAddComponent', (containers) => {
151
- let temp = this.$xdUniHelper.cloneDeep(this.containers);
152
- temp['refreshKey'] = this.$xdUniHelper.randomChar(20);
153
- let {fixed, height} = this.getFixedKey(containers);
154
- this.switchFixed(fixed, height, containers,temp);
155
- this.containers = temp;
156
- this.$nextTick(() => {
157
- setTimeout(() => {
158
- this.setIframeHeigth();
159
- XdBus.message('onBoardSelect', {containerId: item['container_id']});
160
- this.dataListRefreshKey = this.$xdUniHelper.randomChar(20);
161
- }, this.time)
162
- })
163
- })
163
+ reInitData(list,container){
164
+ let res = {
165
+ status: false
166
+ };
167
+ res.data = list.map(item => {
168
+ if (container['container_id'] === item['container_id']){
169
+ //有隐藏与显示操作并且显示操作需要刷新页面
170
+ if(container.hidden !== item.hidden){
171
+ container['refreshKey'] = this.$xdUniHelper.randomChar(20);
172
+ res.status = true;
173
+ }
174
+ return this.$xdUniHelper.cloneDeep(container);
175
+ }
176
+ return item;
177
+ });
178
+ return res;
164
179
  },
165
180
 
166
181
  /**
@@ -168,49 +183,59 @@ export default {
168
183
  */
169
184
  editComponent() {
170
185
  XdBus.addEvent('onEditComponent', ({container, isHeight}) => {
171
- let temp = this.$xdUniHelper.cloneDeep(this.containers);
172
- temp['refreshKey'] = this.$xdUniHelper.randomChar(20);
173
- let {fixed, height} = this.getFixedKey(container, false);
186
+ //有隐藏与显示操作并且显示操作需要刷新页面
187
+ let hasHiddenDoStatus = false;
188
+ let temp = baseCloneDeep(this.containers);
189
+ let fixed = 'body';
190
+ let height = 0;
191
+ container['component']['attrs'].map(it => {
192
+ if (it['key'] === 'fixed') {
193
+ fixed = it['value'];
194
+ }
195
+ if (it['key'] === 'height') {
196
+ height = it['value'];
197
+ }
198
+ });
174
199
  switch (fixed) {
175
200
  case 'top':
176
- temp.tops = temp.tops.map(item => {
177
- if (container['container_id'] === item['container_id']) return container;
178
- return item;
179
- });
201
+ let tops = this.reInitData(temp.tops, container);
202
+ temp.tops = tops.data;
203
+ if(tops.status) hasHiddenDoStatus = true;
204
+
180
205
  if (isHeight) {
181
206
  if (container.hidden) temp.topHeight -= height;
182
207
  else temp.topHeight += height;
183
208
  }
184
209
  break;
185
210
  case 'bottom':
186
- temp.bottoms = temp.bottoms.map(item => {
187
- if (container['container_id'] === item['container_id']) return container;
188
- return item;
189
- });
211
+ let bottoms = this.reInitData(temp.bottoms, container);
212
+ temp.bottoms = bottoms.data;
213
+ if(bottoms.status) hasHiddenDoStatus = true;
214
+
190
215
  if (isHeight) {
191
216
  if (container.hidden) temp.bottomHeight -= height;
192
217
  else temp.bottomHeight += height;
193
218
  }
219
+
194
220
  break;
195
221
  case 'footer':
196
- temp.footers = temp.footers.map(item => {
197
- if (container['container_id'] === item['container_id']) return container;
198
- return item;
199
- });
200
- if (isHeight) {
222
+ let footers = this.reInitData(temp.footers, container);
223
+ temp.footers = footers.data;
224
+ if(footers.status) hasHiddenDoStatus = true;
225
+
226
+ if(isHeight) {
201
227
  if (container.hidden) temp.footerHeight -= height;
202
228
  else temp.footerHeight += height;
203
229
  }
204
230
  break;
205
231
  default:
206
- temp.bodys = temp.bodys.map(item => {
207
- if (container['container_id'] === item['container_id']) return container;
208
- return item;
209
- });
232
+ let bodys = this.reInitData(temp.bodys, container);
233
+ temp.bodys = bodys.data;
234
+ if(bodys.status) hasHiddenDoStatus = true;
210
235
  }
211
236
 
212
237
  //编辑模式更新高度需要设置ref
213
- if (isHeight) {
238
+ if(isHeight) {
214
239
  if (container.hidden) {
215
240
  this.refs = this.refs.filter(ref => {
216
241
  return ref !== container['container_id']
@@ -220,31 +245,102 @@ export default {
220
245
  }
221
246
  }
222
247
  this.containers = temp;
223
-
224
248
  this.$nextTick(() => {
225
249
  setTimeout(() => {
250
+ if(!hasHiddenDoStatus) {
251
+ XdBus.message('onBoardSelect', {containerId: container['container_id']});
252
+ }
253
+
254
+ //由隐藏组件到显示组件时,需要触发操作组件的onJfbLoad事件
255
+ else {
256
+ if(!container.hidden) {
257
+ let ref = this.$refs[container.container_id];
258
+ if(ref instanceof Array) ref = ref[0];
259
+ if(typeof ref.onJfbLoad === 'function'){
260
+ ref.onJfbLoad(this.options)
261
+ }
262
+ }
263
+ }
264
+
226
265
  this.setIframeHeigth(false);
227
- XdBus.message('onBoardSelect', {containerId: container['container_id']});
228
266
  this.dataListRefreshKey = this.$xdUniHelper.randomChar(20);
229
- }, this.time)
267
+ }, 50)
268
+ })
269
+ })
270
+ },
271
+
272
+ /**
273
+ * @description 接受点击加入插件操作
274
+ */
275
+ regAddComponent() {
276
+ XdBus.addEvent('onAddComponent', (item) => {
277
+ let temp = baseCloneDeep(this.containers);
278
+ temp['refreshKey'] = this.$xdUniHelper.randomChar(20);
279
+ let fixed = 'body';
280
+ let height = 0;
281
+ item['component']['attrs'] = AttrToTargetValues(item['component']['attrs']);
282
+ item['component']['attrs'].map(it => {
283
+ if (it['key'] === 'fixed') {
284
+ fixed = it['value'];
285
+ }
286
+ if (it['key'] === 'height') {
287
+ height = it['value'];
288
+ }
289
+ });
290
+ switch (fixed) {
291
+ case 'top':
292
+ temp.tops.push(item);
293
+ if (!item.hidden) temp.topHeight += height;
294
+ break;
295
+ case 'bottom':
296
+ temp.bottoms.push(item);
297
+ if (!item.hidden) temp.bottomHeight += height;
298
+ break;
299
+ case 'footer':
300
+ temp.footers.push(item);
301
+ if (!item.hidden) temp.footerHeight += height;
302
+ break;
303
+ default:
304
+ temp.bodys.push(item);
305
+ }
306
+ this.containers = temp;
307
+ this.refs.push(item['container_id']);
308
+ this.$nextTick(() => {
309
+
310
+ setTimeout(() => {
311
+ this.setIframeHeigth();
312
+ XdBus.message('onBoardSelect', {containerId: item['container_id']});
313
+ this.dataListRefreshKey = this.$xdUniHelper.randomChar(20);
314
+
315
+ //现在组件时候需要触发load事件
316
+ new JfbEvent('onJfbLoad', {
317
+ vm: this,
318
+ data: this.options,
319
+ });
320
+ }, 50)
230
321
  })
231
322
  })
232
323
  },
324
+
325
+
233
326
  //==操作插件相关=================================
234
327
 
235
328
  /**
236
- * @description 刷新父级Iframe高度
237
- * @param type
329
+ * @description 设置容器高度高度问题
238
330
  */
239
331
  setIframeHeigth(type = true) {
240
- let xdLayoutEl = this.$refs[this.layoutId].$el;
241
- let height = parseInt(xdLayoutEl.style.height || window.getComputedStyle(xdLayoutEl).height);
242
- if (height !== this.indexHeight) {
243
- window['XdBus'].send('setIframeHeight', height);
244
- this.indexHeight = height;
332
+ let xdLayoutEl = this.$refs[this.layoutRef];
333
+ if(xdLayoutEl) {
334
+ let height = parseInt(xdLayoutEl.$el.style.height || window.getComputedStyle(xdLayoutEl.$el).height);
335
+ if (height !== this.indexHeight) {
336
+ window['XdBus'].send('setIframeHeight', height);
337
+ this.indexHeight = height;
338
+ }
245
339
  }
246
340
  },
247
341
 
342
+ // #endif
343
+
248
344
  }
249
345
  }
250
346