1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<template>
<app-rawitem
v-if="type == 'FIELD_IMAGE' || type == 'FIELD_TEXT_DYNAMIC'"
class="app-preset-rawitem"
:rawItemDetail="rawItemDetail"
:imageDetail="{ imagePath: imgUrl }"
:contentType="contentType"
:content="value"
:context="context"
:viewparams="viewparams"
/>
<div class="app-preset-rawitem" v-else-if="type == 'STATIC_VIDEOPLAYER'">
<app-video :videoParmas="rawParams" />
</div>
<app-mob-carousel
v-else-if="type == 'STATIC_CAROUSEL'"
class="app-preset-rawitem"
:data="rawParams"
:style="getContentStyle(rawItemDetail.cssStyle)"
:class="getCssName(rawItemDetail)"
></app-mob-carousel>
<app-nav-pos
v-else-if="type == 'NAV_POS'"
class="app-preset-rawitem"
:navData="navData"
></app-nav-pos >
</template>
<script lang="ts">
import { Environment } from '@/environments/environment';
import { Vue, Component, Prop } from 'vue-property-decorator';
import './app-preset-rawitem.less';
@Component({})
export default class AppPresetRawitem extends Vue {
/**
* 父项所有数据
*
* @type {*}
* @memberof AppPresetRawitem
*/
@Prop() public contextData?: any;
/**
* 输入值
*
* @type {*}
* @memberof AppPresetRawitem
*/
@Prop() public value!: any;
/**
* 名称
*
* @type {string}
* @memberof AppPresetRawitem
*/
@Prop() public name!: string;
/**
* 类型
*
* @type {string}
* @memberof AppPresetRawitem
*/
@Prop() public type?: string;
/**
* 应用上下文
*
* @type {*}
* @memberof AppPresetRawitem
*/
@Prop() context: any;
/**
* 视图参数
*
* @type {*}
* @memberof AppPresetRawitem
*/
@Prop() viewparams: any;
/**
* 模型
*
* @type {*}
* @memberof AppPresetRawitem
*/
@Prop() detailModel: any;
/**
* 直接内容模型
*
* @type {*}
* @memberof AppPresetRawitem
*/
@Prop() rawItemDetail: any;
/**
* 图片模型
*
* @type {*}
* @memberof AppPresetRawitem
*/
@Prop() imageDetail: any;
/**
* 导航数据
*
* @type {*}
* @memberof AppPresetRawitem
*/
@Prop() navData: any;
/**
* 内容类型
*
* @type {string}
* @memberof AppPresetRawitem
*/
public contentType: string = '';
/**
* 直接内容参数
*
* @type {*}
* @memberof AppPresetRawitem
*/
public rawParams: any = {};
/**
* 下载文件路径
*
* @memberof AppPreSetRowItem
*/
protected downloadUrl = Environment.BaseUrl + Environment.ExportFile;
/**
* 图片路径
*
* @memberof AppPreSetRowItem
*/
get imgUrl(): string {
let url: string = '';
if (this.value && typeof this.value == 'string') {
try {
const _files = JSON.parse(this.value);
const file = _files instanceof Array ? _files[0] : null;
url = file && file.id ? `${this.downloadUrl}/${file.id}` : '';
} catch (error) {
return '';
}
}
return url;
}
/**
* Vue生命周期 --- Created
*
* @memberof AppPresetRawitem
*/
created() {
this.init();
}
/**
* 初始化
*
* @memberof AppPresetRawitem
*/
protected init() {
switch (this.type) {
case 'FIELD_IMAGE':
this.handleDynaImg();
break;
case 'FIELD_TEXT_DYNAMIC':
this.handleDynaText();
break;
case 'STATIC_VIDEOPLAYER':
this.handleStaticVideo();
break;
case 'STATIC_CAROUSEL':
this.handleStaticCarousel();
break;
case 'STATIC_TEXT':
break;
case 'STATIC_LABEL':
break;
case 'STATIC_IMAGE':
break;
case 'NAV_POS':
case 'NAV_TABS':
default:
console.warn(`${this.type}暂未支持`);
break;
}
}
/**
* 处理动态图片
*
* @memberof AppPresetRawitem
*/
protected handleDynaImg() {
this.contentType = 'IMAGE';
}
/**
* 处理动态文本
*
* @memberof AppPresetRawitem
*/
protected handleDynaText() {
this.contentType = 'RAW';
}
/**
* 处理静态视频播放
*
* @memberof AppPresetRawitem
*/
protected handleStaticVideo() {
if (this.rawItemDetail && this.rawItemDetail.getPSRawItemParams) {
const rawParams: any = {};
this.rawItemDetail.getPSRawItemParams.forEach((param: any) => {
rawParams[param.key.toLowerCase()] = param.value;
});
this.rawParams = rawParams;
}
}
/**
* 处理静态轮播图
*
* @memberof AppPresetRawitem
*/
protected handleStaticCarousel() {
let swipeData: any[] = [];
let swipeConfig: any = {};
if (this.rawItemDetail && this.rawItemDetail.getPSRawItemParams) {
// 判断imgsData后两位是否有配置参数
const imgsData = this.rawItemDetail.getPSRawItemParams;
const configItem = imgsData.findIndex((item: any) => Object.is(item.key, 'autoplay'));
if (configItem > -1) {
// 有配置参数就截掉配置参数
swipeData = imgsData.slice(0, -2);
swipeConfig = this.setSwipeConfig(imgsData.slice(-2));
} else {
swipeData = imgsData;
swipeConfig = this.setSwipeConfig(imgsData);
}
}
swipeData = swipeData.map((item: any) => {
return this.addressProcessing(item);
});
this.rawParams = {
swipeData: swipeData,
swipeConfig: swipeConfig,
};
}
/**
* @description 设置轮播图配置
* @param {*}
* @memberof AppRawItem
*/
private setSwipeConfig(data: any) {
const autoPlay: any = data.find((item: any) => Object.is(item.key, 'autoplay')) || {};
const timeSpan: any = data.find((item: any) => Object.is(item.key, 'timespan')) || {};
return {
isAuto: Object.is(autoPlay?.value, '1') ? true : false,
timeSpan: Number(timeSpan?.value) || 0,
};
}
/**
* 处理轮播图地址
*
* @memberof AppPresetRawitem
*/
private addressProcessing(item: any) {
let _item: any = {};
_item.linkPath = item.linkPath;
_item.imgPath = this.getImagePath(item);
_item.iconClass = this.getImageClass(item) || '';
return _item;
}
/**
* 获取图片路径
*
* @memberof AppPresetRawitem
*/
public getImagePath(item: any) {
if (item && item.getPSSysImage && item.getPSSysImage.imagePath) {
return item.getPSSysImage.imagePath;
}
}
/**
* @description 获取imageClass
* @param {*}
* @memberof AppRawItem
*/
public getImageClass(item: any) {
if (item && item.getPSSysImage && item.getPSSysImage.cssClass) {
return item.getPSSysImage.cssClass;
}
}
/**
* 获取内容样式
*
* @memberof AppPresetRawitem
*/
public getContentStyle(data: any) {
if (data && data.cssStyle) {
const res = data.cssStyle.split('\n');
const target: string[] = [];
res.forEach((item: any) => {
target.push(...item.split(';').filter((value: any) => value));
});
return target
.filter((value: string) => {
return value.split(':').length === 2;
})
.join(';');
}
}
/**
* @description 获取cssName
* @param {*} data
*/
public getCssName(data: any) {
if (data && data.getPSSysCss && data.getPSSysCss.cssName) {
return data.getPSSysCss.cssName;
}
}
}
</script>