import MHeader from '@/components/m-header'; import { Cell, CellGroup, Col, Icon, Row, Tag, Image, showToast, showFailToast, showLoadingToast, showSuccessToast, Popup, Grid, GridItem } from 'vant'; import { defineComponent, nextTick, onMounted, reactive, ref } from 'vue'; import styles from './detail.module.less'; import { browser, toChinesNum } from '@/helpers/utils'; import SOLO from './images/SOLO.png'; import REPRISE from './images/REPRISE.png'; import ENSEMBLE from './images/ENSEMBLE.png'; import UNISON from './images/UNISON.png'; import MImagePreview from '@/components/m-image-preview'; import SkeletionIndexModal from './skeletion-index-modal'; import SkeletionDetailModal from './skeletion-detail-modal'; import request from '@/helpers/request'; import { useRoute, useRouter } from 'vue-router'; import { activeStatus, activityStatus } from '@/helpers/constant'; import dayjs from 'dayjs'; import { formatterTimer } from './operation'; import MPopup from '@/components/m-popup'; import CastModal from './components/cast-modal'; import iconEdit from './images/icon-edit.png'; import html2canvas from 'html2canvas'; import { postMessage, promisefiyPostMessage } from '@/helpers/native-message'; import backIcon from './images/back-icon.png'; import eidtIcon from './images/eidt-icon.png'; import shareIcon from './images/share-icon.png'; import jiemuIcon from './images/jiemu-icon.png'; import hornIcon from './images/horn-icon.png'; import noteIcon from './images/note-icon.png'; import colorBg from './images/colorBg.png'; import dieIcon from './images/die-icon.png'; import dBall from './images/d-ball.png'; import qBall from './images/q-ball.png'; import cBall from './images/c-ball.png'; import hBall from './images/h-ball.png'; import dotIcon from './images/dot-icon.png'; import Detailswiper from './detail-swiper'; import bottomBg from './images/bottomBg.png'; import logo from './images/logo.png'; import MQrcode from '@/components/m-qrcode'; import { state } from '@/state'; import { useRect } from '@vant/use'; import iconWechat from './images/iconWechat.png'; import iconSaveImage from './images/iconSaveImage.png'; import shareBg from './images/shareBg.png'; import schoolIcon from './images/schoolIcon.png'; import popupQrcodeBg from './images/popupQrcodeBg.png'; import shareBottom from './images/shareBottom.png'; import popupShareBg from './images/popup-share-bg.png'; import { vaildTeachingUrl } from '@/helpers/utils'; export default defineComponent({ name: 'detail-page', setup() { const route = useRoute(); const router = useRouter(); // console.log(toChinesNum(11)); const forms = reactive({ id: route.query.id, imageShow: false, imagePreview: [] as any, startPosition: 0, headerLoading: true, detailLoading: true, detail: [] as any[], headerDetail: {} as any, castStatus: false, studentAllList: [] as any, navBarHeight: state.navBarHeight }); const shareForms = reactive({ id: route.query.id, share: route.query.share as any, showQrcode: false, url: vaildTeachingUrl() + '/school/#/activity-record-detail' + `?id=${route.query.id}`, width: 0, height: 0 }); const getDetail = async () => { try { const { data } = await request.get( '/api-web/schoolActivity/detail/' + forms.id ); const { detail, ...res } = data || {}; detail.forEach((item: any) => { item.attachmentUrl = item.attachmentUrl ? item.attachmentUrl.split(',') : []; }); forms.detail = detail; forms.headerDetail = { ...res }; } catch { // } finally { forms.headerLoading = false; forms.detailLoading = false; } }; const formatterStudentList = (list: any[]) => { const tempList: any[] = []; list.map((student: any) => { let count = 0; const students: any[] = []; student.studentList.forEach((item: any) => { if (item.selected) { count++; students.push(item); } }); if (count > 0) { tempList.push({ studentCount: count, subjectId: student.subjectId, subjectName: student.subjectName, studentList: students }); } }); forms.studentAllList = tempList; forms.castStatus = true; }; const formatterImage = (name: string) => { let image: string = ''; switch (name) { case 'SOLO': image = dBall; break; case 'REPRISE': image = cBall; break; case 'ENSEMBLE': image = hBall; break; case 'UNISON': image = qBall; break; default: image = SOLO; break; } return image; }; onMounted(() => { // setTimeout(() => { // // forms.headerLoading = false; // // forms.detailLoading = false; // }, 1000); getDetail(); }); const imgs = reactive({ saveLoading: false, image: null as any, shareLoading: false }); const onSaveImg = async () => { // 判断是否在保存中... if (imgs.saveLoading) { return; } imgs.saveLoading = true; // 判断是否已经生成图片 console.log(imgs.image); 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; console.log(url, 'html2canvas'); saveImg(); }) .catch(() => { // closeToast(); imgs.saveLoading = false; }); } }; const showImageToas = (obj: any) => { forms.imagePreview = obj.imagePreview; forms.imageShow = obj.imageShow; forms.startPosition = obj.startPosition; console.log(forms.imagePreview, 'showImageToas', obj); }; const onShare = () => { console.log('onShare'); if (imgs.shareLoading) { return; } imgs.shareLoading = true; if (imgs.image) { openShare(); console.log('onShareimgs.image'); } 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(); console.log('onShareimgs.Noimage'); }) .catch(e => { // closeToast(); console.log(e); imgs.shareLoading = false; }); } }; const openShare = () => { const image = imgs.image; setTimeout(() => { imgs.shareLoading = false; }, 100); if (image) { console.log('postMessage', 'shareTripartite'); 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('已保存到相册'); } else { showFailToast('保存失败'); } }; return () => (
{`活动日期:${dayjs( forms.headerDetail.startTime ).format('YYYY年MM月DD日')}`}