perf(transfer): 初步集成穿梭框

This commit is contained in:
就眠仪式 2021-10-14 15:33:11 +08:00
parent 99d723c309
commit ae5a2a08a5
7 changed files with 137 additions and 34 deletions

View File

@ -4,7 +4,7 @@
<template> <template>
<lay-form> <lay-form>
<lay-checkbox name="like" skin="primary" v-model:checked="checked1" label="1" >普通</lay-checkbox> <lay-checkbox name="like" skin="primary" v-model:checked="checked1" label="1" ></lay-checkbox>
</lay-form> </lay-form>
</template> </template>

View File

@ -7,6 +7,7 @@
fluid ? 'layui-btn-fluid' : '', fluid ? 'layui-btn-fluid' : '',
radius ? 'layui-btn-radius' : '', radius ? 'layui-btn-radius' : '',
border ? 'layui-border-' + border : '', border ? 'layui-border-' + border : '',
disabled ? 'layui-btn-disabled': ''
]" ]"
> >
<slot /> <slot />
@ -22,5 +23,6 @@ const props = defineProps<{
fluid?: boolean fluid?: boolean
radius?: boolean radius?: boolean
border?: string border?: string
disabled?: boolean
}>() }>()
</script> </script>

View File

@ -16,7 +16,9 @@
</template> </template>
<script setup name="LayCheckbox" lang="ts"> <script setup name="LayCheckbox" lang="ts">
import { defineProps } from 'vue' import { defineProps, useSlots } from 'vue'
const slot = useSlots()
const props = const props =
defineProps<{ defineProps<{

View File

@ -8,13 +8,12 @@
'layui-checkbox-disbaled layui-disabled': disabled, 'layui-checkbox-disbaled layui-disabled': disabled,
}, },
'layui-form-checkbox', 'layui-form-checkbox',
props.modelValue.includes(props.label) ? 'layui-form-checked' : '', modelValue.includes(label) ? 'layui-form-checked' : '',
]" ]"
:lay-skin="skin" :lay-skin="skin"
> >
<span><slot /></span> <span><slot /></span>
<i v-if="skin == 'primary'" class="layui-icon layui-icon-ok" /> <i class="layui-icon layui-icon-ok" />
<i v-if="!skin" class="layui-icon layui-icon-ok" />
</div> </div>
</span> </span>
</template> </template>

View File

