(table): 新增 table 空数据状态

This commit is contained in:
就眠儀式 2022-07-18 22:12:46 +08:00
parent b6a3f37197
commit b85a9ec6ff
7 changed files with 95 additions and 28 deletions

View File

@ -1,14 +1,14 @@
<template> <template>
<lay-dropdown <lay-dropdown
class="layui-cascader" class="layui-cascader"
:class="{'layui-cascader-opend':openState}" :class="{ 'layui-cascader-opend': openState }"
ref="dropdownRef" ref="dropdownRef"
:autoFitMinWidth="false" :autoFitMinWidth="false"
:updateAtScroll="true" :updateAtScroll="true"
:disabled="dropDownDisabled" :disabled="dropDownDisabled"
:size="size" :size="size"
@open="openState=true" @open="openState = true"
@hide="openState=false" @hide="openState = false"
> >
<lay-input <lay-input
v-model="displayValue" v-model="displayValue"
@ -88,7 +88,7 @@ const props = withDefaults(defineProps<LayCascaderProps>(), {
placeholder: "", placeholder: "",
onlyLastLevel: false, onlyLastLevel: false,
allowClear: false, allowClear: false,
size:'md', size: "md",
replaceFields: () => { replaceFields: () => {
return { return {
label: "label", label: "label",
@ -257,7 +257,7 @@ const selectBar = (item: any, selectIndex: number, parentIndex: number) => {
} }
}; };
const displayValue = ref<string | number >(''); const displayValue = ref<string | number>("");
const slots = useSlots(); const slots = useSlots();
const dropdownRef = ref(); const dropdownRef = ref();
const dropDownDisabled = ref(false); const dropDownDisabled = ref(false);
@ -280,5 +280,5 @@ const onClear = () => {
}, 0); }, 0);
}; };
const openState=ref(false) const openState = ref(false);
</script> </script>

View File

@ -5,7 +5,7 @@
:disabled="disabled" :disabled="disabled"
:autoFitMinWidth="false" :autoFitMinWidth="false"
class="layui-date-picker" class="layui-date-picker"
:class="{'layui-date-range-picker':range}" :class="{ 'layui-date-range-picker': range }"
:size="size" :size="size"
> >
<lay-input <lay-input
@ -148,7 +148,7 @@ const props = withDefaults(defineProps<LayDatePickerProps>(), {
rangeSeparator: "至", rangeSeparator: "至",
readonly: false, readonly: false,
allowClear: true, allowClear: true,
size:'md', size: "md",
}); });
const dropdownRef = ref(null); const dropdownRef = ref(null);

View File

@ -33,7 +33,7 @@ const props = withDefaults(defineProps<LayInputProps>(), {
autofocus: false, autofocus: false,
password: false, password: false,
modelValue: "", modelValue: "",
size:'md', size: "md",
}); });
interface InputEmits { interface InputEmits {

View File

@ -31,7 +31,7 @@ export interface LaySelectProps {
keyword: string; keyword: string;
}[]; }[];
size?: "lg" | "md" | "sm" | "xs"; size?: "lg" | "md" | "sm" | "xs";
allowClear:boolean; allowClear: boolean;
} }
const selectRef = shallowRef<undefined | HTMLElement>(undefined); const selectRef = shallowRef<undefined | HTMLElement>(undefined);
@ -48,8 +48,8 @@ const props = withDefaults(defineProps<LaySelectProps>(), {
showEmpty: true, showEmpty: true,
multiple: false, multiple: false,
create: false, create: false,
size:'md', size: "md",
allowClear:true allowClear: true,
}); });
const openState = ref(false); const openState = ref(false);
@ -166,9 +166,9 @@ const selectItemPush = function (p: SelectItem) {
} }
}; };
const clear=()=>{ const clear = () => {
emit('update:modelValue',props.multiple?[]:''); emit("update:modelValue", props.multiple ? [] : "");
} };
provide("selectItemHandle", selectItemHandle); provide("selectItemHandle", selectItemHandle);
provide("selectItemPush", selectItemPush); provide("selectItemPush", selectItemPush);
@ -180,8 +180,11 @@ provide("keyword", txt);
<div <div
ref="selectRef" ref="selectRef"
class="layui-unselect layui-form-select" class="layui-unselect layui-form-select"
:class="{ 'layui-form-selected': openState,'layui-form-select-multiple':multiple }" :class="{
:size='size' 'layui-form-selected': openState,
'layui-form-select-multiple': multiple,
}"
:size="size"
> >
<div class="layui-select-title" @click="open"> <div class="layui-select-title" @click="open">
<input <input
@ -205,8 +208,18 @@ provide("keyword", txt);
]" ]"
/> />
<span class="layui-input-icon-area"> <span class="layui-input-icon-area">
<i :class="['layui-icon layui-icon-down', { 'layui-disabled': disabled }]" :style="{transform:`rotate(${openState?180:0}deg)`}"></i> <i
<i class="layui-icon layui-icon-close-fill" v-if="(value||selectItem.label?.length)&&allowClear" @click.stop="clear"></i> :class="[
'layui-icon layui-icon-down',
{ 'layui-disabled': disabled },
]"
:style="{ transform: `rotate(${openState ? 180 : 0}deg)` }"
></i>
<i
class="layui-icon layui-icon-close-fill"
v-if="(value || selectItem.label?.length) && allowClear"
@click.stop="clear"
></i>
</span> </span>
<!-- 多选 --> <!-- 多选 -->
<div <div

View File

