LatestCouponActivityPopup.vue
5.83 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
<template>
<view class="latest-activity-popup-host">
<uni-popup ref="popupRef" class="latest-activity-popup" type="center" background-color="#fff"
border-radius="16px" :is-mask-click="true" @maskClick="onMaskDismiss">
<view v-if="activity" class="latest-activity-card">
<view class="latest-activity-close" @click.stop="onHeaderCloseTap">
<uni-icons type="closeempty" size="20" color="#999999" />
</view>
<image class="latest-activity-illust" :src="illustSrc" mode="widthFix" />
<view class="latest-activity-title">{{ activity.activityName }}</view>
<scroll-view scroll-y class="latest-activity-scroll" :show-scrollbar="true">
<view class="latest-activity-body">
<rich-text class="latest-activity-body-rich"
:nodes="formatLatestActivityRichText(activity.agreementContent)"></rich-text>
</view>
</scroll-view>
<van-button class="latest-activity-action" round block color="#FF5000"
@click="onParticipate">立即参拍</van-button>
</view>
</uni-popup>
</view>
</template>
<script lang="ts">
import { Component, Prop, Ref, Vue, Watch } from "vue-facing-decorator";
import { couponImageUrl } from "@/common/couponImageUrl";
export interface LatestActivityPopupData {
activityName: string;
agreementContent: string;
}
@Component({
emits: ["close"],
})
export default class LatestCouponActivityPopup extends Vue {
@Prop({ type: Boolean, default: false })
show!: boolean;
@Prop({ type: Object, default: null })
activity!: LatestActivityPopupData | null;
@Ref popupRef: any;
@Watch("show")
onShowPropChanged(): void {
if (!this.show) {
this.dismissPopupShell();
return;
}
if (this.activity != null) {
this.presentWhenShown();
}
}
@Watch("activity")
onActivityPropChanged(): void {
if (this.show && this.activity != null) {
this.presentWhenShown();
}
}
get illustSrc(): string {
return couponImageUrl("Promotion.png");
}
/**
* 与 AgreementPage 一致:弱化编辑器内联样式,便于小程序 rich-text 排版
*/
formatLatestActivityRichText(html: string): string {
if (!html) {
return "";
}
let s = html;
s = s.replace(/class="mce-.*?"/g, "");
s = s.replace(/width:\s*\d+px;/g, "");
s = s.replace(/height:\s*\d+px;/g, "height: auto;");
s = s.replace(/<(\/)?pre[^>]*>/gi, "");
return s;
}
private dismissPopupShell(): void {
this.popupRef?.close?.("center");
}
private presentWhenShown(): void {
this.scheduleUniPopupOpen();
}
onMaskDismiss(): void {
if (!this.activity) {
return;
}
this.$emit("close");
}
onHeaderCloseTap(): void {
if (!this.activity) {
return;
}
this.popupRef?.close?.("center");
this.$emit("close");
}
onParticipate(): void {
if (!this.activity) {
return;
}
this.popupRef?.close?.("center");
uni.switchTab({ url: "/pages/tabbar/AuctionPage" });
this.$emit("close");
}
private scheduleUniPopupOpen(): void {
const popupInstance = (): any =>
this.popupRef ?? (this.$refs as { popupRef?: unknown }).popupRef;
const tryOpenCenter = (): boolean => {
const ref = popupInstance();
if (ref && typeof ref.open === "function") {
ref.open("center");
return true;
}
return false;
};
this.$nextTick(() => {
this.$nextTick(() => {
if (tryOpenCenter()) {
return;
}
setTimeout(() => {
if (tryOpenCenter()) {
return;
}
setTimeout(() => {
if (!tryOpenCenter()) {
console.warn(
"[LatestCouponActivityPopup] uni-popup.open 不可用,popupRef=",
popupInstance(),
);
}
}, 280);
}, 80);
});
});
}
}
</script>
<style scoped lang="scss">
.latest-activity-popup-host {
position: relative;
z-index: 20000;
}
.latest-activity-popup-host :deep(.uni-popup) {
z-index: 20000 !important;
}
.latest-activity-card {
position: relative;
width: 300px;
max-width: 86vw;
padding: 24px 20px 20px;
box-sizing: border-box;
}
.latest-activity-close {
position: absolute;
right: 12px;
top: 12px;
z-index: 2;
padding: 4px;
}
.latest-activity-illust {
display: block;
width: 120px;
margin: 0px auto 0px;
}
.latest-activity-title {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-word;
font-size: 20px;
font-weight: 600;
color: #323233;
line-height: 28px;
text-align: center;
margin-bottom: 12px;
}
.latest-activity-scroll {
max-height: 220px;
margin-bottom: 16px;
}
.latest-activity-body {
background: #f7f8fa;
border-radius: 8px;
padding: 12px;
}
.latest-activity-body-rich {
font-size: 13px;
color: #646566;
line-height: 20px;
white-space: normal !important;
word-wrap: break-word !important;
word-break: break-all !important;
width: 100% !important;
max-width: 100% !important;
}
.latest-activity-action {
margin-top: 4px;
}
</style>