|
39 | 39 | :label="$t('views.document.feishu.allCheck')"
|
40 | 40 | size="large"
|
41 | 41 | class="ml-24"
|
| 42 | + @change="handleAllCheckChange" |
42 | 43 | />
|
43 | 44 | </div>
|
44 | 45 |
|
|
49 | 50 | show-checkbox
|
50 | 51 | node-key="token"
|
51 | 52 | ref="treeRef"
|
52 |
| - /> |
| 53 | + > |
| 54 | + <template #default="{ node, data }"> |
| 55 | + <div class="custom-tree-node flex align-center lighter"> |
| 56 | + <el-icon v-if="data.type === 'folder'"><FolderOpened /></el-icon> |
| 57 | + <el-icon v-else><Document /></el-icon> |
| 58 | + <span class="ml-4">{{ node.label }}</span> |
| 59 | + </div> |
| 60 | + </template> |
| 61 | + </el-tree> |
53 | 62 | </el-form>
|
54 | 63 | </div>
|
55 | 64 | </el-scrollbar>
|
|
67 | 76 | <script setup lang="ts">
|
68 | 77 | import { ref, reactive, computed, onUnmounted } from 'vue'
|
69 | 78 | import { useRouter, useRoute } from 'vue-router'
|
70 |
| -
|
71 |
| -import documentApi from '@/api/document' |
72 | 79 | import { MsgConfirm, MsgSuccess } from '@/utils/message'
|
73 | 80 | import { t } from '@/locales'
|
74 | 81 | import type Node from 'element-plus/es/components/tree/src/model/node'
|
@@ -113,24 +120,46 @@ const props = {
|
113 | 120 | }
|
114 | 121 |
|
115 | 122 | const loadNode = (node: Node, resolve: (nodeData: Tree[]) => void) => {
|
116 |
| - console.log(node) |
117 | 123 | const token = node.level === 0 ? folderToken : node.data.token // 根节点使用 folder_token,其他节点使用 node.data.token
|
118 | 124 | dataset
|
119 | 125 | .getLarkDocumentList(datasetId, token, {}, loading)
|
120 |
| - .then((res) => { |
121 |
| - const data: any = res.data |
122 |
| - resolve(data.files as Tree[]) |
| 126 | + .then((res: any) => { |
| 127 | + const nodes = res.data.files as Tree[] |
| 128 | +
|
| 129 | + nodes.forEach((childNode) => { |
| 130 | + if (childNode.is_exist) { |
| 131 | + treeRef.value?.setchecked(childNode.token, true, false) |
| 132 | + } |
| 133 | + }) |
| 134 | + resolve(nodes) |
123 | 135 | })
|
| 136 | +
|
124 | 137 | .catch((err) => {
|
125 | 138 | console.error('Failed to load tree nodes:', err)
|
126 | 139 | })
|
127 | 140 | }
|
128 | 141 |
|
| 142 | +const handleAllCheckChange = (checked: boolean) => { |
| 143 | + if (checked) { |
| 144 | + // 获取所有已加载的节点 |
| 145 | + const nodes = Object.values(treeRef.value?.store.nodesMap || {}) as any[] |
| 146 | + nodes.forEach((node) => { |
| 147 | + // 只选择未禁用且是文件的节点 |
| 148 | + if (!node.disabled) { |
| 149 | + treeRef.value?.setChecked(node.data, true, false) |
| 150 | + } |
| 151 | + }) |
| 152 | + } else { |
| 153 | + treeRef.value?.setCheckedKeys([]) |
| 154 | + } |
| 155 | +} |
| 156 | +
|
129 | 157 | function submit() {
|
130 | 158 | loading.value = true
|
131 | 159 | // 选中的节点的token
|
132 | 160 | const checkedNodes = treeRef.value?.getCheckedNodes() || []
|
133 |
| - const newList = checkedNodes.map((node: any) => { |
| 161 | + const filteredNodes = checkedNodes.filter((node: any) => !node.is_exist) |
| 162 | + const newList = filteredNodes.map((node: any) => { |
134 | 163 | return {
|
135 | 164 | name: node.name,
|
136 | 165 | token: node.token,
|
|
0 commit comments