CenterPopup.uvue
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
<template>
<un-popup :show="visible"
closeOnClickOverlay
:z-index="99"
:title="title"
:closeable="true"
@close="close"
@close-icon-click="close">
<view class="popup-panel" :style="popupStyle">
<view class="popup-content">
<view v-for="(item, index) in list"
:key="index"
:class="['popup-item', itemRowActive(item) ? 'popup-item-active' : '']"
@tap="handleChoose(index)">
<view class="item-icon">
<text class="item-icon-text">{{ (item as UTSJSONObject).icon ?? '' }}</text>
</view>
<view class="item-text">
<text class="item-title">{{ (item as UTSJSONObject).title ?? '' }}</text>
<text class="item-describe">{{ (item as UTSJSONObject).describe ?? '' }}</text>
</view>
<view v-if="itemRowActive(item)" class="item-active-pill">
<text class="item-active-pill-text">当前</text>
</view>
<view class="item-arrow">
<un-icon name="arrow-right" size="14" color="#8aa0bf"></un-icon>
</view>
</view>
</view>
</view>
</un-popup>
</template>
<script setup lang="uts">
import { computed, defineExpose, ref, withDefaults } from "vue";
const props = withDefaults(defineProps<{
list?: any[]
title?: string
/** 受控显示,父组件传 true 即打开 */
visible?: boolean
/** 与列表项 `typeCode` 比对,高亮当前选中(Pad 业务类型等) */
selectedTypeCode?: string | null
}>(), {
selectedTypeCode: null,
});
const emit = defineEmits<{
choose: [index: number]
"update:visible": [value: boolean]
}>();
const internalVisible = ref(false);
const popupStyle = computed((): UTSJSONObject => {
const info = uni.getWindowInfo();
const winW = info.windowWidth > 0 ? info.windowWidth : 375;
const sideGapPx = 32;
const maxPanelWidthPx = 700;
const widthByWindow = winW - sideGapPx;
const widthPx = Math.max(280, Math.min(maxPanelWidthPx, widthByWindow));
return {
width: `${widthPx}px`
} as UTSJSONObject;
});
const visible = computed((): boolean => {
if (props.visible != null) return props.visible == true;
return internalVisible.value;
});
function itemRowActive(item: any): boolean {
const sel = props.selectedTypeCode;
if (sel == null || sel === "") {
return false;
}
const obj = item as UTSJSONObject;
const code = obj["typeCode"] as string | null;
return code != null && code !== "" && code === sel;
}
function open(): void {
if (props.visible != null) {
emit("update:visible", true);
} else {
internalVisible.value = true;
}
}
function close(): void {
internalVisible.value = false;
emit("update:visible", false);
}
function handleChoose(index: number): void {
emit("choose", index);
close();
}
defineExpose({
open,
close
});
</script>
<style scoped lang="scss">
.popup-panel {
border-radius: 16px;
overflow: hidden;
background-color: var(--bg-card, #FFFFFF);
margin: 0 auto;
display: flex;
flex-direction: column;
align-items: stretch;
}
.popup-content {
padding: 12px;
box-sizing: border-box;
}
.popup-item {
display: flex;
flex-direction: row;
align-items: center;
padding: 12px 12px;
margin-bottom: 10px;
background: rgba(255, 255, 255, 0.96);
border-radius: 12px;
border: 1px solid #dbe6f7;
box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
}
.popup-item:last-child {
margin-bottom: 0;
}
.popup-item-active {
border-color: rgba(44, 102, 247, 0.55);
background: rgba(44, 102, 247, 0.08);
box-shadow: 0 6px 16px rgba(44, 102, 247, 0.18);
}
.item-active-pill {
flex-shrink: 0;
margin-right: 6px;
padding: 2px 8px;
border-radius: 10px;
background: rgba(44, 102, 247, 0.16);
border-width: 1px;
border-style: solid;
border-color: rgba(44, 102, 247, 0.35);
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.item-active-pill-text {
font-size: 11px;
font-weight: 600;
color: #2c66f7;
line-height: 14px;
}
.item-icon {
width: 40px;
height: 40px;
margin-right: 10px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
flex-shrink: 0;
background: #edf4ff;
border-radius: 10px;
}
.item-icon-text {
font-size: 21px;
line-height: 1;
text-align: center;
}
.item-text {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
}
.item-title {
font-weight: 600;
font-size: 14px;
color: #1e293b;
margin-bottom: 2px;
}
.item-describe {
font-size: 12px;
color: #8091aa;
white-space: pre-wrap;
}
.item-arrow {
margin-left: 8px;
width: 16px;
height: 16px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
</style>