systemApi.js
13.5 KB
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
import http from '../request/http'
import { env } from '../../env'
const ENV = env == 'ip' ? 'develop' : env,
serverConfig = {
mockRequestCount: null,
mockTimer: {},
mockCache: null
},
boutiqueServerConfig = {
mockRequestCount: null,
mockTimer: {},
mockCache: null
},
configModule = 'app-tape',
boutiqueConfigModule = 'boutique-pad-config',
configUrl = `https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=${configModule}&env=${ENV}`,
boutiqueConfigUrl = `https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=${boutiqueConfigModule}&env=${ENV}`
/**获取APP配置 */
const getMockData = async (immediate = false) => {
const MOCKDATA = uni.$storage.get('mock_data')
try {
if (!immediate && MOCKDATA && Date.now() - MOCKDATA.createTime < 5 * 60e3) {
try {
require('@/utils/logger/FloatLogConfig.js').default.applyFromMockData(MOCKDATA)
} catch (e) {
/* ignore */
}
return Promise.resolve(MOCKDATA)
} else {
if (!serverConfig.mockRequestCount || immediate) {
serverConfig.mockCache = null
serverConfig.mockRequestCount = Date.now()
const data = await http.uni_request({ url: configUrl })
data.createTime = Date.now()
serverConfig.mockCache = data
uni.$storage.set('mock_data', data)
try {
require('@/utils/logger/FloatLogConfig.js').default.applyFromMockData(data)
} catch (e) {
/* ignore */
}
return Promise.resolve(data)
} else {
const key = Date.now()
return new Promise(resolve => {
serverConfig.mockTimer[key] = setInterval(() => {
if (serverConfig.mockCache) {
clearInterval(serverConfig.mockTimer[key])
serverConfig.mockRequestCount = null
resolve(serverConfig.mockCache)
}
}, 1e3)
})
}
}
} catch (error) {
if (serverConfig.mockTimer[key]) clearInterval(serverConfig.mockTimer[key])
serverConfig.mockRequestCount = null
return Promise.reject(error)
}
}
/**
*权益配置
*/
const findReceptionpriproConfigList = data => {
return http.post({
method: 'dj.api.smartcarlife.recepiton.customer.findReceptionpriproConfigList',
projectName: 'boutique',
...data
})
}
/**
*获取后台延保素材ID
*/
const getEquityMaterialId = data => {
return http.post({
method: 'dj.api.smartcarlife.reception.home.page.material.view',
projectName: 'boutique',
...data
})
}
/**
*获取后台延保素材配置
*/
const getEquityMaterialConfig = data => {
return http.post({
method: 'dj.api.car.boutique.reception.home.page.entrance.material.detail',
projectName: 'boutique',
...data
})
}
/**
*获取轻改配置
*/
const getBoutiqueMockData = async (immediate = false) => {
const MOCKDATA = uni.$storage.get('boutique_mock_data')
try {
if (!immediate && MOCKDATA && Date.now() - MOCKDATA.createTime < 5 * 60e3) {
return Promise.resolve(MOCKDATA)
} else {
if (!boutiqueServerConfig.mockRequestCount || immediate) {
boutiqueServerConfig.mockCache = null
boutiqueServerConfig.mockRequestCount = Date.now()
const data = await http.uni_request({ url: boutiqueConfigUrl })
data.createTime = Date.now()
boutiqueServerConfig.mockCache = data
uni.$storage.set('boutique_mock_data', data)
return Promise.resolve(data)
} else {
const key = Date.now()
return new Promise(resolve => {
boutiqueServerConfig.mockTimer[key] = setInterval(() => {
if (boutiqueServerConfig.mockCache) {
clearInterval(boutiqueServerConfig.mockTimer[key])
boutiqueServerConfig.mockRequestCount = null
resolve(boutiqueServerConfig.mockCache)
}
}, 1e3)
})
}
}
} catch (error) {
if (boutiqueServerConfig.mockTimer[key]) clearInterval(boutiqueServerConfig.mockTimer[key])
boutiqueServerConfig.mockRequestCount = null
return Promise.reject(error)
}
}
// 图片版本号
const getImageVersion = async () => {
const accountInfo = await getMockData()
return accountInfo?.version || Date.now()
}
/**获取素材配置 */
const getSoureData = async (shopMerchantId, sceneType, params = {}) => {
try {
uni.$logger?.local?.info?.(`[systemApi/getSoureData] start, shopMerchantId=${shopMerchantId}, sceneType=${sceneType}`)
const res = await getEquityMaterialId({
merchantId: shopMerchantId,
...params
})
uni.$logger?.local?.info?.(`[systemApi/getSoureData] getEquityMaterialId done, id=${res?.id || ''}`)
if (res && res.id) {
console.log(res.id, 'res.idres.idres.idres.id')
let data = await getEquityMaterialConfig({
id: res.id
})
if (data) {
// detail 接口原始返回(可读写关键字段;图片 URL 过长会截断)
const detailRawForLog = {
id: data.id,
topKeys: Object.keys(data || {}),
toolListLength: data.toolList?.length || 0,
materialInfoList: (data.materialInfoList || []).map(item => {
const copy = { ...item }
;['thumbnail', 'shortTitleUrl', 'productPoster'].forEach(k => {
if (typeof copy[k] === 'string' && copy[k].length > 120) {
copy[k] = `${copy[k].slice(0, 80)}...(len=${copy[k].length})`
}
})
if (Array.isArray(copy.receptionSourceDetailList)) {
copy.receptionSourceDetailList = copy.receptionSourceDetailList.map(d => {
const detail = { ...d }
Object.keys(detail).forEach(k => {
if (typeof detail[k] === 'string' && detail[k].length > 120) {
detail[k] = `${detail[k].slice(0, 80)}...(len=${detail[k].length})`
}
})
return detail
})
}
if (Array.isArray(copy.screenList)) {
copy.screenList = copy.screenList.map(s => {
const screen = { ...s }
Object.keys(screen).forEach(k => {
if (typeof screen[k] === 'string' && screen[k].length > 120) {
screen[k] = `${screen[k].slice(0, 80)}...(len=${screen[k].length})`
}
})
return screen
})
}
return copy
})
}
console.log(
'[detail接口] dj.api.car.boutique.reception.home.page.entrance.material.detail 原始返回:',
JSON.stringify(detailRawForLog, null, 2)
)
console.log('[getSoureData] getEquityMaterialConfig response:', data)
let { toolList, materialInfoList } = data,
storageName = `source_${sceneType}_${shopMerchantId}`
console.log('[getSoureData] materialInfoList:', materialInfoList)
if (materialInfoList?.[0]) {
const first = materialInfoList[0]
console.log('[getSoureData] first item keys:', Object.keys(first))
console.log('[getSoureData] first item long-related:', {
longImage: first.longImage,
isLongImage: first.isLongImage,
is_long_image: first.is_long_image,
imageWidth: first.imageWidth,
imageHeight: first.imageHeight,
image_width: first.image_width,
image_height: first.image_height,
materialTitle: first.materialTitle,
materialName: first.materialName,
detailTitle: first.detailTitle,
thumbnailType: typeof first.thumbnail
})
if (Array.isArray(first.receptionSourceDetailList) && first.receptionSourceDetailList[0]) {
console.log(
'[getSoureData] first receptionSourceDetailList[0] keys:',
Object.keys(first.receptionSourceDetailList[0])
)
console.log(
'[getSoureData] first receptionSourceDetailList[0] long-related:',
{
longImage: first.receptionSourceDetailList[0].longImage,
isLongImage: first.receptionSourceDetailList[0].isLongImage,
imageWidth: first.receptionSourceDetailList[0].imageWidth,
imageHeight: first.receptionSourceDetailList[0].imageHeight
}
)
}
}
console.log(
'[getSoureData] longImage flags:',
(materialInfoList || []).map(i => ({
id: i.id,
detailTitle: i.detailTitle || i.materialTitle || i.materialName,
longImage: i.longImage,
isLongImage: i.isLongImage,
imageWidth: i.imageWidth,
imageHeight: i.imageHeight,
hasOwnLongImage: Object.prototype.hasOwnProperty.call(i, 'longImage'),
hasOwnIsLongImage: Object.prototype.hasOwnProperty.call(i, 'isLongImage')
}))
)
uni.$logger?.local?.info?.(`[systemApi/getSoureData] materialInfoList length=${materialInfoList?.length || 0}`)
if (params.brandId && params.subBrandId) storageName += `_${params.brandId}_${params.subBrandId}`
let insurance = materialInfoList.find(e => e.componentName == 'insurance'),
hasEquity = toolList.find(e => e.id == insurance.id)
if (insurance && hasEquity) {
let configList
try {
configList = await findReceptionpriproConfigList({})
uni.$storage.set('findReceptionpriproConfigList', configList)
} catch (error) {
configList = uni.$storage.get('findReceptionpriproConfigList')
}
const toolOtherList = configList.map(i => {
return {
id: hasEquity.id + 100 + i.id,
shortTitle: i.productName,
shortTitleUrl: i.procuctLog
}
})
toolList = toolList.concat(toolOtherList)
const moduleOtherList = configList.map(i => {
return {
id: hasEquity.id + 100 + i.id,
title: i.productName,
shortTitleUrl: i.procuctLog,
productPoster: i.productPoster,
showAlt: false,
componentName: 'CaseCenter',
receptionpriproCusCaseList: i.receptionpriproCusCaseList,
hide: true,
detailTitle: i.productName,
thumbnail: 'https://img02.glsx.com.cn/weapp/resource/app-tape/common/qsyw.webp'
}
})
materialInfoList = materialInfoList.concat(moduleOtherList)
}
data.toolList = await imgTransformBase64(toolList, ['shortTitleUrl'])
data.moduleList = await imgTransformBase64(materialInfoList, ['thumbnail', 'receptionSourceDetailList', 'screenList'])
console.log('[getSoureData] moduleList(after transform):', data.moduleList)
uni.$logger?.local?.info?.(`[systemApi/getSoureData] moduleList length=${data.moduleList?.length || 0}`)
uni.setStorageSync(storageName, {
moduleList: data.moduleList,
toolList: data.toolList,
id: res.id
})
return Promise.resolve(data)
} else throw false
} else throw false
} catch (error) {
uni.hideLoading()
if (error)
uni.showToast({
title: error,
icon: 'none',
duration: 2000
})
}
}
/**批量图片转base64 */
const imgTransformBase64 = async (imgList = [], keyList = []) => {
return await Promise.all(
imgList?.map(async e => {
await Promise.all(
Object.keys(e).map(async key => {
if (keyList.includes(key)) {
let isArray = Array.isArray(e[key])
if (isArray) {
await Promise.all(
e[key].map(async i => {
await Promise.all(
Object.keys(i).map(async k => {
// i[`original_${k}`] = JSON.parse(JSON.stringify(i[k]))
if (k == 'detailUrl' && i[k]) i[k] = await getBase64(i[k])
})
)
})
)
} else {
if (typeof e[key] === 'string' && e[key]) {
// e[`original_${key}`] = JSON.parse(JSON.stringify(e[key]))
e[key] = await getBase64(e[key])
}
if (e[key] && typeof e[key] === 'object') {
await Promise.all(
Object.keys(e[key]).map(async k => {
// e[key][`original_${k}`] = JSON.parse(JSON.stringify(e[key][k]))
if (e[key][k]) e[key][k] = await getBase64(e[key][k])
})
)
}
}
}
})
)
return e
})
)
}
/**转base64 */
const getBase64 = async url => {
return new Promise((resolve, reject) => {
uni.request({
url,
method: 'GET',
responseType: 'arraybuffer',
success: res => {
const base64 = `data:image/png;base64,${uni.arrayBufferToBase64(res.data)}`
resolve(base64)
},
fail: err => {
resolve(url)
// reject(err)
}
})
})
}
module.exports = {
getImageVersion,
getMockData,
getBoutiqueMockData,
findReceptionpriproConfigList,
getSoureData,
getEquityMaterialId,
getEquityMaterialConfig
}