week-report.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. import OHeader from '@/components/o-header'
  2. import { defineComponent, onMounted, reactive } from 'vue'
  3. import styles from './report.module.less'
  4. import iconOrchestra from '@/views/mine-orchestra/images/icon-or.png'
  5. import {
  6. closeToast,
  7. Grid,
  8. GridItem,
  9. Icon,
  10. Image,
  11. Popup,
  12. showFailToast,
  13. showLoadingToast,
  14. showSuccessToast,
  15. showToast
  16. } from 'vant'
  17. import trainWeek from './images/week/icon-train-week.png'
  18. import OrchestraNum from './modal/orchestra-num'
  19. import TrainClass from './modal/train-class'
  20. import StudentAttendance from './modal/student-attendance'
  21. import TeacherAttendance from './modal/teacher-attendance'
  22. import TrainProgress from './modal/train-progress'
  23. import iconPhoto from './images/icon-photo.png'
  24. import iconClass from './images/icon-class.png'
  25. import iconSaveImage from '@/school/orchestra/images/icon-save-image.png'
  26. import iconWechat from '@/school/orchestra/images/icon-wechat.png'
  27. import iconWeekPoint from './images/week/icon-point.png'
  28. import popupWeekBanner from './images/week/popup-week-banner.png'
  29. import popupQrcodeBg from './images/popup-qrcode-bg.png'
  30. import OQrcode from '@/components/o-qrcode'
  31. import { useRoute, useRouter } from 'vue-router'
  32. import request from '@/helpers/request'
  33. import { postMessage, promisefiyPostMessage } from '@/helpers/native-message'
  34. import html2canvas from 'html2canvas'
  35. export const reportCourseType = {
  36. PERCUSSION: '打击乐',
  37. FLUTE: '长笛',
  38. SAX: '萨克斯',
  39. CLARINET: '单簧管',
  40. TRUMPET: '小号',
  41. TROMBONE: '长号',
  42. HORN: '圆号',
  43. BARITONE_TUBA: '上低音号-大号',
  44. EUPHONIUM: '上低音号',
  45. TUBA: '大号',
  46. MUSIC_THEORY: '乐理',
  47. INSTRUMENTAL_ENSEMBLE: '合奏'
  48. }
  49. export default defineComponent({
  50. name: 'train-report',
  51. setup() {
  52. const router = useRouter()
  53. const route = useRoute()
  54. const forms = reactive({
  55. id: route.query.id,
  56. showQrcode: false,
  57. share: route.query.share as any,
  58. url: window.location.href + '&share=1'
  59. })
  60. const reportData = reactive({
  61. orchestraName: null,
  62. startTime: null,
  63. endTime: null,
  64. COURSEWARE: {},
  65. coursewareList: [] as any,
  66. COURSE_SCHEDULE: {},
  67. KNOWLEDGE: {},
  68. ORCHESTRA: {},
  69. PHOTO: {} as any,
  70. STUDENT_ATTENDANCE: {},
  71. TEACHER_ATTENDANCE: {}
  72. })
  73. const getDetail = async () => {
  74. try {
  75. const { data } = await request.get('/api-school/open/orchestraReport/detail/' + forms.id)
  76. reportData.COURSEWARE = data.reportItem.COURSEWARE || {}
  77. reportData.COURSE_SCHEDULE = data.reportItem.COURSE_SCHEDULE || {}
  78. reportData.KNOWLEDGE = data.reportItem.KNOWLEDGE || {}
  79. reportData.ORCHESTRA = data.reportItem.ORCHESTRA || {}
  80. reportData.PHOTO = data.reportItem.PHOTO || {}
  81. reportData.STUDENT_ATTENDANCE = data.reportItem.STUDENT_ATTENDANCE || {}
  82. reportData.TEACHER_ATTENDANCE = data.reportItem.TEACHER_ATTENDANCE || {}
  83. reportData.orchestraName = data.orchestraName || ''
  84. reportData.startTime = data.startTime || ''
  85. reportData.endTime = data.endTime || ''
  86. const courseware = reportData.COURSEWARE
  87. for (const i in courseware) {
  88. i != 'TOTAL' && reportData.coursewareList.push(reportCourseType[i])
  89. }
  90. } catch {
  91. //
  92. }
  93. }
  94. const imgs = reactive({
  95. saveLoading: false,
  96. image: null as any,
  97. shareLoading: false
  98. })
  99. const onSaveImg = async () => {
  100. // 判断是否在保存中...
  101. if (imgs.saveLoading) {
  102. return
  103. }
  104. imgs.saveLoading = true
  105. // 判断是否已经生成图片
  106. if (imgs.image) {
  107. saveImg()
  108. } else {
  109. const container: any = document.getElementById(`preview-container`)
  110. html2canvas(container, {
  111. allowTaint: true,
  112. useCORS: true,
  113. backgroundColor: null
  114. })
  115. .then(async (canvas) => {
  116. const url = canvas.toDataURL('image/png')
  117. imgs.image = url
  118. saveImg()
  119. })
  120. .catch(() => {
  121. closeToast()
  122. imgs.saveLoading = false
  123. })
  124. }
  125. }
  126. const onShare = () => {
  127. if (imgs.shareLoading) {
  128. return
  129. }
  130. imgs.shareLoading = true
  131. if (imgs.image) {
  132. openShare()
  133. } else {
  134. const container: any = document.getElementById(`preview-container`)
  135. html2canvas(container, {
  136. allowTaint: true,
  137. useCORS: true,
  138. backgroundColor: null
  139. })
  140. .then(async (canvas) => {
  141. const url = canvas.toDataURL('image/png')
  142. imgs.image = url
  143. openShare()
  144. })
  145. .catch(() => {
  146. closeToast()
  147. imgs.shareLoading = false
  148. })
  149. }
  150. }
  151. const openShare = () => {
  152. const image = imgs.image
  153. setTimeout(() => {
  154. imgs.shareLoading = false
  155. }, 100)
  156. if (image) {
  157. postMessage(
  158. {
  159. api: 'shareTripartite',
  160. content: {
  161. title: '',
  162. desc: '',
  163. image,
  164. video: '',
  165. type: 'image',
  166. // button: ['copy']
  167. shareType: 'wechat'
  168. }
  169. },
  170. (res: any) => {
  171. if (res && res.content) {
  172. showToast(res.content.message || (res.content.status ? '分享成功' : '分享失败'))
  173. }
  174. }
  175. )
  176. }
  177. }
  178. const saveImg = async () => {
  179. showLoadingToast({ message: '图片生成中...', forbidClick: true })
  180. setTimeout(() => {
  181. imgs.saveLoading = false
  182. }, 100)
  183. const res = await promisefiyPostMessage({
  184. api: 'savePicture',
  185. content: {
  186. base64: imgs.image
  187. }
  188. })
  189. if (res?.content?.status === 'success') {
  190. showSuccessToast('保存成功')
  191. } else {
  192. showFailToast('保存失败')
  193. }
  194. }
  195. onMounted(() => {
  196. getDetail()
  197. })
  198. return () => (
  199. <div class={[styles.trainWeek, forms.share == 1 ? styles.trasinWeekShare : '']}>
  200. <div class={styles.trainContainer}></div>
  201. <OHeader background="transparent" border={false} title=" " backIconColor="white">
  202. {{
  203. right: () =>
  204. forms.share != 1 && (
  205. <i class={styles.iconShare} onClick={() => (forms.showQrcode = true)}></i>
  206. )
  207. }}
  208. </OHeader>
  209. <div class={styles.headerContant}>
  210. <div class={styles.orchestra}>
  211. <Image src={iconOrchestra} class={styles.iconOrchestra} />
  212. <span>{reportData.orchestraName}</span>
  213. </div>
  214. <div>
  215. <Image src={trainWeek} class={styles.iconTrainWeek} />
  216. </div>
  217. <div class={styles.trainTimer}>
  218. {reportData.startTime}-{reportData.endTime}
  219. </div>
  220. </div>
  221. <OrchestraNum reportData={reportData.ORCHESTRA} />
  222. <TrainClass reportData={reportData.COURSE_SCHEDULE} />
  223. <div class={styles.trainPhoto}>
  224. <Image src={iconPhoto} class={styles.iconPhoto} />
  225. <p
  226. onClick={() => {
  227. if (forms.share == 1) return
  228. router.push({
  229. path: '/school-photo'
  230. })
  231. }}
  232. >
  233. 本周上传<span>{reportData.PHOTO.TOTAL || 0}</span>张训练照片
  234. {forms.share != 1 && <Icon name="arrow" />}
  235. </p>
  236. </div>
  237. <StudentAttendance reportData={reportData.STUDENT_ATTENDANCE} />
  238. <TeacherAttendance reportData={reportData.TEACHER_ATTENDANCE} />
  239. <div class={[styles.trainClass]}>
  240. <Image src={iconClass} class={styles.iconPhoto} />
  241. <div>
  242. <p class={styles.subjectTips}>课件使用未达标班级</p>
  243. <p class={styles.subjectNames}>
  244. {reportData.coursewareList.map((item: string) => item + ' ')}
  245. </p>
  246. </div>
  247. </div>
  248. <TrainProgress reportData={reportData.KNOWLEDGE} />
  249. <Popup
  250. v-model:show={forms.showQrcode}
  251. position="bottom"
  252. style={{ background: 'transparent' }}
  253. >
  254. <div class={styles.codeContainer}>
  255. <div class={styles.codeImg} id="preview-container">
  256. <Image src={popupWeekBanner} class={styles.popupWeekBanner} />
  257. <div class={styles.codeContent}>
  258. <div class={[styles.headerContant, styles.headerContantPopup]}>
  259. <div class={styles.orchestra}>
  260. <Image src={iconOrchestra} class={styles.iconOrchestra} />
  261. <span>{reportData.orchestraName}</span>
  262. </div>
  263. <div>
  264. <Image src={trainWeek} class={styles.iconTrainWeek} />
  265. </div>
  266. <div class={styles.trainTimer}>
  267. <Image class={styles.point} src={iconWeekPoint} />
  268. {reportData.startTime}-{reportData.endTime}
  269. <Image class={styles.point} src={iconWeekPoint} />
  270. {/* {reportData.startTime}-{reportData.endTime} */}
  271. </div>
  272. </div>
  273. <div class={styles.codeQr}>
  274. <Image src={popupQrcodeBg} class={styles.popupQrcodeBg} />
  275. <OQrcode text={forms.url} size={'100%'} logoSize="small" />
  276. </div>
  277. <div style={{ textAlign: 'center' }}>
  278. <span class={styles.codeBtnText}>
  279. 扫描上方二维码<span>查看训练周报</span>
  280. </span>
  281. </div>
  282. </div>
  283. </div>
  284. <div class={styles.codeBottom}>
  285. <Icon
  286. name="cross"
  287. size={22}
  288. class={styles.close}
  289. color="#666"
  290. onClick={() => (forms.showQrcode = false)}
  291. />
  292. <h3 class={styles.title}>
  293. <i></i>分享方式
  294. </h3>
  295. <Grid columnNum={2} border={false}>
  296. <GridItem onClick={onSaveImg}>
  297. {{
  298. icon: () => <Image class={styles.shareImg} src={iconSaveImage} />,
  299. text: () => <div class={styles.shareText}>保存图片</div>
  300. }}
  301. </GridItem>
  302. <GridItem onClick={onShare}>
  303. {{
  304. icon: () => <Image class={styles.shareImg} src={iconWechat} />,
  305. text: () => <div class={styles.shareText}>微信</div>
  306. }}
  307. </GridItem>
  308. </Grid>
  309. </div>
  310. </div>
  311. </Popup>
  312. </div>
  313. )
  314. }
  315. })