-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathToolDialog.vue
More file actions
227 lines (211 loc) · 6.12 KB
/
ToolDialog.vue
File metadata and controls
227 lines (211 loc) · 6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<template>
<el-dialog
v-model="dialogVisible"
width="1000"
append-to-body
class="addTool-dialog"
align-center
:close-on-click-modal="false"
:close-on-press-escape="false"
>
<template #header="{ titleId, titleClass }">
<div class="flex-between mb-8">
<div class="flex">
<h4 :id="titleId" :class="titleClass" class="mr-8">
{{ $t('views.tool.settingTool') }}
</h4>
</div>
<el-button link class="mr-24" @click="refresh">
<el-icon :size="18"><Refresh /></el-icon>
</el-button>
</div>
</template>
<LayoutContainer class="application-manage">
<template #left>
<div class="p-8">
<folder-tree
:data="folderList"
:currentNodeKey="currentFolder?.id"
@handleNodeClick="folderClickHandle"
v-loading="folderLoading"
:canOperation="false"
showShared
:shareTitle="$t('views.shared.shared_tool')"
:treeStyle="{ height: 'calc(100vh - 240px)' }"
/>
</div>
</template>
<div class="layout-bg">
<div class="flex-between p-16 ml-8">
<h4>{{ currentFolder?.name }}</h4>
<el-input
v-model="searchValue"
:placeholder="$t('common.search')"
prefix-icon="Search"
class="w-240 mr-8"
clearable
/>
</div>
<el-scrollbar>
<div class="p-16-24 pt-0" style="height: calc(100vh - 200px)">
<el-row :gutter="12" v-loading="apiLoading" v-if="searchData.length">
<el-col :span="12" v-for="(item, index) in searchData" :key="index" class="mb-16">
<CardCheckbox
value-field="id"
:data="item"
v-model="checkList"
@change="changeHandle"
>
<template #icon>
<el-avatar
v-if="item?.icon"
shape="square"
:size="32"
style="background: none"
class="mr-8"
>
<img :src="resetUrl(item?.icon)" alt="" />
</el-avatar>
<ToolIcon v-else :size="32" :type="item?.tool_type" />
</template>
<span class="ellipsis cursor ml-12" :title="item.name"> {{ item.name }}</span>
</CardCheckbox>
</el-col>
</el-row>
<el-empty :description="$t('common.noData')" v-else />
</div>
</el-scrollbar>
</div>
</LayoutContainer>
<template #footer>
<div class="flex-between">
<div class="flex">
<el-text type="info" class="color-secondary mr-8" v-if="checkList.length > 0">
{{ $t('common.selected') }} {{ checkList.length }}
</el-text>
<el-button link type="primary" v-if="checkList.length > 0" @click="clearCheck">
{{ $t('common.clear') }}
</el-button>
</div>
<span>
<el-button @click.prevent="dialogVisible = false">
{{ $t('common.cancel') }}
</el-button>
<el-button type="primary" @click="submitHandle">
{{ $t('common.add') }}
</el-button>
</span>
</div>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import useStore from '@/stores'
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
import { uniqueArray } from '@/utils/array'
import { resetUrl } from '@/utils/common'
const route = useRoute()
const emit = defineEmits(['refresh'])
const { folder, user } = useStore()
const apiType = computed(() => {
if (route.path.includes('shared')) {
return 'systemShare'
} else if (route.path.includes('resource-management')) {
return 'systemManage'
} else {
return 'workspace'
}
})
const dialogVisible = ref<boolean>(false)
const checkList = ref<Array<string>>([])
const searchValue = ref('')
const searchData = ref<Array<any>>([])
const toolList = ref<Array<any>>([])
const apiLoading = ref(false)
watch(dialogVisible, (bool) => {
if (!bool) {
checkList.value = []
searchValue.value = ''
searchData.value = []
toolList.value = []
}
})
watch(searchValue, (val) => {
if (val) {
searchData.value = toolList.value.filter((v) => v.name.includes(val))
} else {
searchData.value = toolList.value
}
})
function changeHandle() {}
function clearCheck() {
checkList.value = []
}
const open = (checked: any) => {
checkList.value = checked || []
getFolder()
dialogVisible.value = true
}
const submitHandle = () => {
emit('refresh', {
tool_ids: checkList.value,
})
dialogVisible.value = false
}
const refresh = () => {
searchValue.value = ''
toolList.value = []
getList()
}
const folderList = ref<any[]>([])
const currentFolder = ref<any>({})
const folderLoading = ref(false)
// 文件
function folderClickHandle(row: any) {
if (row.id === currentFolder.value?.id) {
return
}
currentFolder.value = row
getList()
}
function getFolder() {
const params = {}
folder.asyncGetFolder('TOOL', params, folderLoading).then((res: any) => {
folderList.value = res.data
currentFolder.value = res.data?.[0] || {}
getList()
})
}
function getList() {
const folder_id = currentFolder.value?.id || user.getWorkspaceId()
loadSharedApi({
type: 'tool',
systemType: apiType.value,
})
.getToolList({ folder_id }, apiLoading)
.then((res: any) => {
toolList.value = uniqueArray([...toolList.value, ...res.data.tools], 'id')
searchData.value = res.data.tools
})
}
defineExpose({ open })
</script>
<style lang="scss">
.addTool-dialog {
padding: 0;
.el-dialog__header {
padding: 12px 20px 4px 24px;
border-bottom: 1px solid var(--el-border-color-light);
}
.el-dialog__footer {
padding: 12px 24px 12px 24px;
border-top: 1px solid var(--el-border-color-light);
}
.el-dialog__headerbtn {
top: 2px;
right: 6px;
}
}
</style>