week-report.tsx 10.0 KB

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