-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathindex.vue
More file actions
479 lines (452 loc) · 13.8 KB
/
index.vue
File metadata and controls
479 lines (452 loc) · 13.8 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
<template>
<div class="application-workflow" v-loading="loading">
<div class="header border-b flex-between p-12-24">
<div class="flex align-center">
<back-button @click="back"></back-button>
<h4>{{ detail?.name }}</h4>
<div v-if="showHistory && disablePublic">
<el-text type="info" class="ml-16 color-secondary"
>{{ $t('views.applicationWorkflow.info.previewVersion') }}
{{ currentVersion.name || datetimeFormat(currentVersion.update_time) }}</el-text
>
</div>
<el-text type="info" class="ml-16 color-secondary" v-else-if="saveTime"
>{{ $t('views.applicationWorkflow.info.saveTime')
}}{{ datetimeFormat(saveTime) }}</el-text
>
</div>
<div v-if="showHistory && disablePublic">
<el-button type="primary" class="mr-8" @click="refreshVersion()">
{{ $t('views.applicationWorkflow.setting.restoreVersion') }}
</el-button>
<el-divider direction="vertical" />
<el-button text @click="closeHistory">
<el-icon><Close /></el-icon>
</el-button>
</div>
<div v-else>
<el-button icon="Plus" @click="showPopover = !showPopover">
{{ $t('views.applicationWorkflow.setting.addComponent') }}
</el-button>
<el-button @click="clickShowDebug" :disabled="showDebug">
<AppIcon iconName="app-play-outlined" class="mr-4"></AppIcon>
{{ $t('views.applicationWorkflow.setting.debug') }}</el-button
>
<el-button @click="saveApplication(true)">
<AppIcon iconName="app-save-outlined" class="mr-4"></AppIcon>
{{ $t('common.save') }}
</el-button>
<el-button type="primary" @click="publicHandle">
{{ $t('views.applicationWorkflow.setting.public') }}
</el-button>
<el-dropdown trigger="click">
<el-button text @click.stop class="ml-8 mt-4">
<el-icon class="rotate-90"><MoreFilled /></el-icon>
</el-button>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="openHistory">
<AppIcon iconName="app-history-outlined"></AppIcon>
{{ $t('views.applicationWorkflow.setting.releaseHistory') }}
</el-dropdown-item>
<el-dropdown-item>
<AppIcon iconName="app-save-outlined"></AppIcon>
{{ $t('views.applicationWorkflow.setting.autoSave') }}
<div class="ml-4">
<el-switch size="small" v-model="isSave" @change="changeSave" />
</div>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div>
<!-- 下拉框 -->
<el-collapse-transition>
<DropdownMenu
:show="showPopover"
:id="id"
v-click-outside="clickoutside"
@clickNodes="clickNodes"
@onmousedown="onmousedown"
:workflowRef="workflowRef"
/>
</el-collapse-transition>
<!-- 主画布 -->
<div class="workflow-main" ref="workflowMainRef">
<workflow ref="workflowRef" v-if="detail" :data="detail?.work_flow" />
</div>
<!-- 调试 -->
<el-collapse-transition>
<div class="workflow-debug-container" :class="enlarge ? 'enlarge' : ''" v-if="showDebug">
<div class="workflow-debug-header" :class="!isDefaultTheme ? 'custom-header' : ''">
<div class="flex-between">
<div class="flex align-center">
<div class="mr-12 ml-24 flex">
<AppAvatar
v-if="isAppIcon(detail?.icon)"
shape="square"
:size="32"
style="background: none"
>
<img :src="detail?.icon" alt="" />
</AppAvatar>
<AppAvatar
v-else-if="detail?.name"
:name="detail?.name"
pinyinColor
shape="square"
:size="32"
/>
</div>
<h4>
{{ detail?.name || $t('views.application.applicationForm.form.appName.label') }}
</h4>
</div>
<div class="mr-16">
<el-button link @click="enlarge = !enlarge">
<AppIcon
:iconName="enlarge ? 'app-minify' : 'app-magnify'"
class="color-secondary"
style="font-size: 20px"
></AppIcon>
</el-button>
<el-button link @click="showDebug = false">
<el-icon :size="20" class="color-secondary"><Close /></el-icon>
</el-button>
</div>
</div>
</div>
<div class="scrollbar-height">
<AiChat :application-details="detail" :type="'debug-ai-chat'"></AiChat>
</div>
</div>
</el-collapse-transition>
<!-- 发布历史 -->
<PublishHistory
v-if="showHistory"
@click="checkVersion"
v-click-outside="clickoutsideHistory"
@refreshVersion="refreshVersion"
/>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount, computed, nextTick } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import type { Action } from 'element-plus'
import Workflow from '@/workflow/index.vue'
import DropdownMenu from '@/views/application-workflow/component/DropdownMenu.vue'
import PublishHistory from '@/views/application-workflow/component/PublishHistory.vue'
import applicationApi from '@/api/application'
import { isAppIcon } from '@/utils/application'
import { MsgSuccess, MsgError, MsgConfirm } from '@/utils/message'
import { datetimeFormat } from '@/utils/time'
import useStore from '@/stores'
import { WorkFlowInstance } from '@/workflow/common/validate'
import { hasPermission } from '@/utils/permission'
import { t } from '@/locales'
const { user, application } = useStore()
const router = useRouter()
const route = useRoute()
const isDefaultTheme = computed(() => {
return user.isDefaultTheme()
})
const {
params: { id }
} = route as any
let interval: any
const workflowRef = ref()
const workflowMainRef = ref()
const loading = ref(false)
const detail = ref<any>(null)
const showPopover = ref(false)
const showDebug = ref(false)
const enlarge = ref(false)
const saveTime = ref<any>('')
const isSave = ref(false)
const showHistory = ref(false)
const disablePublic = ref(false)
const currentVersion = ref<any>({})
const cloneWorkFlow = ref(null)
function back() {
if (JSON.stringify(cloneWorkFlow.value) !== JSON.stringify(getGraphData())) {
MsgConfirm(t('common.tip'), t('views.applicationWorkflow.tip.saveMessage'), {
confirmButtonText: t('views.applicationWorkflow.setting.exitSave'),
cancelButtonText: t('views.applicationWorkflow.setting.exit'),
type: 'warning',
distinguishCancelAndClose: true
})
.then(() => {
saveApplication(true, true)
})
.catch((action: Action) => {
action === 'cancel' && router.push({ path: `/application/${id}/WORK_FLOW/overview` })
})
} else {
router.push({ path: `/application/${id}/WORK_FLOW/overview` })
}
}
function clickoutsideHistory() {
if (!disablePublic.value) {
showHistory.value = false
disablePublic.value = false
}
}
function refreshVersion(item?: any) {
if (item) {
renderGraphData(item)
}
if (hasPermission(`APPLICATION:MANAGE:${id}`, 'AND') && isSave.value) {
initInterval()
}
showHistory.value = false
disablePublic.value = false
}
function checkVersion(item: any) {
disablePublic.value = true
currentVersion.value = item
renderGraphData(item)
closeInterval()
}
function renderGraphData(item: any) {
item.work_flow['nodes'].map((v: any) => {
v['properties']['noRender'] = true
})
detail.value.work_flow = item.work_flow
saveTime.value = item?.update_time
workflowRef.value?.clearGraphData()
nextTick(() => {
workflowRef.value?.render(item.work_flow)
})
}
function closeHistory() {
getDetail()
if (hasPermission(`APPLICATION:MANAGE:${id}`, 'AND') && isSave.value) {
initInterval()
}
showHistory.value = false
disablePublic.value = false
}
function openHistory() {
showHistory.value = true
}
function changeSave(bool: boolean) {
bool ? initInterval() : closeInterval()
localStorage.setItem('workflowAutoSave', bool.toString())
}
function clickNodes(item: any) {
// workflowRef.value?.addNode(item)
showPopover.value = false
}
function onmousedown(item: any) {
// workflowRef.value?.onmousedown(item)
showPopover.value = false
}
function clickoutside() {
showPopover.value = false
}
async function publicHandle() {
// 后执行发布
workflowRef.value
?.validate()
.then(async () => {
const obj = {
work_flow: getGraphData()
}
await application.asyncPutApplication(id, obj)
const workflow = new WorkFlowInstance(obj.work_flow)
try {
workflow.is_valid()
} catch (e: any) {
MsgError(e.toString())
return
}
applicationApi.putPublishApplication(id as String, obj, loading).then(() => {
MsgSuccess(t('views.applicationWorkflow.tip.publicSuccess'))
})
})
.catch((res: any) => {
const node = res.node
const err_message = res.errMessage
if (typeof err_message == 'string') {
MsgError(
res.node.properties?.stepName +
` ${t('views.applicationWorkflow.node').toLowerCase()} ` +
err_message.toLowerCase()
)
} else {
const keys = Object.keys(err_message)
MsgError(
node.properties?.stepName +
` ${t('views.applicationWorkflow.node').toLowerCase()} ` +
err_message[keys[0]]?.[0]?.message.toLowerCase()
)
}
})
}
const clickShowDebug = () => {
workflowRef.value
?.validate()
.then(() => {
const graphData = getGraphData()
const workflow = new WorkFlowInstance(graphData)
try {
workflow.is_valid()
detail.value = {
...detail.value,
type: 'WORK_FLOW',
...workflow.get_base_node()?.properties.node_data,
work_flow: getGraphData()
}
showDebug.value = true
} catch (e: any) {
MsgError(e.toString())
}
})
.catch((res: any) => {
const node = res.node
const err_message = res.errMessage
if (typeof err_message == 'string') {
MsgError(
res.node.properties?.stepName + ` ${t('views.applicationWorkflow.node')},` + err_message
)
} else {
const keys = Object.keys(err_message)
MsgError(
node.properties?.stepName +
` ${t('views.applicationWorkflow.node')},` +
err_message[keys[0]]?.[0]?.message
)
}
})
}
// function clickoutsideDebug(e: any) {
// if (workflowMainRef.value && e && e.target && workflowMainRef.value.contains(e?.target)) {
// showDebug.value = false
// }
// }
function getGraphData() {
return workflowRef.value?.getGraphData()
}
function getDetail() {
application.asyncGetApplicationDetail(id).then((res: any) => {
res.data?.work_flow['nodes'].map((v: any) => {
v['properties']['noRender'] = true
})
detail.value = res.data
detail.value.stt_model_id = res.data.stt_model
detail.value.tts_model_id = res.data.tts_model
detail.value.tts_type = res.data.tts_type
saveTime.value = res.data?.update_time
workflowRef.value?.clearGraphData()
nextTick(() => {
workflowRef.value?.render(detail.value.work_flow)
cloneWorkFlow.value = getGraphData()
})
})
}
function saveApplication(bool?: boolean, back?: boolean) {
const obj = {
work_flow: getGraphData()
}
loading.value = back || false
application
.asyncPutApplication(id, obj)
.then((res) => {
saveTime.value = new Date()
if (bool) {
MsgSuccess(t('common.saveSuccess'))
if (back) {
router.push({ path: `/application/${id}/WORK_FLOW/overview` })
}
}
})
.catch(() => {
loading.value = false
})
}
/**
* 定时保存
*/
const initInterval = () => {
interval = setInterval(() => {
saveApplication()
}, 60000)
}
/**
* 关闭定时
*/
const closeInterval = () => {
if (interval) {
clearInterval(interval)
}
}
onMounted(() => {
getDetail()
const workflowAutoSave = localStorage.getItem('workflowAutoSave')
isSave.value = workflowAutoSave === 'true' ? true : false
// 初始化定时任务
if (hasPermission(`APPLICATION:MANAGE:${id}`, 'AND') && isSave.value) {
initInterval()
}
})
onBeforeUnmount(() => {
// 清除定时任务
closeInterval()
workflowRef.value?.clearGraphData()
})
</script>
<style lang="scss">
.application-workflow {
background: var(--app-layout-bg-color);
height: 100%;
.header {
background: #ffffff;
}
.workflow-main {
height: calc(100vh - 62px);
box-sizing: border-box;
}
.workflow-dropdown-tabs {
.el-tabs__nav-wrap {
padding: 0 16px;
}
}
}
.workflow-debug-container {
z-index: 2000;
position: relative;
border-radius: 8px;
border: 1px solid #ffffff;
background: var(--dialog-bg-gradient-color);
box-shadow: 0px 4px 8px 0px rgba(31, 35, 41, 0.1);
position: fixed;
bottom: 16px;
right: 16px;
overflow: hidden;
width: 450px;
height: 600px;
.workflow-debug-header {
background: var(--app-header-bg-color);
height: var(--app-header-height);
line-height: var(--app-header-height);
box-sizing: border-box;
border-bottom: 1px solid var(--el-border-color);
}
.scrollbar-height {
height: calc(100% - var(--app-header-height) - 24px);
padding-top: 24px;
}
&.enlarge {
width: 50% !important;
height: 100% !important;
bottom: 0 !important;
right: 0 !important;
}
.chat-width {
max-width: 100% !important;
margin: 0 auto;
}
}
</style>