systemApi.js
8.64 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
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) {
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)
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 {
const res = await getEquityMaterialId({
merchantId: shopMerchantId,
...params
})
if (res && res.id) {
console.log(res.id, 'res.idres.idres.idres.id')
let data = await getEquityMaterialConfig({
id: res.id
})
if (data) {
let { toolList, materialInfoList } = data,
storageName = `source_${sceneType}_${shopMerchantId}`
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'])
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
}