Scene.uvue
8.61 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
<template>
<view class="fade-in-up">
<SingleColumnSkeleton v-if="loading" :count="3" />
<view v-else class="list-container">
<template v-if="sceneList.length > 0">
<view v-for="(item, index) in sceneList"
:key="index"
class="items"
:class="[item.actived ? 'active' : '', pressedIndex === index ? 'pressed' : '']"
@touchstart="handleTouchStart(index)"
@touchend="handleTouchEnd"
@click="selectScene(item, index)">
<view class="left">
<view class="scene-icon" :class="[`scene-type-${item.sceneType}`]">
<text class="scene-icon-text">{{ getSceneIconText(item.sceneType) }}</text>
</view>
</view>
<view class="right">
<text class="name">{{ item.sceneName }}</text>
<text class="shop_no">{{ item.sceneDesc }}</text>
</view>
</view>
</template>
<no-data v-else />
</view>
</view>
</template>
<script setup lang="uts">
import { defineExpose, ref } from "vue";
import { apiGetMerchantBrand, apiSelectMerchantScene } from "@/api/user-api.uts";
import NoData from "./NoData.uvue";
import SingleColumnSkeleton from "./Skeleton/SingleColumnSkeleton.uvue";
import { storage } from "@/utils/storage.uts";
type SceneItem = {
actived: boolean
sceneDesc: string
sceneName: string
sceneType: number
}
const sceneList = ref<SceneItem[]>([
{ sceneName: "轻改", sceneDesc: "太阳膜升级转化", sceneType: 1, actived: false },
{ sceneName: "会员权益/升级", sceneDesc: "权益、延保", sceneType: 0, actived: false },
{ sceneName: "二手车", sceneDesc: "二手车业务", sceneType: 7, actived: false }
]);
const loading = ref<boolean>(true);
const pressedIndex = ref<number>(-1);
let userInfo: null | UTSJSONObject = null;
let jumpTimer: number = 0;
function getSceneIconText(sceneType: number): string {
switch (sceneType) {
case 0:
return "权益";
case 1:
return "轻改";
case 7:
return "二手";
default:
return "场景";
}
}
function handleTouchStart(index: number): void {
pressedIndex.value = index;
}
function handleTouchEnd(): void {
pressedIndex.value = -1;
}
function jump(info: UTSJSONObject, data: any | null): void {
const now = Date.now();
if (now - jumpTimer < 3000) {
return;
}
jumpTimer = now;
console.log("跳转进入首页!");
if (data !== null) {
const loginRole = (data as UTSJSONObject).loginRoleOnSelectMerchant;
if (loginRole !== null) {
info.loginRoleOnSelectMerchant = loginRole;
}
}
const shopMerchantId = info.shopMerchantId as null | string;
if (shopMerchantId === null || shopMerchantId === "") {
uni.showToast({ title: "参数异常", icon: "none" });
return;
}
console.log(`调用 getMerchantBrand, merchantId: ${ shopMerchantId}`);
apiGetMerchantBrand({ merchantId: shopMerchantId }).then((res: any): void => {
console.log("getMerchantBrand 成功");
const code = (res as UTSJSONObject).code as null | string;
if (code === "0") {
const dataObj = (res as UTSJSONObject).data as null | UTSJSONObject;
const channelType = dataObj != null ? (dataObj.channelType as null | number) : null;
info.channelType = channelType ?? 1;
} else {
info.channelType = 1;
}
info.staffUuid = info.uuid;
storage.set("userInfo", info, 0);
storage.remove("boutique_YQorderSetting");
const url = "/pages/index/index";
console.log(`准备跳转: ${ url}`);
uni.switchTab({
url,
fail: (_err: any) => {
uni.reLaunch({ url });
}
});
}).catch((error) => {
console.error(`getMerchantBrand 失败: ${ JSON.stringify(error)}`);
info.channelType = 1;
storage.set("userInfo", info, 0);
const url = "/pages/index/index";
console.log(`准备跳转(catch): ${ url}`);
uni.switchTab({
url,
fail: (_err: any) => {
uni.reLaunch({ url });
}
});
});
}
function init(info: any): void {
// 将 any 转换为 UTSJSONObject
userInfo = info as UTSJSONObject;
loading.value = false;
console.log("进入选择场景页!");
const openSceneArr = userInfo.openSceneArr;
console.log(`init - openSceneArr type: ${ typeof openSceneArr}`);
if (openSceneArr != null) {
console.log(`init - openSceneArr length: ${ (openSceneArr as any[]).length}`);
} else {
console.log("init - openSceneArr is null");
}
}
function selectScene(item: SceneItem, index: number): void {
const sceneType = item.sceneType;
console.log(`选择场景${ sceneType }!`);
if (userInfo == null) {
uni.showToast({ title: "参数异常", icon: "none" });
return;
}
const openSceneArr = userInfo.openSceneArr as any[] | null;
const isSuper = userInfo.isSuper as boolean | null;
// 手动检查是否包含 sceneType(indexOf 在 App 端有 bug)
let sceneAllowed = isSuper == true;
if (!sceneAllowed && openSceneArr != null) {
let i = 0;
while (i < openSceneArr.length) {
if (openSceneArr[i] == sceneType) {
sceneAllowed = true;
break;
}
i++;
}
}
if (!sceneAllowed) {
uni.showToast({ title: "暂未开通此场景", icon: "none" });
return;
}
const list = sceneList.value;
let i = 0;
while (i < list.length) {
list[i].actived = false;
i++;
}
list[index].actived = true;
sceneList.value = list;
userInfo.sceneType = sceneType;
if (isSuper == true) {
jump(userInfo, null);
} else {
const shopMerchantId = userInfo.shopMerchantId as null | string;
const shopMerchantName = userInfo.shopMerchantName as null | string;
apiSelectMerchantScene({
merchantId: shopMerchantId ?? "",
merchantName: shopMerchantName ?? "",
sceneType
}).then((data: any): void => {
jump(userInfo, data);
}).catch((error) => {
console.error("selectMerchantScene 失败:", error);
uni.showToast({ title: "网络异常,请稍后重试", icon: "none" });
});
}
}
defineExpose({
init
});
</script>
<style scoped lang="scss">
.list-container {
display: flex;
flex-direction: column;
width: 100%;
}
.items {
min-height: 92px;
background-color: var(--bg-card);
border-radius: 16px;
padding: 18px;
display: flex;
flex-direction: row;
align-items: center;
box-sizing: border-box;
border: 1px solid rgba(226, 232, 240, 0.6);
box-shadow:
0 2px 8px rgba(15, 23, 42, 0.04),
0 8px 24px rgba(15, 23, 42, 0.06);
transition: all 0.1s ease-out;
width: 100%;
margin-bottom: 16px;
position: relative;
overflow: hidden;
&:last-child {
margin-bottom: 0;
}
&:active,
&.pressed {
transform: scale(0.96);
box-shadow:
0 1px 2px rgba(15, 23, 42, 0.08),
0 2px 6px rgba(15, 23, 42, 0.1);
border-color: rgba(22, 119, 255, 0.4);
background-color: var(--bg-pressed);
}
.left {
margin-right: 16px;
flex-shrink: 0;
.scene-icon {
width: 52px;
height: 52px;
border-radius: 26px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
transition: all 0.3s ease;
.scene-icon-text {
font-size: 13px;
font-weight: 700;
text-align: center;
letter-spacing: 0.5px;
}
}
// 不同场景的颜色
.scene-type-0 {
background-color: rgba(255, 157, 10, 0.1);
.scene-icon-text { color: #ff9d0a; }
}
.scene-type-1 {
background-color: rgba(242, 71, 36, 0.1);
.scene-icon-text { color: #f24724; }
}
.scene-type-7 {
background-color: rgba(52, 123, 255, 0.1);
.scene-icon-text { color: #347bff; }
}
}
.right {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
.name {
font-weight: 600;
font-size: 16px;
color: #1e293b;
margin-bottom: 6px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
letter-spacing: 0.3px;
line-height: 1.4;
}
.shop_no {
font-size: 13px;
color: #94a3b8;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
letter-spacing: 0.2px;
}
}
}
.active {
background-color: var(--bg-active);
border-color: rgba(22, 119, 255, 0.3);
box-shadow:
0 4px 16px rgba(22, 119, 255, 0.12),
0 12px 32px rgba(22, 119, 255, 0.16);
.right .name {
color: #1677FF;
font-weight: 700;
}
.left .scene-icon {
box-shadow: 0 4px 12px rgba(22, 119, 255, 0.2);
transform: scale(1.05);
}
}
</style>