gi-component 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gi-component",
3
3
  "type": "module",
4
- "version": "0.0.16",
4
+ "version": "0.0.17",
5
5
  "description": "Vue3中基于Element Plus二次封装基础组件库",
6
6
  "author": "lin",
7
7
  "license": "MIT",
@@ -1,10 +1,9 @@
1
1
  import type { DialogInstance } from '../index'
2
2
  import ElementPlus from 'element-plus'
3
- import { createApp, defineAsyncComponent, h, ref } from 'vue'
3
+ import { createApp, h, ref } from 'vue'
4
+ import DialogContent from './dialog-content.vue'
4
5
  import GiDialog from './dialog.vue'
5
6
 
6
- const DialogContent = defineAsyncComponent(() => import('./dialog-content.vue'))
7
-
8
7
  export type DialogOptions = Partial<DialogInstance['$props']>
9
8
 
10
9
  export interface DialogReturnObject {
@@ -86,19 +86,26 @@ const rightObj = reactive({
86
86
  })
87
87
 
88
88
  const leftAllChecked = computed(() => {
89
+ const rightListKeys = rightObj.options.map((i) => i.value)
89
90
  const arr: string[] = []
90
91
  eachTree(props.data, (i) => {
91
- if (i.children === undefined) {
92
+ // 只考虑叶子节点且不在右侧列表中的节点
93
+ if (i.children === undefined && !rightListKeys.includes(i[nodeKey.value])) {
92
94
  arr.push(i[nodeKey.value])
93
95
  }
94
96
  })
97
+ // 如果左侧没有可选节点,则返回false
98
+ if (arr.length === 0) return false
99
+ // 检查所有左侧叶子节点是否都被选中
95
100
  return arr.every((i) => leftObj.checkedKeys.includes(i))
96
101
  })
97
102
 
98
103
  const getLeftTreeNodes = () => {
104
+ const rightListKeys = rightObj.options.map((i) => i.value)
99
105
  const arr: any[] = []
100
106
  eachTree(props.data, (i) => {
101
- if (i.children === undefined) {
107
+ // 只返回叶子节点且不在右侧列表中的节点
108
+ if (i.children === undefined && !rightListKeys.includes(i[nodeKey.value])) {
102
109
  arr.push(i)
103
110
  }
104
111
  })
@@ -130,8 +137,34 @@ function handleRightAllChecked() {
130
137
  const leftTreeData = computed(() => {
131
138
  const treeData = JSON.parse(JSON.stringify(props.data))
132
139
  const rightListKeys = rightObj.options.map((i) => i.value)
133
- const data = filterTree(treeData, (i: any) => !rightListKeys.includes(i[nodeKey.value]))
134
- return data
140
+
141
+ // 递归过滤树节点,只有当节点不在右侧列表中且有子节点存在于左侧时才保留
142
+ const filterNodes = (nodes: any[]): any[] => {
143
+ const filtered: any[] = []
144
+
145
+ for (const node of nodes) {
146
+ // 深拷贝当前节点
147
+ const newNode = { ...node }
148
+
149
+ // 如果有子节点,递归处理
150
+ if (node.children && node.children.length > 0) {
151
+ newNode.children = filterNodes(node.children)
152
+ // 如果子节点过滤后仍有内容,或者节点本身不在右侧列表中且是叶子节点,则保留该节点
153
+ if (newNode.children.length > 0 || (!rightListKeys.includes(node[nodeKey.value]) && (!node.children || node.children.length === 0))) {
154
+ filtered.push(newNode)
155
+ }
156
+ } else {
157
+ // 叶子节点,只有当它不在右侧列表中时才保留
158
+ if (!rightListKeys.includes(node[nodeKey.value])) {
159
+ filtered.push(newNode)
160
+ }
161
+ }
162
+ }
163
+
164
+ return filtered
165
+ }
166
+
167
+ return filterNodes(treeData)
135
168
  })
136
169
 
137
170
  const handleCheck = (data: any, obj: any) => {