search-group-resources.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import { defineComponent, onMounted, reactive, ref } from 'vue';
  2. import styles from './index.module.less';
  3. import { NButton, NForm, NFormItem, NSpace } from 'naive-ui';
  4. import iconUpload from '../../images/icon-upload.svg';
  5. import iconEdit from '../../images/icon-edit.svg';
  6. import iconSelectAll from '../../images/icon-selectall.svg';
  7. import iconSelectAllDefault from '../../images/icon-selectall-default.svg';
  8. import iconPen from '../../images/icon-pen.svg';
  9. import iconDelete from '../../images/icon-delete.svg';
  10. import TheSearch from '/src/components/TheSearch';
  11. import { resourceTypeArray } from '/src/utils/searchArray';
  12. import { useCatchStore } from '/src/store/modules/catchData';
  13. export default defineComponent({
  14. name: 'search-group',
  15. emits: ['search', 'upload', 'edit', 'selectAll', 'delete', 'update'],
  16. setup(props, { emit }) {
  17. const resourceList = ref([] as any[]);
  18. const catchStore = useCatchStore();
  19. const forms = reactive({
  20. type: '', //
  21. keyword: '',
  22. bookVersionId: null,
  23. subjectId: null
  24. });
  25. const state = reactive({
  26. isEdit: false, // 是否编辑
  27. isSelectAll: false
  28. });
  29. const onSearch = () => {
  30. emit('search', forms);
  31. };
  32. onMounted(async () => {
  33. resourceList.value = [
  34. {
  35. label: '全部',
  36. value: ''
  37. },
  38. ...resourceTypeArray
  39. ];
  40. // 获取声部列表
  41. await catchStore.getSubjects();
  42. });
  43. return () => (
  44. <div class={styles.searchGroup}>
  45. <div class={styles.searchCatatory}>
  46. <NSpace size="small" class={styles.btnType}>
  47. {resourceList.value.map(
  48. (item: any) =>
  49. item.value !== 'MUSIC' && (
  50. <NButton
  51. type={forms.type === item.value ? 'primary' : 'default'}
  52. secondary={forms.type === item.value ? false : true}
  53. round
  54. size="small"
  55. focusable={false}
  56. onClick={() => {
  57. forms.type = item.value;
  58. onSearch();
  59. }}>
  60. {item.label}
  61. </NButton>
  62. )
  63. )}
  64. </NSpace>
  65. <NSpace>
  66. {state.isEdit ? (
  67. <>
  68. <NButton
  69. type="primary"
  70. class={styles.addTrain}
  71. focusable={false}
  72. strong
  73. onClick={() => {
  74. state.isSelectAll = !state.isSelectAll;
  75. emit('selectAll', state.isSelectAll);
  76. }}>
  77. <img
  78. src={
  79. state.isSelectAll ? iconSelectAll : iconSelectAllDefault
  80. }
  81. class={styles.iconSelectAll}
  82. />
  83. 全选
  84. </NButton>
  85. <NButton
  86. type="error"
  87. class={[styles.addTrain, styles.error]}
  88. focusable={false}
  89. strong
  90. onClick={() => emit('delete')}>
  91. <img src={iconDelete} class={styles.iconDelete} />
  92. 删除
  93. </NButton>
  94. <NButton
  95. type="primary"
  96. class={styles.addTrain}
  97. focusable={false}
  98. strong
  99. onClick={() => emit('update')}>
  100. <img src={iconPen} class={styles.iconPen} />
  101. 修改
  102. </NButton>
  103. <NButton
  104. type="primary"
  105. class={styles.addTrain}
  106. focusable={false}
  107. strong
  108. onClick={() => {
  109. state.isEdit = false;
  110. emit('edit', state.isEdit);
  111. }}>
  112. 完成编辑
  113. </NButton>
  114. </>
  115. ) : (
  116. <>
  117. <NButton
  118. type="primary"
  119. class={styles.addTrain}
  120. focusable={false}
  121. {...{ id: 'myResources-0' }}
  122. strong
  123. onClick={() => emit('upload')}>
  124. <img src={iconUpload} class={styles.iconUpload} />
  125. 上传资源
  126. </NButton>
  127. <NButton
  128. type="primary"
  129. class={styles.addTrain}
  130. focusable={false}
  131. strong
  132. onClick={() => {
  133. state.isEdit = true;
  134. emit('edit', state.isEdit);
  135. }}>
  136. <img src={iconEdit} class={styles.iconEdit} />
  137. 编辑资源
  138. </NButton>
  139. </>
  140. )}
  141. </NSpace>
  142. </div>
  143. <NForm labelAlign="left" labelPlacement="left">
  144. <NFormItem label="乐器:">
  145. <NSpace class={styles.spaceSection}>
  146. {catchStore.getSubjectAllList.map((subject: any) => (
  147. <NButton
  148. secondary={forms.subjectId === subject.id}
  149. quaternary={forms.subjectId !== subject.id}
  150. strong
  151. focusable={false}
  152. type={forms.subjectId === subject.id ? 'primary' : 'default'}
  153. onClick={() => {
  154. forms.subjectId = subject.id;
  155. onSearch();
  156. }}>
  157. {subject.name}
  158. </NButton>
  159. ))}
  160. </NSpace>
  161. </NFormItem>
  162. <TheSearch
  163. class={styles.inputSearch}
  164. round
  165. onSearch={(val: string) => {
  166. forms.keyword = val;
  167. onSearch();
  168. }}
  169. />
  170. </NForm>
  171. </div>
  172. );
  173. }
  174. });