UnisKB/ui/src/views/application-workflow/index.vue

438 lines
12 KiB
Vue
Raw Normal View History

2024-07-01 01:45:59 +00:00
<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="router.push({ path: `/application/${id}/WORK_FLOW/overview` })"
></back-button>
<h4>{{ detail?.name }}</h4>
2024-10-23 09:01:19 +00:00
<div v-if="showHistory && disablePublic">
<el-text type="info" class="ml-16 color-secondary"
>预览版本
{{ currentVersion.name || datetimeFormat(currentVersion.update_time) }}</el-text
>
</div>
<el-text type="info" class="ml-16 color-secondary" v-else-if="saveTime"
2024-07-01 01:45:59 +00:00
>保存时间{{ datetimeFormat(saveTime) }}</el-text
>
</div>
2024-10-23 09:01:19 +00:00
<div v-if="showHistory && disablePublic">
<el-button type="primary" class="mr-8" @click="refreshVersion()"> </el-button>
<el-divider direction="vertical" />
<el-button text @click="closeHistory">
<el-icon><Close /></el-icon>
</el-button>
</div>
<div v-else>
2024-08-15 09:17:25 +00:00
<el-button icon="Plus" @click="showPopover = !showPopover"> 添加组件 </el-button>
2024-07-01 01:45:59 +00:00
<el-button @click="clickShowDebug" :disabled="showDebug">
<AppIcon iconName="app-play-outlined" class="mr-4"></AppIcon>
调试</el-button
>
2024-08-28 07:23:59 +00:00
<el-button @click="saveApplication(true)">
2024-07-01 01:45:59 +00:00
<AppIcon iconName="app-save-outlined" class="mr-4"></AppIcon>
保存
</el-button>
<el-button type="primary" @click="publicHandle"> </el-button>
2024-10-23 09:01:19 +00:00
<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>
发布历史
</el-dropdown-item>
<el-dropdown-item>
<AppIcon iconName="app-save-outlined"></AppIcon>
自动保存
2024-10-25 02:36:41 +00:00
<div class="ml-4">
2024-10-23 09:01:19 +00:00
<el-switch size="small" v-model="isSave" @change="changeSave" />
</div>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
2024-07-01 01:45:59 +00:00
</div>
</div>
<!-- 下拉框 -->
<el-collapse-transition>
2024-09-14 06:51:49 +00:00
<DropdownMenu
:show="showPopover"
:id="id"
2024-08-15 09:17:25 +00:00
v-click-outside="clickoutside"
2024-09-14 06:51:49 +00:00
@clickNodes="clickNodes"
@onmousedown="onmousedown"
:workflowRef="workflowRef"
/>
2024-07-01 01:45:59 +00:00
</el-collapse-transition>
<!-- 主画布 -->
<div class="workflow-main" ref="workflowMainRef">
2024-07-01 01:45:59 +00:00
<workflow ref="workflowRef" v-if="detail" :data="detail?.work_flow" />
</div>
<!-- 调试 -->
<el-collapse-transition>
<div
v-click-outside="clickoutsideDebug"
class="workflow-debug-container"
:class="enlarge ? 'enlarge' : ''"
v-if="showDebug"
>
2024-07-23 10:21:46 +00:00
<div class="workflow-debug-header" :class="!isDefaultTheme ? 'custom-header' : ''">
2024-07-01 01:45:59 +00:00
<div class="flex-between">
2024-07-24 05:56:41 +00:00
<div class="flex align-center">
2024-07-26 10:34:45 +00:00
<div class="mr-12 ml-24 flex">
2024-07-24 05:56:41 +00:00
<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>
2024-07-01 01:45:59 +00:00
<div class="mr-16">
<el-button link @click="enlarge = !enlarge">
<AppIcon
2024-07-16 09:32:27 +00:00
:iconName="enlarge ? 'app-minify' : 'app-magnify'"
2024-07-01 01:45:59 +00:00
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">
2024-11-13 02:37:16 +00:00
<AiChat :application-details="detail" :type="'debug-ai-chat'"></AiChat>
2024-07-01 01:45:59 +00:00
</div>
</div>
</el-collapse-transition>
2024-10-23 09:01:19 +00:00
<!-- 发布历史 -->
<PublishHistory
v-if="showHistory"
@click="checkVersion"
v-click-outside="clickoutsideHistory"
@refreshVersion="refreshVersion"
/>
2024-07-01 01:45:59 +00:00
</div>
</template>
<script setup lang="ts">
2024-10-30 08:46:44 +00:00
import { ref, onMounted, onBeforeUnmount, computed, nextTick } from 'vue'
2024-07-01 01:45:59 +00:00
import { useRouter, useRoute } from 'vue-router'
import Workflow from '@/workflow/index.vue'
2024-09-14 06:51:49 +00:00
import DropdownMenu from '@/views/application-workflow/component/DropdownMenu.vue'
2024-10-23 09:01:19 +00:00
import PublishHistory from '@/views/application-workflow/component/PublishHistory.vue'
2024-07-01 01:45:59 +00:00
import applicationApi from '@/api/application'
2024-07-24 05:56:41 +00:00
import { isAppIcon } from '@/utils/application'
2024-10-30 08:46:44 +00:00
import { MsgSuccess, MsgError } from '@/utils/message'
2024-07-01 01:45:59 +00:00
import { datetimeFormat } from '@/utils/time'
import useStore from '@/stores'
import { WorkFlowInstance } from '@/workflow/common/validate'
import { hasPermission } from '@/utils/permission'
2024-07-01 01:45:59 +00:00
2024-07-23 10:21:46 +00:00
const { user, application } = useStore()
2024-07-01 01:45:59 +00:00
const router = useRouter()
const route = useRoute()
2024-07-23 10:21:46 +00:00
const isDefaultTheme = computed(() => {
return user.isDefaultTheme()
})
2024-07-01 01:45:59 +00:00
const {
params: { id }
} = route as any
let interval: any
const workflowRef = ref()
const workflowMainRef = ref()
2024-07-01 01:45:59 +00:00
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>('')
2024-10-23 09:01:19 +00:00
const isSave = ref(false)
const showHistory = ref(false)
const disablePublic = ref(false)
const currentVersion = ref<any>({})
function clickoutsideHistory() {
if (!disablePublic.value) {
showHistory.value = false
2024-10-28 11:18:27 +00:00
disablePublic.value = false
2024-10-23 09:01:19 +00:00
}
}
function refreshVersion(item?: any) {
2024-10-25 08:47:17 +00:00
if (item) {
2024-10-30 08:46:44 +00:00
renderGraphData(item)
2024-10-23 09:01:19 +00:00
}
2024-10-28 11:18:27 +00:00
if (hasPermission(`APPLICATION:MANAGE:${id}`, 'AND') && isSave.value) {
initInterval()
}
2024-10-23 09:01:19 +00:00
showHistory.value = false
disablePublic.value = false
}
2024-10-30 08:46:44 +00:00
2024-10-23 09:01:19 +00:00
function checkVersion(item: any) {
disablePublic.value = true
currentVersion.value = item
2024-10-30 08:46:44 +00:00
renderGraphData(item)
2024-10-23 09:01:19 +00:00
closeInterval()
}
2024-10-30 08:46:44 +00:00
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)
2024-10-23 09:01:19 +00:00
})
}
function closeHistory() {
getDetail()
2024-10-28 11:18:27 +00:00
if (hasPermission(`APPLICATION:MANAGE:${id}`, 'AND') && isSave.value) {
initInterval()
}
2024-10-23 09:01:19 +00:00
showHistory.value = false
2024-10-28 11:18:27 +00:00
disablePublic.value = false
2024-10-23 09:01:19 +00:00
}
function openHistory() {
showHistory.value = true
}
function changeSave(bool: boolean) {
bool ? initInterval() : closeInterval()
localStorage.setItem('workflowAutoSave', bool.toString())
}
2024-07-01 01:45:59 +00:00
2024-09-14 06:51:49 +00:00
function clickNodes(item: any) {
// workflowRef.value?.addNode(item)
showPopover.value = false
}
function onmousedown(item: any) {
// workflowRef.value?.onmousedown(item)
showPopover.value = false
}
2024-10-23 09:01:19 +00:00
2024-09-14 06:51:49 +00:00
function clickoutside() {
showPopover.value = false
}
2024-07-01 01:45:59 +00:00
function publicHandle() {
workflowRef.value
?.validate()
.then(() => {
const obj = {
work_flow: getGraphData()
}
const workflow = new WorkFlowInstance(obj.work_flow)
try {
workflow.is_valid()
} catch (e: any) {
MsgError(e.toString())
return
}
2024-07-01 01:45:59 +00:00
applicationApi.putPublishApplication(id as String, obj, loading).then(() => {
MsgSuccess('发布成功')
})
})
.catch((res: any) => {
const node = res.node
const err_message = res.errMessage
if (typeof err_message == 'string') {
MsgError(res.node.properties?.stepName + '节点 ' + err_message)
} else {
const keys = Object.keys(err_message)
MsgError(node.properties?.stepName + '节点 ' + err_message[keys[0]]?.[0]?.message)
}
})
}
const clickShowDebug = () => {
workflowRef.value
?.validate()
.then(() => {
const graphData = getGraphData()
const workflow = new WorkFlowInstance(graphData)
try {
workflow.is_valid()
detail.value = {
2024-09-09 04:22:53 +00:00
...detail.value,
2024-07-01 01:45:59 +00:00
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 + '节点 ' + err_message)
} else {
const keys = Object.keys(err_message)
MsgError(node.properties?.stepName + '节点 ' + err_message[keys[0]]?.[0]?.message)
}
})
}
2024-09-13 10:41:32 +00:00
function clickoutsideDebug(e: any) {
if (workflowMainRef.value && e && e.target && workflowMainRef.value.contains(e?.target)) {
2024-09-13 10:41:32 +00:00
showDebug.value = false
}
2024-07-01 01:45:59 +00:00
}
function getGraphData() {
return workflowRef.value?.getGraphData()
}
function getDetail() {
2024-10-30 08:46:44 +00:00
application.asyncGetApplicationDetail(id).then((res: any) => {
2024-07-01 01:45:59 +00:00
res.data?.work_flow['nodes'].map((v: any) => {
v['properties']['noRender'] = true
})
detail.value = res.data
2024-09-09 04:22:53 +00:00
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
2024-07-01 01:45:59 +00:00
saveTime.value = res.data?.update_time
2024-10-30 08:46:44 +00:00
workflowRef.value?.clearGraphData()
nextTick(() => {
workflowRef.value?.renderGraphData(detail.value.work_flow)
})
2024-07-01 01:45:59 +00:00
})
}
2024-08-28 07:23:59 +00:00
function saveApplication(bool?: boolean) {
2024-07-01 01:45:59 +00:00
const obj = {
work_flow: getGraphData()
}
application.asyncPutApplication(id, obj).then((res) => {
saveTime.value = new Date()
2024-08-28 07:23:59 +00:00
if (bool) {
MsgSuccess('保存成功')
}
2024-07-01 01:45:59 +00:00
})
}
/**
* 定时保存
*/
const initInterval = () => {
interval = setInterval(() => {
saveApplication()
}, 60000)
}
/**
* 关闭定时
*/
const closeInterval = () => {
if (interval) {
clearInterval(interval)
}
}
onMounted(() => {
getDetail()
2024-10-23 09:01:19 +00:00
const workflowAutoSave = localStorage.getItem('workflowAutoSave')
isSave.value = workflowAutoSave === 'true' ? true : false
2024-07-01 01:45:59 +00:00
// 初始化定时任务
2024-10-28 11:18:27 +00:00
if (hasPermission(`APPLICATION:MANAGE:${id}`, 'AND') && isSave.value) {
initInterval()
}
2024-07-01 01:45:59 +00:00
})
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;
}
2024-08-15 09:17:25 +00:00
.workflow-dropdown-tabs {
.el-tabs__nav-wrap {
padding: 0 16px;
}
}
2024-07-01 01:45:59 +00:00
}
.workflow-debug-container {
z-index: 2000;
position: relative;
border-radius: 8px;
border: 1px solid #ffffff;
background: linear-gradient(
188deg,
rgba(235, 241, 255, 0.2) 39.6%,
rgba(231, 249, 255, 0.2) 94.3%
),
#eff0f1;
box-shadow: 0px 4px 8px 0px rgba(31, 35, 41, 0.1);
position: fixed;
bottom: 16px;
right: 16px;
overflow: hidden;
2024-09-14 03:17:14 +00:00
width: 450px;
2024-07-01 01:45:59 +00:00
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;
}
2024-07-01 01:45:59 +00:00
}
</style>