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,251 @@
1
+ 'use strict';
2
+ import {
3
+ AttrToTargetValues,
4
+ getContainerPropsValue,
5
+ baseCloneDeep,
6
+ } from "@/utils/xd.base";
7
+
8
+
9
+ export default {
10
+ data(){
11
+ return {
12
+ time: 400, //ms
13
+ dataListRefreshKey: '', //编辑时候重置key
14
+ }
15
+ },
16
+
17
+ created(){
18
+ //注册预览模式删除插件事件
19
+ XdBus.addEvent('onDelPackage', (data) => {
20
+ this.deleteComponent(data);
21
+ });
22
+
23
+ //注册预览模式新增插件事件
24
+ this.regAddComponent();
25
+
26
+ //注册预览模式编辑插件面板事件
27
+ this.editComponent();
28
+
29
+ //注册预览模式移动插件面板事件
30
+ this.regMoveComponent()
31
+ },
32
+
33
+ methods: {
34
+ //==移动插件相关=================================
35
+ regMoveComponent() {
36
+ XdBus.addEvent('onMoveComponents', ({container, type}) => {
37
+ let temp = baseCloneDeep(this.containers);
38
+
39
+ //先计算当前移动的插件在那个组中
40
+ let fixed = this.getFixedValue(container);
41
+ let containers = temp[fixed];
42
+
43
+ //数组为0或者为1个长度不处理
44
+ if (containers.length <= 1) {
45
+ alert('当前区域只有一个组件,无需排序操作');
46
+ return;
47
+ }
48
+ let index = this.getItemToContainerIndex(containers, container.containerId);
49
+
50
+ //向上并且已经是第一个
51
+ if (type === 'up' && index === 0) {
52
+ alert('已经是第一个,无需排序操作');
53
+ return;
54
+ }
55
+
56
+ //向下并且已经是最后一个
57
+ if (type === 'down' && index === (containers.length - 1)) {
58
+ alert('已经是最后个,无需排序操作');
59
+ return;
60
+ }
61
+
62
+ let item = baseCloneDeep(containers[index]);
63
+ let newIndex = type === 'up' ? (index - 1) : (index + 1);
64
+ containers.splice(index, 1);
65
+ containers.splice(newIndex, 0, item);
66
+ temp[fixed] = containers;
67
+ let newContainers = baseCloneDeep([].concat(temp.tops, temp.bodys, temp.bottoms));
68
+
69
+ this.containers = baseCloneDeep.cloneDeep(temp);
70
+ let indexObj = {};
71
+ newContainers.map((it, i) => {
72
+ indexObj[it['container_id']] = i;
73
+ });
74
+ XdBus.send('onMoveComponentsIndex', indexObj);
75
+ });
76
+ },
77
+ getItemToContainerIndex(container, containerId) {
78
+ let index = null;
79
+ container.map((item, idx) => {
80
+ if (containerId === item['container_id']) index = idx
81
+ })
82
+ return index;
83
+ },
84
+ getFixedValue(value) {
85
+ let fixed = 'bodys';
86
+ let attr = value['container']['component']['attrs'];
87
+ attr.map(item => {
88
+ if (item['key'] === 'fixed') {
89
+ if (item['value'] === 'top') fixed = 'tops';
90
+ if (item['value'] === 'bottom') fixed = 'bottoms';
91
+ if (item['value'] === 'footer') fixed = 'footers';
92
+ }
93
+ })
94
+ return fixed;
95
+ },
96
+ //==移动插件相关=================================
97
+
98
+
99
+ //==操作插件相关=================================
100
+ /**
101
+ * @description 删除插件
102
+ */
103
+ deleteComponent(data) {
104
+ let temp = this.$xdUniHelper.cloneDeep(this.containers);
105
+ temp['refreshKey'] = this.$xdUniHelper.randomChar(20);
106
+ this.refs = this.refs.filter(item => {
107
+ return item !== data.containerId
108
+ });
109
+
110
+ let {fixed, height} = this.getFixedKey(data, false);
111
+ switch (fixed) {
112
+ case 'top':
113
+ temp.tops = temp.tops.filter(item => {
114
+ return data.containerId !== item['container_id'];
115
+ });
116
+ temp.topHeight -= height;
117
+ break;
118
+ case 'bottom':
119
+ temp.bottoms = temp.bottoms.filter(item => {
120
+ return data.containerId !== item['container_id'];
121
+ });
122
+ temp.bottomHeight -= height;
123
+ break;
124
+ case 'footer':
125
+ temp.footers = temp.footers.filter(item => {
126
+ return data.containerId !== item['container_id'];
127
+ });
128
+ temp.footerHeight -= height;
129
+ break;
130
+ default:
131
+ temp.bodys = temp.bodys.filter(item => {
132
+ return data.containerId !== item['container_id'];
133
+ });
134
+ }
135
+ this.containers = temp;
136
+
137
+ this.$nextTick(() => {
138
+ setTimeout(() => {
139
+ this.setIframeHeigth(false);
140
+ XdBus.send('onDelViewUpdateBoard', {});
141
+ this.dataListRefreshKey = this.$xdUniHelper.randomChar(20);
142
+ }, this.time)
143
+ })
144
+ },
145
+
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
+ })
164
+ },
165
+
166
+ /**
167
+ * @description 编辑页面操作
168
+ */
169
+ editComponent() {
170
+ 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);
174
+ switch (fixed) {
175
+ case 'top':
176
+ temp.tops = temp.tops.map(item => {
177
+ if (container['container_id'] === item['container_id']) return container;
178
+ return item;
179
+ });
180
+ if (isHeight) {
181
+ if (container.hidden) temp.topHeight -= height;
182
+ else temp.topHeight += height;
183
+ }
184
+ break;
185
+ case 'bottom':
186
+ temp.bottoms = temp.bottoms.map(item => {
187
+ if (container['container_id'] === item['container_id']) return container;
188
+ return item;
189
+ });
190
+ if (isHeight) {
191
+ if (container.hidden) temp.bottomHeight -= height;
192
+ else temp.bottomHeight += height;
193
+ }
194
+ break;
195
+ 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) {
201
+ if (container.hidden) temp.footerHeight -= height;
202
+ else temp.footerHeight += height;
203
+ }
204
+ break;
205
+ default:
206
+ temp.bodys = temp.bodys.map(item => {
207
+ if (container['container_id'] === item['container_id']) return container;
208
+ return item;
209
+ });
210
+ }
211
+
212
+ //编辑模式更新高度需要设置ref
213
+ if (isHeight) {
214
+ if (container.hidden) {
215
+ this.refs = this.refs.filter(ref => {
216
+ return ref !== container['container_id']
217
+ });
218
+ } else {
219
+ this.refs.push(container['container_id'])
220
+ }
221
+ }
222
+ this.containers = temp;
223
+
224
+ this.$nextTick(() => {
225
+ setTimeout(() => {
226
+ this.setIframeHeigth(false);
227
+ XdBus.message('onBoardSelect', {containerId: container['container_id']});
228
+ this.dataListRefreshKey = this.$xdUniHelper.randomChar(20);
229
+ }, this.time)
230
+ })
231
+ })
232
+ },
233
+ //==操作插件相关=================================
234
+
235
+ /**
236
+ * @description 刷新父级Iframe高度
237
+ * @param type
238
+ */
239
+ 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;
245
+ }
246
+ },
247
+
248
+ }
249
+ }
250
+
251
+
@@ -0,0 +1,132 @@
1
+ 'use strict';
2
+ import {JfbEvent} from "@/utils/xd.event";
3
+
4
+ /**
5
+ * @description 绑定生命周期 + 操作事件类方法
6
+ */
7
+ export default {
8
+ data(){
9
+ return {
10
+ isFirst: true, //是否为首次访问
11
+ currentPagesIsShow: false, //当前页面是否为显示状态
12
+ layoutInfo: null, //框架信息
13
+ options: null, //参数信息
14
+
15
+ }
16
+ },
17
+ onLoad(options) {
18
+ this.options = options;
19
+ if (this.isCheckAuth) {
20
+ console.warn('event.onLoad.onJfbLoad');
21
+ new JfbEvent('onJfbLoad', {
22
+ vm: this,
23
+ data: options,
24
+ });
25
+ console.log('exec.onLoad', new Date().getTime() - this.time, 'ms');
26
+ } else {
27
+ this.isOnLoad = true;
28
+ }
29
+ },
30
+ onPageScroll(e) {
31
+ console.warn('event.onPageScroll.onJfbScroll');
32
+ new JfbEvent('onJfbScroll', {
33
+ vm: this,
34
+ data: {e, options: this.options},
35
+ })
36
+ },
37
+ onReachBottom(e) {
38
+ console.warn('event.onReachBottom.onJfbReachBottom');
39
+ new JfbEvent('onJfbReachBottom', {
40
+ vm: this,
41
+ data: {e, options: this.options},
42
+ })
43
+ },
44
+ onShow() {
45
+ this.currentPagesIsShow = true;
46
+ if (!this.isFirst) {
47
+ console.log('exec.onShow', new Date().getTime() - this.time, 'ms');
48
+ console.warn('event.onShow.onJfbShow');
49
+ new JfbEvent('onJfbShow', {
50
+ vm: this,
51
+ data: this.options,
52
+ })
53
+ }
54
+ if (this.isFirst) {
55
+ this.isFirst = false;
56
+ }
57
+ },
58
+ onHide() {
59
+ this.currentPagesIsShow = false;
60
+ new JfbEvent('onJfbHide', {
61
+ vm: this,
62
+ data: this.options,
63
+ })
64
+ },
65
+ onUnload() {
66
+ console.warn('event.onUnload.onJfbUnload');
67
+ this.currentPagesIsShow = false;
68
+ new JfbEvent('onJfbUnload', {
69
+ vm: this,
70
+ data: this.options,
71
+ })
72
+ },
73
+ methods: {
74
+
75
+ getCurrentPagesIsShow(){
76
+ return this.currentPagesIsShow
77
+ },
78
+ /**
79
+ * @description 框架完成事件
80
+ * @param layout {object} 框架对象
81
+ * @return {Object}
82
+ */
83
+ handleDone(layout) {
84
+ this.layoutInfo = layout;
85
+
86
+ // #ifdef H5
87
+ if (this.$configProject.viewType === 'preview') {
88
+ this.$nextTick(() => {
89
+ setTimeout(() => {
90
+ this.setIframeHeigth();
91
+ }, 50)
92
+ });
93
+ }
94
+ // #endif
95
+ },
96
+
97
+ /**
98
+ * @description 框架节点发生变化事件
99
+ * @param layout {object} 框架对象
100
+ * @return {Object}
101
+ */
102
+ handleChange(layout) {
103
+ this.layoutInfo = layout;
104
+ },
105
+
106
+ /**
107
+ * 业务组件之间通信事件
108
+ */
109
+ onCustomEvent(action, data) {
110
+ if (this.currentPagesIsShow) {
111
+ console.warn('event.onCustomEvent.onJfbCustomEvent');
112
+ new JfbEvent('onJfbCustomEvent', {
113
+ vm: this,
114
+ data: {action, data, options: this.options},
115
+ })
116
+ }
117
+ },
118
+
119
+ /**
120
+ * @description 绑定自定义导航时候返回事件方法
121
+ */
122
+ back() {
123
+ console.warn('event.back.onJfbBack');
124
+ new JfbEvent('onJfbBack', {
125
+ vm: this,
126
+ data: this.options,
127
+ })
128
+ },
129
+ }
130
+ }
131
+
132
+
@@ -0,0 +1,119 @@
1
+ 'use strict';
2
+ import {mapActions, mapState, mapMutations} from 'vuex';
3
+ import {
4
+ AttrToTargetValues,
5
+ getContainerPropsValue,
6
+ baseCloneDeep,
7
+ } from "@/utils/xd.base";
8
+
9
+ export default {
10
+ data(){
11
+ return {
12
+ time: new Date().getTime(),//与页面加载速度有关
13
+ isOnLoad: false, //是否执行了onload事件
14
+ options: null, //页面参数
15
+ site_id: null, //当前网站ID
16
+ layoutInfo: null, //框架数据
17
+ indexHeight: 0, //预览模式更新Iframe高度有关
18
+ projectAttr: {}, //项目属性
19
+ settings: {}, //编译时刻项目配置对象
20
+
21
+ //保存计算当前页面使用业务组件列表
22
+ containers: {
23
+ topHeight: 0,
24
+ bottomHeight: 0,
25
+ footerHeight: 0,
26
+ tops: [],
27
+ bottoms: [],
28
+ bodys: [],
29
+ footers: [],
30
+ },
31
+ }
32
+ },
33
+ created(){
34
+ this.settings = this.$settings;
35
+ this.site_id = getApp().globalData.$xd.brandInfo.site_id;
36
+ this.projectAttr = getApp().globalData.$xd.brandInfo;
37
+ },
38
+ methods: {
39
+ ...mapActions(['getPageAttr']),
40
+ ...mapMutations(['setPagesHeader', 'setPagesPermission']),
41
+
42
+
43
+ /**
44
+ * @description 获取Containers生产的位置和高度
45
+ * @param item
46
+ * @param isTranform 是否需要转化事件 默认:true
47
+ * @returns {{fixed: *, height: *}}
48
+ */
49
+ getFixedKey(item, isTranform = true) {
50
+ let fixed = 'body';
51
+ let height = 0;
52
+ if (isTranform) item['component']['attrs'] = AttrToTargetValues(item['component']['attrs']);
53
+ item['component']['attrs'].map(it => {
54
+ if (it['key'] === 'fixed') {
55
+ fixed = it['value'];
56
+ }
57
+ if (it['key'] === 'height') {
58
+ height = it['value'];
59
+ }
60
+ });
61
+ return {fixed, height};
62
+ },
63
+
64
+ /**
65
+ * @description 计算top/bottom/footer各自所站高度
66
+ * @param fixed
67
+ * @param height
68
+ * @param oldItem
69
+ * @param containers
70
+ * @returns {*}
71
+ */
72
+ switchFixed(fixed, height, oldItem, containers ){
73
+ switch (fixed) {
74
+ case 'top':
75
+ containers.tops.push(oldItem);
76
+ if (!oldItem.hidden) containers.topHeight += height;
77
+ break;
78
+ case 'bottom':
79
+ containers.bottoms.push(oldItem);
80
+ if (!oldItem.hidden) containers.bottomHeight += height;
81
+ break;
82
+ case 'footer':
83
+ containers.footers.push(oldItem);
84
+ if (!oldItem.hidden) containers.footerHeight += height;
85
+ break;
86
+ default:
87
+ containers.bodys.push(oldItem);
88
+ }
89
+ },
90
+
91
+ /**
92
+ * @description Container数据转化
93
+ * @param containers {Array} 使用业务插件数据
94
+ * @return {Object}
95
+ */
96
+ getContainerGroup(containers) {
97
+ let temp = {
98
+ topHeight: 0,
99
+ bottomHeight: 0,
100
+ footerHeight: 0,
101
+ tops: [],
102
+ bottoms: [],
103
+ bodys: [],
104
+ footers: [],
105
+ };
106
+ let refs = [];
107
+ containers.map(item => {
108
+ item['refreshKey'] = this.$xdUniHelper.randomChar(20);
109
+ if (!item.hidden) refs.push(item['container_id']);
110
+ let {fixed, height} = this.getFixedKey(item);
111
+ this.switchFixed(fixed, height, item, temp);
112
+ });
113
+ this.refs = refs;
114
+ return temp;
115
+ },
116
+ }
117
+ }
118
+
119
+