index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. // 更新数据
  172. const updateCompInfo = compRefs.value[index]?.updateCompInfo
  173. // console.error('刷新数据')
  174. // console.error(updateCompInfo, 'updateCompInfo')
  175. if (updateCompInfo) {
  176. updateCompInfo()
  177. }
  178. }
  179. activeTab.value = cur.value
  180. }
  181. }
  182. const queryObj = computed(() => route.query)
  183. // 纯查看判断
  184. const isView = computed(() => {
  185. return queryObj.value?.view === '1'
  186. })
  187. const lastId = ref()
  188. const getCurrentProcessDetailEv = async () => {
  189. let _id = queryObj.value.id
  190. if (lastId.value !== _id) {
  191. activeTab.value = '基础信息'
  192. lastId.value = _id
  193. flowStore.$reset()
  194. flowStore.setProcessType('main')
  195. if (_id) {
  196. loading.value = true
  197. cache_components.value = {}
  198. process
  199. .processDetailApi(_id)
  200. .then(res => {
  201. processId.value = res.processId
  202. categoryId.value = res.categoryId
  203. processIcon.value = res.processIcon
  204. processKey.value = res.processKey
  205. processName.value = res.processName
  206. remark.value = res.remark
  207. let nodeConfig = JSON.parse(res.modelContent).nodeConfig
  208. modelContent.value = JSON.stringify(nodeConfig)
  209. processForm.value = res.processForm
  210. flowStore.setProcessSetting(res.processSetting)
  211. processPermissionList.value = (res.processPermissionList || []).map(i => ({
  212. ...i,
  213. id: i.userId,
  214. name: i.userName
  215. }))
  216. // 默认执行一次保存
  217. const _refs = compRefs.value
  218. for (let i = 0; i < _refs.length; i++) {
  219. const updateCompInfo = compRefs.value[i]?.updateCompInfo
  220. if (updateCompInfo) {
  221. updateCompInfo()
  222. }
  223. }
  224. })
  225. .finally(() => {
  226. loading.value = false
  227. })
  228. } else {
  229. nextTick(() => {
  230. // 默认执行一次保存
  231. const _refs = compRefs.value
  232. for (let i = 0; i < _refs.length; i++) {
  233. const updateCompInfo = compRefs.value[i]?.updateCompInfo
  234. if (updateCompInfo) {
  235. updateCompInfo()
  236. }
  237. }
  238. })
  239. }
  240. }
  241. }
  242. getCurrentProcessDetailEv()
  243. onActivated(() => {
  244. getCurrentProcessDetailEv()
  245. })
  246. </script>
  247. <style scoped lang="scss">
  248. .create-approval {
  249. //height: 100%;
  250. //min-width: 1200px;
  251. //min-height: 600px;
  252. //overflow: auto;
  253. .scrollbar {
  254. //height: 64px;
  255. //padding: 0 12px;
  256. margin: 0 6px;
  257. //background-color: var(--el-bg-color);
  258. //box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.06);
  259. //height: 100%;
  260. //background-color: var(--el-color-info-light-9);
  261. :deep(.el-scrollbar__bar) {
  262. &.is-horizontal {
  263. height: 2px;
  264. }
  265. }
  266. }
  267. &-header {
  268. justify-content: flex-start;
  269. height: 64px;
  270. //z-index: 12;
  271. position: relative;
  272. box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.06);
  273. background-color: var(--el-bg-color);
  274. padding-right: 12px;
  275. //padding-right: 20px;
  276. &-back {
  277. display: flex;
  278. justify-content: flex-start;
  279. align-items: center;
  280. //height: 100%;
  281. margin-left: 4px;
  282. margin-right: 4px;
  283. padding: 8px;
  284. cursor: pointer;
  285. &:hover {
  286. color: var(--el-color-primary);
  287. }
  288. }
  289. &-left-zh {
  290. //width: calc(50% - 316.5px);
  291. width: 20%;
  292. min-width: 90px;
  293. }
  294. &-name {
  295. font-weight: 500;
  296. font-size: 14px;
  297. //white-space: nowrap;
  298. //cursor: pointer;
  299. //width: -webkit-fit-content;
  300. //width: -moz-fit-content;
  301. //width: fit-content;
  302. //max-width: 100%;
  303. //height: 24px;
  304. //overflow: hidden;
  305. //text-overflow: ellipsis;
  306. display: flex;
  307. align-items: center;
  308. .icon-shower {
  309. width: 24px;
  310. font-size: 24px;
  311. //height: 48px;
  312. border-radius: 50%;
  313. overflow: hidden;
  314. flex-shrink: 0;
  315. }
  316. }
  317. &-time {
  318. width: 100%;
  319. height: 20px;
  320. line-height: 20px;
  321. font-size: 12px;
  322. color: #8f959e;
  323. overflow: hidden;
  324. white-space: nowrap;
  325. text-overflow: ellipsis;
  326. }
  327. &-tab-list {
  328. //margin: 0 6px;
  329. //flex-shrink: 0;
  330. display: flex;
  331. justify-content: center;
  332. width: max-content;
  333. }
  334. &-tab-item {
  335. flex-shrink: 0;
  336. font-size: 18px;
  337. line-height: 26px;
  338. color: #646a73;
  339. margin-right: 18px;
  340. padding: 18px 0;
  341. border-bottom: 2px solid transparent;
  342. cursor: pointer;
  343. &.active {
  344. // var(--el-color-primary);
  345. border-bottom-color: var(--el-color-primary);
  346. color: var(--el-color-primary);
  347. font-weight: 500;
  348. .create-approval-header-tab-counter {
  349. border-color: var(--el-color-primary);
  350. background-color: var(--el-color-primary);
  351. color: var(--el-color-white);
  352. font-weight: 400;
  353. }
  354. }
  355. }
  356. &-tab-counter {
  357. display: inline-block;
  358. margin-right: 6px;
  359. width: 24px;
  360. height: 24px;
  361. border-radius: 50%;
  362. border: 1px solid #646a73;
  363. font-size: 16px;
  364. line-height: 22px;
  365. text-align: center;
  366. }
  367. &-right {
  368. flex: 1 1;
  369. flex-shrink: 0;
  370. display: flex;
  371. justify-content: flex-end;
  372. align-items: center;
  373. position: relative;
  374. height: 100%;
  375. width: -webkit-fit-content;
  376. width: -moz-fit-content;
  377. width: fit-content;
  378. }
  379. }
  380. &-main {
  381. //flex: 1;
  382. height: calc(100% - 64px);
  383. overflow: auto;
  384. }
  385. }
  386. // 手机端兼容
  387. .app-mobile {
  388. .create-approval-header-tab {
  389. &-item {
  390. //background: #f00;
  391. font-size: 14px;
  392. margin-right: 6px;
  393. }
  394. &-counter {
  395. width: 18px;
  396. height: 18px;
  397. line-height: 16px;
  398. margin-right: 4px;
  399. font-size: 13px;
  400. }
  401. }
  402. }
  403. </style>