index.tsx 8.2 KB

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