feat(tree): 完成树形组件复选框功能

This commit is contained in:
落小梅 2021-10-14 16:39:06 +08:00
parent eef31c72af
commit 377171ab94
7 changed files with 82 additions and 71 deletions

View File

@ -1,5 +1,3 @@
::: demo
<template>
@ -25,8 +23,6 @@ export default {
:::
::: demo
<template>
@ -138,11 +134,10 @@ export default {
:::
| Name | Description | Accepted Values |
| -------- | ---- | ----------------------- |
| name | 原始属性 name | -- |
| skin | 主题 | -- |
| label | 选中值 | -- |
| checked ( v-model ) | 是否选中 | `true` `false` |
| change | 切换事件 | isChecked : 当前状态 |
| Name | Description | Accepted Values |
| ------------------- | ------------- | -------------------- |
| name | 原始属性 name | -- |
| skin | 主题 | -- |
| label | 选中值 | -- |
| checked ( v-model ) | 是否选中 | `true` `false` |
| change | 切换事件 | isChecked : 当前状态 |

View File

@ -7,7 +7,7 @@
fluid ? 'layui-btn-fluid' : '',
radius ? 'layui-btn-radius' : '',
border ? 'layui-border-' + border : '',
disabled ? 'layui-btn-disabled': ''
disabled ? 'layui-btn-disabled' : '',
]"
>
<slot />

View File

@ -20,21 +20,20 @@ import { defineProps, useSlots } from 'vue'
const slot = useSlots()
const props =
defineProps<{
name?: string
skin?: string
label?: string
checked?: boolean
disabled?: boolean
}>()
const props = defineProps<{
name?: string
skin?: string
label?: string
checked?: boolean
disabled?: boolean
}>()
const emit = defineEmits(['update:checked', 'change'])
const handleClick = function () {
if (!props.disabled) {
emit('update:checked', !props.checked)
emit('change', { checked: !props.checked, value: props.label })
emit('update:checked', !props.checked)
emit('change', { checked: !props.checked, value: props.label })
}
}
</script>

View File

@ -21,14 +21,13 @@
<script setup name="LayCheckbox" lang="ts">
import { defineProps, ref } from 'vue'
const props =
defineProps<{
modelValue: string[]
label: string
disabled?: boolean
name?: string
skin?: string
}>()
const props = defineProps<{
modelValue: string[]
label: string
disabled?: boolean
name?: string
skin?: string
}>()
const hasValue = ref(false)
@ -45,4 +44,4 @@ const handleClick = function () {
emit('update:modelValue', props.modelValue)
}
}
</script>
</script>

View File

@ -14,7 +14,12 @@
<div class="layui-inline" title="筛选列" lay-event="LAYTABLE_COLS">
<i class="layui-icon layui-icon-cols" />
</div>
<div class="layui-inline" title="打印" lay-event="LAYTABLE_PRINT" @click="print()">
<div
class="layui-inline"
title="打印"
lay-event="LAYTABLE_PRINT"
@click="print()"
>
<i class="layui-icon layui-icon-print" />
</div>
</div>
@ -54,9 +59,9 @@
<td v-if="checkbox" class="layui-table-col-special">
<div class="layui-table-cell laytable-cell-checkbox">
<table-item-checkbox
v-model="tableSelectedKeys"
skin="primary"
:label="data[id]"
v-model="tableSelectedKeys"
>
</table-item-checkbox>
</div>

View File

@ -21,14 +21,13 @@
<script setup name="LayCheckbox" lang="ts">
import { defineProps, ref } from 'vue'
const props =
defineProps<{
modelValue: string[]
label: string
disabled?: boolean
name?: string
skin?: string
}>()
const props = defineProps<{
modelValue: string[]
label: string
disabled?: boolean
name?: string
skin?: string
}>()
const hasValue = ref(false)
@ -45,4 +44,4 @@ const handleClick = function () {
emit('update:modelValue', props.modelValue)
}
}
</script>
</script>

View File

@ -25,10 +25,16 @@
</ul>
</div>
<div class="layui-transfer-active">
<lay-button @click="add" type="primary" :disabled="leftSelectedKeys.length==0"
<lay-button
type="primary"
:disabled="leftSelectedKeys.length == 0"
@click="add"
><i class="layui-icon layui-icon-next"
/></lay-button>
<lay-button @click="remove" type="primary" :disabled="rightSelectedKeys.length==0"
<lay-button
type="primary"
:disabled="rightSelectedKeys.length == 0"
@click="remove"
><i class="layui-icon layui-icon-prev"
/></lay-button>
</div>
@ -74,8 +80,8 @@ const props = withDefaults(
}>(),
{
id: 'id',
title: function() {
return ['主列表','副列表']
title: function () {
return ['主列表', '副列表']
},
dataSource: function () {
return []
@ -106,13 +112,17 @@ const allLeftChange = function ({ checked }: any) {
}
}
watch(leftSelectedKeys, function(){
if(leftDataSource.value.length === leftSelectedKeys.value.length ) {
allLeftChecked.value = true
} else {
allLeftChecked.value = false
}
},{deep:true})
watch(
leftSelectedKeys,
function () {
if (leftDataSource.value.length === leftSelectedKeys.value.length) {
allLeftChecked.value = true
} else {
allLeftChecked.value = false
}
},
{ deep: true }
)
const allRightChange = function ({ checked }: any) {
if (checked) {
@ -125,25 +135,29 @@ const allRightChange = function ({ checked }: any) {
}
}
watch(rightSelectedKeys, function(){
if(rightDataSource.value.length === rightSelectedKeys.value.length ) {
allRightChecked.value = true
} else {
allRightChecked.value = false
}
},{deep:true})
watch(
rightSelectedKeys,
function () {
if (rightDataSource.value.length === rightSelectedKeys.value.length) {
allRightChecked.value = true
} else {
allRightChecked.value = false
}
},
{ deep: true }
)
const add = function() {
// leftDataSource
rightDataSource.value = leftDataSource.value.filter(
item => leftSelectedKeys.value.indexOf(item.id) != -1
)
const add = function () {
// leftDataSource
rightDataSource.value = leftDataSource.value.filter(
(item) => leftSelectedKeys.value.indexOf(item.id) != -1
)
}
const remove = function() {
// rightDataSource
leftDataSource.value = rightDataSource.value.filter(
item => rightSelectedKeys.value.indexOf(item.id) != -1
)
const remove = function () {
// rightDataSource
leftDataSource.value = rightDataSource.value.filter(
(item) => rightSelectedKeys.value.indexOf(item.id) != -1
)
}
</script>