index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. import {
  2. PropType,
  3. defineComponent,
  4. nextTick,
  5. onMounted,
  6. reactive,
  7. ref,
  8. toRef
  9. } from 'vue';
  10. import styles from './index.module.less';
  11. import { NTabs, NTabPane, NModal } from 'naive-ui';
  12. import SelectMusicModal from '../../model/select-music';
  13. import { usePrepareStore } from '/src/store/modules/prepareLessons';
  14. import SelectResources from '../../model/select-resources';
  15. import SelectMusic, { typeFormat } from './components/select-music';
  16. import ResourceItem from './components/resource-item';
  17. import TrainUpdate from '/src/views/attend-class/model/train-update';
  18. import requestOrigin from 'umi-request';
  19. import { eventGlobal } from '/src/utils';
  20. import useDrag from '@/hooks/useDrag';
  21. import Dragbom from '@/hooks/useDrag/dragbom';
  22. import { useUserStore } from '@/store/modules/users';
  23. import { useCatchStore } from '/src/store/modules/catchData';
  24. import { modalClickMask } from '/src/state';
  25. export default defineComponent({
  26. name: 'resource-main',
  27. props: {
  28. /** 类型 */
  29. cardType: {
  30. type: String as PropType<'' | 'homerowk-record' | 'prepare'>,
  31. default: ''
  32. },
  33. from: {
  34. // 来自哪里
  35. type: String,
  36. default: ''
  37. }
  38. },
  39. setup(props, { expose }) {
  40. const prepareStore = usePrepareStore();
  41. const catchStore = useCatchStore();
  42. const forms = reactive({
  43. tabType: 'relateResources',
  44. tabWorkType: 'myMusic',
  45. selectMusicStatus: false,
  46. selectResourceStatus: false,
  47. editStatus: false,
  48. editItem: {} as any
  49. });
  50. const tabRef = ref();
  51. const workRef = ref();
  52. const onAdd = async (item: any) => {
  53. let xmlStatus = 'init';
  54. // 第一个声部小节
  55. let firstMeasures: any = null;
  56. try {
  57. // 获取文件
  58. const res = await requestOrigin.get(item.xmlFileUrl, {
  59. mode: 'cors'
  60. });
  61. const xmlParse = new DOMParser().parseFromString(res, 'text/xml');
  62. const parts = xmlParse.getElementsByTagName('part');
  63. firstMeasures = parts[0]?.getElementsByTagName('measure');
  64. xmlStatus = 'success';
  65. } catch (error) {
  66. xmlStatus = 'error';
  67. }
  68. // 判断读取小节数
  69. if (xmlStatus == 'success') {
  70. item.practiceChapterMax = firstMeasures.length;
  71. } else {
  72. item.practiceChapterMax = 0;
  73. }
  74. item.coursewareKnowledgeDetailId = prepareStore.getSelectKey;
  75. item.subjectId = prepareStore.getSubjectId;
  76. forms.editItem = item;
  77. forms.editStatus = true;
  78. };
  79. const resetTabPosition = () => {
  80. nextTick(() => {
  81. tabRef.value?.syncBarPosition();
  82. workRef.value?.syncBarPosition();
  83. });
  84. };
  85. onMounted(async () => {
  86. resetTabPosition();
  87. // 获取教材分类列表
  88. await catchStore.getMusicSheetCategory(true);
  89. });
  90. // 弹窗拖动
  91. // 曲目资源
  92. let selectResourceStatusAddBoxDragData: any;
  93. let selectResourceStatusAddBoxClass: string;
  94. if (props.from === 'class') {
  95. const users = useUserStore();
  96. selectResourceStatusAddBoxClass = 'selectResourceStatusAddBoxClass_drag';
  97. selectResourceStatusAddBoxDragData = useDrag(
  98. [
  99. `${selectResourceStatusAddBoxClass} .select-resource>.n-tabs>.n-tabs-nav--top.n-tabs-nav`,
  100. `${selectResourceStatusAddBoxClass} .bom_drag`
  101. ],
  102. selectResourceStatusAddBoxClass,
  103. toRef(forms, 'selectMusicStatus'),
  104. users.info.id
  105. );
  106. }
  107. // 曲目资源 作业设置
  108. let workSetingBoxDragData: any;
  109. let workSetingBoxClass: string;
  110. if (props.from === 'class') {
  111. const users = useUserStore();
  112. workSetingBoxClass = 'workSetingBoxClass_drag';
  113. workSetingBoxDragData = useDrag(
  114. [
  115. `${workSetingBoxClass}>.n-card-header`,
  116. `${workSetingBoxClass} .bom_drag`
  117. ],
  118. workSetingBoxClass,
  119. toRef(forms, 'editStatus'),
  120. users.info.id
  121. );
  122. }
  123. //
  124. expose({
  125. resetTabPosition
  126. });
  127. return () => (
  128. <div
  129. class={[
  130. styles['resource-main'],
  131. forms.selectMusicStatus || forms.selectResourceStatus
  132. ? styles.resourceClose
  133. : ''
  134. ]}>
  135. {prepareStore.getTabType === 'courseware' &&
  136. !['homerowk-record', 'prepare'].includes(props.cardType) ? (
  137. <NTabs
  138. id="lessonsIn-0"
  139. ref={tabRef}
  140. animated
  141. class={styles.homerowkTabs}
  142. value={forms.tabType}
  143. paneClass={styles.paneTitle}
  144. paneWrapperClass={styles.paneWrapperContainer}
  145. onUpdate:value={(val: string) => {
  146. forms.tabType = val;
  147. }}>
  148. {{
  149. suffix: () => (
  150. <div
  151. class={styles.iconScreen}
  152. onClick={() => {
  153. forms.selectResourceStatus = true;
  154. prepareStore.setSelectResourceStatus(true);
  155. }}>
  156. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
  157. <g fill="none">
  158. <path
  159. 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"
  160. fill="#198CFE"></path>
  161. </g>
  162. </svg>
  163. </div>
  164. ),
  165. default: () => (
  166. <>
  167. <NTabPane name="relateResources" tab="相关资源">
  168. <ResourceItem type="relateResources" />
  169. </NTabPane>
  170. <NTabPane
  171. name="shareResources"
  172. tab="共享资源"
  173. // displayDirective="show:lazy"
  174. >
  175. <ResourceItem type="shareResources" />
  176. </NTabPane>
  177. <NTabPane
  178. name="myResources"
  179. tab="我的资源"
  180. // displayDirective="show:lazy"
  181. >
  182. <ResourceItem type="myResources" />
  183. </NTabPane>
  184. <NTabPane
  185. name="myCollect"
  186. tab="我的收藏"
  187. // displayDirective="show:lazy"
  188. >
  189. <ResourceItem type="myCollect" />
  190. </NTabPane>
  191. </>
  192. )
  193. }}
  194. </NTabs>
  195. ) : (
  196. <NTabs
  197. ref={workRef}
  198. animated
  199. value={forms.tabWorkType}
  200. paneClass={styles.paneTitle}
  201. paneWrapperClass={styles.paneWrapperContainer}
  202. onUpdate:value={(val: string) => {
  203. forms.tabWorkType = val;
  204. }}>
  205. {{
  206. suffix: () => (
  207. <div
  208. class={styles.iconScreen}
  209. onClick={() => {
  210. forms.selectMusicStatus = true;
  211. prepareStore.setSelectMusicStatus(true);
  212. }}>
  213. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
  214. <g fill="none">
  215. <path
  216. 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"
  217. fill="#198CFE"></path>
  218. </g>
  219. </svg>
  220. </div>
  221. ),
  222. default: () => (
  223. <>
  224. <NTabPane name="myMusic" tab="我的曲目">
  225. <SelectMusic
  226. from={props.from}
  227. cardType={props.cardType}
  228. type="myMusic"
  229. />
  230. </NTabPane>
  231. <NTabPane name="sahreMusic" tab="共享曲目">
  232. <SelectMusic
  233. from={props.from}
  234. cardType={props.cardType}
  235. type="sahreMusic"
  236. />
  237. </NTabPane>
  238. <NTabPane name="collectMusic" tab="收藏曲目">
  239. <SelectMusic
  240. from={props.from}
  241. cardType={props.cardType}
  242. type="collectMusic"
  243. />
  244. </NTabPane>
  245. </>
  246. )
  247. }}
  248. </NTabs>
  249. )}
  250. <NModal
  251. maskClosable={modalClickMask}
  252. v-model:show={forms.selectResourceStatus}
  253. onUpdate:show={(val: any) => {
  254. if (!val) {
  255. prepareStore.setSelectResourceStatus(val);
  256. }
  257. }}
  258. class={['modalTitle', styles.selectMusicModal]}
  259. preset="card"
  260. title={'选择资源'}>
  261. <SelectResources type={forms.tabType} />
  262. </NModal>
  263. <NModal
  264. maskClosable={modalClickMask}
  265. style={
  266. props.from === 'class'
  267. ? selectResourceStatusAddBoxDragData.styleDrag.value
  268. : {}
  269. }
  270. v-model:show={forms.selectMusicStatus}
  271. onUpdate:show={(val: any) => {
  272. if (!val) {
  273. prepareStore.setSelectMusicStatus(val);
  274. }
  275. }}
  276. class={[
  277. 'modalTitle',
  278. styles.selectMusicModal,
  279. selectResourceStatusAddBoxClass
  280. ]}
  281. preset="card"
  282. title={'选择曲目'}>
  283. <SelectMusicModal
  284. from={props.from}
  285. onAdd={(item: any) => onAdd(item)}
  286. />
  287. {props.from === 'class' && <Dragbom></Dragbom>}
  288. </NModal>
  289. <NModal
  290. maskClosable={modalClickMask}
  291. style={
  292. props.from === 'class' ? workSetingBoxDragData.styleDrag.value : {}
  293. }
  294. v-model:show={forms.editStatus}
  295. class={[
  296. 'modalTitle background',
  297. styles.trainEditModal,
  298. workSetingBoxClass
  299. ]}
  300. preset="card"
  301. title="作业设置">
  302. <TrainUpdate
  303. item={forms.editItem}
  304. onClose={() => (forms.editStatus = false)}
  305. onConfirm={(item: any) => {
  306. const tList = typeFormat(
  307. item.trainingType,
  308. item.trainingConfigJson
  309. );
  310. const train = {
  311. ...item,
  312. id: null,
  313. musicName: forms.editItem.title,
  314. typeList: tList
  315. };
  316. eventGlobal.emit('onTrainAddItem', train);
  317. }}
  318. />
  319. {props.from === 'class' && <Dragbom></Dragbom>}
  320. </NModal>
  321. </div>
  322. );
  323. }
  324. });