@ -8,6 +8,7 @@ export default {
import { Recordable } from "../../types"; import { Recordable } from "../../types";
import { computed, ref, StyleValue, useSlots, WritableComputedRef } from "vue"; import { computed, ref, StyleValue, useSlots, WritableComputedRef } from "vue";
import LayCheckbox from "../checkbox/index.vue"; import LayCheckbox from "../checkbox/index.vue";
import LayRadio from "../radio/index.vue";
import LayDropdown from "../dropdown/index.vue"; import LayDropdown from "../dropdown/index.vue";
import LayTooltip from "../tooltip/index.vue"; import LayTooltip from "../tooltip/index.vue";
import { LayIcon } from "@layui/icons-vue"; import { LayIcon } from "@layui/icons-vue";
@ -193,7 +194,6 @@ const renderFixedClassName = (column: any, columnIndex: number) => {
<template v-for="(column, columnIndex) in columns" :key="columnIndex"> <template v-for="(column, columnIndex) in columns" :key="columnIndex">
<!-- 展示否 --> <!-- 展示否 -->
<template v-if="tableColumnKeys.includes(column.key)"> <template v-if="tableColumnKeys.includes(column.key)">
<template v-if="column.type == 'radio'"> <template v-if="column.type == 'radio'">
<td <td
class="layui-table-cell layui-table-cell-radio" class="layui-table-cell layui-table-cell-radio"
@ -237,10 +237,7 @@ const renderFixedClassName = (column: any, columnIndex: number) => {
@click="handleExpand" @click="handleExpand"
></lay-icon> ></lay-icon>
<lay-radio <lay-radio v-model="tableSelectedKey" :value="data[id]" />
v-model="tableSelectedKey"
:value="data[id]"
/>
</td> </td>
</template> </template>

View File

@ -15,7 +15,7 @@ import {
onUpdated, onUpdated,
StyleValue, StyleValue,
WritableComputedRef, WritableComputedRef,
computed, computed,
} from "vue"; } from "vue";
import { v4 as uuidv4 } from "../../utils/guidUtil"; import { v4 as uuidv4 } from "../../utils/guidUtil";
import { Recordable } from "../../types"; import { Recordable } from "../../types";
@ -23,6 +23,7 @@ import { LayIcon } from "@layui/icons-vue";
import LayCheckbox from "../checkbox/index.vue"; import LayCheckbox from "../checkbox/index.vue";
import LayDropdown from "../dropdown/index.vue"; import LayDropdown from "../dropdown/index.vue";
import LayPage from "../page/index.vue"; import LayPage from "../page/index.vue";
import LayEmpty from "../empty/index.vue";
import TableRow from "./TableRow.vue"; import TableRow from "./TableRow.vue";
export interface LayTableProps { export interface LayTableProps {
@ -395,7 +396,9 @@ const renderFixedClassName = (column: any, columnIndex: number) => {
:class="[ :class="[
column.fixed ? `layui-table-fixed-${column.fixed}` : '', column.fixed ? `layui-table-fixed-${column.fixed}` : '',
renderFixedClassName(column, columnIndex), renderFixedClassName(column, columnIndex),
column.type == 'checkbox' ? 'layui-table-cell-checkbox' : '', column.type == 'checkbox'
? 'layui-table-cell-checkbox'
: '',
column.type == 'radio' ? 'layui-table-cell-radio' : '', column.type == 'radio' ? 'layui-table-cell-radio' : '',
column.type == 'number' ? 'layui-table-cell-number' : '', column.type == 'number' ? 'layui-table-cell-number' : '',
]" ]"
@ -462,6 +465,7 @@ const renderFixedClassName = (column: any, columnIndex: number) => {
ref="tableBody" ref="tableBody"
> >
<table <table
v-if="tableDataSource.length > 0"
class="layui-table" class="layui-table"
:class="{ 'layui-table-even': props.even }" :class="{ 'layui-table-even': props.even }"
:lay-size="size" :lay-size="size"
@ -500,7 +504,7 @@ const renderFixedClassName = (column: any, columnIndex: number) => {
@row-double="rowDoubleClick" @row-double="rowDoubleClick"
@contextmenu="contextmenu" @contextmenu="contextmenu"
v-model:selectedKeys="tableSelectedKeys" v-model:selectedKeys="tableSelectedKeys"
v-model:selectedKey="tableSelectedKey" v-model:selectedKey="tableSelectedKey"
> >
<template v-for="name in slotsData" #[name]="{ data }"> <template v-for="name in slotsData" #[name]="{ data }">
<slot :name="name" :data="data"></slot> <slot :name="name" :data="data"></slot>
@ -512,6 +516,7 @@ const renderFixedClassName = (column: any, columnIndex: number) => {
</template> </template>
</tbody> </tbody>
</table> </table>
<lay-empty v-else></lay-empty>
</div> </div>
</div> </div>
<div v-if="page" class="layui-table-page"> <div v-if="page" class="layui-table-page">

View File

@ -796,6 +796,58 @@ export default {
::: :::
::: title 暂无数据
:::
::: demo 通过 `columns` 配置 `type:'radio'` 开启单选列。
<template>
<lay-table :columns="columns25" :dataSource="dataSource25"></lay-table>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const columns25 = [
{
title:"账户",
width:"200px",
key:"username"
},{
title:"密码",
width: "300px",
key:"password"
},{
title:"性别",
key:"sex"
},{
title:"年龄",
width: "300px",
key:"age"
},{
title:"备注",
width: "180px",
key:"remark",
ellipsisTooltip: true
}
]
const dataSource25 = [
]
return {
columns25,
dataSource25,
}
}
}
</script>
:::
::: title 刷新数据 ::: title 刷新数据
::: :::