system-api.uts
8.17 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
import { env } from "@/api/env.uts";
/**
* 系统/配置 API(从 gl_tape/api/module/systemApi.js 迁移)
* 可先返回 mock 对象,后续接入真实配置中心
*/
import http from "@/api/request/http.uts";
import { storage } from "@/utils/storage.uts";
const ENV_STR = env == "production" ? "prod" : (env == "develop" ? "develop" : "test");
const CONFIG_MODULE = "app-tape";
const BOUTIQUE_CONFIG_MODULE = "boutique-pad-config";
const CONFIG_BASE = "https://config-center-backend.glsx.com.cn/glsxAdmin/config";
const CONFIG_URL = `${CONFIG_BASE}?moduleUrl=${CONFIG_MODULE}&env=${ENV_STR}`;
const BOUTIQUE_CONFIG_URL = `${CONFIG_BASE}?moduleUrl=${BOUTIQUE_CONFIG_MODULE}&env=${ENV_STR}`;
const _emptyList: any[] = [] as any[];
const defaultBoutiqueMock: UTSJSONObject = {
"createTime": 0,
"moduleList": _emptyList,
"toolList": _emptyList,
"defaultCarId": ""
};
function parseStorageJson(key: string): null | UTSJSONObject {
const raw = storage.get(key);
if (raw == null) return null;
if (typeof raw === "string") {
const s = (raw as string).trim();
if (s == "" || s.length === 0) return null;
try {
return JSON.parse(s) as UTSJSONObject;
} catch {
return null;
}
}
return raw as UTSJSONObject;
}
/** 获取 APP 配置 */
export function getMockData(immediate: boolean = false): Promise<UTSJSONObject> {
const cached = parseStorageJson("mock_data");
if (!immediate && cached != null) {
const createTime = (cached.createTime as number) ?? 0;
if (Date.now() - createTime < 5 * 60 * 1000) {
return Promise.resolve(cached);
}
}
return http.uni_request({ "url": CONFIG_URL }).then((data: any): UTSJSONObject => {
const result = (data != null ? data : {}) as UTSJSONObject;
result.createTime = Date.now();
// ✅ 性能优化:异步写入 Storage,避免阻塞主线程
setTimeout(() => {
storage.set("mock_data", result, 0);
}, 0);
return result;
}).catch((): UTSJSONObject => {
const fallback: UTSJSONObject = { "createTime": Date.now() };
return fallback;
});
}
/** 获取轻改配置(moduleList, toolList, defaultCarId) */
export function getBoutiqueMockData(immediate: boolean = false): Promise<UTSJSONObject> {
const cached = parseStorageJson("boutique_mock_data");
if (!immediate && cached != null) {
const createTime = (cached.createTime as number) ?? 0;
if (Date.now() - createTime < 5 * 60 * 1000) {
return Promise.resolve(cached);
}
}
return http.uni_request({ "url": BOUTIQUE_CONFIG_URL }).then((data: any): UTSJSONObject => {
const result = (data != null ? data : {}) as UTSJSONObject;
result.createTime = Date.now();
result.moduleList = result.moduleList != null ? result.moduleList : _emptyList;
result.toolList = result.toolList != null ? result.toolList : _emptyList;
result.defaultCarId = result.defaultCarId != null ? result.defaultCarId : "";
// ✅ 性能优化:异步写入 Storage,避免阻塞主线程
setTimeout(() => {
storage.set("boutique_mock_data", result, 0);
}, 0);
return result;
}).catch((): UTSJSONObject => {
const fallback = { ...defaultBoutiqueMock, "createTime": Date.now() } as UTSJSONObject;
return fallback;
});
}
/**
* 获取后台延保素材ID
*/
export function getEquityMaterialId(data: UTSJSONObject): Promise<any> {
return http.post({
method: "dj.api.smartcarlife.reception.home.page.material.view",
projectName: "boutique",
...data
} as UTSJSONObject);
}
/**
* 获取后台延保素材配置
*/
export function getEquityMaterialConfig(data: UTSJSONObject): Promise<any> {
return http.post({
method: "dj.api.car.boutique.reception.home.page.entrance.material.detail",
projectName: "boutique",
...data
} as UTSJSONObject);
}
/**
* 权益配置
*/
export function findReceptionpriproConfigList(data: UTSJSONObject): Promise<any> {
return http.post({
method: "dj.api.smartcarlife.recepiton.customer.findReceptionpriproConfigList",
projectName: "boutique",
...data
} as UTSJSONObject);
}
/** 获取素材配置 */
export async function getSoureData(
shopMerchantId: number | string,
sceneType: number | string,
params: UTSJSONObject = {}
): Promise<any> {
try {
const res = await getEquityMaterialId({
merchantId: shopMerchantId,
...params
});
if (res != null && (res as UTSJSONObject).id != null) {
console.log((res as UTSJSONObject).id, "res.idres.idres.idres.id");
const data = await getEquityMaterialConfig({
id: (res as UTSJSONObject).id
});
if (data != null) {
const dataObj = data as UTSJSONObject;
const storageName = `source_${sceneType}_${shopMerchantId}`;
let toolList: Array<any> = [];
if (dataObj.toolList != null) {
toolList = dataObj.toolList as Array<any>;
}
let materialInfoList: Array<any> = [];
if (dataObj.materialInfoList != null) {
materialInfoList = dataObj.materialInfoList as Array<any>;
}
if (toolList.length == 0 && materialInfoList.length > 0) {
toolList = materialInfoList.map((item: any) => {
const obj = item as UTSJSONObject;
const shortTitle =
(obj.materialTitle as null | string)
?? (obj.detailTitle as null | string)
?? (obj.materialName as null | string)
?? "";
const shortTitleUrl =
(obj.thumbnail as null | string)
?? (obj.thumbnailUrl as null | string)
?? (obj.homeEntranceCover as null | string)
?? (obj.contentPicUrl as null | string)
?? "";
return {
id: obj.id,
shortTitle,
shortTitleUrl
} as UTSJSONObject;
});
}
const insurance = (materialInfoList as Array<any>).find((e: any) => (e as UTSJSONObject).componentName == "insurance");
const hasEquity = (toolList as Array<any>).find((e: any) => (e as UTSJSONObject).id == (insurance as UTSJSONObject).id);
if (insurance != null && hasEquity != null) {
let configList: Array<any> = [];
try {
configList = await findReceptionpriproConfigList({}) as Array<any>;
// ✅ 性能优化:异步写入 Storage,避免阻塞主线程
setTimeout(() => {
storage.set("findReceptionpriproConfigList", configList, 0);
}, 0);
} catch {
configList = storage.get("findReceptionpriproConfigList") as Array<any>;
}
console.log("[equity] findReceptionpriproConfigList:", configList);
const toolOtherList = (configList as Array<any>).map((i: any) => {
return {
id: ((hasEquity as UTSJSONObject).id as number) + 100 + ((i as UTSJSONObject).id as number),
shortTitle: (i as UTSJSONObject).productName,
shortTitleUrl: (i as UTSJSONObject).procuctLog
} as UTSJSONObject;
});
toolList = toolList.concat(toolOtherList);
const moduleOtherList = (configList as Array<any>).map((i: any) => {
const iObj = i as UTSJSONObject;
const productIntro =
(iObj.briefIntroduction as null | string)
?? (iObj.productIntroduction as null | string)
?? (iObj.introduction as null | string)
?? (iObj.desc as null | string)
?? "";
return {
id: ((hasEquity as UTSJSONObject).id as number) + 100 + (iObj.id as number),
title: iObj.productName,
shortTitleUrl: iObj.procuctLog,
productPoster: iObj.productPoster,
briefIntroduction: productIntro,
showAlt: false,
componentName: "CaseCenter",
receptionpriproCusCaseList: iObj.receptionpriproCusCaseList,
hide: true,
detailTitle: iObj.productName,
thumbnail: "https://img02.glsx.com.cn/weapp/resource/app-tape/common/qsyw.webp"
} as UTSJSONObject;
});
console.log("[equity] moduleOtherList:", moduleOtherList);
materialInfoList = materialInfoList.concat(moduleOtherList);
}
/** 权益素材直接使用网络 URL:App 端 `<image>` / un-image 可加载 https,转 base64 体积大、慢且无必要 */
dataObj.toolList = toolList;
dataObj.moduleList = materialInfoList;
// ✅ 返回数据,由调用方决定是否缓存
return dataObj;
} else {
throw new Error("获取数据失败");
}
} else {
throw new Error("未找到素材 ID");
}
} catch (error) {
uni.hideLoading();
if (error != null) {
uni.showToast({
title: `${error}`,
icon: "none",
duration: 2000
});
}
return Promise.reject(error);
}
}