addTrainStandard.tsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. import { useUserStore } from '@/store/modules/user'
  2. import {
  3. FormItemRule,
  4. NAlert,
  5. NButton,
  6. NDivider,
  7. NForm,
  8. NFormItem,
  9. NImage,
  10. NInput,
  11. NInputNumber,
  12. NSpace,
  13. NTabPane,
  14. NTabs,
  15. useMessage
  16. } from 'naive-ui'
  17. import { defineComponent, reactive } from 'vue'
  18. import { lessonTrainingDetailBatchInsert, lessonTrainingDetailTempBatchUpSet } from '../../api'
  19. import ColVideo from '@/components/col-video'
  20. export default defineComponent({
  21. name: 'addTrainStandard',
  22. props: {
  23. item: {
  24. type: Object,
  25. default: () => {}
  26. }
  27. },
  28. emits: ['handleAdd', 'close'],
  29. setup(props, { emit }) {
  30. console.log('🚀 ~ props', props.item)
  31. const userStore = useUserStore()
  32. const prefix = /(localhost|192)/.test(location.host)
  33. ? 'https://ponline.colexiu.com'
  34. : location.origin //
  35. const src =
  36. prefix +
  37. `/orchestra-music-score/?_t=${Date.now()}&id=${
  38. props.item.content
  39. }&modelType=practice&Authorization=${userStore.getToken}`
  40. const message = useMessage()
  41. const state = reactive({
  42. current: 1,
  43. list: [
  44. {
  45. id: 1,
  46. name: '单团学生',
  47. materialType: props.item?.type,
  48. practiceTimes: '',
  49. startSection: '',
  50. endSection: '',
  51. speed: '',
  52. practiceDuration: ''
  53. },
  54. {
  55. id: 2,
  56. name: '双团学生',
  57. materialType: props.item?.type,
  58. practiceTimes: '',
  59. startSection: '',
  60. endSection: '',
  61. speed: '',
  62. practiceDuration: ''
  63. },
  64. {
  65. id: 3,
  66. name: '多团学生',
  67. materialType: props.item?.type,
  68. practiceTimes: '',
  69. startSection: '',
  70. endSection: '',
  71. speed: '',
  72. practiceDuration: ''
  73. }
  74. ]
  75. })
  76. const init = () => {
  77. if (Array.isArray(props?.item?.standards)) {
  78. for (let i = 0; i < props.item.standards.length; i++) {
  79. let trainingConfigJson: any = {}
  80. try {
  81. trainingConfigJson = JSON.parse(props.item.standards[i].trainingConfigJson)
  82. } catch (error) {}
  83. state.list[i].practiceTimes = trainingConfigJson.practiceTimes
  84. state.list[i].startSection = trainingConfigJson.startSection
  85. state.list[i].endSection = trainingConfigJson.endSection
  86. state.list[i].speed = trainingConfigJson.speed
  87. state.list[i].practiceDuration = trainingConfigJson.practiceDuration
  88. }
  89. }
  90. }
  91. init()
  92. const handleAdd = async () => {
  93. if (props.item?.type == 'VIDEO') {
  94. for (let i = 0; i < state.list.length; i++) {
  95. if (!state.list[i].practiceTimes) {
  96. message.error(`请完善${state.list[i].name}的观看次数`)
  97. return
  98. }
  99. if (!/^\+?[1-9]\d*$/.test(state.list[i].practiceTimes)) {
  100. message.error(`请输入${state.list[i].name}正确的数字观看次数`)
  101. return
  102. }
  103. }
  104. }
  105. if (props.item?.type == 'SONG') {
  106. for (let i = 0; i < state.list.length; i++) {
  107. if (
  108. !state.list[i].startSection ||
  109. !state.list[i].endSection ||
  110. !state.list[i].speed ||
  111. !state.list[i].practiceDuration
  112. ) {
  113. message.error(`请完善${state.list[i].name}的训练要求`)
  114. return
  115. }
  116. if (
  117. !/^\+?[1-9]\d*$/.test(state.list[i].startSection) ||
  118. !/^\+?[1-9]\d*$/.test(state.list[i].endSection) ||
  119. !/^\+?[1-9]\d*$/.test(state.list[i].speed) ||
  120. !/^\+?[1-9]\d*$/.test(state.list[i].practiceDuration)
  121. ) {
  122. message.error(`请输入${state.list[i].name}正确的数字`)
  123. return
  124. }
  125. }
  126. }
  127. let list = state.list.map((n: any, i: number) => {
  128. return {
  129. studentLevel: i + 1,
  130. lessonTrainingId: props.item?.lessonTrainingId,
  131. lessonTrainingDetailId: props.item?.id,
  132. trainingConfigJson: JSON.stringify({
  133. materialType: n.materialType,
  134. practiceTimes: n.practiceTimes,
  135. startSection: n.startSection,
  136. endSection: n.endSection,
  137. speed: n.speed,
  138. practiceDuration: n.practiceDuration
  139. })
  140. }
  141. })
  142. console.log('🚀 ~ list', list)
  143. try {
  144. const res: any = await lessonTrainingDetailTempBatchUpSet(list)
  145. message.success('保存成功')
  146. } catch (error) {}
  147. emit('handleAdd')
  148. }
  149. /** 云教练选段 */
  150. window.addEventListener('message', (event: MessageEvent) => {
  151. console.log(event.data)
  152. const data = event.data
  153. if (data.api === 'admin-selectMusicMeasure') {
  154. state.list.forEach((n: any) => {
  155. n.startSection = n.startSection && !data.change ? n.startSection : data.start + ''
  156. n.endSection = n.endSection && !data.change ? n.endSection : data.end + ''
  157. n.speed = n.speed && !data.change ? n.speed : data.speed + ''
  158. })
  159. }
  160. })
  161. console.log(state.list, 'state.list')
  162. return () => (
  163. <div>
  164. <div>{props.item?.materialName}</div>
  165. {props.item?.type == 'VIDEO' && (
  166. <div>
  167. {/* <video style={{ width: '100%' }} src={props.item.content} controls></video> */}
  168. <ColVideo styleValue={{ width: '100%', height: '375px' }} src={props.item.content} />
  169. {state.list.map((item: any) => {
  170. return (
  171. <NForm labelPlacement="left">
  172. <NAlert
  173. title={item.name}
  174. showIcon={false}
  175. bordered={true}
  176. style={{ marginBottom: '12px' }}
  177. />
  178. <NFormItem required label="观看次数">
  179. <NInputNumber
  180. placeholder="请输入观看次数"
  181. showButton={false}
  182. v-model:value={item.practiceTimes}
  183. min={0}
  184. />
  185. </NFormItem>
  186. </NForm>
  187. )
  188. })}
  189. </div>
  190. )}
  191. {props.item?.type === 'SONG' && (
  192. <div>
  193. <iframe width={'667px'} height={'375px'} frameborder="0" src={src}></iframe>
  194. <NForm labelPlacement="left">
  195. {state.list.map((item: any) => {
  196. return (
  197. <>
  198. <NAlert
  199. title={item.name}
  200. showIcon={false}
  201. bordered={true}
  202. style={{ marginBottom: '12px' }}
  203. />
  204. <NFormItem required label="练习小节">
  205. <NInputNumber
  206. showButton={false}
  207. placeholder="开始小节"
  208. v-model:value={item.startSection}
  209. min={0}
  210. style={{ width: '180px' }}
  211. />
  212. ~
  213. <NInputNumber
  214. showButton={false}
  215. placeholder="结束小节"
  216. v-model:value={item.endSection}
  217. min={0}
  218. style={{ width: '180px' }}
  219. />
  220. </NFormItem>
  221. <NFormItem label="练习速度" required>
  222. <NInputNumber
  223. showButton={false}
  224. placeholder="练习速度"
  225. v-model:value={item.speed}
  226. min={0}
  227. style={{ width: '180px' }}
  228. />
  229. </NFormItem>
  230. <NFormItem label="练习时长" required>
  231. <NInputNumber
  232. v-slots={{ suffix: () => '分钟' }}
  233. v-model:value={item.practiceDuration}
  234. showButton={false}
  235. min={0}
  236. style={{ width: '180px' }}
  237. ></NInputNumber>
  238. </NFormItem>
  239. </>
  240. )
  241. })}
  242. </NForm>
  243. {/* <NTabs type="segment" v-model:value={state.current}>
  244. {state.list.map((item: any) => {
  245. return (
  246. <NTabPane name={item.id} tab={item.name}>
  247. <NSpace>
  248. <NFormItem required label="练习小节">
  249. <NInput placeholder="开始小节" v-model:value={item.startSection} />
  250. ~
  251. <NInput placeholder="结束小节" v-model:value={item.endSection} />
  252. </NFormItem>
  253. <NFormItem label="练习速度" required>
  254. <NInput v-model:value={item.speed}></NInput>
  255. </NFormItem>
  256. </NSpace>
  257. <NFormItem label="练习时长" required>
  258. <NInput
  259. style={{ width: '50%' }}
  260. v-slots={{ suffix: () => '分钟' }}
  261. v-model:value={item.practiceDuration}
  262. ></NInput>
  263. </NFormItem>
  264. </NTabPane>
  265. )
  266. })}
  267. </NTabs> */}
  268. </div>
  269. )}
  270. {props.item?.type === 'IMG' && (
  271. <div>
  272. <NImage width={200} height={200} src={props?.item?.content} />
  273. </div>
  274. )}
  275. <NSpace justify="end">
  276. <NButton onClick={() => emit('close')}>取消</NButton>
  277. <NButton type="primary" onClick={() => handleAdd()}>
  278. 确认
  279. </NButton>
  280. </NSpace>
  281. </div>
  282. )
  283. }
  284. })