@uxda/appkit 4.2.82 → 4.2.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.mjs +7 -7
- package/README.md +187 -187
- package/babel.config.js +12 -12
- package/dist/appkit.css +41 -3
- package/dist/index.js +994 -535
- package/package.json +81 -81
- package/project.config.json +15 -15
- package/project.tt.json +13 -13
- package/rollup.config.mjs +77 -77
- package/src/Appkit.ts +67 -67
- package/src/balance/api/endpoints.ts +133 -133
- package/src/balance/api/index.ts +112 -106
- package/src/balance/components/AccountView.vue +773 -773
- package/src/balance/components/BalanceCard.vue +210 -210
- package/src/balance/components/BalanceReminder.vue +84 -84
- package/src/balance/components/ConsumptionFilter.vue +218 -218
- package/src/balance/components/ConsumptionRules.vue +68 -68
- package/src/balance/components/DateFilter.vue +259 -259
- package/src/balance/components/DateRange.vue +111 -111
- package/src/balance/components/ListFilter.vue +62 -62
- package/src/balance/components/ListFilterPicker.vue +191 -191
- package/src/balance/components/PromoterCard.vue +310 -310
- package/src/balance/components/SecondBalance.vue +77 -77
- package/src/balance/components/Tip.vue +45 -45
- package/src/balance/components/index.ts +8 -8
- package/src/balance/types.ts +99 -99
- package/src/components/bt-cropper/index.vue +730 -730
- package/src/components/bt-cropper/utils/calcCropper.js +42 -42
- package/src/components/bt-cropper/utils/calcImagePosition.js +23 -23
- package/src/components/bt-cropper/utils/calcImageSize.js +37 -37
- package/src/components/bt-cropper/utils/calcPointDistance.js +12 -12
- package/src/components/bt-cropper/utils/calcRightAndBottom.js +7 -7
- package/src/components/bt-cropper/utils/ratio.js +3 -3
- package/src/components/bt-cropper/utils/tools.js +25 -25
- package/src/components/dd-area/index.vue +225 -225
- package/src/components/dd-icon/doc.md +21 -21
- package/src/components/dd-icon/index.vue +23 -23
- package/src/components/dd-notice-bar/index.vue +78 -78
- package/src/components/dd-search/doc.md +34 -34
- package/src/components/dd-search/index.vue +168 -168
- package/src/components/dd-selector/index.vue +124 -124
- package/src/components/dd-skeleton/doc.md +19 -19
- package/src/components/dd-skeleton/index.vue +36 -36
- package/src/global.ts +6 -6
- package/src/index.ts +93 -93
- package/src/main.scss +1 -1
- package/src/notice/api/endpoints.ts +54 -17
- package/src/notice/api/index.ts +115 -106
- package/src/notice/components/NoticeBanner.vue +247 -247
- package/src/notice/components/NoticeEntry.vue +99 -99
- package/src/notice/components/NoticeList.vue +311 -311
- package/src/notice/components/NoticeList2.vue +243 -0
- package/src/notice/components/NoticePopup.vue +163 -163
- package/src/notice/components/index.ts +6 -5
- package/src/notice/components/useCommonList.ts +86 -86
- package/src/notice/components/useNotice.ts +35 -35
- package/src/notice/index.ts +1 -1
- package/src/notice/types.ts +25 -25
- package/src/payment/api/config.ts +7 -7
- package/src/payment/api/endpoints.ts +95 -95
- package/src/payment/api/index.ts +101 -101
- package/src/payment/components/AmountPicker.vue +90 -90
- package/src/payment/components/RechargeResult.vue +69 -69
- package/src/payment/components/RechargeView.vue +190 -190
- package/src/payment/components/RightsPicker.vue +105 -105
- package/src/payment/components/TradeView.vue +363 -363
- package/src/payment/components/UserAgreement.vue +234 -234
- package/src/payment/components/index.ts +22 -22
- package/src/payment/index.ts +5 -5
- package/src/payment/services/index.ts +16 -16
- package/src/payment/services/invoke-recharge.ts +25 -25
- package/src/payment/services/request-payment.ts +130 -130
- package/src/payment/types.ts +32 -32
- package/src/register/components/SelfRegistration.vue +233 -233
- package/src/register/components/index.ts +2 -2
- package/src/scenarios/components/SharePoster.vue +364 -364
- package/src/scenarios/components/index.ts +2 -2
- package/src/scenarios/components/poster-paste.vue +93 -93
- package/src/scenarios/components/share-poster.md +273 -273
- package/src/shared/components/AppDrawer.vue +53 -53
- package/src/shared/components/AppVerify.vue +128 -128
- package/src/shared/components/DeviceVersion.vue +78 -78
- package/src/shared/components/EmptyView.vue +33 -33
- package/src/shared/components/OcrBusinessLicense.vue +137 -137
- package/src/shared/components/OcrIcon.vue +229 -229
- package/src/shared/components/PageHeader.vue +84 -84
- package/src/shared/components/index.ts +8 -8
- package/src/shared/composables/index.ts +9 -9
- package/src/shared/composables/useAmount.ts +46 -46
- package/src/shared/composables/useCountdown.ts +46 -46
- package/src/shared/composables/useCrypto.ts +76 -76
- package/src/shared/composables/useDeviceEnv.ts +11 -11
- package/src/shared/composables/useDragBox.ts +97 -97
- package/src/shared/composables/useEncode.ts +43 -43
- package/src/shared/composables/useLogger.ts +131 -131
- package/src/shared/composables/useSafeArea.ts +46 -46
- package/src/shared/composables/useTabbar.ts +24 -24
- package/src/shared/composables/useUpload.ts +61 -61
- package/src/shared/composables/useValidator.ts +32 -32
- package/src/shared/composables/useWxAuth.ts +48 -48
- package/src/shared/http/Http.ts +148 -146
- package/src/shared/http/index.ts +1 -1
- package/src/shared/http/types.ts +163 -160
- package/src/shared/index.ts +8 -8
- package/src/shared/weixin/index.ts +9 -9
- package/src/shared/weixin/jssdk.ts +103 -103
- package/src/shared/weixin/payment.ts +38 -38
- package/src/styles/vars.scss +3 -3
- package/src/user/api/endpoints.ts +17 -17
- package/src/user/api/index.ts +117 -111
- package/src/user/components/LoginSetting.vue +114 -114
- package/src/user/components/UserAuth.vue +220 -220
- package/src/user/components/UserBinding.vue +277 -277
- package/src/user/components/UserBindingSuccess.vue +80 -80
- package/src/user/components/UserEntry.vue +139 -139
- package/src/user/components/UserFeedback.vue +427 -427
- package/src/user/components/UserFeedbackEntry.vue +175 -175
- package/src/user/components/UserHeadCrop.vue +65 -65
- package/src/user/components/UserInfo.vue +708 -708
- package/src/user/components/UserResourceEmpty.vue +75 -75
- package/src/user/components/index.ts +23 -23
- package/src/user/index.ts +1 -1
- package/src/utils/utils.ts +28 -28
- package/tsconfig.json +30 -30
- package/types/global.d.ts +22 -22
- package/types/vue.d.ts +10 -10
- /package/dist/assets/{asset-DcH8Kg-2 → asset-3B_CoPto} +0 -0
|
@@ -1,364 +1,364 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<nut-popup round v-model:visible="sheetOpen" position="bottom">
|
|
3
|
-
<template v-if="sheetOpen">
|
|
4
|
-
<div class="share-dialog column align-stretch">
|
|
5
|
-
<div class="swiper-container">
|
|
6
|
-
<div
|
|
7
|
-
class="poster-display row justify-center"
|
|
8
|
-
v-if="posters.length === 1"
|
|
9
|
-
>
|
|
10
|
-
<poster-paste
|
|
11
|
-
:poster="posters[0]"
|
|
12
|
-
:logo="config.logo"
|
|
13
|
-
:nick="config.nick"
|
|
14
|
-
:zoom="zoom"
|
|
15
|
-
/>
|
|
16
|
-
</div>
|
|
17
|
-
<swiper
|
|
18
|
-
v-if="posters.length > 1"
|
|
19
|
-
class="swiper"
|
|
20
|
-
:current="current"
|
|
21
|
-
:autoplay="false"
|
|
22
|
-
:indicator-dots="false"
|
|
23
|
-
:circular="true"
|
|
24
|
-
display-multiple-items="3"
|
|
25
|
-
@change="onSwiperChange"
|
|
26
|
-
>
|
|
27
|
-
<swiper-item
|
|
28
|
-
:class="['swiper-item', { center: isCenter(index) }]"
|
|
29
|
-
v-for="(poster, index) in posters"
|
|
30
|
-
:key="`${index}`"
|
|
31
|
-
>
|
|
32
|
-
<div class="slide">
|
|
33
|
-
<poster-paste
|
|
34
|
-
:poster="poster"
|
|
35
|
-
:logo="config.logo"
|
|
36
|
-
:nick="config.nick"
|
|
37
|
-
:zoom="zoom"
|
|
38
|
-
/>
|
|
39
|
-
</div>
|
|
40
|
-
</swiper-item>
|
|
41
|
-
</swiper>
|
|
42
|
-
</div>
|
|
43
|
-
<div class="swiper-dots" justify="center" :gap="8">
|
|
44
|
-
<div
|
|
45
|
-
class="dot"
|
|
46
|
-
:class="{
|
|
47
|
-
current:
|
|
48
|
-
current === index || current - posters.length / 2 === index,
|
|
49
|
-
}"
|
|
50
|
-
v-for="(_, index) in Array(posters.length / 2).fill('')"
|
|
51
|
-
:key="index"
|
|
52
|
-
/>
|
|
53
|
-
</div>
|
|
54
|
-
<div
|
|
55
|
-
class="text-center"
|
|
56
|
-
style="font-size: 13px; color: #666666; margin: 10px"
|
|
57
|
-
v-if="text"
|
|
58
|
-
>
|
|
59
|
-
{{ text }}
|
|
60
|
-
</div>
|
|
61
|
-
<div class="line"></div>
|
|
62
|
-
<div class="bottom">
|
|
63
|
-
<nut-button class="cancel-btn" @click="onCancelClick"
|
|
64
|
-
>取消</nut-button
|
|
65
|
-
>
|
|
66
|
-
<nut-button type="primary" @click="onPosterShare">确定</nut-button>
|
|
67
|
-
</div>
|
|
68
|
-
</div>
|
|
69
|
-
<canvas
|
|
70
|
-
type="2d"
|
|
71
|
-
id="poster-canvas"
|
|
72
|
-
:style="`height: ${o.h}px;width:${o.w}px;transform:translate3d(-5000px, 0, 0);position: absolute;`"
|
|
73
|
-
>
|
|
74
|
-
</canvas>
|
|
75
|
-
</template>
|
|
76
|
-
</nut-popup>
|
|
77
|
-
</template>
|
|
78
|
-
|
|
79
|
-
<script lang="ts" setup>
|
|
80
|
-
import { ref, watch } from 'vue';
|
|
81
|
-
import Taro from '@tarojs/taro';
|
|
82
|
-
import PosterPaste from '../components/poster-paste.vue';
|
|
83
|
-
import { dataURItoBlob, isWeb } from '../../utils/utils';
|
|
84
|
-
import { Swiper, SwiperItem } from '@tarojs/components';
|
|
85
|
-
|
|
86
|
-
const emit = defineEmits(['share']);
|
|
87
|
-
|
|
88
|
-
export type ShareDialogProps = {
|
|
89
|
-
// 海报列表
|
|
90
|
-
posters: any[];
|
|
91
|
-
text?: string;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const props = defineProps<ShareDialogProps>();
|
|
95
|
-
|
|
96
|
-
const o = {
|
|
97
|
-
// 图片原始大小
|
|
98
|
-
w: 375,
|
|
99
|
-
h: 812,
|
|
100
|
-
},
|
|
101
|
-
z = 480, // 缩放后高度
|
|
102
|
-
zoom = z / o.h;
|
|
103
|
-
|
|
104
|
-
const config = ref();
|
|
105
|
-
config.value = {
|
|
106
|
-
nick: '',
|
|
107
|
-
logo: '',
|
|
108
|
-
qr: '',
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// 真实的 current
|
|
112
|
-
const current = ref(0);
|
|
113
|
-
|
|
114
|
-
const getCentered = () => {
|
|
115
|
-
// change 事件返回的 current 为三张图中最左侧一张
|
|
116
|
-
// 为了中间放大的效果, 将 swiper 属性 current 设置为 下一张
|
|
117
|
-
if (props.posters.length === 1) return 0;
|
|
118
|
-
// 多张海报, *假选中*中间一张
|
|
119
|
-
let centered: number = current.value + 1;
|
|
120
|
-
centered = centered === props.posters.length ? 0 : centered;
|
|
121
|
-
return centered;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const isCenter = (index: number) => {
|
|
125
|
-
return getCentered() === index;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const onSwiperChange = ({ detail }) => {
|
|
129
|
-
current.value = detail.current;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const initCanvas = () => {
|
|
133
|
-
return new Promise((resolve) => {
|
|
134
|
-
setTimeout(() => {
|
|
135
|
-
if (Taro.getEnv() === 'WEB') {
|
|
136
|
-
const canvas = document.getElementById(
|
|
137
|
-
'poster-canvas'
|
|
138
|
-
) as HTMLCanvasElement;
|
|
139
|
-
const context = canvas.getContext('2d');
|
|
140
|
-
canvas.height = o.h * 2;
|
|
141
|
-
canvas.width = o.w * 2;
|
|
142
|
-
resolve({ context, canvas });
|
|
143
|
-
} else {
|
|
144
|
-
const pageInstance = Taro.getCurrentInstance()?.page || {}; // 拿到当前页面实例
|
|
145
|
-
const query = Taro.createSelectorQuery().in(pageInstance); // 确定在当前页面内匹配子元素
|
|
146
|
-
query
|
|
147
|
-
.select('#poster-canvas')
|
|
148
|
-
.fields({ node: true, size: true, context: true }, (res) => {
|
|
149
|
-
const canvas = res.node;
|
|
150
|
-
const context = canvas.getContext('2d');
|
|
151
|
-
canvas.height = o.h * 2;
|
|
152
|
-
canvas.width = o.w * 2;
|
|
153
|
-
canvas.destHeight = o.h * 2;
|
|
154
|
-
canvas.destWidth = o.w * 2;
|
|
155
|
-
resolve({ context, canvas });
|
|
156
|
-
})
|
|
157
|
-
.exec();
|
|
158
|
-
}
|
|
159
|
-
}, 300);
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
const drawImage = async (
|
|
164
|
-
canvas: any,
|
|
165
|
-
context: any,
|
|
166
|
-
src: string,
|
|
167
|
-
x?: number,
|
|
168
|
-
y?: number,
|
|
169
|
-
w?: number,
|
|
170
|
-
h?: number
|
|
171
|
-
) => {
|
|
172
|
-
return new Promise((resolve, reject) => {
|
|
173
|
-
if (!src) {
|
|
174
|
-
resolve(void 0);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
const image = !isWeb() ? canvas.createImage() : new Image();
|
|
178
|
-
image.crossOrigin = 'Anonymous';
|
|
179
|
-
image.src = src;
|
|
180
|
-
image.onload = function () {
|
|
181
|
-
context.drawImage(image, x || 0, y || 0, w || o.w, h || o.h);
|
|
182
|
-
resolve(void 0);
|
|
183
|
-
};
|
|
184
|
-
image.onerror = (e) => {
|
|
185
|
-
resolve(image);
|
|
186
|
-
};
|
|
187
|
-
});
|
|
188
|
-
};
|
|
189
|
-
const onPosterShare = async () => {
|
|
190
|
-
!isWeb() && Taro.showLoading({ title: '加载中...', mask: true });
|
|
191
|
-
// @ts-ignore
|
|
192
|
-
const { context, canvas } = await initCanvas(),
|
|
193
|
-
c = getCentered();
|
|
194
|
-
const p = props.posters[c];
|
|
195
|
-
await drawImage(canvas, context, p.back, 0, 0, o.w * 2, o.h * 2);
|
|
196
|
-
if (p.qr) {
|
|
197
|
-
await drawImage(
|
|
198
|
-
canvas,
|
|
199
|
-
context,
|
|
200
|
-
p.qr,
|
|
201
|
-
p.qrX * 2,
|
|
202
|
-
p.qrY * 2,
|
|
203
|
-
p.qrW * 2,
|
|
204
|
-
p.qrH * 2
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
if (config.value.nick) {
|
|
208
|
-
context.font = '24px sans-serif';
|
|
209
|
-
context.fillText(config.value.nick, p.nickX * 2 - 10, p.nickY * 2 + 34);
|
|
210
|
-
}
|
|
211
|
-
if (config.value.logo) {
|
|
212
|
-
await drawImage(
|
|
213
|
-
canvas,
|
|
214
|
-
context,
|
|
215
|
-
config.value.logo,
|
|
216
|
-
p.logoX * 2,
|
|
217
|
-
p.logoY * 2,
|
|
218
|
-
54,
|
|
219
|
-
54
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
context.save();
|
|
223
|
-
if (isWeb()) {
|
|
224
|
-
const dataURL = canvas.toDataURL('image/png');
|
|
225
|
-
const blob = dataURItoBlob(dataURL);
|
|
226
|
-
const imgUrl = URL.createObjectURL(blob);
|
|
227
|
-
emit('share', imgUrl);
|
|
228
|
-
} else {
|
|
229
|
-
Taro.canvasToTempFilePath({
|
|
230
|
-
canvas,
|
|
231
|
-
success: (result) => {
|
|
232
|
-
Taro.hideLoading();
|
|
233
|
-
Taro.showShareImageMenu({
|
|
234
|
-
path: result.tempFilePath,
|
|
235
|
-
});
|
|
236
|
-
},
|
|
237
|
-
fail: () => {
|
|
238
|
-
Taro.showToast({
|
|
239
|
-
title: '海报生成失败,请重试',
|
|
240
|
-
icon: 'none',
|
|
241
|
-
});
|
|
242
|
-
},
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
watch(
|
|
248
|
-
() => props.posters,
|
|
249
|
-
() => {
|
|
250
|
-
if (props.posters[0]?.nick) {
|
|
251
|
-
config.value.nick = props.posters[0].nick;
|
|
252
|
-
}
|
|
253
|
-
if (props.posters[0]?.logo) {
|
|
254
|
-
config.value.logo = props.posters[0].logo;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
const sheetOpen = ref(false);
|
|
260
|
-
const onCancelClick = () => {
|
|
261
|
-
sheetOpen.value = false;
|
|
262
|
-
};
|
|
263
|
-
function openShareDialog() {
|
|
264
|
-
sheetOpen.value = !sheetOpen.value;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
defineExpose({
|
|
268
|
-
openShareDialog,
|
|
269
|
-
});
|
|
270
|
-
</script>
|
|
271
|
-
|
|
272
|
-
<style lang="scss">
|
|
273
|
-
.share-dialog {
|
|
274
|
-
padding: 40px 0 0;
|
|
275
|
-
overflow: hidden auto;
|
|
276
|
-
|
|
277
|
-
.swiper-container {
|
|
278
|
-
position: relative;
|
|
279
|
-
width: 100%;
|
|
280
|
-
height: 480px;
|
|
281
|
-
overflow: hidden;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
.swiper {
|
|
285
|
-
width: 180%;
|
|
286
|
-
height: 100%;
|
|
287
|
-
margin: 0 -40%;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
.swiper-item {
|
|
291
|
-
width: 100%;
|
|
292
|
-
display: flex;
|
|
293
|
-
flex-direction: row;
|
|
294
|
-
align-items: center;
|
|
295
|
-
|
|
296
|
-
.poster-paste {
|
|
297
|
-
transform: scale(0.8);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
&.center {
|
|
301
|
-
.poster-paste {
|
|
302
|
-
transform: scale(1);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
.swiper-dots {
|
|
308
|
-
margin-top: 10px;
|
|
309
|
-
height: 20px;
|
|
310
|
-
display: flex;
|
|
311
|
-
justify-content: center;
|
|
312
|
-
align-items: center;
|
|
313
|
-
.dot {
|
|
314
|
-
width: 6px;
|
|
315
|
-
height: 6px;
|
|
316
|
-
background-color: #b0b7c4;
|
|
317
|
-
border-radius: 3px;
|
|
318
|
-
transition: width 0.5s;
|
|
319
|
-
margin: 0 2px;
|
|
320
|
-
|
|
321
|
-
&.current {
|
|
322
|
-
background-color: #017fff;
|
|
323
|
-
width: 15px;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
.slide {
|
|
329
|
-
width: 100%;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
.buttons {
|
|
333
|
-
margin-top: 60px;
|
|
334
|
-
|
|
335
|
-
.btn {
|
|
336
|
-
width: 50px;
|
|
337
|
-
height: 50px;
|
|
338
|
-
background-size: 100% 100%;
|
|
339
|
-
background-color: #f8f8f8;
|
|
340
|
-
border-radius: 10px;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
.bottom {
|
|
345
|
-
padding: 12px;
|
|
346
|
-
display: flex;
|
|
347
|
-
.nut-button {
|
|
348
|
-
flex: 1;
|
|
349
|
-
}
|
|
350
|
-
.cancel-btn {
|
|
351
|
-
margin-right: 12px;
|
|
352
|
-
flex: 1;
|
|
353
|
-
border: 1px solid #017fff;
|
|
354
|
-
color: #017fff;
|
|
355
|
-
background: #fff;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
.line {
|
|
360
|
-
background: #f1f5f9;
|
|
361
|
-
height: 8.5px;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<nut-popup round v-model:visible="sheetOpen" position="bottom">
|
|
3
|
+
<template v-if="sheetOpen">
|
|
4
|
+
<div class="share-dialog column align-stretch">
|
|
5
|
+
<div class="swiper-container">
|
|
6
|
+
<div
|
|
7
|
+
class="poster-display row justify-center"
|
|
8
|
+
v-if="posters.length === 1"
|
|
9
|
+
>
|
|
10
|
+
<poster-paste
|
|
11
|
+
:poster="posters[0]"
|
|
12
|
+
:logo="config.logo"
|
|
13
|
+
:nick="config.nick"
|
|
14
|
+
:zoom="zoom"
|
|
15
|
+
/>
|
|
16
|
+
</div>
|
|
17
|
+
<swiper
|
|
18
|
+
v-if="posters.length > 1"
|
|
19
|
+
class="swiper"
|
|
20
|
+
:current="current"
|
|
21
|
+
:autoplay="false"
|
|
22
|
+
:indicator-dots="false"
|
|
23
|
+
:circular="true"
|
|
24
|
+
display-multiple-items="3"
|
|
25
|
+
@change="onSwiperChange"
|
|
26
|
+
>
|
|
27
|
+
<swiper-item
|
|
28
|
+
:class="['swiper-item', { center: isCenter(index) }]"
|
|
29
|
+
v-for="(poster, index) in posters"
|
|
30
|
+
:key="`${index}`"
|
|
31
|
+
>
|
|
32
|
+
<div class="slide">
|
|
33
|
+
<poster-paste
|
|
34
|
+
:poster="poster"
|
|
35
|
+
:logo="config.logo"
|
|
36
|
+
:nick="config.nick"
|
|
37
|
+
:zoom="zoom"
|
|
38
|
+
/>
|
|
39
|
+
</div>
|
|
40
|
+
</swiper-item>
|
|
41
|
+
</swiper>
|
|
42
|
+
</div>
|
|
43
|
+
<div class="swiper-dots" justify="center" :gap="8">
|
|
44
|
+
<div
|
|
45
|
+
class="dot"
|
|
46
|
+
:class="{
|
|
47
|
+
current:
|
|
48
|
+
current === index || current - posters.length / 2 === index,
|
|
49
|
+
}"
|
|
50
|
+
v-for="(_, index) in Array(posters.length / 2).fill('')"
|
|
51
|
+
:key="index"
|
|
52
|
+
/>
|
|
53
|
+
</div>
|
|
54
|
+
<div
|
|
55
|
+
class="text-center"
|
|
56
|
+
style="font-size: 13px; color: #666666; margin: 10px"
|
|
57
|
+
v-if="text"
|
|
58
|
+
>
|
|
59
|
+
{{ text }}
|
|
60
|
+
</div>
|
|
61
|
+
<div class="line"></div>
|
|
62
|
+
<div class="bottom">
|
|
63
|
+
<nut-button class="cancel-btn" @click="onCancelClick"
|
|
64
|
+
>取消</nut-button
|
|
65
|
+
>
|
|
66
|
+
<nut-button type="primary" @click="onPosterShare">确定</nut-button>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
<canvas
|
|
70
|
+
type="2d"
|
|
71
|
+
id="poster-canvas"
|
|
72
|
+
:style="`height: ${o.h}px;width:${o.w}px;transform:translate3d(-5000px, 0, 0);position: absolute;`"
|
|
73
|
+
>
|
|
74
|
+
</canvas>
|
|
75
|
+
</template>
|
|
76
|
+
</nut-popup>
|
|
77
|
+
</template>
|
|
78
|
+
|
|
79
|
+
<script lang="ts" setup>
|
|
80
|
+
import { ref, watch } from 'vue';
|
|
81
|
+
import Taro from '@tarojs/taro';
|
|
82
|
+
import PosterPaste from '../components/poster-paste.vue';
|
|
83
|
+
import { dataURItoBlob, isWeb } from '../../utils/utils';
|
|
84
|
+
import { Swiper, SwiperItem } from '@tarojs/components';
|
|
85
|
+
|
|
86
|
+
const emit = defineEmits(['share']);
|
|
87
|
+
|
|
88
|
+
export type ShareDialogProps = {
|
|
89
|
+
// 海报列表
|
|
90
|
+
posters: any[];
|
|
91
|
+
text?: string;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const props = defineProps<ShareDialogProps>();
|
|
95
|
+
|
|
96
|
+
const o = {
|
|
97
|
+
// 图片原始大小
|
|
98
|
+
w: 375,
|
|
99
|
+
h: 812,
|
|
100
|
+
},
|
|
101
|
+
z = 480, // 缩放后高度
|
|
102
|
+
zoom = z / o.h;
|
|
103
|
+
|
|
104
|
+
const config = ref();
|
|
105
|
+
config.value = {
|
|
106
|
+
nick: '',
|
|
107
|
+
logo: '',
|
|
108
|
+
qr: '',
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// 真实的 current
|
|
112
|
+
const current = ref(0);
|
|
113
|
+
|
|
114
|
+
const getCentered = () => {
|
|
115
|
+
// change 事件返回的 current 为三张图中最左侧一张
|
|
116
|
+
// 为了中间放大的效果, 将 swiper 属性 current 设置为 下一张
|
|
117
|
+
if (props.posters.length === 1) return 0;
|
|
118
|
+
// 多张海报, *假选中*中间一张
|
|
119
|
+
let centered: number = current.value + 1;
|
|
120
|
+
centered = centered === props.posters.length ? 0 : centered;
|
|
121
|
+
return centered;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const isCenter = (index: number) => {
|
|
125
|
+
return getCentered() === index;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const onSwiperChange = ({ detail }) => {
|
|
129
|
+
current.value = detail.current;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const initCanvas = () => {
|
|
133
|
+
return new Promise((resolve) => {
|
|
134
|
+
setTimeout(() => {
|
|
135
|
+
if (Taro.getEnv() === 'WEB') {
|
|
136
|
+
const canvas = document.getElementById(
|
|
137
|
+
'poster-canvas'
|
|
138
|
+
) as HTMLCanvasElement;
|
|
139
|
+
const context = canvas.getContext('2d');
|
|
140
|
+
canvas.height = o.h * 2;
|
|
141
|
+
canvas.width = o.w * 2;
|
|
142
|
+
resolve({ context, canvas });
|
|
143
|
+
} else {
|
|
144
|
+
const pageInstance = Taro.getCurrentInstance()?.page || {}; // 拿到当前页面实例
|
|
145
|
+
const query = Taro.createSelectorQuery().in(pageInstance); // 确定在当前页面内匹配子元素
|
|
146
|
+
query
|
|
147
|
+
.select('#poster-canvas')
|
|
148
|
+
.fields({ node: true, size: true, context: true }, (res) => {
|
|
149
|
+
const canvas = res.node;
|
|
150
|
+
const context = canvas.getContext('2d');
|
|
151
|
+
canvas.height = o.h * 2;
|
|
152
|
+
canvas.width = o.w * 2;
|
|
153
|
+
canvas.destHeight = o.h * 2;
|
|
154
|
+
canvas.destWidth = o.w * 2;
|
|
155
|
+
resolve({ context, canvas });
|
|
156
|
+
})
|
|
157
|
+
.exec();
|
|
158
|
+
}
|
|
159
|
+
}, 300);
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const drawImage = async (
|
|
164
|
+
canvas: any,
|
|
165
|
+
context: any,
|
|
166
|
+
src: string,
|
|
167
|
+
x?: number,
|
|
168
|
+
y?: number,
|
|
169
|
+
w?: number,
|
|
170
|
+
h?: number
|
|
171
|
+
) => {
|
|
172
|
+
return new Promise((resolve, reject) => {
|
|
173
|
+
if (!src) {
|
|
174
|
+
resolve(void 0);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const image = !isWeb() ? canvas.createImage() : new Image();
|
|
178
|
+
image.crossOrigin = 'Anonymous';
|
|
179
|
+
image.src = src;
|
|
180
|
+
image.onload = function () {
|
|
181
|
+
context.drawImage(image, x || 0, y || 0, w || o.w, h || o.h);
|
|
182
|
+
resolve(void 0);
|
|
183
|
+
};
|
|
184
|
+
image.onerror = (e) => {
|
|
185
|
+
resolve(image);
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
const onPosterShare = async () => {
|
|
190
|
+
!isWeb() && Taro.showLoading({ title: '加载中...', mask: true });
|
|
191
|
+
// @ts-ignore
|
|
192
|
+
const { context, canvas } = await initCanvas(),
|
|
193
|
+
c = getCentered();
|
|
194
|
+
const p = props.posters[c];
|
|
195
|
+
await drawImage(canvas, context, p.back, 0, 0, o.w * 2, o.h * 2);
|
|
196
|
+
if (p.qr) {
|
|
197
|
+
await drawImage(
|
|
198
|
+
canvas,
|
|
199
|
+
context,
|
|
200
|
+
p.qr,
|
|
201
|
+
p.qrX * 2,
|
|
202
|
+
p.qrY * 2,
|
|
203
|
+
p.qrW * 2,
|
|
204
|
+
p.qrH * 2
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
if (config.value.nick) {
|
|
208
|
+
context.font = '24px sans-serif';
|
|
209
|
+
context.fillText(config.value.nick, p.nickX * 2 - 10, p.nickY * 2 + 34);
|
|
210
|
+
}
|
|
211
|
+
if (config.value.logo) {
|
|
212
|
+
await drawImage(
|
|
213
|
+
canvas,
|
|
214
|
+
context,
|
|
215
|
+
config.value.logo,
|
|
216
|
+
p.logoX * 2,
|
|
217
|
+
p.logoY * 2,
|
|
218
|
+
54,
|
|
219
|
+
54
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
context.save();
|
|
223
|
+
if (isWeb()) {
|
|
224
|
+
const dataURL = canvas.toDataURL('image/png');
|
|
225
|
+
const blob = dataURItoBlob(dataURL);
|
|
226
|
+
const imgUrl = URL.createObjectURL(blob);
|
|
227
|
+
emit('share', imgUrl);
|
|
228
|
+
} else {
|
|
229
|
+
Taro.canvasToTempFilePath({
|
|
230
|
+
canvas,
|
|
231
|
+
success: (result) => {
|
|
232
|
+
Taro.hideLoading();
|
|
233
|
+
Taro.showShareImageMenu({
|
|
234
|
+
path: result.tempFilePath,
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
fail: () => {
|
|
238
|
+
Taro.showToast({
|
|
239
|
+
title: '海报生成失败,请重试',
|
|
240
|
+
icon: 'none',
|
|
241
|
+
});
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
watch(
|
|
248
|
+
() => props.posters,
|
|
249
|
+
() => {
|
|
250
|
+
if (props.posters[0]?.nick) {
|
|
251
|
+
config.value.nick = props.posters[0].nick;
|
|
252
|
+
}
|
|
253
|
+
if (props.posters[0]?.logo) {
|
|
254
|
+
config.value.logo = props.posters[0].logo;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
const sheetOpen = ref(false);
|
|
260
|
+
const onCancelClick = () => {
|
|
261
|
+
sheetOpen.value = false;
|
|
262
|
+
};
|
|
263
|
+
function openShareDialog() {
|
|
264
|
+
sheetOpen.value = !sheetOpen.value;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
defineExpose({
|
|
268
|
+
openShareDialog,
|
|
269
|
+
});
|
|
270
|
+
</script>
|
|
271
|
+
|
|
272
|
+
<style lang="scss">
|
|
273
|
+
.share-dialog {
|
|
274
|
+
padding: 40px 0 0;
|
|
275
|
+
overflow: hidden auto;
|
|
276
|
+
|
|
277
|
+
.swiper-container {
|
|
278
|
+
position: relative;
|
|
279
|
+
width: 100%;
|
|
280
|
+
height: 480px;
|
|
281
|
+
overflow: hidden;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
.swiper {
|
|
285
|
+
width: 180%;
|
|
286
|
+
height: 100%;
|
|
287
|
+
margin: 0 -40%;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
.swiper-item {
|
|
291
|
+
width: 100%;
|
|
292
|
+
display: flex;
|
|
293
|
+
flex-direction: row;
|
|
294
|
+
align-items: center;
|
|
295
|
+
|
|
296
|
+
.poster-paste {
|
|
297
|
+
transform: scale(0.8);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
&.center {
|
|
301
|
+
.poster-paste {
|
|
302
|
+
transform: scale(1);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.swiper-dots {
|
|
308
|
+
margin-top: 10px;
|
|
309
|
+
height: 20px;
|
|
310
|
+
display: flex;
|
|
311
|
+
justify-content: center;
|
|
312
|
+
align-items: center;
|
|
313
|
+
.dot {
|
|
314
|
+
width: 6px;
|
|
315
|
+
height: 6px;
|
|
316
|
+
background-color: #b0b7c4;
|
|
317
|
+
border-radius: 3px;
|
|
318
|
+
transition: width 0.5s;
|
|
319
|
+
margin: 0 2px;
|
|
320
|
+
|
|
321
|
+
&.current {
|
|
322
|
+
background-color: #017fff;
|
|
323
|
+
width: 15px;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
.slide {
|
|
329
|
+
width: 100%;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
.buttons {
|
|
333
|
+
margin-top: 60px;
|
|
334
|
+
|
|
335
|
+
.btn {
|
|
336
|
+
width: 50px;
|
|
337
|
+
height: 50px;
|
|
338
|
+
background-size: 100% 100%;
|
|
339
|
+
background-color: #f8f8f8;
|
|
340
|
+
border-radius: 10px;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
.bottom {
|
|
345
|
+
padding: 12px;
|
|
346
|
+
display: flex;
|
|
347
|
+
.nut-button {
|
|
348
|
+
flex: 1;
|
|
349
|
+
}
|
|
350
|
+
.cancel-btn {
|
|
351
|
+
margin-right: 12px;
|
|
352
|
+
flex: 1;
|
|
353
|
+
border: 1px solid #017fff;
|
|
354
|
+
color: #017fff;
|
|
355
|
+
background: #fff;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
.line {
|
|
360
|
+
background: #f1f5f9;
|
|
361
|
+
height: 8.5px;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
</style>
|