index.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import {
  2. PropType,
  3. defineComponent,
  4. nextTick,
  5. onMounted,
  6. reactive,
  7. ref
  8. } from 'vue';
  9. import styles from './index.module.less';
  10. import { NTabs, NTabPane, NModal } from 'naive-ui';
  11. import SelectMusicModal from '../../model/select-music';
  12. import { usePrepareStore } from '/src/store/modules/prepareLessons';
  13. import SelectResources from '../../model/select-resources';
  14. import SelectMusic, { typeFormat } from './components/select-music';
  15. import ResourceItem from './components/resource-item';
  16. import TrainUpdate from '/src/views/attend-class/model/train-update';
  17. import requestOrigin from 'umi-request';
  18. import { eventGlobal } from '/src/utils';
  19. export default defineComponent({
  20. name: 'resource-main',
  21. props: {
  22. /** 类型 */
  23. cardType: {
  24. type: String as PropType<'' | 'homerowk-record'>,
  25. default: ''
  26. }
  27. },
  28. setup(props, { expose }) {
  29. const prepareStore = usePrepareStore();
  30. const forms = reactive({
  31. tabType: 'relateResources',
  32. tabWorkType: 'myMusic',
  33. selectMusicStatus: false,
  34. selectResourceStatus: false,
  35. editStatus: false,
  36. editItem: {} as any
  37. });
  38. const tabRef = ref();
  39. const workRef = ref();
  40. const onAdd = async (item: any) => {
  41. let xmlStatus = 'init';
  42. // 第一个声部小节
  43. let firstMeasures: any = null;
  44. try {
  45. // 获取文件
  46. const res = await requestOrigin.get(item.xmlFileUrl, {
  47. mode: 'cors'
  48. });
  49. const xmlParse = new DOMParser().parseFromString(res, 'text/xml');
  50. const parts = xmlParse.getElementsByTagName('part');
  51. firstMeasures = parts[0]?.getElementsByTagName('measure');
  52. xmlStatus = 'success';
  53. } catch (error) {
  54. xmlStatus = 'error';
  55. }
  56. // 判断读取小节数
  57. if (xmlStatus == 'success') {
  58. item.practiceChapterMax = firstMeasures.length;
  59. } else {
  60. item.practiceChapterMax = 0;
  61. }
  62. item.coursewareKnowledgeDetailId = prepareStore.getSelectKey;
  63. item.subjectId = prepareStore.getSubjectId;
  64. forms.editItem = item;
  65. forms.editStatus = true;
  66. };
  67. const resetTabPosition = () => {
  68. nextTick(() => {
  69. tabRef.value?.syncBarPosition();
  70. workRef.value?.syncBarPosition();
  71. });
  72. };
  73. onMounted(() => {
  74. resetTabPosition();
  75. });
  76. expose({
  77. resetTabPosition
  78. });
  79. return () => (
  80. <div
  81. class={[
  82. styles['resource-main'],
  83. forms.selectMusicStatus || forms.selectResourceStatus
  84. ? styles.resourceClose
  85. : ''
  86. ]}>
  87. {prepareStore.getTabType === 'courseware' &&
  88. props.cardType !== 'homerowk-record' ? (
  89. <NTabs
  90. ref={tabRef}
  91. animated
  92. class={styles.homerowkTabs}
  93. value={forms.tabType}
  94. paneClass={styles.paneTitle}
  95. paneWrapperClass={styles.paneWrapperContainer}
  96. onUpdate:value={(val: string) => {
  97. forms.tabType = val;
  98. }}>
  99. {{
  100. suffix: () => (
  101. <div
  102. class={styles.iconScreen}
  103. onClick={() => {
  104. forms.selectResourceStatus = true;
  105. prepareStore.setSelectResourceStatus(true);
  106. }}>
  107. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
  108. <g fill="none">
  109. <path
  110. d="M5 6a1 1 0 0 1 1-1h2a1 1 0 0 0 0-2H6a3 3 0 0 0-3 3v2a1 1 0 0 0 2 0V6zm0 12a1 1 0 0 0 1 1h2a1 1 0 1 1 0 2H6a3 3 0 0 1-3-3v-2a1 1 0 1 1 2 0v2zM18 5a1 1 0 0 1 1 1v2a1 1 0 1 0 2 0V6a3 3 0 0 0-3-3h-2a1 1 0 1 0 0 2h2zm1 13a1 1 0 0 1-1 1h-2a1 1 0 1 0 0 2h2a3 3 0 0 0 3-3v-2a1 1 0 1 0-2 0v2z"
  111. fill="#198CFE"></path>
  112. </g>
  113. </svg>
  114. </div>
  115. ),
  116. default: () => (
  117. <>
  118. <NTabPane name="relateResources" tab="相关资源">
  119. <ResourceItem type="relateResources" />
  120. </NTabPane>
  121. <NTabPane
  122. name="shareResources"
  123. tab="共享资源"
  124. // displayDirective="show:lazy"
  125. >
  126. <ResourceItem type="shareResources" />
  127. </NTabPane>
  128. <NTabPane
  129. name="myResources"
  130. tab="我的资源"
  131. // displayDirective="show:lazy"
  132. >
  133. <ResourceItem type="myResources" />
  134. </NTabPane>
  135. <NTabPane
  136. name="myCollect"
  137. tab="我的收藏"
  138. // displayDirective="show:lazy"
  139. >
  140. <ResourceItem type="myCollect" />
  141. </NTabPane>
  142. </>
  143. )
  144. }}
  145. </NTabs>
  146. ) : (
  147. <NTabs
  148. ref={workRef}
  149. animated
  150. value={forms.tabWorkType}
  151. paneClass={styles.paneTitle}
  152. paneWrapperClass={styles.paneWrapperContainer}
  153. onUpdate:value={(val: string) => {
  154. forms.tabWorkType = val;
  155. }}>
  156. {{
  157. suffix: () => (
  158. <div
  159. class={styles.iconScreen}
  160. onClick={() => {
  161. forms.selectMusicStatus = true;
  162. prepareStore.setSelectMusicStatus(true);
  163. }}>
  164. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
  165. <g fill="none">
  166. <path
  167. d="M5 6a1 1 0 0 1 1-1h2a1 1 0 0 0 0-2H6a3 3 0 0 0-3 3v2a1 1 0 0 0 2 0V6zm0 12a1 1 0 0 0 1 1h2a1 1 0 1 1 0 2H6a3 3 0 0 1-3-3v-2a1 1 0 1 1 2 0v2zM18 5a1 1 0 0 1 1 1v2a1 1 0 1 0 2 0V6a3 3 0 0 0-3-3h-2a1 1 0 1 0 0 2h2zm1 13a1 1 0 0 1-1 1h-2a1 1 0 1 0 0 2h2a3 3 0 0 0 3-3v-2a1 1 0 1 0-2 0v2z"
  168. fill="#198CFE"></path>
  169. </g>
  170. </svg>
  171. </div>
  172. ),
  173. default: () => (
  174. <>
  175. <NTabPane name="myMusic" tab="我的曲目">
  176. <SelectMusic cardType={props.cardType} type="myMusic" />
  177. </NTabPane>
  178. <NTabPane name="sahreMusic" tab="共享曲目">
  179. <SelectMusic cardType={props.cardType} type="sahreMusic" />
  180. </NTabPane>
  181. <NTabPane name="collectMusic" tab="收藏曲目">
  182. <SelectMusic
  183. cardType={props.cardType}
  184. type="collectMusic"
  185. />
  186. </NTabPane>
  187. </>
  188. )
  189. }}
  190. </NTabs>
  191. )}
  192. <NModal
  193. v-model:show={forms.selectResourceStatus}
  194. onUpdate:show={(val: any) => {
  195. if (!val) {
  196. prepareStore.setSelectResourceStatus(val);
  197. }
  198. }}
  199. class={['modalTitle', styles.selectMusicModal]}
  200. preset="card"
  201. title={'选择资源'}>
  202. <SelectResources type={forms.tabType} />
  203. </NModal>
  204. <NModal
  205. v-model:show={forms.selectMusicStatus}
  206. onUpdate:show={(val: any) => {
  207. if (!val) {
  208. prepareStore.setSelectMusicStatus(val);
  209. }
  210. }}
  211. class={['modalTitle', styles.selectMusicModal]}
  212. preset="card"
  213. title={'选择曲目'}>
  214. <SelectMusicModal onAdd={(item: any) => onAdd(item)} />
  215. </NModal>
  216. <NModal
  217. v-model:show={forms.editStatus}
  218. class={['modalTitle background', styles.trainEditModal]}
  219. preset="card"
  220. title="作业设置">
  221. <TrainUpdate
  222. item={forms.editItem}
  223. onClose={() => (forms.editStatus = false)}
  224. onConfirm={(item: any) => {
  225. const tList = typeFormat(
  226. item.trainingType,
  227. item.trainingConfigJson
  228. );
  229. const train = {
  230. ...item,
  231. id: null,
  232. musicName: forms.editItem.title,
  233. typeList: tList
  234. };
  235. eventGlobal.emit('onTrainAddItem', train);
  236. }}
  237. />
  238. </NModal>
  239. </div>
  240. );
  241. }
  242. });