index.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. import { defineComponent, reactive, ref } from 'vue';
  2. import { NImage, NModal } from 'naive-ui';
  3. import styles from './index.module.less';
  4. import icon1 from '../../images/addSource/icon1.png';
  5. import icon2 from '../../images/addSource/icon2.png';
  6. import icon3 from '../../images/addSource/icon3.png';
  7. import icon4 from '../../images/addSource/icon4.png';
  8. import icon5 from '../../images/addSource/icon5.png';
  9. import icon6 from '../../images/addSource/icon6.png';
  10. import icon7 from '../../images/addSource/icon7.png';
  11. import icon8 from '../../images/addSource/icon8.png';
  12. import { useRouter } from 'vue-router';
  13. import SourceRhythm from '../source-rhythm';
  14. import SourceInstrument from '../source-instrument';
  15. import SourceKnowledge from '../source-knowledge';
  16. import SourceMusician from '../source-musician';
  17. import SourceMusic from '../source-music';
  18. import { eventGlobal } from '/src/utils';
  19. import SubjectSync from '../subject-sync';
  20. import { usePrepareStore } from '/src/store/modules/prepareLessons';
  21. import UploadModal, {
  22. formatUrlType
  23. } from '/src/views/natural-resources/components/my-resources/upload-modal';
  24. import SaveModal from '/src/views/natural-resources/components/my-resources/save-modal';
  25. import { modalClickMask } from '/src/state';
  26. export default defineComponent({
  27. name: 'add-other-source',
  28. emits: ['close', 'comfirm'],
  29. setup(props, { emit }) {
  30. const prepareStore = usePrepareStore();
  31. const router = useRouter();
  32. const sourceList = ref([
  33. {
  34. image: icon8,
  35. name: '上传资源',
  36. index: 7
  37. },
  38. {
  39. image: icon1,
  40. name: '听音练习',
  41. index: 0
  42. },
  43. {
  44. image: icon2,
  45. name: '节奏练习',
  46. index: 1
  47. },
  48. {
  49. image: icon3,
  50. name: '乐器百科',
  51. index: 2
  52. },
  53. {
  54. image: icon6,
  55. name: '名曲鉴赏',
  56. index: 3
  57. },
  58. {
  59. image: icon5,
  60. name: '音乐家',
  61. index: 4
  62. },
  63. {
  64. image: icon4,
  65. name: '乐理知识',
  66. index: 5
  67. }
  68. // {
  69. // image: icon7,
  70. // name: '制作曲谱',
  71. // index: 6
  72. // }
  73. ]);
  74. const state = reactive({
  75. listenStatus: false, // 听音练习
  76. rhythmStatus: false, //节奏
  77. theoryStatus: false, //
  78. musicStatus: false, //
  79. instrumentStatus: false, //
  80. musicianStatus: false, //
  81. uploadStatus: false,
  82. saveStatus: false,
  83. editStatus: false, // 是否编辑
  84. editList: [] as any, // TOD
  85. editIds: [] as any, // 编辑的
  86. editOverIds: [] as any // 确认修改的数据
  87. });
  88. // LISTEN:听音,RHYTHM:节奏,THEORY:乐理知识,MUSIC_WIKI:曲目 INSTRUMENT:乐器 MUSICIAN:音乐家)
  89. const onDetail = (item: any) => {
  90. switch (item.index) {
  91. case 0:
  92. state.listenStatus = true;
  93. break;
  94. case 1:
  95. state.rhythmStatus = true;
  96. break;
  97. case 2:
  98. state.instrumentStatus = true;
  99. break;
  100. case 3:
  101. state.musicStatus = true;
  102. break;
  103. case 4:
  104. state.musicianStatus = true;
  105. break;
  106. case 5:
  107. state.theoryStatus = true;
  108. break;
  109. case 6:
  110. eventGlobal.emit('pageBeforeLeave', () => {
  111. // 直接跳转到制谱页面 (临时存储数据)
  112. sessionStorage.setItem('notation-open-create', '1');
  113. router.push('/notation');
  114. });
  115. break;
  116. case 7:
  117. // eventGlobal.emit('pageBeforeLeave', () => {
  118. // // 直接跳转到制谱页面 (临时存储数据)
  119. // sessionStorage.setItem('notation-open-create', '1');
  120. // router.push('/notation');
  121. // });
  122. state.saveStatus = true;
  123. break;
  124. default:
  125. break;
  126. }
  127. };
  128. return () => (
  129. <>
  130. <div class={styles.addOtherSource}>
  131. {sourceList.value.map(source => (
  132. <div class={styles.sourceItem} onClick={() => onDetail(source)}>
  133. <NImage
  134. class={styles.coverImg}
  135. src={source.image}
  136. previewDisabled
  137. />
  138. <p class={styles.name}>{source.name}</p>
  139. </div>
  140. ))}
  141. </div>
  142. {/*
  143. 百科: https://oss.dayaedu.com/ktqy/17101370093153448b2cd.png
  144. jianshang https://oss.dayaedu.com/ktqy/1710137009315eedcdeed.png
  145. jiezou https://oss.dayaedu.com/ktqy/171013700931689a322a6.png
  146. yinyuejia https://oss.dayaedu.com/ktqy/1710137009316fbd65d39.png
  147. yueli https://oss.dayaedu.com/ktqy/17101370093160d479afe.png
  148. */}
  149. {/* 节奏练习 */}
  150. <NModal
  151. maskClosable={modalClickMask}
  152. v-model:show={state.rhythmStatus}
  153. preset="card"
  154. class={['modalTitle background', styles.addOtherSourceModal]}
  155. title={'节奏练习'}>
  156. <SourceRhythm
  157. onClose={() => (state.rhythmStatus = false)}
  158. onConfirm={(item: any) => {
  159. state.rhythmStatus = false;
  160. emit('comfirm', {
  161. materialId: null,
  162. coverImg: item.coverImg,
  163. dataJson: item.dataJson,
  164. title: '节奏练习',
  165. isCollect: false,
  166. isSelected: false,
  167. content: null,
  168. type: 'RHYTHM'
  169. });
  170. emit('close');
  171. }}
  172. />
  173. </NModal>
  174. {/* 乐器百科 */}
  175. <NModal
  176. maskClosable={modalClickMask}
  177. v-model:show={state.instrumentStatus}
  178. preset="card"
  179. class={['modalTitle', styles.instrumentModal]}
  180. title={'乐器百科'}>
  181. <SourceInstrument
  182. onClose={() => (state.instrumentStatus = false)}
  183. onConfirm={(val: any) => {
  184. state.instrumentStatus = false;
  185. const value = val || [];
  186. const temp: any[] = [];
  187. value.forEach((item: any) => {
  188. temp.push({
  189. materialId: item.materialId,
  190. coverImg: item.coverImg,
  191. dataJson: null,
  192. title: item.title,
  193. isCollect: false,
  194. isSelected: false,
  195. content: item.content,
  196. type: 'INSTRUMENT'
  197. });
  198. });
  199. emit('comfirm', temp);
  200. emit('close');
  201. }}
  202. />
  203. </NModal>
  204. {/* 乐理知识 */}
  205. <NModal
  206. maskClosable={modalClickMask}
  207. v-model:show={state.theoryStatus}
  208. preset="card"
  209. class={['modalTitle', styles.theoryModal]}
  210. title={'乐理知识'}>
  211. <SourceKnowledge
  212. onClose={() => (state.theoryStatus = false)}
  213. onConfirm={(val: any) => {
  214. state.theoryStatus = false;
  215. const value = val || [];
  216. const temp: any[] = [];
  217. value.forEach((item: any) => {
  218. temp.push({
  219. materialId: item.materialId,
  220. coverImg: item.coverImg,
  221. dataJson: null,
  222. title: item.title,
  223. isCollect: false,
  224. isSelected: false,
  225. content: item.content,
  226. type: 'THEORY'
  227. });
  228. });
  229. emit('comfirm', temp);
  230. emit('close');
  231. }}
  232. />
  233. </NModal>
  234. {/* 音乐家 */}
  235. <NModal
  236. maskClosable={modalClickMask}
  237. v-model:show={state.musicianStatus}
  238. preset="card"
  239. class={['modalTitle', styles.instrumentModal]}
  240. title={'音乐家'}>
  241. <SourceMusician
  242. onClose={() => (state.musicianStatus = false)}
  243. onConfirm={(val: any) => {
  244. state.musicianStatus = false;
  245. const value = val || [];
  246. const temp: any[] = [];
  247. value.forEach((item: any) => {
  248. temp.push({
  249. materialId: item.materialId,
  250. coverImg: item.coverImg,
  251. dataJson: null,
  252. title: item.title,
  253. isCollect: false,
  254. isSelected: false,
  255. content: item.content,
  256. type: 'MUSICIAN'
  257. });
  258. });
  259. emit('comfirm', temp);
  260. emit('close');
  261. }}
  262. />
  263. </NModal>
  264. {/* 名曲鉴赏 */}
  265. <NModal
  266. maskClosable={modalClickMask}
  267. v-model:show={state.musicStatus}
  268. preset="card"
  269. class={['modalTitle', styles.musicModal]}
  270. title={'名曲鉴赏'}>
  271. <SourceMusic
  272. onClose={() => (state.musicStatus = false)}
  273. onConfirm={(val: any) => {
  274. state.musicStatus = false;
  275. const value = val || [];
  276. const temp: any[] = [];
  277. value.forEach((item: any) => {
  278. temp.push({
  279. materialId: item.materialId,
  280. coverImg: item.coverImg,
  281. dataJson: null,
  282. title: item.title,
  283. isCollect: false,
  284. isSelected: false,
  285. content: item.content,
  286. type: 'MUSIC_WIKI'
  287. });
  288. });
  289. emit('comfirm', temp);
  290. emit('close');
  291. }}
  292. />
  293. </NModal>
  294. {/* 听音练习 */}
  295. <NModal
  296. maskClosable={modalClickMask}
  297. v-model:show={state.listenStatus}
  298. preset="card"
  299. class={['modalTitle background', styles.subjectSyncModal]}
  300. title={'选择乐器'}>
  301. <SubjectSync
  302. // subjectId={prepareStore.getSubjectId as any}
  303. onClose={() => (state.listenStatus = false)}
  304. onConfirm={async (item: any) => {
  305. //
  306. try {
  307. state.musicStatus = false;
  308. const value = item.subjectCode || [];
  309. const temp: any[] = [];
  310. value.forEach((item: any) => {
  311. temp.push({
  312. materialId: item.materialId,
  313. coverImg: item.coverImg,
  314. dataJson: null,
  315. title: item.title,
  316. isCollect: false,
  317. isSelected: false,
  318. content: item.content,
  319. type: 'LISTEN'
  320. });
  321. });
  322. state.listenStatus = false;
  323. emit('comfirm', temp);
  324. emit('close');
  325. } catch {
  326. //
  327. }
  328. }}
  329. />
  330. </NModal>
  331. <NModal
  332. maskClosable={modalClickMask}
  333. v-model:show={state.uploadStatus}
  334. preset="card"
  335. showIcon={false}
  336. class={['modalTitle background', styles.attendClassModal]}
  337. title={state.editStatus ? '修改资源' : '上传资源'}
  338. blockScroll={false}>
  339. <UploadModal
  340. editStatus={state.editStatus}
  341. onClose={() => {
  342. state.uploadStatus = false;
  343. }}
  344. onConfirm={(item: any) => {
  345. state.editIds = [];
  346. state.editList = [];
  347. state.editOverIds = [];
  348. state.saveStatus = false;
  349. try {
  350. state.musicStatus = false;
  351. const value = item || [];
  352. const temp: any[] = [];
  353. value.forEach((item: any) => {
  354. temp.push({
  355. materialId: item.id,
  356. coverImg: item.coverImg,
  357. dataJson: null,
  358. title: item.name,
  359. isCollect: false,
  360. isSelected: false,
  361. content: item.content,
  362. type: item.type
  363. });
  364. });
  365. // state.listenStatus = false;
  366. emit('comfirm', temp);
  367. emit('close');
  368. } catch {
  369. //
  370. }
  371. }}
  372. list={state.editList}
  373. />
  374. </NModal>
  375. <NModal
  376. maskClosable={modalClickMask}
  377. v-model:show={state.saveStatus}
  378. preset="card"
  379. showIcon={false}
  380. class={['modalTitle background', styles.attendClassSaveModal]}
  381. title={'上传资源'}
  382. blockScroll={false}>
  383. <SaveModal
  384. onClose={() => (state.saveStatus = false)}
  385. onConfrim={(val: any) => {
  386. const list = val || [];
  387. const temp: any = [];
  388. list.forEach((item: any) => {
  389. temp.push({
  390. subjectIds: null,
  391. openFlag: false,
  392. coverImg: item.coverImg,
  393. title: item.name || '',
  394. type: formatUrlType(item.content),
  395. enableFlag: 1,
  396. content: item.content,
  397. id: null
  398. });
  399. });
  400. state.editList = temp;
  401. state.uploadStatus = true;
  402. state.editStatus = false;
  403. }}
  404. />
  405. </NModal>
  406. </>
  407. );
  408. }
  409. });