From e64f4b83c8f6cd01ea352ad7040e205613ea87d3 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期五, 14 七月 2023 22:39:34 +0800 Subject: [PATCH] update 优化 toggleRowSelection 缺失一个参数警告问题 --- src/components/TreeSelect/index.vue | 36 +++++++++++++++++++----------------- 1 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/components/TreeSelect/index.vue b/src/components/TreeSelect/index.vue index 4ff0e76..3076804 100644 --- a/src/components/TreeSelect/index.vue +++ b/src/components/TreeSelect/index.vue @@ -28,9 +28,7 @@ </div> </template> -<script setup> - -const { proxy } = getCurrentInstance(); +<script setup lang="ts"> const props = defineProps({ /* 閰嶇疆椤� */ @@ -68,6 +66,9 @@ } }) + +const selectTree = ref<ElTreeSelectInstance>(); + const emit = defineEmits(['update:value']); const valueId = computed({ @@ -77,16 +78,16 @@ } }); const valueTitle = ref(''); -const defaultExpandedKey = ref([]); +const defaultExpandedKey = ref<any[]>([]); -function initHandle() { +const initHandle = () => { nextTick(() => { const selectedValue = valueId.value; - if(selectedValue !== null && typeof (selectedValue) !== 'undefined') { - const node = proxy.$refs.selectTree.getNode(selectedValue) + if (selectedValue !== null && typeof (selectedValue) !== 'undefined') { + const node = selectTree.value?.getNode(selectedValue) if (node) { valueTitle.value = node.data[props.objMap.label] - proxy.$refs.selectTree.setCurrentKey(selectedValue) // 璁剧疆榛樿閫変腑 + selectTree.value?.setCurrentKey(selectedValue) // 璁剧疆榛樿閫変腑 defaultExpandedKey.value = [selectedValue] // 璁剧疆榛樿灞曞紑 } } else { @@ -94,27 +95,27 @@ } }) } -function handleNodeClick(node) { +const handleNodeClick = (node: any) => { valueTitle.value = node[props.objMap.label] valueId.value = node[props.objMap.value]; defaultExpandedKey.value = []; - proxy.$refs.treeSelect.blur() + selectTree.value?.blur() selectFilterData('') } -function selectFilterData(val) { - proxy.$refs.selectTree.filter(val) +const selectFilterData = (val: any) => { + selectTree.value?.filter(val) } -function filterNode(value, data) { +const filterNode = (value: any, data: any) => { if (!value) return true return data[props.objMap['label']].indexOf(value) !== -1 } -function clearHandle() { +const clearHandle = () => { valueTitle.value = '' valueId.value = '' defaultExpandedKey.value = []; clearSelected() } -function clearSelected() { +const clearSelected = () => { const allNode = document.querySelectorAll('#tree-option .el-tree-node') allNode.forEach((element) => element.classList.remove('is-current')) } @@ -128,8 +129,9 @@ }) </script> -<style lang='scss' scoped> +<style lang="scss" scoped> @import "@/assets/styles/variables.module.scss"; + .el-scrollbar .el-scrollbar__view .el-select-dropdown__item { padding: 0; background-color: #fff; @@ -153,4 +155,4 @@ background-color: mix(#fff, $--color-primary, 90%); color: $--color-primary; } -</style> \ No newline at end of file +</style> -- Gitblit v1.9.3