index.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. import { PropType, defineComponent, onMounted, reactive, ref } from 'vue';
  2. import styles from './index.module.less';
  3. import {
  4. NButton,
  5. NForm,
  6. NFormItem,
  7. NInputGroup,
  8. NInputGroupLabel,
  9. NInputNumber,
  10. NSpace,
  11. useMessage
  12. } from 'naive-ui';
  13. import {
  14. lessonPreTrainingAdd,
  15. lessonPreTrainingUpdate
  16. } from '/src/views/prepare-lessons/api';
  17. export default defineComponent({
  18. name: 'train-update',
  19. props: {
  20. /** 初始数据 */
  21. item: {
  22. type: Object,
  23. default: () => ({})
  24. },
  25. /** 操作类型 */
  26. type: {
  27. type: String as PropType<'train' | 'homework'>,
  28. default: 'train'
  29. }
  30. },
  31. emits: ['close', 'confirm'],
  32. setup(props, { emit }) {
  33. // 'practice' | 'evaluation'
  34. const message = useMessage();
  35. const forms = reactive({
  36. id: null as any,
  37. uploading: false,
  38. baseMaxScore: 99,
  39. type: 'PRACTICE',
  40. musicId: '',
  41. musicName: '',
  42. coursewareKnowledgeDetailId: '', // 章节编号
  43. minScore: null as any,
  44. maxScore: null as any,
  45. subjectId: '',
  46. coverImg: '',
  47. practiceSpeed: null as any, // 练习速度
  48. practiceTimes: null as any, // 练习时长
  49. difficulty: 'BEGINNER', // 评测难度
  50. evaluationSpeed: null as any, // 评测速度
  51. evaluationScore: null as any // 评测分数
  52. });
  53. const formsRef = ref();
  54. const onSubmit = async () => {
  55. formsRef.value?.validate(async (err: any) => {
  56. if (err) {
  57. return;
  58. }
  59. forms.uploading = true;
  60. try {
  61. const params = {
  62. trainingType: forms.type,
  63. musicId: forms.musicId,
  64. musicName: forms.musicName,
  65. coursewareKnowledgeDetailId: forms.coursewareKnowledgeDetailId,
  66. subjectId: forms.subjectId,
  67. id: forms.id,
  68. coverImg: forms.coverImg,
  69. trainingConfigJson: ''
  70. };
  71. const configJson: any = {};
  72. if (forms.type === 'PRACTICE') {
  73. configJson.practiceChapterBegin = forms.minScore;
  74. configJson.practiceChapterEnd = forms.maxScore;
  75. configJson.practiceSpeed = forms.practiceSpeed;
  76. configJson.trainingTimes = forms.practiceTimes;
  77. } else {
  78. configJson.evaluateDifficult = forms.difficulty;
  79. configJson.evaluateSpeed = forms.evaluationSpeed;
  80. configJson.trainingTimes = forms.evaluationScore;
  81. }
  82. configJson.practiceChapterMax = forms.baseMaxScore;
  83. params.trainingConfigJson = configJson;
  84. if (props.type === 'train') {
  85. if (forms.id) {
  86. await lessonPreTrainingUpdate(params);
  87. message.success('修改成功');
  88. } else {
  89. await lessonPreTrainingAdd(params);
  90. message.success('添加成功');
  91. }
  92. }
  93. emit('close');
  94. emit('confirm', params);
  95. } catch {
  96. //
  97. }
  98. forms.uploading = false;
  99. });
  100. };
  101. onMounted(() => {
  102. const item = props.item;
  103. if (item.trainId) {
  104. forms.id = item.trainId;
  105. forms.minScore = item.practiceChapterBegin;
  106. forms.maxScore = item.practiceChapterEnd;
  107. forms.practiceSpeed = item.practiceSpeed;
  108. forms.type = item.trainingType;
  109. if (item.trainingType === 'PRACTICE') {
  110. forms.practiceTimes = item.trainingTimes;
  111. } else {
  112. forms.evaluationScore = item.trainingTimes;
  113. }
  114. forms.difficulty = item.evaluateDifficult || 'BEGINNER';
  115. forms.evaluationSpeed = item.evaluateSpeed;
  116. } else {
  117. forms.minScore = 1;
  118. forms.maxScore = item.practiceChapterMax ? item.practiceChapterMax : 1;
  119. }
  120. forms.baseMaxScore = item.practiceChapterMax || 99;
  121. forms.musicId = item.id;
  122. forms.musicName = item.musicName;
  123. forms.coursewareKnowledgeDetailId = item.coursewareKnowledgeDetailId;
  124. forms.subjectId = item.subjectId;
  125. forms.coverImg = item.coverImg;
  126. });
  127. return () => (
  128. <div class={styles.trainUpdate}>
  129. <NForm
  130. ref={formsRef}
  131. model={forms}
  132. labelAlign="right"
  133. labelPlacement="left">
  134. <NFormItem
  135. label="训练方式"
  136. path="type"
  137. rule={[{ required: true, message: '请选择训练方式' }]}>
  138. <NSpace>
  139. <NButton
  140. secondary
  141. class={[
  142. styles.switch,
  143. forms.type === 'PRACTICE' ? styles.active : ''
  144. ]}
  145. onClick={() => (forms.type = 'PRACTICE')}>
  146. 练习
  147. </NButton>
  148. <NButton
  149. secondary
  150. class={[
  151. styles.switch,
  152. forms.type === 'EVALUATION' ? styles.active : ''
  153. ]}
  154. onClick={() => (forms.type = 'EVALUATION')}>
  155. 评测
  156. </NButton>
  157. </NSpace>
  158. </NFormItem>
  159. {forms.type === 'PRACTICE' && (
  160. <>
  161. <div class={styles.scoreGroup}>
  162. <NFormItem
  163. label="练习小节"
  164. path="minScore"
  165. rule={[
  166. {
  167. required: true,
  168. message: '请输入最小练习小节',
  169. trigger: ['blur', 'change'],
  170. type: 'number'
  171. }
  172. ]}>
  173. <NInputNumber
  174. v-model:value={forms.minScore}
  175. showButton={false}
  176. min={1}
  177. max={forms.baseMaxScore}
  178. placeholder="最小练习小节"
  179. onUpdate:value={() => {
  180. forms.maxScore = null;
  181. }}
  182. clearable
  183. />
  184. </NFormItem>
  185. <div
  186. style={{
  187. '--n-feedback-height': '24px',
  188. display: 'flex',
  189. alignItems: 'center',
  190. margin: '-2px 2% 0 2%',
  191. marginBottom: 'var(--n-feedback-height)'
  192. }}>
  193. -
  194. </div>
  195. <NFormItem
  196. path="maxScore"
  197. rule={[
  198. {
  199. required: true,
  200. message: '请输入最大练习小节',
  201. trigger: ['blur', 'change'],
  202. type: 'number'
  203. }
  204. ]}>
  205. <NInputNumber
  206. v-model:value={forms.maxScore}
  207. showButton={false}
  208. min={forms.minScore || 1}
  209. max={forms.baseMaxScore}
  210. placeholder="最大练习小节"
  211. clearable
  212. />
  213. </NFormItem>
  214. </div>
  215. <NFormItem
  216. label="练习速度"
  217. path="practiceSpeed"
  218. rule={[
  219. {
  220. required: true,
  221. message: '请输入练习速度',
  222. trigger: ['blur', 'change'],
  223. type: 'number'
  224. }
  225. ]}>
  226. <NInputNumber
  227. min={60}
  228. max={270}
  229. showButton={false}
  230. style={{ width: '100%' }}
  231. v-model:value={forms.practiceSpeed}
  232. placeholder="练习速度范围60~270"
  233. clearable
  234. />
  235. </NFormItem>
  236. <NFormItem
  237. label="练习时长"
  238. path="practiceTimes"
  239. rule={[
  240. {
  241. required: true,
  242. message: '请输入练习时长',
  243. trigger: ['blur', 'change'],
  244. type: 'number'
  245. }
  246. ]}>
  247. <NInputGroup>
  248. <NInputNumber
  249. min={0}
  250. showButton={false}
  251. style={{ width: '100%' }}
  252. v-model:value={forms.practiceTimes}
  253. placeholder="请输入练习时长"
  254. clearable
  255. />
  256. <NInputGroupLabel>分钟</NInputGroupLabel>
  257. </NInputGroup>
  258. </NFormItem>
  259. </>
  260. )}
  261. {forms.type === 'EVALUATION' && (
  262. <>
  263. <NFormItem
  264. label="评测难度"
  265. path="type"
  266. rule={[{ required: true, message: '请选择评测难度' }]}>
  267. <NSpace>
  268. <NButton
  269. secondary
  270. class={[
  271. styles.switch,
  272. forms.difficulty === 'BEGINNER' ? styles.active : ''
  273. ]}
  274. onClick={() => (forms.difficulty = 'BEGINNER')}>
  275. 入门级
  276. </NButton>
  277. <NButton
  278. secondary
  279. class={[
  280. styles.switch,
  281. forms.difficulty === 'ADVANCED' ? styles.active : ''
  282. ]}
  283. onClick={() => (forms.difficulty = 'ADVANCED')}>
  284. 进阶级
  285. </NButton>
  286. <NButton
  287. secondary
  288. class={[
  289. styles.switch,
  290. forms.difficulty === 'PERFORMER' ? styles.active : ''
  291. ]}
  292. onClick={() => (forms.difficulty = 'PERFORMER')}>
  293. 大师级
  294. </NButton>
  295. </NSpace>
  296. </NFormItem>
  297. {/* <NFormItem
  298. label="评测速度"
  299. path="evaluationSpeed"
  300. rule={[
  301. {
  302. required: true,
  303. message: '请输入评测速度',
  304. trigger: ['blur', 'change'],
  305. type: 'number'
  306. }
  307. ]}>
  308. <NInputNumber
  309. min={60}
  310. max={270}
  311. showButton={false}
  312. style={{ width: '100%' }}
  313. v-model:value={forms.evaluationSpeed}
  314. placeholder="评测速度范围60~270"
  315. clearable
  316. />
  317. </NFormItem> */}
  318. <NFormItem
  319. label="合格分数"
  320. path="evaluationScore"
  321. rule={[
  322. {
  323. required: true,
  324. message: '请输入合格分数',
  325. trigger: ['blur', 'change'],
  326. type: 'number'
  327. }
  328. ]}>
  329. <NInputGroup>
  330. <NInputNumber
  331. min={0}
  332. showButton={false}
  333. style={{ width: '100%' }}
  334. v-model:value={forms.evaluationScore}
  335. placeholder="请输入合格分数"
  336. clearable
  337. />
  338. <NInputGroupLabel>分</NInputGroupLabel>
  339. </NInputGroup>
  340. </NFormItem>
  341. </>
  342. )}
  343. <NSpace class={styles.updateBtnGroup}>
  344. <NButton strong type="default" round onClick={() => emit('close')}>
  345. 取消
  346. </NButton>
  347. <NButton strong type="primary" round onClick={() => onSubmit()}>
  348. 确认
  349. </NButton>
  350. </NSpace>
  351. </NForm>
  352. </div>
  353. );
  354. }
  355. });