index.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import { defineComponent, onMounted, reactive, ref } from 'vue';
  2. import styles from './index.module.less';
  3. import {
  4. NButton,
  5. NCascader,
  6. NInput,
  7. NSelect,
  8. NSwitch,
  9. NTooltip
  10. } from 'naive-ui';
  11. import { usePrepareStore } from '/src/store/modules/prepareLessons';
  12. import { eventGlobal } from '/src/utils';
  13. import { useCatchStore } from '/src/store/modules/catchData';
  14. import deepClone from '/src/helpers/deep-clone';
  15. export default defineComponent({
  16. name: 'courseware-head',
  17. setup(props, { emit, expose }) {
  18. const prepareStore = usePrepareStore();
  19. // 第一个课件名称,第二个课件声部
  20. const checkForms = ref<any[]>(['', '']);
  21. const subjectList = ref([] as any);
  22. const forms = reactive({
  23. subjects: [] as any,
  24. openFlagEnable: true, // 是否支持修改公开状态
  25. autoPlay: false,
  26. name: '',
  27. openFlag: false
  28. });
  29. // 全选
  30. const chioseAll = (list: any) => {
  31. // 全选
  32. const ids = [] as any;
  33. list.map((item: any) => {
  34. if (Array.isArray(item.instruments)) {
  35. item.instruments.forEach((c: any) => {
  36. ids.push(c.value);
  37. });
  38. }
  39. }) as any;
  40. // item.instrumentIds = ids;
  41. forms.subjects = ids;
  42. eventGlobal.emit('coursewareSubjectChange', forms.subjects)
  43. checkForms.value[1] = forms.subjects?.length > 0 ? '' : 'error';
  44. };
  45. const getForms = () => {
  46. return forms;
  47. };
  48. const updateDefaultInfo = (item: any) => {
  49. forms.subjects = item.subjects;
  50. forms.openFlagEnable = item.openFlagEnable;
  51. forms.autoPlay = item.autoPlay;
  52. forms.name = item.name;
  53. forms.openFlag = item.openFlag;
  54. updateSubjectList(item.subjects || []);
  55. };
  56. const checkCoursewareForm = (type: string = 'ALL') => {
  57. //
  58. if(type === 'name') {
  59. checkForms.value[0] = forms.name ? '' : 'error';
  60. } else if(type === "subject") {
  61. checkForms.value[1] = forms.subjects?.length > 0 ? '' : 'error';
  62. } else {
  63. checkForms.value[0] = forms.name ? '' : 'error';
  64. checkForms.value[1] = forms.subjects?.length > 0 ? '' : 'error';
  65. }
  66. };
  67. const updateSubjectList = (ids?: any[]) => {
  68. // 获取适用乐器编号 ,修改的乐器编号,集合
  69. ids = ids || [];
  70. const courseIds: any = [];
  71. prepareStore.getInstrumentList.forEach((item: any) => {
  72. if (Array.isArray(item.instruments)) {
  73. item.instruments.forEach((child: any) => {
  74. courseIds.push(child.id);
  75. });
  76. }
  77. });
  78. const allIds = [...new Set([...courseIds, ...ids])];
  79. const tempList: any = [];
  80. useCatchStore().getSubjectList.forEach((item: any) => {
  81. const temp = deepClone(item);
  82. temp.enableFlag = false;
  83. if (Array.isArray(temp.instruments)) {
  84. temp.instruments.forEach((child: any) => {
  85. child.enableFlag = false;
  86. if (allIds.includes(child.id)) {
  87. child.enableFlag = true;
  88. temp.enableFlag = true;
  89. }
  90. });
  91. }
  92. tempList.push(temp);
  93. });
  94. const tempSubjects: any[] = [];
  95. tempList.forEach((subject: any) => {
  96. if (subject.enableFlag) {
  97. const { instruments, ...r } = subject;
  98. if (instruments && instruments.length > 0) {
  99. const tempChild: any[] = [];
  100. instruments?.forEach((instrument: any) => {
  101. if (instrument.enableFlag) {
  102. tempChild.push(instrument);
  103. }
  104. });
  105. if (tempChild.length > 0)
  106. tempSubjects.push({ ...r, instruments: tempChild });
  107. }
  108. }
  109. });
  110. subjectList.value = tempSubjects;
  111. };
  112. onMounted(async () => {
  113. await useCatchStore().getSubjects();
  114. updateSubjectList();
  115. eventGlobal.on('updateCoursewareHeadInfo', updateDefaultInfo);
  116. eventGlobal.on('checkCoursewareForm', checkCoursewareForm);
  117. });
  118. expose({
  119. getForms
  120. });
  121. return () => (
  122. <>
  123. <div class={styles.headerTitle}>
  124. <i class={styles.iconBook}></i>
  125. <span>{prepareStore.getSelectName}</span>
  126. </div>
  127. <div class={styles.formContainer}>
  128. <div class={[styles.btnItem, styles.block]}>
  129. <span class={[styles.btnTitle]}>
  130. <span>*</span>课件名称
  131. </span>
  132. <NInput
  133. placeholder="请输入课件名称"
  134. v-model:value={forms.name}
  135. maxlength={20}
  136. clearable
  137. status={checkForms.value[0]}
  138. onUpdate:value={() => {
  139. checkForms.value[0] = forms.name ? '' : 'error';
  140. eventGlobal.emit('coursewareHeadSyncData', getForms())
  141. }}
  142. />
  143. </div>
  144. <div class={[styles.btnItem, styles.block]}>
  145. <span class={[styles.btnTitle]}>
  146. <span>*</span>适用乐器
  147. </span>
  148. <NCascader
  149. status={checkForms.value[1]}
  150. placeholder="请选择乐器(可多选)"
  151. class={styles.btnSubjectList}
  152. options={subjectList.value}
  153. checkStrategy="child"
  154. showPath={false}
  155. childrenField="instruments"
  156. expandTrigger="hover"
  157. labelField="name"
  158. valueField="id"
  159. clearable
  160. filterable
  161. multiple
  162. maxTagCount={1}
  163. v-model:value={forms.subjects}
  164. onUpdate:value={() => {
  165. checkForms.value[1] = forms.subjects?.length > 0 ? '' : 'error';
  166. // console.log(form)
  167. eventGlobal.emit('coursewareSubjectChange', forms.subjects)
  168. }}
  169. v-slots={{
  170. action: () => (
  171. <>
  172. <NButton
  173. text
  174. style=" --n-width: 100% "
  175. size="small"
  176. onClick={() => chioseAll(subjectList.value)}>
  177. 全选
  178. </NButton>
  179. </>
  180. )
  181. }}
  182. />
  183. </div>
  184. <div class={styles.btnItem}>
  185. <span class={styles.btnTitle}>
  186. 自动播放
  187. <NTooltip style={{ maxWidth: '200px' }} showArrow={false}>
  188. {{
  189. trigger: () => <i class={styles.iconQuestion}></i>,
  190. default: () =>
  191. '开启自动播放后,课件内视频、音频资源将自动播放'
  192. }}
  193. </NTooltip>
  194. </span>
  195. <NSwitch v-model:value={forms.autoPlay} onUpdate:value={() => {
  196. eventGlobal.emit('coursewareHeadSyncData', getForms())
  197. }} />
  198. </div>
  199. <div class={styles.btnItem}>
  200. <span class={styles.btnTitle}>
  201. 公开课件
  202. <NTooltip style={{ maxWidth: '200px' }} showArrow={false}>
  203. {{
  204. trigger: () => <i class={styles.iconQuestion}></i>,
  205. default: () => '公开课件后,其它老师可以使用该课件上课'
  206. }}
  207. </NTooltip>
  208. </span>
  209. {!forms.openFlagEnable ? (
  210. <NTooltip style={{ maxWidth: '200px' }} showArrow={false}>
  211. {{
  212. trigger: () => (
  213. <NSwitch
  214. v-model:value={forms.openFlag}
  215. disabled={!forms.openFlagEnable}
  216. onUpdate:value={() => {
  217. eventGlobal.emit('coursewareHeadSyncData', getForms())
  218. }}
  219. />
  220. ),
  221. default: () =>
  222. '为尊重课件原作者,在“相关课件”中添加的课件不支持公开'
  223. }}
  224. </NTooltip>
  225. ) : (
  226. <NSwitch
  227. v-model:value={forms.openFlag}
  228. disabled={!forms.openFlagEnable}
  229. onUpdate:value={() => {
  230. eventGlobal.emit('coursewareHeadSyncData', getForms())
  231. }}
  232. />
  233. )}
  234. </div>
  235. </div>
  236. </>
  237. );
  238. }
  239. });