[优化] table 和 tranfer 组件复选实现
This commit is contained in:
parent
88c38dddf0
commit
6baec91cdd
@ -18,6 +18,7 @@
|
|||||||
[修复] themeline 时间线,因 mackdown 造成的样式污染。<br>
|
[修复] themeline 时间线,因 mackdown 造成的样式污染。<br>
|
||||||
[新增] layer 弹层出场动画, 允许使用 isOutAmin 关闭。<br>
|
[新增] layer 弹层出场动画, 允许使用 isOutAmin 关闭。<br>
|
||||||
[新增] checkbox-group 复选框组, 更方便的复选方式。<br>
|
[新增] checkbox-group 复选框组, 更方便的复选方式。<br>
|
||||||
|
[优化] table 和 tranfer 组件复选实现。<br>
|
||||||
[删除] rate 评分 theme 属性默认值。<br>
|
[删除] rate 评分 theme 属性默认值。<br>
|
||||||
</lay-timeline-item>
|
</lay-timeline-item>
|
||||||
<lay-timeline-item title="0.2.3">
|
<lay-timeline-item title="0.2.3">
|
||||||
|
@ -11,8 +11,8 @@ import "./index.less";
|
|||||||
export interface LayCheckboxProps {
|
export interface LayCheckboxProps {
|
||||||
name?: string;
|
name?: string;
|
||||||
skin?: string;
|
skin?: string;
|
||||||
label: string;
|
label: string | object;
|
||||||
modelValue: boolean | Array<string>;
|
modelValue: boolean | Array<string | object>;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div @click.stop="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>
|
|
||||||
</div>
|
|
||||||
</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>
|
|
@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export default {
|
export default {
|
||||||
name: 'LayTable',
|
name: "LayTable",
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@ -12,39 +12,47 @@ import {
|
|||||||
defineProps,
|
defineProps,
|
||||||
withDefaults,
|
withDefaults,
|
||||||
defineEmits,
|
defineEmits,
|
||||||
} from 'vue'
|
} from "vue";
|
||||||
import { Recordable } from '../type'
|
import { Recordable } from "../type";
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
id?: string
|
id?: string;
|
||||||
skin?: string
|
skin?: string;
|
||||||
size?: string
|
size?: string;
|
||||||
page?: Recordable
|
page?: Recordable;
|
||||||
checkbox?: boolean
|
checkbox?: boolean;
|
||||||
columns: Recordable[]
|
columns: Recordable[];
|
||||||
dataSource: Recordable[]
|
dataSource: Recordable[];
|
||||||
defaultToolbar?: boolean
|
defaultToolbar?: boolean;
|
||||||
selectedKeys?: Array<string>
|
selectedKeys?: Recordable[];
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
id: 'id',
|
id: "id",
|
||||||
size: 'md',
|
size: "md",
|
||||||
dataSource: () => [],
|
dataSource: () => [],
|
||||||
selectedKeys: () => [],
|
selectedKeys: () => [],
|
||||||
}
|
}
|
||||||
)
|
);
|
||||||
|
|
||||||
const emit = defineEmits(['change', 'row', 'row-double', 'update:selectedKeys'])
|
const emit = defineEmits([
|
||||||
|
"change",
|
||||||
|
"row",
|
||||||
|
"row-double",
|
||||||
|
"update:selectedKeys",
|
||||||
|
]);
|
||||||
|
|
||||||
const slot = useSlots()
|
const slot = useSlots();
|
||||||
const slots = slot.default && slot.default()
|
const slots = slot.default && slot.default();
|
||||||
|
|
||||||
const allChecked = ref(false)
|
const allChecked = ref(false);
|
||||||
const tableSelectedKeys = ref([...props.selectedKeys])
|
const tableSelectedKeys = ref([...props.selectedKeys]);
|
||||||
const tableColumns = ref([...props.columns])
|
const tableColumns = ref([...props.columns]);
|
||||||
|
const tableColumnKeys = ref(props.columns.map((item: any) => {
|
||||||
|
return item.key;
|
||||||
|
}));
|
||||||
|
|
||||||
const changeAll = function ( checked : any) {
|
const changeAll = function (checked: any) {
|
||||||
const ids = props.dataSource.map((item: any) => {
|
const ids = props.dataSource.map((item: any) => {
|
||||||
return item[props.id];
|
return item[props.id];
|
||||||
});
|
});
|
||||||
@ -55,42 +63,42 @@ const changeAll = function ( checked : any) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
emit("update:selectedKeys", tableSelectedKeys.value);
|
emit("update:selectedKeys", tableSelectedKeys.value);
|
||||||
}
|
};
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
tableSelectedKeys,
|
tableSelectedKeys,
|
||||||
function () {
|
function () {
|
||||||
if (tableSelectedKeys.value.length === props.dataSource.length) {
|
if (tableSelectedKeys.value.length === props.dataSource.length) {
|
||||||
allChecked.value = true
|
allChecked.value = true;
|
||||||
} else {
|
} else {
|
||||||
allChecked.value = false
|
allChecked.value = false;
|
||||||
}
|
}
|
||||||
emit('update:selectedKeys', tableSelectedKeys.value)
|
emit("update:selectedKeys", tableSelectedKeys.value);
|
||||||
},
|
},
|
||||||
{ deep: true }
|
{ deep: true }
|
||||||
)
|
);
|
||||||
|
|
||||||
const change = function (page: any) {
|
const change = function (page: any) {
|
||||||
emit('change', page)
|
emit("change", page);
|
||||||
}
|
};
|
||||||
|
|
||||||
const rowClick = function (data: any) {
|
const rowClick = function (data: any) {
|
||||||
emit('row', data)
|
emit("row", data);
|
||||||
}
|
};
|
||||||
|
|
||||||
const rowDoubleClick = function (data: any) {
|
const rowDoubleClick = function (data: any) {
|
||||||
emit('row-double', data)
|
emit("row-double", data);
|
||||||
}
|
};
|
||||||
|
|
||||||
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;
|
||||||
let oldContent = document.body.innerHTML
|
let oldContent = document.body.innerHTML;
|
||||||
document.body.innerHTML = newContent
|
document.body.innerHTML = newContent;
|
||||||
window.print()
|
window.print();
|
||||||
window.location.reload()
|
window.location.reload();
|
||||||
document.body.innerHTML = oldContent
|
document.body.innerHTML = oldContent;
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -113,9 +121,9 @@ const print = function () {
|
|||||||
<lay-checkbox
|
<lay-checkbox
|
||||||
v-for="column in columns"
|
v-for="column in columns"
|
||||||
:key="column"
|
:key="column"
|
||||||
v-model="tableColumns"
|
v-model="tableColumnKeys"
|
||||||
skin="primary"
|
skin="primary"
|
||||||
:label="column"
|
:label="column.key"
|
||||||
>{{ column.title }}</lay-checkbox
|
>{{ column.title }}</lay-checkbox
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
@ -149,7 +157,7 @@ const print = function () {
|
|||||||
</div>
|
</div>
|
||||||
</th>
|
</th>
|
||||||
<template v-for="column in columns" :key="column">
|
<template v-for="column in columns" :key="column">
|
||||||
<th v-if="tableColumns.includes(column)">
|
<th v-if="tableColumnKeys.includes(column.key)">
|
||||||
<div
|
<div
|
||||||
class="layui-table-cell"
|
class="layui-table-cell"
|
||||||
:style="{ width: column.width }"
|
:style="{ width: column.width }"
|
||||||
@ -183,7 +191,7 @@ const print = function () {
|
|||||||
</td>
|
</td>
|
||||||
|
|
||||||
<template v-for="column in columns" :key="column">
|
<template v-for="column in columns" :key="column">
|
||||||
<template v-if="tableColumns.includes(column)">
|
<template v-if="tableColumnKeys.includes(column.key)">
|
||||||
<template v-if="column.customSlot">
|
<template v-if="column.customSlot">
|
||||||
<td class="layui-table-cell">
|
<td class="layui-table-cell">
|
||||||
<div :style="{ width: column.width }">
|
<div :style="{ width: column.width }">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user