jufubao-base 1.0.238-beta1 → 1.0.238-beta68

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,74 @@
1
+ 'use strict';
2
+ //#ifdef H5
3
+ import cookie from "@/common/cookie";
4
+ //#endif
5
+
6
+ export default {
7
+ data(){
8
+ return {
9
+ debuggerCount:0,
10
+ debuggerTimer:null,
11
+ jumpLogin: false,
12
+ }
13
+ },
14
+ watch:{
15
+ debuggerCount(val){
16
+ console.warn(`debuggerCount: ${val}`)
17
+ if(val >= 10) {
18
+ //#ifdef MP-WEIXIN
19
+ this.handleOpenWxDebugger();
20
+ // #endif
21
+ //#ifdef H5
22
+ this.handleOpenH5Debugger();
23
+ // #endif
24
+ this.debuggerCount = 0;
25
+ }
26
+ }
27
+ },
28
+ methods:{
29
+ openDebugger(jumpLogin = false){
30
+ this.jumpLogin = jumpLogin;
31
+ this.debuggerCount ++;
32
+ if(this.debuggerTimer){
33
+ clearTimeout(this.debuggerTimer);
34
+ this.debuggerTimer = null;
35
+ }
36
+ this.debuggerTimer = setTimeout(()=>{
37
+ this.debuggerCount = 0;
38
+ }, 2000);
39
+ },
40
+ //#ifdef MP-WEIXIN
41
+ handleOpenWxDebugger(){
42
+ if(this.$configProject.isPreview) return;
43
+ this.isDebugPreview = true;
44
+ },
45
+ // #endif
46
+
47
+ //#ifdef H5
48
+ handleOpenH5Debugger(){
49
+ if(this.$configProject.isPreview) return;
50
+ this.$xdConfirm({
51
+ title: '调试模式',
52
+ content:'即将开启体验模式或者vConsole调试模式',
53
+ confirmText:'体验码',
54
+ cancelText:'vConsole',
55
+ success:(res)=>{
56
+ if(res.confirm) {
57
+ if(this.jumpLogin && this.jfbAuthorize) {
58
+ if(this.jfbAuthorize.LoginPath) {
59
+ uni.redirectTo({
60
+ url: `${this.jfbAuthorize.LoginPath}`
61
+ })
62
+ }
63
+ }else this.isDebugPreview = true;
64
+ }
65
+ else{
66
+ cookie.set('open_vConsole_status', 1);
67
+ window.location.replace(window.location.href);
68
+ }
69
+ }
70
+ })
71
+ },
72
+ // #endif
73
+ }
74
+ }
@@ -0,0 +1,347 @@
1
+ 'use strict';
2
+ import {
3
+ AttrToTargetValues,
4
+ getContainerPropsValue,
5
+ baseCloneDeep,
6
+ } from "@/utils/xd.base";
7
+ import {JfbEvent} from "@/utils/xd.event";
8
+
9
+
10
+ export default {
11
+ data(){
12
+ return {
13
+ time: 400, //ms
14
+ dataListRefreshKey: '', //编辑时候重置key
15
+ }
16
+ },
17
+
18
+ created(){
19
+ // #ifdef H5
20
+ if (this.$configProject.viewType === 'preview') {
21
+ //注册预览模式删除插件事件
22
+ XdBus.addEvent('onDelPackage', (data) => {
23
+ this.deleteComponent(data);
24
+ });
25
+
26
+
27
+ //注册预览模式新增插件事件
28
+ this.regAddComponent();
29
+
30
+ //注册预览模式编辑插件面板事件
31
+ this.editComponent();
32
+
33
+ //注册预览模式移动插件面板事件
34
+ this.regMoveComponent()
35
+ }
36
+ // #endif
37
+ },
38
+
39
+ methods: {
40
+ // #ifdef H5
41
+ //==移动插件相关=================================
42
+ /**
43
+ * @description 绑定监听插件移动事件
44
+ */
45
+ regMoveComponent(){
46
+ XdBus.addEvent('onMoveComponents', ({container, type}) => {
47
+ let temp = baseCloneDeep(this.containers);
48
+ //先计算当前移动的插件在那个组中
49
+ let fixed = this.getFixedValue(container);
50
+ let containers = temp[fixed];
51
+ //数组为0或者为1个长度不处理
52
+ if(containers.length <= 1){
53
+ alert('当前区域只有一个组件,无需排序操作');
54
+ return;
55
+ }
56
+ let index = this.getItemToContainerIndex(containers, container.containerId);
57
+ //向上并且已经是第一个
58
+ if (type === 'up' && index === 0){
59
+ alert('已经是第一个,无需排序操作');
60
+ return;
61
+ }
62
+ //向下并且已经是最后一个
63
+ if (type === 'down' && index === (containers.length - 1)){
64
+ alert('已经是最后个,无需排序操作');
65
+ return;
66
+ }
67
+ let item = baseCloneDeep(containers[index]);
68
+ let newIndex = type === 'up' ? (index - 1): (index + 1);
69
+ containers.splice(index,1);
70
+ containers.splice(newIndex, 0, item);
71
+ temp[fixed] = containers;
72
+ let newContainers = baseCloneDeep([].concat(temp.tops, temp.bodys, temp.bottoms,temp.footers));
73
+ this.containers = baseCloneDeep(temp);
74
+
75
+ let indexObj = {};
76
+ newContainers.map((it, i) => {
77
+ indexObj[it['container_id']] = i;
78
+ })
79
+ XdBus.send('onMoveComponentsIndex', indexObj);
80
+ });
81
+ },
82
+
83
+ getItemToContainerIndex(container, containerId){
84
+ let index = null;
85
+ container.map((item,idx) =>{
86
+ if(containerId === item['container_id']) index = idx
87
+ })
88
+ return index;
89
+ },
90
+
91
+ getFixedValue(value){
92
+ let fixed = 'bodys';
93
+ let attr = value['container']['component']['attrs'];
94
+ attr.map(item=>{
95
+ if(item['key'] ==='fixed') {
96
+ if (item['value'] === 'top') fixed = 'tops';
97
+ if (item['value'] === 'bottom') fixed = 'bottoms';
98
+ if (item['value'] === 'footer') fixed = 'footers';
99
+ }
100
+ })
101
+ return fixed;
102
+ },
103
+ //==移动插件相关=================================
104
+
105
+
106
+ //==操作插件相关=================================
107
+ /**
108
+ * @description 删除插件
109
+ */
110
+ deleteComponent(data) {
111
+ let temp = baseCloneDeep(this.containers);
112
+ temp['refreshKey'] = this.$xdUniHelper.randomChar(20);
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=>{
126
+ return item !== data.containerId
127
+ });
128
+
129
+ switch (fixed) {
130
+ case 'top':
131
+ temp.tops = temp.tops.filter(item => {
132
+ return data.containerId !== item['container_id'];
133
+ });
134
+ temp.topHeight -= height;
135
+ break;
136
+ case 'bottom':
137
+ temp.bottoms = temp.bottoms.filter(item => {
138
+ return data.containerId !== item['container_id'];
139
+ });
140
+ temp.bottomHeight -= height;
141
+ break;
142
+ case 'footer':
143
+ temp.footers = temp.footers.filter(item => {
144
+ return data.containerId !== item['container_id'];
145
+ });
146
+ temp.footerHeight -= height;
147
+ break;
148
+ default:
149
+ temp.bodys = temp.bodys.filter(item => {
150
+ return data.containerId !== item['container_id'];
151
+ });
152
+ }
153
+ this.containers = temp;
154
+ this.$nextTick(() => {
155
+ setTimeout(() => {
156
+ this.setIframeHeigth(false);
157
+ XdBus.send('onDelViewUpdateBoard', {});
158
+ this.dataListRefreshKey = this.$xdUniHelper.randomChar(20);
159
+ }, 100)
160
+ })
161
+ },
162
+
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;
179
+ },
180
+
181
+ /**
182
+ * @description 编辑页面操作
183
+ */
184
+ editComponent() {
185
+ XdBus.addEvent('onEditComponent', ({container, isHeight}) => {
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
+ });
199
+ switch (fixed) {
200
+ case 'top':
201
+ let tops = this.reInitData(temp.tops, container);
202
+ temp.tops = tops.data;
203
+ if(tops.status) hasHiddenDoStatus = true;
204
+
205
+ if (isHeight) {
206
+ if (container.hidden) temp.topHeight -= height;
207
+ else temp.topHeight += height;
208
+ }
209
+ break;
210
+ case 'bottom':
211
+ let bottoms = this.reInitData(temp.bottoms, container);
212
+ temp.bottoms = bottoms.data;
213
+ if(bottoms.status) hasHiddenDoStatus = true;
214
+
215
+ if (isHeight) {
216
+ if (container.hidden) temp.bottomHeight -= height;
217
+ else temp.bottomHeight += height;
218
+ }
219
+
220
+ break;
221
+ case 'footer':
222
+ let footers = this.reInitData(temp.footers, container);
223
+ temp.footers = footers.data;
224
+ if(footers.status) hasHiddenDoStatus = true;
225
+
226
+ if(isHeight) {
227
+ if (container.hidden) temp.footerHeight -= height;
228
+ else temp.footerHeight += height;
229
+ }
230
+ break;
231
+ default:
232
+ let bodys = this.reInitData(temp.bodys, container);
233
+ temp.bodys = bodys.data;
234
+ if(bodys.status) hasHiddenDoStatus = true;
235
+ }
236
+
237
+ //编辑模式更新高度需要设置ref
238
+ if(isHeight) {
239
+ if (container.hidden) {
240
+ this.refs = this.refs.filter(ref => {
241
+ return ref !== container['container_id']
242
+ });
243
+ } else {
244
+ this.refs.push(container['container_id'])
245
+ }
246
+ }
247
+ this.containers = temp;
248
+ this.$nextTick(() => {
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
+
265
+ this.setIframeHeigth(false);
266
+ this.dataListRefreshKey = this.$xdUniHelper.randomChar(20);
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)
321
+ })
322
+ })
323
+ },
324
+
325
+
326
+ //==操作插件相关=================================
327
+
328
+ /**
329
+ * @description 设置容器高度高度问题
330
+ */
331
+ setIframeHeigth(type = true) {
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
+ }
339
+ }
340
+ },
341
+
342
+ // #endif
343
+
344
+ }
345
+ }
346
+
347
+