Skip to content

Commit 82289a9

Browse files
sleepritegitee-org
authored andcommitted
!166 2.1.1
Merge pull request !166 from 就眠儀式/2.x
2 parents f2d4466 + e92e8bd commit 82289a9

File tree

28 files changed

+1289
-1406
lines changed

28 files changed

+1289
-1406
lines changed

package/component/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@layui/layui-vue",
3-
"version": "2.0.5",
3+
"version": "2.1.1",
44
"author": "就眠儀式",
55
"license": "MIT",
66
"description": "a component library for Vue 3 base on layui-vue",

package/component/src/component/checkbox/index.less

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,19 @@
8080
}
8181

8282
.layui-form-checkbox i {
83-
top: 0;
84-
right: 0;
8583
width: 29px;
86-
height: 28px;
84+
height: 30px;
8785
position: absolute;
86+
box-sizing: border-box;
8887
border-top: 1px solid var(--global-neutral-color-6);
8988
border-bottom: 1px solid var(--global-neutral-color-6);
9089
border-right: 1px solid var(--global-neutral-color-6);
9190
border-radius: 0 2px 2px 0;
92-
color: #fff;
93-
font-size: 20px;
9491
text-align: center;
92+
font-size: 20px;
93+
color: #fff;
94+
right: 0;
95+
top: 0;
9596
}
9697

