index.vue 10 KB

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