@ -183,7 +183,6 @@ const change = function (page: any) {
emit('change', page) emit('change', page)
} }
///
const print = function () { const print = function () {
let subOutputRankPrint = document.getElementById('lay-table') as HTMLElement let subOutputRankPrint = document.getElementById('lay-table') as HTMLElement
let newContent = subOutputRankPrint.innerHTML let newContent = subOutputRankPrint.innerHTML

View File

@ -0,0 +1,48 @@
<template>
<span @click="handleClick">
<input type="checkbox" :name="name" :value="label" />
<div
class="layui-unselect"
:class="[
{
'layui-checkbox-disbaled layui-disabled': disabled,
},
'layui-form-checkbox',
modelValue.includes(label) ? 'layui-form-checked' : '',
]"
:lay-skin="skin"
>
<span><slot /></span>
<i class="layui-icon layui-icon-ok" />
</div>
</span>
</template>
<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 hasValue = ref(false)
const emit = defineEmits(['update:modelValue'])
const handleClick = function () {
if (!props.disabled) {
if (!props.modelValue.includes(props.label)) {
props.modelValue.push(props.label)
} else {
let index = props.modelValue.indexOf(props.label)
props.modelValue.splice(index, 1)
}
emit('update:modelValue', props.modelValue)
}
}
</script>

View File

@ -4,59 +4,54 @@
<div class="layui-transfer-box" style="width: 200px; height: 360px"> <div class="layui-transfer-box" style="width: 200px; height: 360px">
<div class="layui-transfer-header"> <div class="layui-transfer-header">
<lay-checkbox <lay-checkbox
v-model="allLeftSelectedKeys" v-model:checked="allLeftChecked"
skin="primary" skin="primary"
label="all" label="all"
@change="allLeftChange"
> >
<span>列表一</span> <span>{{ title[0] }}</span>
</lay-checkbox> </lay-checkbox>
</div> </div>
<ul class="layui-transfer-data" style="height: 320px"> <ul class="layui-transfer-data" style="height: 320px">
<li v-for="dataSource in leftDataSource" :key="dataSource"> <li v-for="dataSource in leftDataSource" :key="dataSource">
<lay-checkbox <transfer-checkbox
v-model="leftSelectedKeys" v-model="leftSelectedKeys"
skin="primary" skin="primary"
:label="dataSource[id]" :label="dataSource[id]"
> >
<span>{{ dataSource.title }}</span> <span>{{ dataSource.title }}</span>
</lay-checkbox> </transfer-checkbox>
</li> </li>
</ul> </ul>
</div> </div>
<div class="layui-transfer-active"> <div class="layui-transfer-active">
<button <lay-button @click="add" type="primary" :disabled="leftSelectedKeys.length==0"
type="button" ><i class="layui-icon layui-icon-next"
class="layui-btn layui-btn-sm layui-btn-primary layui-btn-disabled" /></lay-button>
data-index="0" <lay-button @click="remove" type="primary" :disabled="rightSelectedKeys.length==0"
> ><i class="layui-icon layui-icon-prev"
<i class="layui-icon layui-icon-next" /></button /></lay-button>
><button
type="button"
class="layui-btn layui-btn-sm layui-btn-primary layui-btn-disabled"
data-index="1"
>
<i class="layui-icon layui-icon-prev" />
</button>
</div> </div>
<div class="layui-transfer-box" style="width: 200px; height: 360px"> <div class="layui-transfer-box" style="width: 200px; height: 360px">
<div class="layui-transfer-header"> <div class="layui-transfer-header">
<lay-checkbox <lay-checkbox
v-model="allRightSelectedKeys" v-model:checked="allRightChecked"
skin="primary" skin="primary"
label="all" label="all"
@change="allRightChange"
> >
<span>列表二</span> <span>{{ title[1] }}</span>
</lay-checkbox> </lay-checkbox>
</div> </div>
<ul class="layui-transfer-data" style="height: 320px"> <ul class="layui-transfer-data" style="height: 320px">
<li v-for="dataSource in rightDataSource" :key="dataSource"> <li v-for="dataSource in rightDataSource" :key="dataSource">
<lay-checkbox <transfer-checkbox
v-model="rightSelectedKeys" v-model="rightSelectedKeys"
skin="primary" skin="primary"
:label="dataSource[id]" :label="dataSource[id]"
> >
<span>{{ dataSource.title }}</span> <span>{{ dataSource.title }}</span>
</lay-checkbox> </transfer-checkbox>
</li> </li>
</ul> </ul>
</div> </div>
@ -65,17 +60,23 @@
</template> </template>
<script setup name="LayTransfer"></script> <script setup name="LayTransfer"></script>
<script setup lang="ts"> <script setup lang="ts">
import { defineProps, ref } from 'vue' import { defineProps, Ref, ref, watch } from 'vue'
import { Recordable } from '/@src/module/type' import { Recordable } from '/@src/module/type'
import transferCheckbox from './component/checkbox.vue'
import { check } from 'prettier'
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
id?: string id?: string
title?: string[]
dataSource: Recordable[] dataSource: Recordable[]
selectedKeys: Array<string> selectedKeys: Array<string>
}>(), }>(),
{ {
id: 'id', id: 'id',
title: function() {
return ['主列表','副列表']
},
dataSource: function () { dataSource: function () {
return [] return []
}, },
@ -85,12 +86,64 @@ const props = withDefaults(
} }
) )
const leftDataSource = ref([...props.dataSource]) const leftDataSource: Ref<any[]> = ref([...props.dataSource])
const rightDataSource = ref([]) const rightDataSource: Ref<any[]> = ref([])
const leftSelectedKeys = ref([]) const leftSelectedKeys: Ref<string[]> = ref([])
const rightSelectedKeys = ref([]) const rightSelectedKeys: Ref<string[]> = ref([])
const allLeftSelectedKeys = ref([]) const allLeftChecked = ref(false)
const allRightSelectedKeys = ref([]) const allRightChecked = ref(false)
const allLeftChange = function ({ checked }: any) {
if (checked) {
const ids = leftDataSource.value.map((item: any) => {
return item[props.id]
})
leftSelectedKeys.value = ids
} else {
leftSelectedKeys.value = []
}
}
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) {
const ids = rightDataSource.value.map((item: any) => {
return item[props.id]
})
rightSelectedKeys.value = ids
} else {
rightSelectedKeys.value = []
}
}
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 remove = function() {
// rightDataSource
leftDataSource.value = rightDataSource.value.filter(
item => rightSelectedKeys.value.indexOf(item.id) != -1
)
}
</script> </script>