Merge branch 'master' of https://gitee.com/layui-vue/layui-vue
This commit is contained in:
commit
71e07cb0ac
@ -127,7 +127,7 @@ export default {
|
||||
|
||||
<template>
|
||||
{{selectedKeys}}
|
||||
<lay-table :columns="columns" id="id" :dataSource="dataSource" default-toolbar="true" :selectedKeys="selectedKeys" checkbox="true">
|
||||
<lay-table :columns="columns" id="id" :dataSource="dataSource" default-toolbar="true" :selectedKeys="selectedKeys" @changeSelectedKeys="changeSelectedKeys" checkbox="true">
|
||||
<template v-slot:toolbar>
|
||||
<lay-button>新增</lay-button>
|
||||
<lay-button>删除</lay-button>
|
||||
@ -149,6 +149,10 @@ export default {
|
||||
|
||||
const selectedKeys = ref(['1'])
|
||||
|
||||
const changeSelectedKeys = function(val) {
|
||||
selectedKeys.value = val
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title:"账户",
|
||||
@ -181,6 +185,7 @@ export default {
|
||||
columns,
|
||||
dataSource,
|
||||
selectedKeys,
|
||||
changeSelectedKeys
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
'layui-checkbox-disbaled layui-disabled': disabled,
|
||||
},
|
||||
'layui-form-checkbox',
|
||||
hasValue ? 'layui-form-checked' : '',
|
||||
props.modelValue.includes(props.label) ? 'layui-form-checked' : '',
|
||||
]"
|
||||
:lay-skin="skin"
|
||||
>
|
||||
@ -24,7 +24,7 @@ import { defineProps, ref, watch } from 'vue'
|
||||
|
||||
const props =
|
||||
defineProps<{
|
||||
modelValue: Array<unknown>
|
||||
modelValue: string[]
|
||||
label: string
|
||||
disabled?: boolean
|
||||
name?: string
|
||||
@ -33,14 +33,6 @@ const props =
|
||||
|
||||
const hasValue = ref(false)
|
||||
|
||||
watch(props.modelValue, (val) => {
|
||||
if (props.modelValue.includes(props.label)) {
|
||||
hasValue.value = true
|
||||
} else {
|
||||
hasValue.value = false
|
||||
}
|
||||
},{immediate: true})
|
||||
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
|
||||
const handleClick = function () {
|
||||
@ -51,14 +43,6 @@ const handleClick = function () {
|
||||
let index = props.modelValue.indexOf(props.label)
|
||||
props.modelValue.splice(index, 1)
|
||||
}
|
||||
props.modelValue.includes(props.label)
|
||||
? (hasValue.value = true)
|
||||
: (hasValue.value = false)
|
||||
if (props.modelValue.includes(props.label)) {
|
||||
hasValue.value = true
|
||||
} else {
|
||||
hasValue.value = false
|
||||
}
|
||||
emit('update:modelValue', props.modelValue)
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
</template>
|
||||
|
||||
<script setup name="LayMenuItem" lang="ts">
|
||||
import { defineProps, inject, provide, Ref, ref, useSlots } from 'vue'
|
||||
import { defineProps, inject, Ref, ref, useSlots } from 'vue'
|
||||
const slots = useSlots()
|
||||
|
||||
const props =
|
||||
|
@ -29,7 +29,11 @@
|
||||
<tr>
|
||||
<th class="layui-table-col-special" v-if="checkbox">
|
||||
<div class="layui-table-cell laytable-cell-checkbox">
|
||||
<lay-checkbox skin="primary" v-model="tableSelectedKeys" label="all"></lay-checkbox>
|
||||
<lay-checkbox
|
||||
skin="primary"
|
||||
v-model="allSelectedKeys"
|
||||
label="all"
|
||||
></lay-checkbox>
|
||||
</div>
|
||||
</th>
|
||||
<th v-for="column in columns" :key="column">
|
||||
@ -51,7 +55,11 @@
|
||||
<tr>
|
||||
<td class="layui-table-col-special" v-if="checkbox">
|
||||
<div class="layui-table-cell laytable-cell-checkbox">
|
||||
<lay-checkbox skin="primary" v-model="tableSelectedKeys" :label="data[id]"></lay-checkbox>
|
||||
<lay-checkbox
|
||||
skin="primary"
|
||||
v-model="tableSelectedKeys"
|
||||
:label="data[id]"
|
||||
></lay-checkbox>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
@ -105,28 +113,56 @@
|
||||
</div>
|
||||
</template>
|
||||
<script setup name="LayTable" lang="ts">
|
||||
import { defineProps, ref, useSlots, watch, withDefaults, defineEmits } from 'vue'
|
||||
import {
|
||||
defineProps,
|
||||
ref,
|
||||
useSlots,
|
||||
watch,
|
||||
withDefaults,
|
||||
defineEmits,
|
||||
computed,
|
||||
} from 'vue'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
id?: string,
|
||||
id?: string
|
||||
skin?: string
|
||||
page?: Object
|
||||
checkbox?: Boolean
|
||||
columns?: Object[]
|
||||
dataSource?: Object[]
|
||||
dataSource: Object[]
|
||||
defaultToolbar?: Boolean
|
||||
selectedKeys: Array<String>
|
||||
}>(),
|
||||
{
|
||||
id: "id",
|
||||
selectedKeys: function() { return [] }
|
||||
id: 'id',
|
||||
dataSource: function () {
|
||||
return []
|
||||
},
|
||||
selectedKeys: function () {
|
||||
return []
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const allSelectedKeys = ref([])
|
||||
const tableSelectedKeys = ref(props.selectedKeys)
|
||||
|
||||
const emit = defineEmits(['change'])
|
||||
watch(
|
||||
allSelectedKeys,
|
||||
function (val: String[]) {
|
||||
const ids = props.dataSource.map((item: any) => {
|
||||
return item[props.id]
|
||||
})
|
||||
tableSelectedKeys.value.splice(0, ids.length)
|
||||
if (val.includes('all')) {
|
||||
ids.forEach(id => { tableSelectedKeys.value.push(id) })
|
||||
}
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
const emit = defineEmits(['change', 'changeSelectedKeys'])
|
||||
|
||||
const slot = useSlots()
|
||||
const slots = slot.default && slot.default()
|
||||
|
Loading…
Reference in New Issue
Block a user