week-report.tsx 11 KB

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