fix table重新渲染会修改props

This commit is contained in:
Theluyuan 2023-05-18 14:35:17 +08:00
parent 71a3b6f1c4
commit 9c7280105d
7 changed files with 98 additions and 69 deletions

View File

@ -1058,7 +1058,7 @@ const _sfc_main = defineComponent({
});
};
findFinalNode(0, tableColumns.value);
const tableSelectedKeys = ref([...props.selectedKeys]);
const tableSelectedKeys = ref(props.selectedKeys);
const tableExpandKeys = ref([...props.expandKeys]);
watch(() => props.selectedKeys, () => {
tableSelectedKeys.value = props.selectedKeys;
@ -1102,7 +1102,10 @@ const _sfc_main = defineComponent({
} else {
hasChecked.value = false;
}
emit("update:selectedKeys", tableSelectedKeys.value);
if (tableSelectedKeys.value != props.selectedKeys) {
console.log("\u521D\u59CB\u5316\u8D4B\u503C\u89E6\u53D1\u4FEE\u6539", tableSelectedKeys.value, props.selectedKeys);
emit("update:selectedKeys", tableSelectedKeys.value);
}
}, { deep: true, immediate: true });
watch(tableExpandKeys, () => {
emit("update:expandKeys", tableExpandKeys.value);

View File

@ -1,5 +1,5 @@
import { w as withInstall } from "../badge/index2.js";
import { defineComponent, useSlots, computed, resolveComponent, openBlock, createElementBlock, Fragment, renderList, normalizeClass, createElementVNode, createVNode, unref, withModifiers, createBlock, createCommentVNode, renderSlot, createTextVNode, toDisplayString, withCtx, createSlots, ref, watch, onMounted, nextTick } from "vue";
import { defineComponent, useSlots, computed, resolveComponent, openBlock, createElementBlock, Fragment, renderList, normalizeClass, createElementVNode, createVNode, unref, withModifiers, createBlock, createCommentVNode, renderSlot, createTextVNode, toDisplayString, withCtx, createSlots, ref, watch, nextTick, onMounted } from "vue";
import { _ as _sfc_main$2E, a as _sfc_main$2 } from "../checkbox/index2.js";
import { _ as _sfc_main$3 } from "../transition/index2.js";
const _hoisted_1 = ["onClick"];
@ -65,6 +65,9 @@ const _sfc_main$1 = defineComponent({
if (!node.isDisabled) {
emit("node-click", node);
}
if (props.showCheckbox) {
node.isChecked = !node.isChecked;
}
}
function handleRowClick(node) {
if (!props.showLine) {
@ -146,7 +149,7 @@ const _sfc_main$1 = defineComponent({
class: normalizeClass({
"layui-tree-txt": true,
"layui-disabled": node.isDisabled,
"layui-this": __props.selectedKey === node.id
"layui-this": __props.selectedKey === node.id || node.isChecked
}),
onClick: withModifiers(($event) => handleTitleClick(node), ["stop"])
}, [
@ -418,18 +421,21 @@ const _sfc_main = defineComponent({
loadNodeList();
}, { deep: true, immediate: true });
watch(() => props.checkedKeys, () => {
console.log(tree.value);
if (!unWatch.value) {
loadNodeList();
}
}, {
deep: true
});
watch(tree, () => {
if (initStatus.value) {
const { checkedKeys } = tree.value.getKeys();
unWatch.value = true;
emit("update:checkedKeys", checkedKeys);
setTimeout(() => {
nextTick(() => {
unWatch.value = false;
}, 0);
});
}
}, { deep: true });
onMounted(() => {

View File

@ -17662,6 +17662,9 @@ const _sfc_main$K = defineComponent({
if (!node.isDisabled) {
emit("node-click", node);
}
if (props.showCheckbox) {
node.isChecked = !node.isChecked;
}
}
function handleRowClick(node) {
if (!props.showLine) {
@ -17743,7 +17746,7 @@ const _sfc_main$K = defineComponent({
class: normalizeClass({
"layui-tree-txt": true,
"layui-disabled": node.isDisabled,
"layui-this": __props.selectedKey === node.id
"layui-this": __props.selectedKey === node.id || node.isChecked
}),
onClick: withModifiers(($event) => handleTitleClick(node), ["stop"])
}, [
@ -18015,18 +18018,21 @@ const _sfc_main$J = defineComponent({
loadNodeList();
}, { deep: true, immediate: true });
watch(() => props.checkedKeys, () => {
console.log(tree.value);
if (!unWatch.value) {
loadNodeList();
}
}, {
deep: true
});
watch(tree, () => {
if (initStatus.value) {
const { checkedKeys } = tree.value.getKeys();
unWatch.value = true;
emit("update:checkedKeys", checkedKeys);
setTimeout(() => {
nextTick(() => {
unWatch.value = false;
}, 0);
});
}
}, { deep: true });
onMounted(() => {
@ -19492,7 +19498,7 @@ const _sfc_main$D = defineComponent({
});
};
findFinalNode(0, tableColumns.value);
const tableSelectedKeys = ref([...props.selectedKeys]);
const tableSelectedKeys = ref(props.selectedKeys);
const tableExpandKeys = ref([...props.expandKeys]);
watch(() => props.selectedKeys, () => {
tableSelectedKeys.value = props.selectedKeys;
@ -19536,7 +19542,10 @@ const _sfc_main$D = defineComponent({
} else {
hasChecked.value = false;
}
emit("update:selectedKeys", tableSelectedKeys.value);
if (tableSelectedKeys.value != props.selectedKeys) {
console.log("\u521D\u59CB\u5316\u8D4B\u503C\u89E6\u53D1\u4FEE\u6539", tableSelectedKeys.value, props.selectedKeys);
emit("update:selectedKeys", tableSelectedKeys.value);
}
}, { deep: true, immediate: true });
watch(tableExpandKeys, () => {
emit("update:expandKeys", tableExpandKeys.value);

View File

@ -238,7 +238,8 @@ const findFinalNode = (level: number, columns: any[]) => {
findFinalNode(0, tableColumns.value);
const tableSelectedKeys = ref<Recordable[]>([...props.selectedKeys]);
//
const tableSelectedKeys = ref<Recordable[]>(props.selectedKeys);
const tableExpandKeys = ref<Recordable[]>([...props.expandKeys]);
watch(
@ -313,7 +314,10 @@ watch(
} else {
hasChecked.value = false;
}
emit("update:selectedKeys", tableSelectedKeys.value);
if(tableSelectedKeys.value != props.selectedKeys){
console.log("初始化赋值触发修改",tableSelectedKeys.value,props.selectedKeys)
emit("update:selectedKeys", tableSelectedKeys.value);
}
},
{ deep: true, immediate: true }
);

View File

@ -101,6 +101,9 @@ function handleTitleClick(node: TreeData) {
if (!node.isDisabled) {
emit("node-click", node);
}
if(props.showCheckbox){
node.isChecked = !node.isChecked
}
}
function handleRowClick(node: TreeData) {
@ -182,7 +185,7 @@ const isChildAllSelected = computed(() => {
:class="{
'layui-tree-txt': true,
'layui-disabled': node.isDisabled,
'layui-this': selectedKey === node.id,
'layui-this': selectedKey === node.id || node.isChecked,
}"
@click.stop="handleTitleClick(node)"
>

View File

@ -103,9 +103,13 @@ watch(
watch(
() => props.checkedKeys,
() => {
console.log(tree.value)
if (!unWatch.value) {
loadNodeList();
}
},
{
deep: true
}
);
@ -116,9 +120,9 @@ watch(
const { checkedKeys } = tree.value.getKeys();
unWatch.value = true;
emit("update:checkedKeys", checkedKeys);
setTimeout(() => {
nextTick(() => {
unWatch.value = false;
}, 0);
});
}
},
{ deep: true }

File diff suppressed because one or more lines are too long