9798
.layui-form-checkbox:hover i {

package/component/src/component/checkcard/index.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,13 @@ watch(
150150
getDisabled.value = val;
151151
}
152152
}
153-
)
154-
watch(() => props.modelValue, (val) => {
155-
initValue.value = val
156-
})
153+
);
154+
watch(
155+
() => props.modelValue,
156+
(val) => {
157+
initValue.value = val;
158+
}
159+
);
157160
const getStyle = computed(() => {
158161
return {
159162
"layui-checkcard-checked": getCheckState.value,

package/component/src/component/checkcardGroup/index.vue

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,32 @@ export interface CheckCardGroup {
2626
const props = withDefaults(defineProps<CheckCardGroup>(), {
2727
modelValue: undefined,
2828
disabled: false,
29-
single: false
29+
single: false,
3030
});
3131
3232
const emit = defineEmits(["update:modelValue", "change"]);
3333
3434
const disabled = ref(props.disabled);
35-
const modelVal = ref(props.modelValue)
36-
watch(() => props.single, (single) => {
37-
if (single && Array.isArray(modelVal.value)) {
38-
modelVal.value = ''
39-
}
40-
if (!single && !Array.isArray(modelVal.value)) {
41-
modelVal.value = []
35+
const modelVal = ref(props.modelValue);
36+
watch(
37+
() => props.single,
38+
(single) => {
39+
if (single && Array.isArray(modelVal.value)) {
40+
modelVal.value = "";
41+
}
42+
if (!single && !Array.isArray(modelVal.value)) {
43+
modelVal.value = [];
44+
}
45+
},
46+
{
47+
deep: true,
48+
immediate: true,
4249
}
43-
}, {
44-
deep: true,
45-
immediate: true
46-
})
50+
);
4751
provide("checkcardGroup", {
4852
name: "LayCheckCardGroup",
4953
modelVal: modelVal,
50-
disabled: disabled
54+
disabled: disabled,
5155
});
5256
5357
watch(

package/component/src/component/table/hooks/useResize.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,54 @@ import { useThrottleFn } from "@vueuse/core";
44
let isResizing = false;
55
let stashColumn: any = null;
66
let targetElem: HTMLElement | null = null;
7+
let targetElemBody: HTMLElement | null = null;
78
let startX = 0;
89
let startWidth = 0;
10+
let colWidthTotal = 0;
911

1012
const resizing = useThrottleFn((e: MouseEvent) => {
1113
if (!isResizing) return;
1214
const offset = e.clientX - startX;
1315
const newWidth = startWidth + offset;
1416
if (newWidth < 0) return false;
1517
stashColumn.width = newWidth + "px";
16-
if (targetElem) {
17-
targetElem.style.width = newWidth + "px";
18+
if (targetElem && targetElemBody) {
19+
targetElem.style.width = colWidthTotal + offset + "px";
20+
targetElemBody.style.width = colWidthTotal + offset + "px";
1821
}
1922
}, 20);
2023

2124
const stopResize = () => {
2225
startX = 0;
2326
startWidth = 0;
27+
colWidthTotal = 0;
2428
stashColumn = null;
2529
targetElem = null;
30+
targetElemBody = null;
2631
isResizing = false;
2732
};
2833

2934
document.addEventListener("mousemove", resizing);
3035
document.addEventListener("mouseup", stopResize);
3136

32-
export const startResize = (e: MouseEvent, column: TableColumn) => {
37+
export const startResize = (
38+
e: MouseEvent,
39+
column: TableColumn,
40+
tableHeaderTable: any,
41+
tableBodyTable: any
42+
) => {
43+
targetElem = tableHeaderTable;
44+
targetElemBody = tableBodyTable;
3345
stashColumn = column;
3446
startX = e.clientX;
47+
const colWidthArr: any[] = [];
48+
tableHeaderTable.firstChild.childNodes.forEach((item: any) => {
49+
if (item.clientWidth) {
50+
colWidthArr.push(item.clientWidth);
51+
}
52+
});
53+
colWidthTotal = colWidthArr.reduce((sum, item) => sum + item, 0);
54+
3555
isResizing = true;
3656
const target = e.target as HTMLElement;
3757
const parentNode = target.parentNode as HTMLElement;

package/component/src/component/table/hooks/useTable.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,46 @@ const useTable = (props: any) => {
2222
forEach(columns, outcome);
2323
return outcome;
2424
};
25-
return { columnSlotNames };
25+
26+
const calculateDataSourceCount = function (dataSource: Recordable[]) {
27+
const count: number[] = [0];
28+
const forEach = function (dataSource: Recordable[], count: number[]) {
29+
dataSource.map((item) => {
30+
count[0]++;
31+
if (item.children) {
32+
forEach(item.children, count);
33+
}
34+
});
35+
};
36+
forEach(dataSource, count);
37+
return count[0];
38+
};
39+
40+
const dataSourceCount = computed(() => {
41+
return calculateDataSourceCount(props.dataSource);
42+
});
43+
44+
const calculateNeedSelectedKeys = function (dataSource: Recordable[]) {
45+
const keys: string[] = [];
46+
const forEach = function (dataSource: Recordable[], keys: string[]) {
47+
dataSource.map((item, index) => {
48+
if (!props.getCheckboxProps(item, index)?.disabled) {
49+
keys.push(item[props.id]);
50+
}
51+
if (item.children) {
52+
forEach(item.children, keys);
53+
}
54+
});
55+
};
56+
forEach(dataSource, keys);
57+
return keys;
58+
};
59+
60+
const needSelectedKeys = computed(() => {
61+
return calculateNeedSelectedKeys(props.dataSource);
62+
});
63+
64+
return { columnSlotNames, dataSourceCount, needSelectedKeys };
2665
};
2766

2867
export default useTable;

package/component/src/component/table/index.vue

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ const tableColumns = computed(() => {
9999
return [...props.columns];
100100
});
101101
102+
const { columnSlotNames, dataSourceCount, needSelectedKeys } = useTable(props);
103+
102104
const tableColumnKeys = ref<any[]>([]);
103105
const tableHeadColumns = ref<any[]>([]);
104106
const tableBodyColumns = ref<any[]>([]);
@@ -336,13 +338,7 @@ watch(
336338
337339
const changeAll = (isChecked: boolean) => {
338340
if (isChecked) {
339-
const datasources = props.dataSource.filter((item: any, index: number) => {
340-
return !props.getCheckboxProps(item, index)?.disabled;
341-
});
342-
const ids = datasources.map((item) => {
343-
return item[props.id];
344-
});
345-
tableSelectedKeys.value = [...ids];
341+
tableSelectedKeys.value = [...needSelectedKeys.value];
346342
} else {
347343
tableSelectedKeys.value = [];
348344
}
@@ -351,7 +347,7 @@ const changeAll = (isChecked: boolean) => {
351347
watch(
352348
tableSelectedKeys,
353349
() => {
354-
if (tableSelectedKeys.value.length === props.dataSource.length) {
350+
if (tableSelectedKeys.value.length === dataSourceCount.value) {
355351
allChecked.value = true;
356352
} else {
357353
allChecked.value = false;
@@ -507,6 +503,7 @@ const sortTable = (e: any, key: string, sort: string) => {
507503
let tableBody = ref<HTMLElement | null>(null);
508504
let tableHeader = ref<HTMLElement | null>(null);
509505
let tableHeaderTable = ref<HTMLElement | null>(null);
506+
let tableBodyTable = ref<HTMLElement | null>(null);
510507
const tableBodyEmptyWidth = ref();
511508
let scrollWidthCell = ref(0);
512509
@@ -584,8 +581,6 @@ const getFixedColumn = () => {
584581
}
585582
};
586583
587-
const { columnSlotNames } = useTable(props);
588-
589584
const currentIndentSize = ref(0);
590585
591586
const childrenExpandSpace = computed(() => {
@@ -1104,7 +1099,14 @@ defineExpose({ getCheckData });
11041099
<div
11051100
v-if="props.resize || column.resize"
11061101
class="lay-table-cols-resize"
1107-
@mousedown="startResize($event, column)"
1102+
@mousedown="
1103+
startResize(
1104+
$event,
1105+
column,
1106+
tableHeaderTable,
1107+
tableBodyTable
1108+
)
1109+
"
11081110
></div>
11091111
</th>
11101112
</template>
@@ -1127,6 +1129,7 @@ defineExpose({ getCheckData });
11271129
:class="{ 'layui-table-even': props.even }"
11281130
:lay-size="size"
11291131
:lay-skin="skin"
1132+
ref="tableBodyTable"
11301133
>
11311134
<colgroup>
11321135
<template

package/component/src/component/tag/index.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@tagColors: {
2-
primary: #009688;
2+
primary: #16baaa;
33
normal: #1e9fff;
44
warm: #ffb800;
55
danger: #ff5722;

package/component/test/checkcard-group.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,35 @@ describe("LayCheckCard.vue", () => {
1515
expect(wrapper.find(".layui-checkcard-group").exists()).toBe(true);
1616
wrapper.unmount();
1717
});
18-
test("render disabled test", async() => {
18+
test("render disabled test", async () => {
1919
const wrapper = mount(LayCheckCardGroup, {
2020
props: {
21-
disabled: true
22-
}
21+
disabled: true,
22+
},
2323
});
24-
25-
await wrapper.setProps({ disabled: false })
26-
expect(wrapper.vm.disabled).toBe(false)
24+
25+
await wrapper.setProps({ disabled: false });
26+
expect(wrapper.vm.disabled).toBe(false);
2727
});
28-
test("render single test", async() => {
28+
test("render single test", async () => {
2929
const wrapper = mount(LayCheckCardGroup, {
3030
props: {
3131
single: true,
32-
modelValue: [1, 2, 3]
33-
}
32+
modelValue: [1, 2, 3],
33+
},
3434
});
35-
await wrapper.setProps({ single: false })
36-
await wrapper.setProps({ modelValue: ['10'] })
37-
expect(wrapper.vm.modelValue).toEqual(['10'])
38-
expect(wrapper.vm.single).toBe(false)
35+
await wrapper.setProps({ single: false });
36+
await wrapper.setProps({ modelValue: ["10"] });
37+
expect(wrapper.vm.modelValue).toEqual(["10"]);
38+
expect(wrapper.vm.single).toBe(false);
3939
});
40-
test("render modelValue test", async() => {
40+
test("render modelValue test", async () => {
4141
const wrapper = mount(LayCheckCardGroup, {
4242
props: {
43-
modelValue: ['1', '2', '3']
44-
}
43+
modelValue: ["1", "2", "3"],
44+
},
4545
});
46-
await wrapper.setProps({ modelValue: ['10'] })
47-
expect(wrapper.vm.modelValue).toEqual(['10'])
46+
await wrapper.setProps({ modelValue: ["10"] });
47+
expect(wrapper.vm.modelValue).toEqual(["10"]);
4848
});
4949
});

package/component/test/checkcard.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ describe("LayCheckCard.vue", () => {
4343
wrapper.unmount();
4444
});
4545

46-
test("render modelValue test", async() => {
46+
test("render modelValue test", async () => {
4747
const wrapper = mount(LayCheckCard, {
4848
props: {
4949
modelValue: true,
5050
},
5151
});
52-
await wrapper.setProps({ modelValue: false })
53-
expect(Object.is(wrapper.vm.modelValue, false)).toBe(true)
52+
await wrapper.setProps({ modelValue: false });
53+
expect(Object.is(wrapper.vm.modelValue, false)).toBe(true);
5454
expect(wrapper.find(".layui-checkcard-checked").exists()).toBe(false);
5555
wrapper.unmount();
5656
});
@@ -129,11 +129,11 @@ describe("LayCheckCard.vue", () => {
129129
expect(wrapper.find(".layui-checkcard").classes()).toContain(
130130
"layui-checkcard-disabled"
131131
);
132-
await wrapper.setProps({ disabled: false })
133-
expect(wrapper.vm.disabled).toBe(false)
132+
await wrapper.setProps({ disabled: false });
133+
expect(wrapper.vm.disabled).toBe(false);
134134
await wrapper.find(".layui-checkcard").trigger("click");
135135
expect(wrapper.emitted()).toHaveProperty("click");
136-
136+
137137
wrapper.unmount();
138138
});
139139
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy