index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <div class="create-approval">
  3. <div class="create-approval-header flex flex_align-center">
  4. <div v-if="false" class="create-approval-header-back">
  5. <el-icon :size="18">
  6. <ArrowLeft />
  7. </el-icon>
  8. </div>
  9. <div class="create-approval-header-left-zh">
  10. <div class="create-approval-header-name">{{ processName }}</div>
  11. <div v-if="false" class="create-approval-header-time">最近保存:6 分钟前</div>
  12. </div>
  13. <div class="create-approval-header-tab-list">
  14. <div
  15. v-for="(item, idx) in componentsArr"
  16. :key="idx"
  17. class="create-approval-header-tab-item"
  18. :class="[item.value === activeTab ? 'active' : '']"
  19. @click="activeComponent(idx)"
  20. >
  21. <span class="create-approval-header-tab-counter">{{ idx + 1 }}</span>
  22. <span>{{ item.label }}</span>
  23. </div>
  24. </div>
  25. <div class="create-approval-header-right">
  26. <el-button v-show="!isView" type="primary" @click="submitHandler">发布</el-button>
  27. </div>
  28. </div>
  29. <div class="create-approval-main">
  30. <component :is="item.component" v-for="(item, idx) in componentsArr" v-show="item.value === activeTab" ref="compRefs" :key="idx" />
  31. </div>
  32. </div>
  33. </template>
  34. <script setup name="flow_create">
  35. import { computed, nextTick, ref } from 'vue'
  36. import { storeToRefs } from 'pinia'
  37. import useFlowStore from '@/store/modules/flow'
  38. import BasicInfoTab from './components/BasicInfo.vue'
  39. import ExtendSetTab from './components/ExtendSet.vue'
  40. import FlowDesignTab from './components/FlowDesign.vue'
  41. import FormDesignTab from './components/FormDesign.vue'
  42. import { useRoute, useRouter } from 'vue-router'
  43. import process from '@/api/flow/process'
  44. import useStore from '@/store'
  45. import { ElMessage } from 'element-plus'
  46. const { tagsView } = useStore()
  47. const router = useRouter()
  48. const route = useRoute()
  49. const flowStore = useFlowStore()
  50. const { categoryId, processId, processIcon, processKey, processName, remark, modelContent, local_processForm, processSetting } = storeToRefs(flowStore)
  51. const compRefs = ref() // 实例化子组件
  52. const cache_components = ref({})
  53. const componentsArr = [
  54. {
  55. component: BasicInfoTab,
  56. label: '基础信息',
  57. value: '基础信息'
  58. // ref: 'basicInfoRef'
  59. },
  60. {
  61. component: FormDesignTab,
  62. label: '表单设计',
  63. value: '表单设计'
  64. // ref: 'formDesignRef'
  65. },
  66. {
  67. component: FlowDesignTab,
  68. label: '流程设计',
  69. value: '流程设计'
  70. // ref: 'flowDesignRef'
  71. },
  72. {
  73. component: ExtendSetTab,
  74. label: '扩展设置',
  75. value: '扩展设置'
  76. // ref: 'extendSetRef'
  77. }
  78. ]
  79. const activeTab = ref('基础信息')
  80. const removeCurTab = () => {
  81. cache_components.value = {}
  82. const _view = tagsView.visitedViews.find(v => v.path === '/flow_create/index')
  83. if (_view)
  84. tagsView.delView(_view).then(res => {
  85. const latestView = res.visitedViews.slice(-1)[0]
  86. if (latestView && latestView.fullPath) {
  87. router.push(latestView.fullPath)
  88. } else {
  89. router.push('/')
  90. }
  91. flowStore.$reset()
  92. })
  93. }
  94. const submitHandler = async () => {
  95. // 基础信息
  96. // 表单设计
  97. // 流程设计
  98. // 扩展设置
  99. let leavePageFlag = await validateTabs()
  100. // let _id = queryObj.value.id
  101. // if (_id) {
  102. //
  103. // } else {
  104. // leavePageFlag = await validateTabs()
  105. // }
  106. if (!leavePageFlag) return
  107. const params = {
  108. categoryId: categoryId.value,
  109. processIcon: processIcon.value,
  110. processType: 'main',
  111. processKey: processKey.value,
  112. processName: processName.value,
  113. remark: remark.value,
  114. processId: processId.value,
  115. processForm: JSON.stringify(local_processForm.value),
  116. modelContent: JSON.stringify({
  117. key: processKey.value,
  118. name: processName.value,
  119. nodeConfig: JSON.parse(modelContent.value || '{}')
  120. }),
  121. processSetting: processSetting.value
  122. }
  123. const res = await process.progressCreateApi(params)
  124. ElMessage.success('操作成功')
  125. // 创建完成 删除 当前tab页
  126. removeCurTab()
  127. }
  128. // 切换选项卡之前,做相应的保存操作
  129. const validateTabs = async () => {
  130. const _refs = compRefs.value
  131. // await nextTick()
  132. for (let i = 0; i < _refs.length; i++) {
  133. let bool = true
  134. /*// 若没开启过的 tab 需要尝试 进行更新数据
  135. if (!cache_components.value[i]) {
  136. cache_components.value[i]?.updateCompInfo()
  137. }*/
  138. const _validate =
  139. _refs[i]?.validate ||
  140. function () {
  141. return Promise.resolve()
  142. }
  143. await _validate().catch(e => {
  144. activeTab.value = componentsArr[i].label
  145. if (activeTab.value === '表单设计') {
  146. ElMessage.error('请为流程设计表单内容')
  147. }
  148. bool = false
  149. })
  150. if (!bool) return false
  151. }
  152. return true
  153. }
  154. const activeComponent = index => {
  155. const cur = componentsArr[index]
  156. if (activeTab.value !== cur.value) {
  157. if (activeTab.value === '表单设计') {
  158. compRefs.value[1]?.exportJsonEv()
  159. }
  160. // 当前缓存
  161. if (!cache_components.value[index]) {
  162. // 更新数据
  163. const updateCompInfo = compRefs.value[index]?.updateCompInfo
  164. // console.error('刷新数据')
  165. // console.error(updateCompInfo, 'updateCompInfo')
  166. if (updateCompInfo) {
  167. updateCompInfo()
  168. }
  169. }
  170. activeTab.value = cur.value
  171. }
  172. }
  173. const queryObj = computed(() => route.query)
  174. // 纯查看判断
  175. const isView = computed(() => {
  176. return queryObj.value?.view === '1'
  177. })
  178. const getCurrentProcessDetailEv = () => {
  179. let _id = queryObj.value.id
  180. if (_id) {
  181. cache_components.value = {}
  182. process.processDetailApi(_id).then(res => {
  183. processId.value = res.processId
  184. categoryId.value = res.categoryId
  185. processIcon.value = res.processIcon
  186. processKey.value = res.processKey
  187. processName.value = res.processName
  188. remark.value = res.remark
  189. let nodeConfig = JSON.parse(res.modelContent).nodeConfig
  190. modelContent.value = JSON.stringify(nodeConfig)
  191. local_processForm.value = JSON.parse(res.processForm) || {}
  192. // processForm.value = JSON.parse(res.processForm) || {}
  193. // flowStore.setProcessForm(processForm)
  194. flowStore.setProcessSetting(res.processSetting)
  195. // 默认执行一次保存
  196. const _refs = compRefs.value
  197. for (let i = 0; i < _refs.length; i++) {
  198. const updateCompInfo = compRefs.value[i]?.updateCompInfo
  199. if (updateCompInfo) {
  200. updateCompInfo()
  201. }
  202. }
  203. })
  204. }
  205. }
  206. getCurrentProcessDetailEv()
  207. </script>
  208. <style scoped lang="scss">
  209. .create-approval {
  210. height: 100%;
  211. min-width: 1200px;
  212. min-height: 600px;
  213. overflow: auto;
  214. &-header {
  215. justify-content: flex-start;
  216. height: 64px;
  217. //z-index: 12;
  218. position: relative;
  219. box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.06);
  220. padding-left: 16px;
  221. padding-right: 20px;
  222. &-back {
  223. display: flex;
  224. justify-content: flex-start;
  225. align-items: center;
  226. height: 100%;
  227. margin-right: 15px;
  228. }
  229. &-left-zh {
  230. width: calc(50% - 316.5px);
  231. min-width: 248px;
  232. }
  233. &-name {
  234. font-weight: 500;
  235. font-size: 16px;
  236. white-space: nowrap;
  237. cursor: pointer;
  238. width: -webkit-fit-content;
  239. width: -moz-fit-content;
  240. width: fit-content;
  241. max-width: 100%;
  242. height: 24px;
  243. overflow: hidden;
  244. text-overflow: ellipsis;
  245. }
  246. &-time {
  247. width: 100%;
  248. height: 20px;
  249. line-height: 20px;
  250. font-size: 12px;
  251. color: #8f959e;
  252. overflow: hidden;
  253. white-space: nowrap;
  254. text-overflow: ellipsis;
  255. }
  256. &-tab-list {
  257. margin-left: 10px;
  258. flex-shrink: 0;
  259. display: flex;
  260. justify-content: center;
  261. }
  262. &-tab-item {
  263. font-family: PingFang SC, Microsoft YaHei;
  264. font-size: 18px;
  265. line-height: 28px;
  266. color: #646a73;
  267. margin-right: 42px;
  268. padding: 18px 0;
  269. border-bottom: 2px solid transparent;
  270. cursor: pointer;
  271. &.active {
  272. // var(--el-color-primary);
  273. border-bottom-color: var(--el-color-primary);
  274. color: var(--el-color-primary);
  275. font-weight: 500;
  276. .create-approval-header-tab-counter {
  277. border-color: var(--el-color-primary);
  278. background-color: var(--el-color-primary);
  279. color: var(--el-color-white);
  280. font-weight: 400;
  281. }
  282. }
  283. }
  284. &-tab-counter {
  285. display: inline-block;
  286. margin-right: 6px;
  287. width: 24px;
  288. height: 24px;
  289. border-radius: 50%;
  290. border: 1px solid #646a73;
  291. font-size: 16px;
  292. line-height: 22px;
  293. text-align: center;
  294. }
  295. &-right {
  296. flex: 1 1;
  297. flex-shrink: 0;
  298. display: flex;
  299. justify-content: flex-end;
  300. align-items: center;
  301. position: relative;
  302. height: 100%;
  303. width: -webkit-fit-content;
  304. width: -moz-fit-content;
  305. width: fit-content;
  306. }
  307. }
  308. &-main {
  309. height: calc(100% - 64px);
  310. }
  311. }
  312. </style>