Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
AutoDict组件增强:checkbox增加全选按钮
  • Loading branch information
4linuxfun committed Nov 24, 2022
commit 0deb50d45ac2e2ebc007484066eecf1e7d89b63f
33 changes: 30 additions & 3 deletions www/src/components/AutoDict.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</template>

<template v-else-if="type === 'checkbox'">
<el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange">全选</el-checkbox>
<el-checkbox-group v-model="modelValue" @change="handleUpdate">
<el-row :gutter="20">
<el-col v-for="item in itemArray" :key="item.value" :span="colSpan">
Expand Down Expand Up @@ -54,15 +55,41 @@
const {type, code, col, modelValue} = toRefs(props)
const itemArray = ref(null)
const colSpan = 24 / col.value
const checkAll = ref(false)
const isIndeterminate = ref(true)

let allItems = []

function handleUpdate(currentValue) {
if (type.value === 'checkbox') {
const checkedCount = currentValue.length
checkAll.value = checkedCount === allItems.length
isIndeterminate.value = checkedCount > 0 && checkedCount < allItems.length
}
emit('update:modelValue', currentValue)
}

function handleCheckAllChange(val) {
if (val) {
emit('update:modelValue', allItems)
} else {
emit('update:modelValue', [])
}
isIndeterminate.value = false
}

GetDictItems(code.value).then(response => {
itemArray.value = response
if (type.value === 'checkbox') {
itemArray.value.forEach((item) => {
console.log('add to items:' + item['value'])
allItems.push(item['value'])
})
}
})

onMounted(() => {
GetDictItems(code.value).then(response => {
itemArray.value = response
})

})
</script>

Expand Down