index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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="router.back()" />
  11. <span class="ml-10px text-16px truncate" :title="formData.name || '创建流程'">
  12. {{ formData.name || '创建流程' }}
  13. </span>
  14. </div>
  15. <!-- 步骤条 -->
  16. <div class="flex-1 flex items-center justify-center h-full">
  17. <div class="w-400px flex items-center justify-between h-full">
  18. <div
  19. v-for="(step, index) in steps"
  20. :key="index"
  21. class="flex items-center cursor-pointer mx-15px relative h-full"
  22. :class="[
  23. currentStep === index
  24. ? 'text-[#3473ff] border-[#3473ff] border-b-2 border-b-solid'
  25. : 'text-gray-500'
  26. ]"
  27. @click="handleStepClick(index)"
  28. >
  29. <div
  30. class="w-28px h-28px rounded-full flex items-center justify-center mr-8px border-2 border-solid text-15px"
  31. :class="[
  32. currentStep === index
  33. ? 'bg-[#3473ff] text-white border-[#3473ff]'
  34. : 'border-gray-300 bg-white text-gray-500'
  35. ]"
  36. >
  37. {{ index + 1 }}
  38. </div>
  39. <span class="text-16px font-bold whitespace-nowrap">{{ step.title }}</span>
  40. </div>
  41. </div>
  42. </div>
  43. <!-- 右侧按钮 -->
  44. <div class="w-200px flex items-center justify-end gap-2">
  45. <el-button @click="handleSave">保 存</el-button>
  46. <el-button type="primary" @click="handleDeploy">发 布</el-button>
  47. </div>
  48. </div>
  49. <!-- 主体内容 -->
  50. <div class="mt-50px">
  51. <!-- 第一步:基本信息 -->
  52. <div v-if="currentStep === 0" class="mx-auto" style="max-width: 1024px">
  53. <BasicInfo
  54. v-model="formData"
  55. :categoryList="categoryList"
  56. :userList="userList"
  57. ref="basicInfoRef"
  58. />
  59. </div>
  60. <!-- 第二步:表单设计 -->
  61. <div v-if="currentStep === 1" class="mx-auto w-1024px">
  62. <FormDesign v-model="formData" :formList="formList" ref="formDesignRef" />
  63. </div>
  64. <!-- 第三步:流程设计 -->
  65. <ProcessDesign
  66. v-if="currentStep === 2"
  67. v-model="formData"
  68. ref="processDesignRef"
  69. @success="handleDesignSuccess"
  70. />
  71. </div>
  72. </div>
  73. </ContentWrap>
  74. </template>
  75. <script lang="ts" setup>
  76. import { useRouter, useRoute } from 'vue-router'
  77. import { useMessage } from '@/hooks/web/useMessage'
  78. import * as ModelApi from '@/api/bpm/model'
  79. import * as FormApi from '@/api/bpm/form'
  80. import { CategoryApi } from '@/api/bpm/category'
  81. import * as UserApi from '@/api/system/user'
  82. import { useUserStoreWithOut } from '@/store/modules/user'
  83. import { BpmModelType, BpmModelFormType } from '@/utils/constants'
  84. import BasicInfo from './BasicInfo.vue'
  85. import FormDesign from './FormDesign.vue'
  86. import ProcessDesign from './ProcessDesign.vue'
  87. const router = useRouter()
  88. const route = useRoute()
  89. const message = useMessage()
  90. const userStore = useUserStoreWithOut()
  91. // 组件引用
  92. const basicInfoRef = ref()
  93. const formDesignRef = ref()
  94. const processDesignRef = ref()
  95. /** 步骤校验函数 */
  96. const validateStep1 = async () => {
  97. await basicInfoRef.value?.validate()
  98. }
  99. const validateStep2 = async () => {
  100. await formDesignRef.value?.validate()
  101. }
  102. const validateStep3 = async () => {
  103. await processDesignRef.value?.validate()
  104. }
  105. // 步骤控制
  106. const currentStep = ref(0)
  107. const steps = [
  108. { title: '基本信息', validator: validateStep1 },
  109. { title: '表单设计', validator: validateStep2 },
  110. { title: '流程设计', validator: validateStep3 }
  111. ]
  112. // 表单数据
  113. const formData: any = ref({
  114. id: undefined,
  115. name: '',
  116. key: '',
  117. category: undefined,
  118. icon: undefined,
  119. description: '',
  120. type: BpmModelType.BPMN,
  121. formType: BpmModelFormType.NORMAL,
  122. formId: '',
  123. formCustomCreatePath: '',
  124. formCustomViewPath: '',
  125. visible: true,
  126. startUserType: undefined,
  127. managerUserType: undefined,
  128. startUserIds: [],
  129. managerUserIds: []
  130. })
  131. // 数据列表
  132. const formList = ref([])
  133. const categoryList = ref([])
  134. const userList = ref<UserApi.UserVO[]>([])
  135. /** 初始化数据 */
  136. const initData = async () => {
  137. const modelId = route.params.id as string
  138. if (modelId) {
  139. // 修改场景
  140. formData.value = await ModelApi.getModel(modelId)
  141. } else {
  142. // 新增场景
  143. formData.value.managerUserIds.push(userStore.getUser.id)
  144. }
  145. // 获取表单列表
  146. formList.value = await FormApi.getFormSimpleList()
  147. // 获取分类列表
  148. categoryList.value = await CategoryApi.getCategorySimpleList()
  149. // 获取用户列表
  150. userList.value = await UserApi.getSimpleUserList()
  151. }
  152. /** 保存操作 */
  153. const handleSave = async () => {
  154. try {
  155. // 保存前确保当前步骤的数据已经验证通过
  156. if (typeof steps[currentStep.value].validator === 'function') {
  157. await steps[currentStep.value].validator()
  158. }
  159. // 如果是第三步,需要先获取最新的流程设计数据
  160. if (currentStep.value === 2) {
  161. const bpmnXml = processDesignRef.value?.getXmlString()
  162. if (bpmnXml) {
  163. formData.value.bpmnXml = bpmnXml
  164. }
  165. }
  166. if (formData.value.id) {
  167. await ModelApi.updateModel(formData.value)
  168. message.success('修改成功')
  169. } else {
  170. const result = await ModelApi.createModel(formData.value)
  171. formData.value.id = result.id
  172. message.success('新增成功')
  173. }
  174. } catch (error) {
  175. console.error('保存失败:', error)
  176. message.error(error.message || '保存失败')
  177. }
  178. }
  179. /** 发布操作 */
  180. const handleDeploy = async () => {
  181. try {
  182. await message.confirm('是否确认发布该流程?')
  183. // 发布时才进行全部校验
  184. for (const step of steps) {
  185. if (step.validator) {
  186. await step.validator()
  187. }
  188. }
  189. // 如果是第三步,需要先获取最新的流程设计数据
  190. if (currentStep.value === 2) {
  191. const bpmnXml = processDesignRef.value?.getXmlString()
  192. if (bpmnXml) {
  193. formData.value.bpmnXml = bpmnXml
  194. }
  195. }
  196. await handleSave()
  197. await ModelApi.deployModel(formData.value.id)
  198. message.success('发布成功')
  199. router.push({ name: 'BpmModel' })
  200. } catch (error) {
  201. if (error instanceof Error) {
  202. // 校验失败时,跳转到对应步骤
  203. const failedStep = steps.findIndex((step) => {
  204. try {
  205. step.validator && step.validator()
  206. return false
  207. } catch {
  208. return true
  209. }
  210. })
  211. if (failedStep !== -1) {
  212. currentStep.value = failedStep
  213. message.warning('请完善必填信息')
  214. }
  215. }
  216. }
  217. }
  218. /** 步骤切换处理 */
  219. const handleStepClick = async (index: number) => {
  220. // 如果是切换到第三步(流程设计),需要校验key和name
  221. if (index === 2) {
  222. if (!formData.value.key || !formData.value.name) {
  223. message.warning('请先填写流程标识和流程名称')
  224. return
  225. }
  226. }
  227. // 只有在向后切换时才进行校验
  228. if (index > currentStep.value) {
  229. try {
  230. if (typeof steps[currentStep.value].validator === 'function') {
  231. await steps[currentStep.value].validator()
  232. }
  233. currentStep.value = index
  234. } catch (error) {
  235. message.warning('请先完善当前步骤必填信息')
  236. }
  237. } else {
  238. // 向前切换时直接切换
  239. currentStep.value = index
  240. }
  241. }
  242. /** 处理设计器保存成功 */
  243. const handleDesignSuccess = (bpmnXml?: string) => {
  244. if (bpmnXml) {
  245. formData.value.bpmnXml = bpmnXml
  246. }
  247. }
  248. /** 初始化 */
  249. onMounted(async () => {
  250. await initData()
  251. })
  252. </script>
  253. <style lang="scss" scoped>
  254. .border-bottom {
  255. border-bottom: 1px solid #dcdfe6;
  256. }
  257. .text-primary {
  258. color: #3473ff;
  259. }
  260. .bg-primary {
  261. background-color: #3473ff;
  262. }
  263. .border-primary {
  264. border-color: #3473ff;
  265. }
  266. </style>