|
| 1 | +<template> |
| 2 | + <ContentWrap> |
| 3 | + <div class="mx-auto"> |
| 4 | + <!-- 头部导航栏 --> |
| 5 | + <div |
| 6 | + class="absolute top-0 left-0 right-0 h-50px bg-white border-bottom z-10 flex items-center px-20px" |
| 7 | + > |
| 8 | + <!-- 左侧标题 --> |
| 9 | + <div class="w-200px flex items-center overflow-hidden"> |
| 10 | + <Icon icon="ep:arrow-left" class="cursor-pointer flex-shrink-0" @click="handleBack" /> |
| 11 | + <span class="ml-10px text-16px truncate" :title="formData.name || '创建流程'"> |
| 12 | + {{ formData.name || '创建流程' }} |
| 13 | + </span> |
| 14 | + </div> |
| 15 | + |
| 16 | + <!-- 步骤条 --> |
| 17 | + <div class="flex-1 flex items-center justify-center h-full"> |
| 18 | + <div class="w-400px flex items-center justify-between h-full"> |
| 19 | + <div |
| 20 | + v-for="(step, index) in steps" |
| 21 | + :key="index" |
| 22 | + class="flex items-center cursor-pointer mx-15px relative h-full" |
| 23 | + :class="[ |
| 24 | + currentStep === index |
| 25 | + ? 'text-[#3473ff] border-[#3473ff] border-b-2 border-b-solid' |
| 26 | + : 'text-gray-500' |
| 27 | + ]" |
| 28 | + @click="handleStepClick(index)" |
| 29 | + > |
| 30 | + <div |
| 31 | + class="w-28px h-28px rounded-full flex items-center justify-center mr-8px border-2 border-solid text-15px" |
| 32 | + :class="[ |
| 33 | + currentStep === index |
| 34 | + ? 'bg-[#3473ff] text-white border-[#3473ff]' |
| 35 | + : 'border-gray-300 bg-white text-gray-500' |
| 36 | + ]" |
| 37 | + > |
| 38 | + {{ index + 1 }} |
| 39 | + </div> |
| 40 | + <span class="text-16px font-bold whitespace-nowrap">{{ step.title }}</span> |
| 41 | + </div> |
| 42 | + </div> |
| 43 | + </div> |
| 44 | + |
| 45 | + <!-- 右侧按钮 --> |
| 46 | + <div class="w-200px flex items-center justify-end gap-2"> |
| 47 | + <el-button type="primary" @click="handleSave"> 保 存 </el-button> |
| 48 | + </div> |
| 49 | + </div> |
| 50 | + |
| 51 | + <!-- 主体内容 --> |
| 52 | + <div class="mt-50px"> |
| 53 | + <!-- 第一步:基本信息 --> |
| 54 | + <div v-if="currentStep === 0" class="mx-auto w-560px"> |
| 55 | + <BasicInfo v-model="formData" ref="basicInfoRef" /> |
| 56 | + </div> |
| 57 | + |
| 58 | + <!-- 第二步:工作流设计 --> |
| 59 | + <WorkflowDesign |
| 60 | + v-if="currentStep === 1" |
| 61 | + v-model="formData" |
| 62 | + :provider="provider" |
| 63 | + ref="workflowDesignRef" |
| 64 | + /> |
| 65 | + </div> |
| 66 | + </div> |
| 67 | + </ContentWrap> |
| 68 | +</template> |
| 69 | + |
| 70 | +<script setup lang="ts"> |
| 71 | +import { useTagsViewStore } from '@/store/modules/tagsView' |
| 72 | +import { CommonStatusEnum } from '@/utils/constants' |
| 73 | +import * as WorkflowApi from '@/api/ai/workflow' |
| 74 | +import BasicInfo from './BasicInfo.vue' |
| 75 | +import WorkflowDesign from './WorkflowDesign.vue' |
| 76 | +import { ApiKeyApi } from '@/api/ai/model/apiKey' |
| 77 | +
|
| 78 | +const router = useRouter() |
| 79 | +const { delView } = useTagsViewStore() |
| 80 | +const route = useRoute() |
| 81 | +const message = useMessage() |
| 82 | +
|
| 83 | +const basicInfoRef = ref() |
| 84 | +const workflowDesignRef = ref() |
| 85 | +
|
| 86 | +const validateBasic = async () => { |
| 87 | + await basicInfoRef.value?.validate() |
| 88 | +} |
| 89 | +const validateWorkflow = async () => { |
| 90 | + await workflowDesignRef.value?.validate() |
| 91 | +} |
| 92 | +
|
| 93 | +const currentStep = ref(-1) |
| 94 | +const steps = [ |
| 95 | + { title: '基本信息', validator: validateBasic }, |
| 96 | + { title: '工作流设计', validator: validateWorkflow } |
| 97 | +] |
| 98 | +
|
| 99 | +const formData: any = ref({ |
| 100 | + id: undefined, |
| 101 | + name: '', |
| 102 | + code: '', |
| 103 | + remark: '', |
| 104 | + graph: '', |
| 105 | + status: CommonStatusEnum.ENABLE |
| 106 | +}) |
| 107 | +// TODO @lesan:待接入 |
| 108 | +const provider = ref<any>() |
| 109 | +const workflowData = ref<any>({}) |
| 110 | +provide('workflowData', workflowData) |
| 111 | +
|
| 112 | +/** 初始化数据 */ |
| 113 | +const actionType = route.params.type as string |
| 114 | +const initData = async () => { |
| 115 | + if (actionType === 'update') { |
| 116 | + const workflowId = route.params.id as string |
| 117 | + formData.value = await WorkflowApi.getWorkflow(workflowId) |
| 118 | + workflowData.value = JSON.parse(formData.value.graph) |
| 119 | + } |
| 120 | +
|
| 121 | + const apiKeys = await ApiKeyApi.getApiKeySimpleList() |
| 122 | + provider.value = { |
| 123 | + llm: () => |
| 124 | + apiKeys.map(({ id, name }) => ({ |
| 125 | + value: id, |
| 126 | + label: name |
| 127 | + })), |
| 128 | + knowledge: () => [], |
| 129 | + internal: () => [] |
| 130 | + } |
| 131 | +
|
| 132 | + currentStep.value = 0 |
| 133 | +} |
| 134 | +
|
| 135 | +/** 校验所有步骤数据是否完整 */ |
| 136 | +const validateAllSteps = async () => { |
| 137 | + try { |
| 138 | + // 基本信息校验 |
| 139 | + try { |
| 140 | + await validateBasic() |
| 141 | + } catch (error) { |
| 142 | + currentStep.value = 0 |
| 143 | + throw new Error('请完善基本信息') |
| 144 | + } |
| 145 | +
|
| 146 | + // 工作流设计校验 |
| 147 | + try { |
| 148 | + await validateWorkflow() |
| 149 | + } catch (error) { |
| 150 | + currentStep.value = 1 |
| 151 | + throw new Error('请完善工作流信息') |
| 152 | + } |
| 153 | + return true |
| 154 | + } catch (error) { |
| 155 | + throw error |
| 156 | + } |
| 157 | +} |
| 158 | +
|
| 159 | +/** 保存操作 */ |
| 160 | +const handleSave = async () => { |
| 161 | + try { |
| 162 | + // 保存前校验所有步骤的数据 |
| 163 | + await validateAllSteps() |
| 164 | +
|
| 165 | + // 更新表单数据 |
| 166 | + const data = { |
| 167 | + ...formData.value |
| 168 | + } |
| 169 | +
|
| 170 | + data.graph = JSON.stringify(workflowData.value) |
| 171 | +
|
| 172 | + if (actionType === 'update') { |
| 173 | + await WorkflowApi.updateWorkflow(data) |
| 174 | + } else { |
| 175 | + await WorkflowApi.createWorkflow(data) |
| 176 | + } |
| 177 | +
|
| 178 | + delView(unref(router.currentRoute)) |
| 179 | + await router.push({ name: 'AiWorkflow' }) |
| 180 | + } catch (error: any) { |
| 181 | + console.error('保存失败:', error) |
| 182 | + message.warning(error.message || '请完善所有步骤的必填信息') |
| 183 | + } |
| 184 | +} |
| 185 | +
|
| 186 | +/** 步骤切换处理 */ |
| 187 | +const handleStepClick = async (index: number) => { |
| 188 | + try { |
| 189 | + if (index !== 0) { |
| 190 | + await validateBasic() |
| 191 | + } |
| 192 | + if (index !== 1) { |
| 193 | + await validateWorkflow() |
| 194 | + } |
| 195 | +
|
| 196 | + // 切换步骤 |
| 197 | + currentStep.value = index |
| 198 | + } catch (error) { |
| 199 | + console.error('步骤切换失败:', error) |
| 200 | + message.warning('请先完善当前步骤必填信息') |
| 201 | + } |
| 202 | +} |
| 203 | +
|
| 204 | +/** 返回列表页 */ |
| 205 | +const handleBack = () => { |
| 206 | + // 先删除当前页签 |
| 207 | + delView(unref(router.currentRoute)) |
| 208 | + // 跳转到列表页 |
| 209 | + router.push({ name: 'AiWorkflow' }) |
| 210 | +} |
| 211 | +
|
| 212 | +/** 初始化 */ |
| 213 | +onMounted(async () => { |
| 214 | + await initData() |
| 215 | +}) |
| 216 | +</script> |
| 217 | + |
| 218 | +<style lang="scss" scoped> |
| 219 | +.border-bottom { |
| 220 | + border-bottom: 1px solid #dcdfe6; |
| 221 | +} |
| 222 | +
|
| 223 | +.text-primary { |
| 224 | + color: #3473ff; |
| 225 | +} |
| 226 | +
|
| 227 | +.bg-primary { |
| 228 | + background-color: #3473ff; |
| 229 | +} |
| 230 | +
|
| 231 | +.border-primary { |
| 232 | + border-color: #3473ff; |
| 233 | +} |
| 234 | +</style> |
0 commit comments