index.tsx 8.3 KB

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