|
@@ -1,5 +1,20 @@
|
|
|
import OSticky from '@/components/o-sticky'
|
|
|
-import { Button, DatePicker, Grid, GridItem, Icon, Image, List, Picker, Popover, Popup } from 'vant'
|
|
|
+import {
|
|
|
+ Button,
|
|
|
+ closeToast,
|
|
|
+ DatePicker,
|
|
|
+ Grid,
|
|
|
+ GridItem,
|
|
|
+ Icon,
|
|
|
+ Image,
|
|
|
+ List,
|
|
|
+ Picker,
|
|
|
+ Popover,
|
|
|
+ Popup,
|
|
|
+ showLoadingToast,
|
|
|
+ showSuccessToast,
|
|
|
+ showToast
|
|
|
+} from 'vant'
|
|
|
import { computed, defineComponent, nextTick, onMounted, reactive } from 'vue'
|
|
|
import styles from './information.module.less'
|
|
|
import iconSaveImage from '../images/icon-save-image.png'
|
|
@@ -10,6 +25,8 @@ import { useRoute } from 'vue-router'
|
|
|
import { CountUp } from 'countup.js'
|
|
|
import OEmpty from '@/components/o-empty'
|
|
|
import dayjs from 'dayjs'
|
|
|
+import { promisefiyPostMessage, postMessage } from '@/helpers/native-message'
|
|
|
+import html2canvas from 'html2canvas'
|
|
|
|
|
|
export default defineComponent({
|
|
|
name: 'detail-information',
|
|
@@ -181,6 +198,109 @@ export default defineComponent({
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ const imgs = reactive({
|
|
|
+ saveLoading: false,
|
|
|
+ image: null as any,
|
|
|
+ shareLoading: false
|
|
|
+ })
|
|
|
+ const onSaveImg = async () => {
|
|
|
+ // 判断是否在保存中...
|
|
|
+ if (imgs.saveLoading) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ imgs.saveLoading = true
|
|
|
+ // 判断是否已经生成图片
|
|
|
+ if (imgs.image) {
|
|
|
+ saveImg()
|
|
|
+ } else {
|
|
|
+ const container: any = document.getElementById(`preview-container`)
|
|
|
+ html2canvas(container, {
|
|
|
+ allowTaint: true,
|
|
|
+ useCORS: true,
|
|
|
+ backgroundColor: null
|
|
|
+ })
|
|
|
+ .then(async (canvas) => {
|
|
|
+ const url = canvas.toDataURL('image/png')
|
|
|
+ imgs.image = url
|
|
|
+ saveImg()
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ closeToast()
|
|
|
+ imgs.saveLoading = false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const onShare = () => {
|
|
|
+ if (imgs.shareLoading) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ imgs.shareLoading = true
|
|
|
+ if (imgs.image) {
|
|
|
+ openShare()
|
|
|
+ } else {
|
|
|
+ const container: any = document.getElementById(`preview-container`)
|
|
|
+ html2canvas(container, {
|
|
|
+ allowTaint: true,
|
|
|
+ useCORS: true,
|
|
|
+ backgroundColor: null
|
|
|
+ })
|
|
|
+ .then(async (canvas) => {
|
|
|
+ const url = canvas.toDataURL('image/png')
|
|
|
+ imgs.image = url
|
|
|
+ openShare()
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ closeToast()
|
|
|
+ imgs.shareLoading = false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const openShare = () => {
|
|
|
+ const image = imgs.image
|
|
|
+ setTimeout(() => {
|
|
|
+ imgs.shareLoading = false
|
|
|
+ }, 100)
|
|
|
+ if (image) {
|
|
|
+ postMessage(
|
|
|
+ {
|
|
|
+ api: 'shareTripartite',
|
|
|
+ content: {
|
|
|
+ title: '',
|
|
|
+ desc: '',
|
|
|
+ image,
|
|
|
+ video: '',
|
|
|
+ type: 'image',
|
|
|
+ // button: ['copy']
|
|
|
+ shareType: 'wechat'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ (res: any) => {
|
|
|
+ if (res && res.content) {
|
|
|
+ showToast(res.content.message || (res.content.status ? '分享成功' : '分享失败'))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const saveImg = async () => {
|
|
|
+ showLoadingToast({ message: '图片生成中...', forbidClick: true })
|
|
|
+ setTimeout(() => {
|
|
|
+ imgs.saveLoading = false
|
|
|
+ }, 100)
|
|
|
+ const res = await promisefiyPostMessage({
|
|
|
+ api: 'savePicture',
|
|
|
+ content: {
|
|
|
+ base64: imgs.image
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (res?.content?.status === 'success') {
|
|
|
+ showSuccessToast('保存成功')
|
|
|
+ form.showQrcode = false
|
|
|
+ } else {
|
|
|
+ showFailToast('保存失败')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
onMounted(() => {
|
|
|
getDetails()
|
|
|
getStatistics()
|
|
@@ -309,7 +429,7 @@ export default defineComponent({
|
|
|
// safeAreaInsetBottom={true}
|
|
|
>
|
|
|
<div class={styles.codeContainer}>
|
|
|
- <div class={styles.codeImg}>
|
|
|
+ <div class={styles.codeImg} id="preview-container">
|
|
|
<div class={styles.codeContent}>
|
|
|
<h2 class={styles.codeTitle}>乐团报名</h2>
|
|
|
<div class={[styles.codeName, 'van-ellipsis']}>{state.orchestraInfo.name}</div>
|
|
@@ -336,13 +456,13 @@ export default defineComponent({
|
|
|
<i></i>分享方式
|
|
|
</h3>
|
|
|
<Grid columnNum={2} border={false}>
|
|
|
- <GridItem>
|
|
|
+ <GridItem onClick={onSaveImg}>
|
|
|
{{
|
|
|
icon: () => <Image class={styles.shareImg} src={iconSaveImage} />,
|
|
|
text: () => <div class={styles.shareText}>保存图片</div>
|
|
|
}}
|
|
|
</GridItem>
|
|
|
- <GridItem>
|
|
|
+ <GridItem onClick={onShare}>
|
|
|
{{
|
|
|
icon: () => <Image class={styles.shareImg} src={iconWechat} />,
|
|
|
text: () => <div class={styles.shareText}>微信</div>
|