|
| 1 | +<template> |
| 2 | + <el-dialog |
| 3 | + :title="$t('common.moveTo')" |
| 4 | + v-model="dialogVisible" |
| 5 | + append-to-body |
| 6 | + :close-on-click-modal="false" |
| 7 | + :close-on-press-escape="false" |
| 8 | + > |
| 9 | + <folder-tree |
| 10 | + :source="source" |
| 11 | + :data="folderList" |
| 12 | + :treeStyle="{ |
| 13 | + height: 'auto', |
| 14 | + border: '1px solid #ebeef5', |
| 15 | + borderRadius: '6px', |
| 16 | + padding: '8px', |
| 17 | + }" |
| 18 | + :default-expanded-keys="['default']" |
| 19 | + :canOperation="false" |
| 20 | + class="move-to-dialog-tree" |
| 21 | + @handleNodeClick="folderClickHandel" |
| 22 | + /> |
| 23 | + <template #footer> |
| 24 | + <span class="dialog-footer"> |
| 25 | + <el-button @click.prevent="dialogVisible = false" :loading="loading"> |
| 26 | + {{ $t('common.cancel') }} |
| 27 | + </el-button> |
| 28 | + <el-button type="primary" @click="submitHandle" :loading="loading"> |
| 29 | + {{ $t('common.confirm') }} |
| 30 | + </el-button> |
| 31 | + </span> |
| 32 | + </template> |
| 33 | + </el-dialog> |
| 34 | +</template> |
| 35 | +<script setup lang="ts"> |
| 36 | +import { ref, watch, reactive } from 'vue' |
| 37 | +import { MsgError, MsgSuccess } from '@/utils/message' |
| 38 | +import { t } from '@/locales' |
| 39 | +import useStore from '@/stores' |
| 40 | +import { SourceTypeEnum } from '@/enums/common' |
| 41 | +import KnowledgeApi from '@/api/knowledge/knowledge' |
| 42 | +import ToolApi from '@/api/tool/tool' |
| 43 | +const { folder, application } = useStore() |
| 44 | +const emit = defineEmits(['refresh']) |
| 45 | +
|
| 46 | +const props = defineProps({ |
| 47 | + source: { |
| 48 | + type: String, |
| 49 | + default: '', |
| 50 | + }, |
| 51 | +}) |
| 52 | +
|
| 53 | +const loading = ref(false) |
| 54 | +const dialogVisible = ref(false) |
| 55 | +const folderList = ref<any[]>([]) |
| 56 | +const detail = ref<any>({}) |
| 57 | +const selectForderId = ref<any>('') |
| 58 | +
|
| 59 | +watch(dialogVisible, (bool) => { |
| 60 | + if (!bool) { |
| 61 | + detail.value = {} |
| 62 | + selectForderId.value = '' |
| 63 | + folderList.value = [] |
| 64 | + } |
| 65 | +}) |
| 66 | +
|
| 67 | +const open = (data: any) => { |
| 68 | + detail.value = data |
| 69 | + getFolder() |
| 70 | + dialogVisible.value = true |
| 71 | +} |
| 72 | +
|
| 73 | +function getFolder() { |
| 74 | + const params = {} |
| 75 | + folder.asyncGetFolder(props.source, params, loading).then((res: any) => { |
| 76 | + folderList.value = res.data |
| 77 | + }) |
| 78 | +} |
| 79 | +
|
| 80 | +function folderClickHandel(item: any) { |
| 81 | + selectForderId.value = item.id |
| 82 | +} |
| 83 | +
|
| 84 | +const submitHandle = async () => { |
| 85 | + if (selectForderId.value) { |
| 86 | + const obj = { |
| 87 | + ...detail.value, |
| 88 | + folder_id: selectForderId.value, |
| 89 | + } |
| 90 | + if (props.source === SourceTypeEnum.KNOWLEDGE) { |
| 91 | + if (detail.value.type === 2) { |
| 92 | + KnowledgeApi.putLarkKnowledge(detail.value.id, obj, loading).then(() => { |
| 93 | + MsgSuccess(t('common.saveSuccess')) |
| 94 | + emit('refresh', detail.value) |
| 95 | + dialogVisible.value = false |
| 96 | + }) |
| 97 | + } else { |
| 98 | + KnowledgeApi.putKnowledge(detail.value.id, obj, loading).then(() => { |
| 99 | + MsgSuccess(t('common.saveSuccess')) |
| 100 | + emit('refresh', detail.value) |
| 101 | + dialogVisible.value = false |
| 102 | + }) |
| 103 | + } |
| 104 | + } else if (props.source === SourceTypeEnum.TOOL) { |
| 105 | + ToolApi.putTool(detail.value.id, obj, loading).then(() => { |
| 106 | + MsgSuccess(t('common.saveSuccess')) |
| 107 | + emit('refresh', detail.value) |
| 108 | + dialogVisible.value = false |
| 109 | + }) |
| 110 | + } else if (props.source === SourceTypeEnum.APPLICATION) { |
| 111 | + application.asyncPutApplication(detail.value.id, obj, loading).then((res) => { |
| 112 | + MsgSuccess(t('common.saveSuccess')) |
| 113 | + emit('refresh', detail.value) |
| 114 | + dialogVisible.value = false |
| 115 | + }) |
| 116 | + } |
| 117 | + } else { |
| 118 | + MsgError(t('components.folder.requiredMessage')) |
| 119 | + } |
| 120 | +} |
| 121 | +
|
| 122 | +defineExpose({ open }) |
| 123 | +</script> |
| 124 | +<style lang="scss" scoped> |
| 125 | +.move-to-dialog-tree { |
| 126 | + :deep(.el-input) { |
| 127 | + padding: 0 !important; |
| 128 | + margin-bottom: 8px; |
| 129 | + } |
| 130 | +} |
| 131 | +</style> |
0 commit comments