index.tsx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. }}
  139. />
  140. </div>
  141. <div class={[styles.btnItem, styles.block]}>
  142. <span class={[styles.btnTitle]}>
  143. <span>*</span>课件乐器
  144. </span>
  145. <NCascader
  146. status={checkForms.value[1]}
  147. placeholder="请选择乐器(可多选)"
  148. class={styles.btnSubjectList}
  149. options={subjectList.value}
  150. checkStrategy="child"
  151. showPath={false}
  152. childrenField="instruments"
  153. expandTrigger="hover"
  154. labelField="name"
  155. valueField="id"
  156. clearable
  157. filterable
  158. multiple
  159. maxTagCount={1}
  160. v-model:value={forms.subjects}
  161. onUpdate:value={() => {
  162. checkForms.value[1] = forms.subjects?.length > 0 ? '' : 'error';
  163. // console.log(form)
  164. eventGlobal.emit('coursewareSubjectChange', forms.subjects)
  165. }}
  166. v-slots={{
  167. action: () => (
  168. <>
  169. <NButton
  170. text
  171. style=" --n-width: 100% "
  172. size="small"
  173. onClick={() => chioseAll(subjectList.value)}>
  174. 全选
  175. </NButton>
  176. </>
  177. )
  178. }}
  179. />
  180. </div>
  181. <div class={styles.btnItem}>
  182. <span class={styles.btnTitle}>
  183. 自动播放
  184. <NTooltip style={{ maxWidth: '200px' }} showArrow={false}>
  185. {{
  186. trigger: () => <i class={styles.iconQuestion}></i>,
  187. default: () =>
  188. '开启自动播放后,课件内视频、音频资源将自动播放'
  189. }}
  190. </NTooltip>
  191. </span>
  192. <NSwitch v-model:value={forms.autoPlay} />
  193. </div>
  194. <div class={styles.btnItem}>
  195. <span class={styles.btnTitle}>
  196. 公开课件
  197. <NTooltip style={{ maxWidth: '200px' }} showArrow={false}>
  198. {{
  199. trigger: () => <i class={styles.iconQuestion}></i>,
  200. default: () => '公开课件后,其它老师可以使用该课件上课'
  201. }}
  202. </NTooltip>
  203. </span>
  204. {!forms.openFlagEnable ? (
  205. <NTooltip style={{ maxWidth: '200px' }} showArrow={false}>
  206. {{
  207. trigger: () => (
  208. <NSwitch
  209. v-model:value={forms.openFlag}
  210. disabled={!forms.openFlagEnable}
  211. />
  212. ),
  213. default: () =>
  214. '为尊重课件原作者,在“相关课件”中添加的课件不支持公开'
  215. }}
  216. </NTooltip>
  217. ) : (
  218. <NSwitch
  219. v-model:value={forms.openFlag}
  220. disabled={!forms.openFlagEnable}
  221. />
  222. )}
  223. </div>
  224. </div>
  225. </>
  226. );
  227. }
  228. });