index.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { defineComponent, onMounted, ref } from 'vue';
  2. import styles from './index.module.less';
  3. import { NButton, NSpace, useMessage } from 'naive-ui';
  4. import { useCatchStore } from '/src/store/modules/catchData';
  5. import iconSelect from '../../images/icon-select.png';
  6. export default defineComponent({
  7. name: 'subject-sync',
  8. props: {
  9. subjectId: {
  10. type: [String, Number],
  11. default: ''
  12. }
  13. },
  14. emits: ['close', 'confirm'],
  15. setup(props, { emit }) {
  16. const catchStore = useCatchStore();
  17. const message = useMessage();
  18. const selectSubjectIds = ref([] as any);
  19. const onSubmit = () => {
  20. if (selectSubjectIds.value.length <= 0) {
  21. message.error('至少选择一个声部进行同步');
  22. return;
  23. }
  24. emit('confirm', selectSubjectIds.value);
  25. };
  26. onMounted(async () => {
  27. // 获取教材分类列表
  28. await catchStore.getSubjects();
  29. if (props.subjectId) {
  30. selectSubjectIds.value = [Number(props.subjectId)];
  31. }
  32. });
  33. return () => (
  34. <div class={styles.subjectSync}>
  35. <div class={styles.tips}>
  36. 请选择当前课件可使用的乐器
  37. <span>(勾选后则对应乐器下的课件内容将被当前课件内容全部替换)</span>
  38. </div>
  39. <div class={styles.subjectList}>
  40. {catchStore.getSubjectList.map((subject: any) => (
  41. <div
  42. class={[
  43. styles.subjectItem,
  44. selectSubjectIds.value.includes(subject.id)
  45. ? styles.subjectSelect
  46. : ''
  47. ]}
  48. onClick={() => {
  49. if (selectSubjectIds.value.includes(subject.id)) {
  50. const index = selectSubjectIds.value.indexOf(subject.id);
  51. selectSubjectIds.value.splice(index, 1);
  52. } else {
  53. selectSubjectIds.value.push(subject.id);
  54. }
  55. }}>
  56. <div class={styles.imgSection}>
  57. <img src={subject.img} />
  58. {selectSubjectIds.value.includes(subject.id) && (
  59. <img src={iconSelect} class={styles.iconSelect} />
  60. )}
  61. </div>
  62. <p class={styles.subjectName}>{subject.name}</p>
  63. </div>
  64. ))}
  65. </div>
  66. <NSpace class={styles.btnGroupModal} justify="center">
  67. <NButton round onClick={() => emit('close')}>
  68. 取消
  69. </NButton>
  70. <NButton round type="primary" onClick={onSubmit}>
  71. 确定
  72. </NButton>
  73. </NSpace>
  74. </div>
  75. );
  76. }
  77. });