index.vue 8.2 KB

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