Browse Source

🐞 fix: #2705 同一类型下只允许选择一个

wolyshaw 3 years ago
parent
commit
0e71a6af5e

+ 13 - 1
src/student/music/search/select-tag.tsx

@@ -20,9 +20,17 @@ export default defineComponent({
     defaultValue: {
       type: String,
       default: ''
+    },
+    rowSingle: {
+      type: Boolean,
+      default: false
+    },
+    needAllButton: {
+      type: Boolean,
+      default: true
     }
   },
-  setup({ onCancel, onComfirm, defaultValue }) {
+  setup({ onCancel, onComfirm, defaultValue, ...restProps }) {
     const prefix =
       appState.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
     const { isLoading, state } = useAsyncState(
@@ -62,6 +70,9 @@ export default defineComponent({
           <h4 class={styles.title}>全部标签</h4>
           <div class={styles.content}>
             {list.map(item => {
+              if (!item.children || item.children.length <= 0) {
+                return null
+              }
               return (
                 <div class={styles.list} key={item.id}>
                   <div class={styles.tit}>{item.name}</div>
@@ -73,6 +84,7 @@ export default defineComponent({
                     onSelect={val => {
                       tags[item.id] = val
                     }}
+                    {...restProps}
                   />
                 </div>
               )

+ 34 - 13
src/student/music/search/select-tags-child.tsx

@@ -1,5 +1,5 @@
 import { defineComponent } from 'vue'
-import { Tag, CheckboxGroup, Checkbox } from 'vant'
+import { Tag, CheckboxGroup, Checkbox, RadioGroup, Radio } from 'vant'
 import styles from './select.module.less'
 import classNames from 'classnames'
 
@@ -13,9 +13,17 @@ export default defineComponent({
     onSelect: {
       type: Function,
       default: () => {}
+    },
+    rowSingle: {
+      type: Boolean,
+      default: false
+    },
+    needAllButton: {
+      type: Boolean,
+      default: true
     }
   },
-  setup({ child, onSelect }, { attrs }) {
+  setup({ child, onSelect, needAllButton, rowSingle }, { attrs }) {
     return () => {
       const selected = attrs.selected as number[]
       return (
@@ -26,19 +34,32 @@ export default defineComponent({
             onSelect(val)
           }}
         >
-          <Checkbox name={0} class={styles.radio} onClick={() => onSelect([])}>
-            <Tag
-              class={classNames(styles.item, 'van-ellipsis')}
-              type="primary"
-              plain={selected.length !== 0}
-              round
-              size="large"
+          {needAllButton && (
+            <Checkbox
+              name={0}
+              class={styles.radio}
+              onClick={() => onSelect([])}
             >
-              全部
-            </Tag>
-          </Checkbox>
+              <Tag
+                class={classNames(styles.item, 'van-ellipsis')}
+                type="primary"
+                plain={selected.length !== 0}
+                round
+                size="large"
+              >
+                全部
+              </Tag>
+            </Checkbox>
+          )}
           {child.map((item: any) => (
-            <Checkbox key={item.id} name={item.id} class={styles.radio}>
+            <Checkbox
+              key={item.id}
+              name={item.id}
+              class={styles.radio}
+              onClick={() => {
+                rowSingle && onSelect([item.id])
+              }}
+            >
               <Tag
                 class={classNames(styles.item, 'van-ellipsis')}
                 plain={!selected.includes(item.id)}

+ 6 - 1
src/teacher/music/upload/index.tsx

@@ -560,7 +560,12 @@ export default defineComponent({
           teleport="body"
           onUpdate:show={val => (this.tagVisibility = val)}
         >
-          <SelectTag onComfirm={this.onComfirm} onCancel={() => {}} />
+          <SelectTag
+            onComfirm={this.onComfirm}
+            onCancel={() => {}}
+            rowSingle
+            needAllButton={false}
+          />
         </Popup>
       </Form>
     )