|
@@ -0,0 +1,263 @@
|
|
1
|
+import { ref, computed, reactive, nextTick } from 'vue'
|
|
2
|
+import { reactiveTableAndAny } from '@/api/ApiModel'
|
|
3
|
+import _ from 'lodash'
|
|
4
|
+
|
|
5
|
+//创意素材
|
|
6
|
+function handleMultiple({
|
|
7
|
+ originalityBasicInfoData,
|
|
8
|
+ computeCount,
|
|
9
|
+ ResuseConfigRef
|
|
10
|
+}) {
|
|
11
|
+ const CreativeMaterialRef = ref<{
|
|
12
|
+ switchShow: (val: boolean, isEdit: boolean, arr: any) => void,
|
|
13
|
+ clearAllEvent: () => void, creatice_reuseEvent: () => void, deleAcEvent: (arr: any, haveAssign: boolean) => void
|
|
14
|
+ }>()
|
|
15
|
+ const cMaterial = reactive<reactiveTableAndAny>({
|
|
16
|
+ list: [],
|
|
17
|
+ list_copy: [],
|
|
18
|
+ key: 1,
|
|
19
|
+ haveCoverOrVideo: 1, // 1:视频和图片 2:视频 3:图片
|
|
20
|
+ video_tips: {},
|
|
21
|
+ image_tips: {},
|
|
22
|
+ array_property: [],//image_list 时图片个数限制 max_number min_number
|
|
23
|
+ resResult: [],//提审后台需要的值
|
|
24
|
+ haveShowVideoObj: {
|
|
25
|
+ show: false, // 是否展示视频号
|
|
26
|
+ name: '',
|
|
27
|
+ val: false,// 视频号是否开启
|
|
28
|
+ },
|
|
29
|
+ imgOrVideoInfo: {},//视频或者图片需要的数据详情
|
|
30
|
+ })
|
|
31
|
+
|
|
32
|
+ //处理素材返回来的值
|
|
33
|
+ const handle_resResult = (resResult: any, val: any) => {
|
|
34
|
+ // let str_imageorVideo: any = originalityBasicInfoData?.receiveForm?.originalityForm?.api_value?.originalityForm
|
|
35
|
+ let resArr: any = []
|
|
36
|
+ console.log('resResultresResult', resResult)
|
|
37
|
+ resResult.forEach(item => {
|
|
38
|
+ if (item) {
|
|
39
|
+ let obj: any = {}
|
|
40
|
+ obj.account_id = item.account_id
|
|
41
|
+ obj.list = []
|
|
42
|
+ for (let i in item) {
|
|
43
|
+ let arr = val.filter((v) => {
|
|
44
|
+ return v.itemId == i
|
|
45
|
+ })
|
|
46
|
+ if(item[i]?.material_res){
|
|
47
|
+ let itemObj: any = _.cloneDeep(cMaterial.imgOrVideoInfo)
|
|
48
|
+ itemObj = Object.assign(itemObj, {self_info: arr.length > 0 ? arr[0] : {}})
|
|
49
|
+ if(cMaterial.haveCoverOrVideo == 1) {//视频和图片
|
|
50
|
+ if (item[i]?.material_res?.video_id) {
|
|
51
|
+ setValueInNestedObject(itemObj, 'video_id', item[i].material_res.video_id);
|
|
52
|
+ } else if (item[i]?.material_res?.cover?.image_id) {
|
|
53
|
+ setValueInNestedObject(itemObj, 'image_id', item[i].material_res.cover.image_id);
|
|
54
|
+ }
|
|
55
|
+ if (cMaterial.haveShowVideoObj.show && cMaterial.haveShowVideoObj.name) {
|
|
56
|
+ itemObj[cMaterial.haveShowVideoObj.name] = cMaterial.haveShowVideoObj.val
|
|
57
|
+ }
|
|
58
|
+ }
|
|
59
|
+ if(cMaterial.haveCoverOrVideo == 2) {//视频
|
|
60
|
+ if (item[i]?.material_res?.video_id) {
|
|
61
|
+ setValueInNestedObject(itemObj, 'video_id', item[i].material_res.video_id);
|
|
62
|
+ }
|
|
63
|
+ }
|
|
64
|
+ if(cMaterial.haveCoverOrVideo == 3) {//图片
|
|
65
|
+ if(itemObj.image && item[i]?.material_res?.image_id) {
|
|
66
|
+ setValueInNestedObject(itemObj, 'image_id', item[i].material_res.cover.image_id);
|
|
67
|
+ }
|
|
68
|
+ if(itemObj.image_list && item[i]?.material_res?.image_id) {
|
|
69
|
+ let imageArr: any = []
|
|
70
|
+ imageArr.push(item[i]?.material_res?.image_id)
|
|
71
|
+ setValueInNestedObject(itemObj, 'image_list', imageArr);
|
|
72
|
+ }
|
|
73
|
+ }
|
|
74
|
+ obj.list.push(itemObj)
|
|
75
|
+ }
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+ // if (str_imageorVideo == 'video' && item[i]?.material_res) {
|
|
79
|
+ // let itemObj: any = {
|
|
80
|
+ // self_info: arr.length > 0 ? arr[0] : {}
|
|
81
|
+ // }
|
|
82
|
+ // if (item[i]?.material_res?.video_id) {
|
|
83
|
+ // itemObj.video = item[i].material_res.video_id
|
|
84
|
+ // } else if (item[i]?.material_res?.cover?.image_id) {
|
|
85
|
+ // itemObj.image = item[i].material_res.cover.image_id
|
|
86
|
+ // }
|
|
87
|
+ // if (cMaterial.haveShowVideoObj.show && cMaterial.haveShowVideoObj.name) {
|
|
88
|
+ // itemObj[cMaterial.haveShowVideoObj.name] = cMaterial.haveShowVideoObj.val
|
|
89
|
+ // }
|
|
90
|
+ // obj.list.push(itemObj)
|
|
91
|
+ // } else if (str_imageorVideo == 'img' && item[i]?.material_res) {
|
|
92
|
+ // if (item[i]?.material_res?.image_id) {
|
|
93
|
+ // let imageArr: any = []
|
|
94
|
+ // imageArr.push(item[i]?.material_res?.image_id)
|
|
95
|
+ // obj.list.push({
|
|
96
|
+ // image_list: imageArr,
|
|
97
|
+ // self_info: arr.length > 0 ? arr[0] : {}
|
|
98
|
+ // })
|
|
99
|
+ // }
|
|
100
|
+ // }
|
|
101
|
+ }
|
|
102
|
+ resArr.push(obj)
|
|
103
|
+ }
|
|
104
|
+ })
|
|
105
|
+ return resArr
|
|
106
|
+ }
|
|
107
|
+ //创意素材值回显
|
|
108
|
+ const assignEvent_CreativeMaterial = async (val: any, videoOnPuse?: any) => {
|
|
109
|
+ cMaterial.list_copy = _.cloneDeep(val)
|
|
110
|
+ cMaterial.haveShowVideoObj.val = videoOnPuse
|
|
111
|
+ console.log('val',val)
|
|
112
|
+ //所有素材列表,此时的素材个数已是正确的
|
|
113
|
+ let cMaterial_resResult_list: any = []
|
|
114
|
+ val.forEach(vItem => {
|
|
115
|
+ cMaterial_resResult_list = cMaterial_resResult_list.concat(vItem.resResult)
|
|
116
|
+ })
|
|
117
|
+ console.log('cMaterial_resResult_list', cMaterial_resResult_list);
|
|
118
|
+
|
|
119
|
+ let arr_: any = []
|
|
120
|
+ let cloneRes: any = await handle_resResult(_.cloneDeep(cMaterial_resResult_list), _.cloneDeep(val))
|
|
121
|
+ //图片形式的originalityBasicInfoData.params格式需要给
|
|
122
|
+ console.log(originalityBasicInfoData, 'assignEvent_CreativeMaterial');
|
|
123
|
+ console.log(cloneRes, 'cloneRes');
|
|
124
|
+ await originalityBasicInfoData.params.forEach(item => {
|
|
125
|
+ cloneRes.forEach(cItem => {
|
|
126
|
+ if (item.account_id == cItem.account_id) {
|
|
127
|
+ cItem.list.forEach(c => {
|
|
128
|
+ let outerAdcreative = _.cloneDeep(item)
|
|
129
|
+ outerAdcreative.adcreative_elements = Object.assign(outerAdcreative.adcreative_elements, c)
|
|
130
|
+ arr_.push(outerAdcreative)
|
|
131
|
+ })
|
|
132
|
+ }
|
|
133
|
+ })
|
|
134
|
+ })
|
|
135
|
+
|
|
136
|
+ cMaterial.key++
|
|
137
|
+ cMaterial.resResult = arr_
|
|
138
|
+ await computeCount()
|
|
139
|
+ console.log('cMaterial.resResult', cMaterial.resResult);
|
|
140
|
+ if (val && val.length > 0) {
|
|
141
|
+ close_reuse_loading()
|
|
142
|
+ }
|
|
143
|
+ }
|
|
144
|
+
|
|
145
|
+ //得到是否有封面 , 以及视频和图片尺寸 / 获取是否展示-开启视频号
|
|
146
|
+ const get_cover_info = () => {
|
|
147
|
+ console.log('创意基本信息originalityBasicInfoData', originalityBasicInfoData)
|
|
148
|
+ let obj: any = originalityBasicInfoData?.apiResult?.adTemplateItem?.adcreative_elements
|
|
149
|
+ if (obj?.finder_object_visibility?.name) { // 是否展示视频号
|
|
150
|
+ cMaterial.haveShowVideoObj.show = true
|
|
151
|
+ cMaterial.haveShowVideoObj.name = obj.finder_object_visibility.name
|
|
152
|
+ } else {
|
|
153
|
+ cMaterial.haveShowVideoObj.show = false
|
|
154
|
+ }
|
|
155
|
+
|
|
156
|
+ for (let key in cMaterial.imgOrVideoInfo) {//清空数据
|
|
157
|
+ delete cMaterial.imgOrVideoInfo[key]
|
|
158
|
+ }
|
|
159
|
+ //获取数据
|
|
160
|
+ let situationArr: { type: string, _tips: any }[] = []
|
|
161
|
+ if (obj.video) {
|
|
162
|
+ situationArr.push({
|
|
163
|
+ type: 'video',
|
|
164
|
+ _tips: obj?.video?.restriction?.video_restriction
|
|
165
|
+ })
|
|
166
|
+ cMaterial.imgOrVideoInfo['video'] = 'video_id'
|
|
167
|
+ }
|
|
168
|
+ if (obj.image) {
|
|
169
|
+ situationArr.push({
|
|
170
|
+ type: 'image',
|
|
171
|
+ _tips: obj?.image?.restriction?.image_restriction
|
|
172
|
+ })
|
|
173
|
+ cMaterial.imgOrVideoInfo['image'] = 'image_id'
|
|
174
|
+ }
|
|
175
|
+ if (obj.short_video_struct && obj.short_video_struct.child) {
|
|
176
|
+ cMaterial.imgOrVideoInfo['short_video_struct'] = {}
|
|
177
|
+ if (obj.short_video_struct.child.short_video1) {
|
|
178
|
+ situationArr.push({
|
|
179
|
+ type: 'video',
|
|
180
|
+ _tips: obj?.short_video_struct?.child?.short_video1?.restriction?.video_restriction
|
|
181
|
+ })
|
|
182
|
+ cMaterial.imgOrVideoInfo['short_video_struct']['short_video1'] = 'video_id'
|
|
183
|
+ }
|
|
184
|
+ if (obj.short_video_struct.child.short_video2) {
|
|
185
|
+ situationArr.push({
|
|
186
|
+ type: 'video',
|
|
187
|
+ _tips: obj?.short_video_struct?.child?.short_video2?.restriction?.video_restriction
|
|
188
|
+ })
|
|
189
|
+ cMaterial.imgOrVideoInfo['short_video_struct']['short_video2'] = 'video_id'
|
|
190
|
+ }
|
|
191
|
+ if (obj.short_video_struct.child.video_cover_img_id) {
|
|
192
|
+ situationArr.push({
|
|
193
|
+ type: 'image',
|
|
194
|
+ _tips: obj?.short_video_struct?.child?.video_cover_img_id?.restriction?.image_restriction
|
|
195
|
+ })
|
|
196
|
+ cMaterial.imgOrVideoInfo['short_video_struct']['video_cover_img_id'] = 'image_id'
|
|
197
|
+ }
|
|
198
|
+ }
|
|
199
|
+ if (obj.image_list) {
|
|
200
|
+ situationArr.push({
|
|
201
|
+ type: 'image_list',
|
|
202
|
+ _tips: obj?.image_list?.restriction?.image_restriction
|
|
203
|
+ })
|
|
204
|
+ cMaterial.array_property = obj?.image_list?.array_property;
|
|
205
|
+ cMaterial.imgOrVideoInfo['image_list'] = 'image_list'
|
|
206
|
+ }
|
|
207
|
+ console.log('situationArr', situationArr)
|
|
208
|
+ // 留口子 现在逻辑是image video image_list不共存 暂未发现共存的情况
|
|
209
|
+ situationArr.forEach((item)=>{
|
|
210
|
+ if(item.type == 'video'){
|
|
211
|
+ cMaterial.video_tips = item._tips
|
|
212
|
+ }
|
|
213
|
+ if(item.type == 'image' || item.type == 'image_list'){
|
|
214
|
+ cMaterial.image_tips = item._tips
|
|
215
|
+ }
|
|
216
|
+ })
|
|
217
|
+ let transit_arr = situationArr.map((v) => v.type)
|
|
218
|
+ if (transit_arr.includes('image') && transit_arr.includes('video')) {
|
|
219
|
+ cMaterial.haveCoverOrVideo = 1
|
|
220
|
+ } else if (transit_arr.includes('video')) {
|
|
221
|
+ cMaterial.haveCoverOrVideo = 2
|
|
222
|
+ } else if (transit_arr.includes('image')) {
|
|
223
|
+ cMaterial.haveCoverOrVideo = 3
|
|
224
|
+ } else if (transit_arr.includes('image_list')) {
|
|
225
|
+ cMaterial.haveCoverOrVideo = 3
|
|
226
|
+ }
|
|
227
|
+ }
|
|
228
|
+
|
|
229
|
+ //关闭复用loading和弹框
|
|
230
|
+ const close_reuse_loading = () => {
|
|
231
|
+ //复用回显成功后再关闭全屏loading
|
|
232
|
+ nextTick(() => {
|
|
233
|
+ ResuseConfigRef.value?.switchShow(false)
|
|
234
|
+ ResuseConfigRef.value?.switchShow_loading(false)
|
|
235
|
+ })
|
|
236
|
+ }
|
|
237
|
+
|
|
238
|
+ //递归赋值
|
|
239
|
+ const setValueInNestedObject = (obj, targetValue, newValue) => {
|
|
240
|
+ for (const key in obj) {
|
|
241
|
+ if (obj[key] === targetValue) {
|
|
242
|
+ obj[key] = newValue;
|
|
243
|
+ return true; // 找到并赋值,返回 true 表示成功
|
|
244
|
+ } else if (typeof obj[key] === 'object') {
|
|
245
|
+ // 递归搜索下一层
|
|
246
|
+ if (setValueInNestedObject(obj[key], targetValue, newValue)) {
|
|
247
|
+ return true; // 如果找到并赋值,返回 true
|
|
248
|
+ }
|
|
249
|
+ }
|
|
250
|
+ }
|
|
251
|
+ return false; // 没有找到目标值,返回 false 表示失败
|
|
252
|
+ }
|
|
253
|
+
|
|
254
|
+ return {
|
|
255
|
+ CreativeMaterialRef,
|
|
256
|
+ cMaterial,
|
|
257
|
+ assignEvent_CreativeMaterial,
|
|
258
|
+ get_cover_info,
|
|
259
|
+ close_reuse_loading
|
|
260
|
+ }
|
|
261
|
+}
|
|
262
|
+
|
|
263
|
+export default handleMultiple
|