detail.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. import MHeader from '@/components/m-header';
  2. import {
  3. Cell,
  4. CellGroup,
  5. Col,
  6. Icon,
  7. Row,
  8. Tag,
  9. Image,
  10. showToast,
  11. showFailToast,
  12. showLoadingToast,
  13. showSuccessToast,
  14. Popup,
  15. Grid,
  16. GridItem
  17. } from 'vant';
  18. import { defineComponent, nextTick, onMounted, reactive, ref } from 'vue';
  19. import styles from './detail.module.less';
  20. import { browser, toChinesNum } from '@/helpers/utils';
  21. import SOLO from './images/SOLO.png';
  22. import REPRISE from './images/REPRISE.png';
  23. import ENSEMBLE from './images/ENSEMBLE.png';
  24. import UNISON from './images/UNISON.png';
  25. import MImagePreview from '@/components/m-image-preview';
  26. import SkeletionIndexModal from './skeletion-index-modal';
  27. import SkeletionDetailModal from './skeletion-detail-modal';
  28. import request from '@/helpers/request';
  29. import { useRoute, useRouter } from 'vue-router';
  30. import { activeStatus, activityStatus } from '@/helpers/constant';
  31. import dayjs from 'dayjs';
  32. import { formatterTimer } from './operation';
  33. import MPopup from '@/components/m-popup';
  34. import CastModal from './components/cast-modal';
  35. import iconEdit from './images/icon-edit.png';
  36. import html2canvas from 'html2canvas';
  37. import { postMessage, promisefiyPostMessage } from '@/helpers/native-message';
  38. import backIcon from './images/back-icon.png';
  39. import eidtIcon from './images/eidt-icon.png';
  40. import shareIcon from './images/share-icon.png';
  41. import jiemuIcon from './images/jiemu-icon.png';
  42. import hornIcon from './images/horn-icon.png';
  43. import noteIcon from './images/note-icon.png';
  44. import colorBg from './images/colorBg.png';
  45. import dieIcon from './images/die-icon.png';
  46. import dBall from './images/d-ball.png';
  47. import qBall from './images/q-ball.png';
  48. import cBall from './images/c-ball.png';
  49. import hBall from './images/h-ball.png';
  50. import dotIcon from './images/dot-icon.png';
  51. import Detailswiper from './detail-swiper';
  52. import bottomBg from './images/bottomBg.png';
  53. import logo from './images/logo.png';
  54. import MQrcode from '@/components/m-qrcode';
  55. import { state } from '@/state';
  56. import { useRect } from '@vant/use';
  57. import iconWechat from './images/iconWechat.png';
  58. import iconSaveImage from './images/iconSaveImage.png';
  59. import shareBg from './images/shareBg.png';
  60. import schoolIcon from './images/schoolIcon.png';
  61. import popupQrcodeBg from './images/popupQrcodeBg.png';
  62. import shareBottom from './images/shareBottom.png';
  63. import popupShareBg from './images/popup-share-bg.png';
  64. import { vaildTeachingUrl } from '@/helpers/utils';
  65. export default defineComponent({
  66. name: 'detail-page',
  67. setup() {
  68. const route = useRoute();
  69. const router = useRouter();
  70. // console.log(toChinesNum(11));
  71. const forms = reactive({
  72. id: route.query.id,
  73. imageShow: false,
  74. imagePreview: [] as any,
  75. startPosition: 0,
  76. headerLoading: true,
  77. detailLoading: true,
  78. detail: [] as any[],
  79. headerDetail: {} as any,
  80. castStatus: false,
  81. studentAllList: [] as any,
  82. navBarHeight: state.navBarHeight
  83. });
  84. const shareForms = reactive({
  85. id: route.query.id,
  86. share: route.query.share as any,
  87. showQrcode: false,
  88. url:
  89. vaildTeachingUrl() +
  90. '/school/#/activity-record-detail' +
  91. `?id=${route.query.id}`,
  92. width: 0,
  93. height: 0
  94. });
  95. const getDetail = async () => {
  96. try {
  97. const { data } = await request.get(
  98. '/api-web/schoolActivity/detail/' + forms.id
  99. );
  100. const { detail, ...res } = data || {};
  101. detail.forEach((item: any) => {
  102. item.attachmentUrl = item.attachmentUrl
  103. ? item.attachmentUrl.split(',')
  104. : [];
  105. });
  106. forms.detail = detail;
  107. forms.headerDetail = { ...res };
  108. } catch {
  109. //
  110. } finally {
  111. forms.headerLoading = false;
  112. forms.detailLoading = false;
  113. }
  114. };
  115. const formatterStudentList = (list: any[]) => {
  116. const tempList: any[] = [];
  117. list.map((student: any) => {
  118. let count = 0;
  119. const students: any[] = [];
  120. student.studentList.forEach((item: any) => {
  121. if (item.selected) {
  122. count++;
  123. students.push(item);
  124. }
  125. });
  126. if (count > 0) {
  127. tempList.push({
  128. studentCount: count,
  129. subjectId: student.subjectId,
  130. subjectName: student.subjectName,
  131. studentList: students
  132. });
  133. }
  134. });
  135. forms.studentAllList = tempList;
  136. forms.castStatus = true;
  137. };
  138. const formatterImage = (name: string) => {
  139. let image: string = '';
  140. switch (name) {
  141. case 'SOLO':
  142. image = dBall;
  143. break;
  144. case 'REPRISE':
  145. image = cBall;
  146. break;
  147. case 'ENSEMBLE':
  148. image = hBall;
  149. break;
  150. case 'UNISON':
  151. image = qBall;
  152. break;
  153. default:
  154. image = SOLO;
  155. break;
  156. }
  157. return image;
  158. };
  159. onMounted(() => {
  160. // setTimeout(() => {
  161. // // forms.headerLoading = false;
  162. // // forms.detailLoading = false;
  163. // }, 1000);
  164. getDetail();
  165. });
  166. const imgs = reactive({
  167. saveLoading: false,
  168. image: null as any,
  169. shareLoading: false
  170. });
  171. const onSaveImg = async () => {
  172. // 判断是否在保存中...
  173. if (imgs.saveLoading) {
  174. return;
  175. }
  176. imgs.saveLoading = true;
  177. // 判断是否已经生成图片
  178. console.log(imgs.image);
  179. if (imgs.image) {
  180. saveImg();
  181. } else {
  182. const container: any = document.getElementById(`preview-container`);
  183. html2canvas(container, {
  184. allowTaint: true,
  185. useCORS: true,
  186. backgroundColor: null
  187. })
  188. .then(async canvas => {
  189. const url = canvas.toDataURL('image/png');
  190. imgs.image = url;
  191. console.log(url, 'html2canvas');
  192. saveImg();
  193. })
  194. .catch(() => {
  195. // closeToast();
  196. imgs.saveLoading = false;
  197. });
  198. }
  199. };
  200. const showImageToas = (obj: any) => {
  201. forms.imagePreview = obj.imagePreview;
  202. forms.imageShow = obj.imageShow;
  203. forms.startPosition = obj.startPosition;
  204. console.log(forms.imagePreview, 'showImageToas', obj);
  205. };
  206. const onShare = () => {
  207. console.log('onShare');
  208. if (imgs.shareLoading) {
  209. return;
  210. }
  211. imgs.shareLoading = true;
  212. if (imgs.image) {
  213. openShare();
  214. console.log('onShareimgs.image');
  215. } else {
  216. const container: any = document.getElementById(`preview-container`);
  217. html2canvas(container, {
  218. allowTaint: true,
  219. useCORS: true,
  220. backgroundColor: null
  221. })
  222. .then(async canvas => {
  223. const url = canvas.toDataURL('image/png');
  224. imgs.image = url;
  225. openShare();
  226. console.log('onShareimgs.Noimage');
  227. })
  228. .catch(e => {
  229. // closeToast();
  230. console.log(e);
  231. imgs.shareLoading = false;
  232. });
  233. }
  234. };
  235. const openShare = () => {
  236. const image = imgs.image;
  237. setTimeout(() => {
  238. imgs.shareLoading = false;
  239. }, 100);
  240. if (image) {
  241. console.log('postMessage', 'shareTripartite');
  242. postMessage(
  243. {
  244. api: 'shareTripartite',
  245. content: {
  246. title: '',
  247. desc: '',
  248. image,
  249. video: '',
  250. type: 'image',
  251. // button: ['copy']
  252. shareType: 'wechat'
  253. }
  254. },
  255. (res: any) => {
  256. if (res && res.content) {
  257. showToast(
  258. res.content.message ||
  259. (res.content.status ? '分享成功' : '分享失败')
  260. );
  261. }
  262. }
  263. );
  264. }
  265. };
  266. const saveImg = async () => {
  267. showLoadingToast({ message: '图片生成中...', forbidClick: true });
  268. setTimeout(() => {
  269. imgs.saveLoading = false;
  270. }, 100);
  271. const res = await promisefiyPostMessage({
  272. api: 'savePicture',
  273. content: {
  274. base64: imgs.image
  275. }
  276. });
  277. if (res?.content?.status === 'success') {
  278. showSuccessToast('已保存到相册');
  279. } else {
  280. showFailToast('保存失败');
  281. }
  282. };
  283. return () => (
  284. <div class={styles.detail}>
  285. {/* <MHeader>
  286. {{
  287. right: () => (
  288. <>
  289. <Icon
  290. name={iconEdit}
  291. class={styles.iconEdit}
  292. onClick={() => {
  293. router.push({
  294. path: '/activity-record-operation',
  295. query: {
  296. id: forms.id
  297. }
  298. });
  299. }}
  300. />
  301. <Icon
  302. name={iconEdit}
  303. class={styles.iconEdit}
  304. onClick={() => onShare()}
  305. />
  306. </>
  307. )
  308. }}
  309. </MHeader> */}
  310. <div
  311. class={styles.detailTop}
  312. style={{
  313. '--bar-height': state.navBarHeight + 'px'
  314. }}>
  315. {!browser().isApp ? (
  316. <>
  317. <div
  318. class={styles.fixWrap}
  319. style={{ top: state.navBarHeight + 20 + 'px' }}>
  320. <div class={styles.fixWrapLeft}>
  321. <Image
  322. src={backIcon}
  323. onClick={() => {
  324. if (browser().isApp) {
  325. postMessage({
  326. api: 'goBack'
  327. });
  328. } else {
  329. router.back();
  330. }
  331. }}></Image>
  332. </div>
  333. <div class={styles.fixWrapRight}>
  334. <Image
  335. src={eidtIcon}
  336. class={styles.editIcon}
  337. onClick={() => {
  338. router.push({
  339. path: '/activity-record-operation',
  340. query: {
  341. id: forms.id
  342. }
  343. });
  344. }}></Image>
  345. <Image
  346. src={shareIcon}
  347. onClick={() => {
  348. shareForms.showQrcode = true;
  349. nextTick(() => {
  350. const previewContainer = document.querySelector(
  351. '#preview-container'
  352. ) as HTMLElement;
  353. const share = useRect(previewContainer);
  354. shareForms.width = share.width;
  355. shareForms.height = share.height;
  356. if (share.width > 0 && share.height > 0) {
  357. previewContainer.style.width =
  358. Math.round(share.width) + 'px';
  359. previewContainer.style.height =
  360. Math.round(share.height) + 'px';
  361. }
  362. });
  363. }}></Image>
  364. </div>
  365. </div>
  366. </>
  367. ) : null}
  368. <div class={styles.wall}> </div>
  369. <Image src={jiemuIcon} class={styles.jiemuIcon}></Image>
  370. <div class={styles.typeCard}>
  371. {' '}
  372. {activityStatus[forms.headerDetail.type]}
  373. </div>
  374. <SkeletionIndexModal
  375. v-model:show={forms.headerLoading}
  376. showCount={[1]}
  377. isLink={false}>
  378. {/* <CellGroup inset class={styles.cellGroup}>
  379. <Cell center class={styles.cellTitle}>
  380. {{
  381. icon: () => (
  382. <Tag plain type="primary" class={styles.tag}>
  383. {activityStatus[forms.headerDetail.type]}
  384. </Tag>
  385. ),
  386. title: () => (
  387. <div class={[styles.title, 'van-ellipsis']}>
  388. {forms.headerDetail.name}
  389. </div>
  390. )
  391. }}
  392. </Cell>
  393. <Cell
  394. class={styles.cellTimer}
  395. center
  396. title={`活动日期:${dayjs(forms.headerDetail.startTime).format(
  397. 'YYYY年MM月DD日'
  398. )}`}
  399. value={activeStatus[forms.headerDetail.status]}
  400. valueClass={
  401. forms.headerDetail.status === 'PROCESSING' ? styles.ing : ''
  402. }></Cell>
  403. </CellGroup> */}
  404. <div class={styles.activeInfo}>
  405. <Image src={hornIcon} class={styles.hornIcon}></Image>
  406. <h4 class={styles.headerName}> {forms.headerDetail.name}</h4>
  407. <p class={styles.headerTimes}>{`活动日期:${dayjs(
  408. forms.headerDetail.startTime
  409. ).format('YYYY年MM月DD日')}`}</p>
  410. <Image src={noteIcon} class={styles.noteIcon}></Image>
  411. </div>
  412. </SkeletionIndexModal>
  413. </div>
  414. <SkeletionDetailModal
  415. v-model:show={forms.detailLoading}
  416. showCount={[1, 2]}>
  417. <div class={styles.programWrap}>
  418. <div class={styles.programList}>
  419. {forms.detail.map((item: any, index: number) => (
  420. <div class={styles.programItem}>
  421. <Image src={colorBg} class={styles.colorBg}></Image>
  422. <div class={styles.pTitle}>节目{toChinesNum(index + 1)}</div>
  423. <div class={styles.programInfo}>
  424. <Image
  425. class={styles.ballIcon}
  426. src={formatterImage(item.type)}></Image>
  427. <div class={styles.programInfoTitleWrap}>
  428. <Image class={styles.dieIcon} src={dieIcon}></Image>
  429. <div class={styles.programInfoTitle}> {item.name}</div>
  430. <Image class={styles.dotIcon} src={dotIcon}></Image>
  431. </div>
  432. <Row class={styles.itemRow}>
  433. <Col span={6} class={styles.label}>
  434. 表演乐团:
  435. </Col>
  436. <Col span={18} class={styles.content}>
  437. {item.musicGroupName}
  438. <span
  439. onClick={() => {
  440. if (item.studentNum <= 0) return;
  441. formatterStudentList(item.studentList);
  442. }}>
  443. 共{item.studentNum}名 <Icon name="arrow" />
  444. </span>
  445. </Col>
  446. </Row>
  447. <Row class={styles.itemRow} style={{ marginBottom: '0' }}>
  448. <Col span={6} class={styles.label}>
  449. 表演团队:
  450. </Col>
  451. <Col span={18} class={styles.content}>
  452. {item.subjectNameList}
  453. </Col>
  454. </Row>
  455. <Row class={styles.itemRow} style={{ marginBottom: '0' }}>
  456. <Col span={6} class={styles.label}>
  457. 节目时长:
  458. </Col>
  459. <Col span={18} class={styles.content}>
  460. {formatterTimer(item.time).minute}分
  461. {formatterTimer(item.time).secord}秒
  462. </Col>
  463. </Row>
  464. </div>
  465. <Detailswiper
  466. item={item}
  467. onShowImageToas={showImageToas}></Detailswiper>
  468. {/* <CellGroup inset class={styles.pCellGroup}>
  469. <Cell center>
  470. {{
  471. icon: () => (
  472. <img
  473. src={formatterImage(item.type)}
  474. class={styles.imgType}
  475. />
  476. ),
  477. title: () => (
  478. <div class={[styles.title, 'van-ellipsis']}>
  479. {item.name}
  480. </div>
  481. ),
  482. value: () => {
  483. const timer = formatterTimer(item.time);
  484. return (
  485. <span class={styles.time}>
  486. {timer.minute}分{timer.secord}秒
  487. </span>
  488. );
  489. }
  490. }}
  491. </Cell>
  492. <Cell
  493. center
  494. class={styles.moreCell}
  495. valueClass={styles.valueClass}>
  496. <Row class={styles.item}>
  497. <Col span={6} class={styles.label}>
  498. 表演乐团
  499. </Col>
  500. <Col span={18} class={styles.content}>
  501. {item.musicGroupName}
  502. <span
  503. onClick={() => {
  504. if (item.studentNum <= 0) return;
  505. formatterStudentList(item.studentList);
  506. }}>
  507. 共{item.studentNum}名 <Icon name="arrow" />
  508. </span>
  509. </Col>
  510. </Row>
  511. <Row class={styles.item} style={{ marginBottom: '0' }}>
  512. <Col span={6} class={styles.label}>
  513. 表演团队
  514. </Col>
  515. <Col span={18} class={styles.content}>
  516. {item.subjectNameList}
  517. </Col>
  518. </Row>
  519. {item.attachmentUrl ? (
  520. <div class={styles.photoList}>
  521. {item.attachmentUrl.map(
  522. (i: any, index: number) =>
  523. index <= 3 && (
  524. <div
  525. class={styles.photo}
  526. onClick={() => {
  527. forms.imagePreview = item.attachmentUrl;
  528. forms.imageShow = true;
  529. forms.startPosition = index;
  530. }}>
  531. {checkFile(i, 'image') ? (
  532. <Image
  533. src={i}
  534. fit="cover"
  535. />
  536. ) : (
  537. <video
  538. style={{ backgroundColor: '#F8F8F8' }}
  539. poster={iconVideoDefault}
  540. src={i + '#t=1,4'}
  541. />
  542. )}
  543. {item.attachmentUrl.length > 4 &&
  544. index === 3 ? (
  545. <div class={styles.photoMore}>
  546. +{item.attachmentUrl.length - 4}
  547. </div>
  548. ) : (
  549. ''
  550. )}
  551. </div>
  552. )
  553. )}
  554. </div>
  555. ) : (
  556. ''
  557. )}
  558. </Cell>
  559. </CellGroup> */}
  560. </div>
  561. ))}
  562. </div>
  563. <div class={styles.bottomWrap}>
  564. {browser().isApp ? null : (
  565. <Image class={styles.logo} src={logo}></Image>
  566. )}
  567. <Image class={styles.bottomBg} src={bottomBg}></Image>
  568. </div>
  569. </div>
  570. </SkeletionDetailModal>
  571. <MImagePreview
  572. v-model:show={forms.imageShow}
  573. images={forms.imagePreview}
  574. startPosition={forms.startPosition}
  575. />
  576. {/* 演员名单 */}
  577. <MPopup v-model:modelValue={forms.castStatus}>
  578. <CastModal
  579. type="look"
  580. subjectAllList={forms.studentAllList}
  581. onClose={() => (forms.castStatus = false)}
  582. />
  583. </MPopup>
  584. <Popup
  585. v-model:show={shareForms.showQrcode}
  586. position="bottom"
  587. style={{ background: 'transparent' }}>
  588. <div class={styles.codeContainer}>
  589. <div
  590. class={[styles.codeImg, styles.teacherCodeImg]}
  591. id="preview-container">
  592. <Image src={popupShareBg} class={styles.popupWeekBanner} />
  593. <div class={styles.timerBg}>
  594. {dayjs(forms.headerDetail.startTime).format('YYYY年MM月DD日')}
  595. </div>
  596. <div class={styles.codeContent}>
  597. {/* <Image
  598. class={styles.schoolLogo}
  599. fit="cover"
  600. src={
  601. forms.headerDetail?.cooperationOrganLogo
  602. ? forms.headerDetail?.cooperationOrganLogo
  603. : schoolIcon
  604. }></Image> */}
  605. <img
  606. class={[styles.schoolLogo]}
  607. src={
  608. forms.headerDetail?.cooperationOrganLogo
  609. ? forms.headerDetail?.cooperationOrganLogo +
  610. '?t=' +
  611. Date.now()
  612. : schoolIcon
  613. }
  614. crossorigin="anonymous"
  615. style={{
  616. objectFit: 'cover'
  617. }}
  618. />
  619. <div class={[styles.schoolName, 'van-multi-ellipsis--l2']}>
  620. {forms.headerDetail?.cooperationOrganName || '--'}
  621. 武昌学校武昌学校武昌学校武昌学校武昌学校武昌学校武昌学校武昌学校武昌学校武昌学校武昌学校武昌学校武昌学校武昌学校武昌学校武昌学校武昌学校武昌学校
  622. </div>
  623. <div class={[styles.shareName, 'van-ellipsis']}>
  624. {forms.headerDetail.name}
  625. </div>
  626. <div class={styles.codeQr}>
  627. <Image src={popupQrcodeBg} class={styles.popupQrcodeBg} />
  628. <MQrcode
  629. text={shareForms.url}
  630. size={'100%'}
  631. logoSize="small"
  632. />
  633. </div>
  634. <Image src={shareBottom} class={styles.shareBottom}></Image>
  635. </div>
  636. </div>
  637. <div class={styles.codeBottom}>
  638. <Icon
  639. name="cross"
  640. size={22}
  641. class={styles.close}
  642. color="#666"
  643. onClick={() => (shareForms.showQrcode = false)}
  644. />
  645. <h3 class={styles.title}>
  646. <i></i>分享方式
  647. </h3>
  648. <Grid columnNum={2} border={false}>
  649. <GridItem onClick={onSaveImg}>
  650. {{
  651. icon: () => (
  652. <Image class={styles.shareImg} src={iconSaveImage} />
  653. ),
  654. text: () => <div class={styles.shareText}>保存图片</div>
  655. }}
  656. </GridItem>
  657. <GridItem onClick={onShare}>
  658. {{
  659. icon: () => (
  660. <Image class={styles.shareImg} src={iconWechat} />
  661. ),
  662. text: () => <div class={styles.shareText}>微信</div>
  663. }}
  664. </GridItem>
  665. </Grid>
  666. </div>
  667. </div>
  668. </Popup>
  669. </div>
  670. );
  671. }
  672. });