index.tsx 8.4 KB

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