-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathDebugDrawer.vue
More file actions
167 lines (163 loc) · 4.81 KB
/
DebugDrawer.vue
File metadata and controls
167 lines (163 loc) · 4.81 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
<template>
<el-drawer
v-model="drawerVisible"
:title="$t('common.debug')"
size="800px"
direction="rtl"
destroy-on-close
:before-close="close"
>
<div style="height: calc(100% - 57px)" v-loading="loading">
<keep-alive :key="key" :include="['data_source', 'knowledge_base']">
<component
ref="ActionRef"
:is="ak[active]"
v-model:loading="loading"
:workflow="_workflow"
:knowledge_id="id"
:id="action_id"
></component>
</keep-alive>
</div>
<template #footer>
<el-button v-if="active == 'result'" @click="continueImporting">
{{ $t('views.document.buttons.continueImporting') }}
</el-button>
<el-button
v-if="base_form_list.length > 0 && active == 'knowledge_base'"
:loading="loading"
@click="up"
>
{{ $t('views.document.buttons.prev') }}</el-button
>
<el-button
v-if="base_form_list.length > 0 && active == 'data_source'"
:loading="loading"
@click="next"
>
{{ $t('views.document.buttons.next') }}
</el-button>
<el-button
v-if="base_form_list.length > 0 ? active == 'knowledge_base' : true"
@click="upload"
type="primary"
:loading="loading"
>
{{ $t('views.document.buttons.import') }}
</el-button>
<el-button v-if="active == 'result'" type="primary" @click="goDocument">{{
$t('views.knowledge.ResultSuccess.buttons.toDocument')
}}</el-button>
</template>
</el-drawer>
</template>
<script setup lang="ts">
import { computed, ref, provide, type Ref, nextTick } from 'vue'
import DataSource from '@/views/knowledge-workflow/component/action/DataSource.vue'
import Result from '@/views/knowledge-workflow/component/action/Result.vue'
import applicationApi from '@/api/application/application'
import KnowledgeBase from '@/views/knowledge-workflow/component/action/KnowledgeBase.vue'
import { WorkflowType } from '@/enums/application'
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
import permissionMap from '@/permission'
import { MsgError } from '@/utils/message'
import { t } from '@/locales'
import { useRoute, useRouter } from 'vue-router'
provide('upload', (file: any, loading?: Ref<boolean>) => {
return applicationApi.postUploadFile(file, id, 'KNOWLEDGE', loading)
})
const key = ref<number>(0)
const router = useRouter()
const route = useRoute()
const {
params: { id, folderId },
/*
id 为 knowledge_id
*/
} = route as any
const ak = {
data_source: DataSource,
knowledge_base: KnowledgeBase,
result: Result,
}
const apiType = computed(() => {
if (route.path.includes('shared')) {
return 'systemShare'
} else if (route.path.includes('resource-management')) {
return 'systemManage'
} else {
return 'workspace'
}
})
const loading = ref<boolean>(false)
const action_id = ref<string>()
const ActionRef = ref()
const form_data = ref<any>({})
const active = ref<'data_source' | 'knowledge_base' | 'result'>('data_source')
const drawerVisible = ref<boolean>(false)
const _workflow = ref<any>(null)
const close = () => {
drawerVisible.value = false
_workflow.value = null
active.value = 'data_source'
}
const open = (workflow: any) => {
drawerVisible.value = true
_workflow.value = workflow
}
const base_form_list = computed(() => {
const kBase = _workflow.value?.nodes?.find((n: any) => n.type === WorkflowType.KnowledgeBase)
if (kBase) {
return kBase.properties.user_input_field_list
}
return []
})
const next = () => {
ActionRef.value.validate().then(() => {
form_data.value[active.value] = ActionRef.value.get_data()
active.value = 'knowledge_base'
})
}
const up = () => {
ActionRef.value.validate().then(() => {
active.value = 'data_source'
})
}
const permissionPrecise = computed(() => {
return permissionMap['knowledge'][apiType.value]
})
const upload = () => {
if (permissionPrecise.value.doc_create(id)) {
ActionRef.value.validate().then(() => {
form_data.value[active.value] = ActionRef.value.get_data()
loadSharedApi({ type: 'knowledge', systemType: apiType.value })
.workflowAction(id, form_data.value, loading)
.then((ok: any) => {
action_id.value = ok.data.id
active.value = 'result'
})
})
} else {
MsgError(t('views.application.tip.noDocPermission'))
}
}
const continueImporting = () => {
active.value = 'data_source'
key.value++
action_id.value = undefined
const c_workflow = _workflow.value
_workflow.value = null
form_data.value = {}
nextTick(() => {
_workflow.value = c_workflow
})
}
const goDocument = () => {
const newUrl = router.resolve({
path: `/knowledge/${id}/${folderId}/4/document`,
}).href
window.open(newUrl)
}
defineExpose({ close, open })
</script>
<style lang="scss" scoped></style>