FormProcessDesign_20240320143102.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <el-container>
  3. <el-header style="background: white">
  4. <layout-header v-model="activeSelect" @publish="publishProcess" @preview="preview"></layout-header>
  5. </el-header>
  6. <div class="layout-body">
  7. <form-base-setting ref="baseSetting" v-show="activeSelect === 'baseSetting'"/>
  8. <form-design ref="formSetting" v-show="activeSelect === 'formSetting'"/>
  9. <process-design ref="processDesign" v-show="activeSelect === 'processDesign'"/>
  10. <form-pro-setting ref="proSetting" v-show="activeSelect === 'proSetting'"/>
  11. </div>
  12. <w-dialog :showFooter="false" v-model="validVisible" title="设置项检查">
  13. <el-steps align-center :active="validStep" finish-status="success">
  14. <el-step v-for="(step, i) in validOptions" :title="step.title" :key="i"
  15. :icon="step.icon" :status="step.status" :description="step.description"/>
  16. </el-steps>
  17. <el-result :icon="validIcon" :title="errTitle" :subTitle="validResult.desc">
  18. <i slot="icon" style="font-size: 30px" v-if="!validResult.finished" class="el-icon-loading"></i>
  19. <div slot="subTitle" class="err-info" v-if="validResult.errs.length > 0">
  20. <ellipsis hover-tip v-for="(err, i) in validResult.errs" :key="i + '_err'" :content="err">
  21. <i slot="pre" class="el-icon-warning-outline"></i>
  22. </ellipsis>
  23. </div>
  24. <template slot="extra">
  25. <el-button type="primary" v-if="validResult.finished" size="medium" @click="doAfter">
  26. {{ validResult.action }}
  27. </el-button>
  28. </template>
  29. </el-result>
  30. </w-dialog>
  31. </el-container>
  32. </template>
  33. <script>
  34. import LayoutHeader from './LayoutHeader'
  35. import {getFormDetail, createForm, updateFormDetail} from '@/api/design'
  36. import FormBaseSetting from '@/views/admin/layout/FormBaseSetting'
  37. import FormDesign from '@/views/admin/layout/FormDesign'
  38. import ProcessDesign from '@/views/admin/layout/ProcessDesign'
  39. import FormProSetting from '@/views/admin/layout/FormProSetting'
  40. export default {
  41. name: "FormProcessDesign",
  42. components: {LayoutHeader, FormBaseSetting, FormDesign, ProcessDesign, FormProSetting},
  43. data() {
  44. return {
  45. isNew: true,
  46. validStep: 0,
  47. timer: null,
  48. activeSelect: 'baseSetting',
  49. validVisible: false,
  50. validResult: {},
  51. validOptions: [
  52. {title: '基础信息', description: '', icon: '', status: ''},
  53. {title: '审批表单', description: '', icon: '', status: ''},
  54. {title: '审批流程', description: '', icon: '', status: ''},
  55. {title: '扩展设置', description: '', icon: '', status: ''}
  56. ],
  57. validComponents: ['baseSetting', 'formSetting', 'processDesign', 'proSetting'],
  58. }
  59. },
  60. computed: {
  61. setup() {
  62. return this.$store.state.design
  63. },
  64. errTitle(){
  65. if (this.validResult.finished && !this.validResult.success){
  66. return this.validResult.title + ` (${this.validResult.errs.length}项错误) 😥`
  67. }
  68. return this.validResult.title
  69. },
  70. validIcon() {
  71. if (!this.validResult.finished) {
  72. return 'el-icon-loading'
  73. } else if (this.validResult.success) {
  74. return 'success'
  75. } else {
  76. return 'warning'
  77. }
  78. }
  79. },
  80. created() {
  81. this.showValiding()
  82. let formId = this.$route.query.code
  83. //判断传参,决定是新建还是加载原始数据
  84. this.loadInitFrom()
  85. if (this.$isNotEmpty(formId)) {
  86. this.isNew = false
  87. this.loadFormInfo(formId)
  88. }
  89. let group = this.$route.query.group
  90. this.setup.groupId = this.$isNotEmpty(group) ? parseInt(group) : null
  91. },
  92. beforeDestroy() {
  93. this.stopTimer()
  94. },
  95. methods: {
  96. loadFormInfo(formId) {
  97. getFormDetail(formId).then(rsp => {
  98. console.log(rsp.data)
  99. let form = rsp.data;
  100. form.logo = JSON.parse(form.logo)
  101. form.settings = JSON.parse(form.settings)
  102. form.formItems = JSON.parse(form.formItems)
  103. form.process = JSON.parse(form.process)
  104. this.$store.commit('loadForm', form)
  105. }).catch(err => {
  106. this.$message.error(err)
  107. })
  108. },
  109. loadInitFrom() {
  110. this.$store.commit('loadForm', {
  111. formId: null,
  112. formName: "未命名表单",
  113. logo: {
  114. icon: "el-icon-eleme",
  115. background: "#1e90ff"
  116. },
  117. settings: {
  118. commiter: [],
  119. admin: [],
  120. sign: false,
  121. notify: {
  122. types: ["APP"],
  123. title: "消息通知标题"
  124. }
  125. },
  126. groupId: undefined,
  127. formItems: [],
  128. process: {
  129. id: "root",
  130. parentId: null,
  131. type: "ROOT",
  132. name: "发起人",
  133. desc: "任何人",
  134. props: {
  135. assignedUser: [],
  136. formPerms: []
  137. },
  138. children: {}
  139. },
  140. remark: "备注说明"
  141. })
  142. },
  143. validateDesign() {
  144. console.log('000')
  145. this.validVisible = true
  146. this.validStep = 0
  147. this.showValiding()
  148. this.stopTimer()
  149. this.timer = setInterval(() => {
  150. this.validResult.errs = this.$refs[this.validComponents[this.validStep]].validate()
  151. if (Array.isArray(this.validResult.errs) && this.validResult.errs.length === 0) {
  152. this.validStep++;
  153. if (this.validStep >= this.validOptions.length) {
  154. this.stopTimer()
  155. this.showValidFinish(true)
  156. }
  157. } else {
  158. this.stopTimer()
  159. this.validOptions[this.validStep].status = 'error'
  160. this.showValidFinish(false, this.getDefaultValidErr())
  161. }
  162. }, 300)
  163. },
  164. getDefaultValidErr() {
  165. switch (this.validStep) {
  166. case 0:
  167. return '请检查基础设置项';
  168. case 1:
  169. return '请检查审批表单相关设置'
  170. case 2:
  171. return '请检查审批流程,查看对应标注节点错误信息'
  172. case 3:
  173. return '请检查扩展设置'
  174. default:
  175. return '未知错误'
  176. }
  177. },
  178. showValidFinish(success, err) {
  179. this.validResult.success = success
  180. this.validResult.finished = true
  181. this.validResult.title = success ? '校验完成 😀' : '校验失败 '
  182. this.validResult.desc = success ? '设置项校验成功,是否提交?' : err
  183. this.validResult.action = success ? '提 交' : '去修改'
  184. },
  185. showValiding() {
  186. this.validResult = {
  187. errs: [],
  188. finished: false,
  189. success: false,
  190. title: '检查中...',
  191. action: '处理',
  192. desc: '正在检查设置项'
  193. }
  194. this.validStep = 0
  195. this.validOptions.forEach(op => {
  196. op.status = ''
  197. op.icon = ''
  198. op.description = ''
  199. })
  200. },
  201. doAfter() {
  202. if (this.validResult.success) {
  203. this.doPublish()
  204. } else {
  205. this.activeSelect = this.validComponents[this.validStep]
  206. this.validVisible = false
  207. }
  208. },
  209. stopTimer() {
  210. if (this.timer) {
  211. clearInterval(this.timer)
  212. }
  213. },
  214. preview() {
  215. this.validateDesign()
  216. },
  217. publishProcess() {
  218. this.validateDesign()
  219. },
  220. doPublish() {
  221. this.$confirm('如果您只想预览请选择预览,确认发布后流程立即生效,是否继续?', '提示', {
  222. confirmButtonText: '发布',
  223. cancelButtonText: '取消',
  224. type: 'warning'
  225. }).then(() => {
  226. console.log(this.setup)
  227. let processNew = JSON.parse(JSON.stringify(this.setup.process));
  228. //判断条件分支
  229. this.conditionRecursion(processNew);
  230. let template = {
  231. formId: this.setup.formId,
  232. formName: this.setup.formName,
  233. logo: JSON.stringify(this.setup.logo),
  234. settings: JSON.stringify(this.setup.settings),
  235. groupId: this.setup.groupId,
  236. formItems: JSON.stringify(this.setup.formItems),
  237. process: JSON.stringify(processNew),
  238. remark: this.setup.remark
  239. }
  240. console.log(template);
  241. // return;
  242. if (this.isNew || !this.$isNotEmpty(this.setup.formId)) {
  243. createForm(template).then(rsp => {
  244. this.$message.success("创建表单成功")
  245. this.$router.push("/formsPanel")
  246. }).catch(err => {
  247. this.$message.error(err)
  248. })
  249. } else {
  250. updateFormDetail(template).then(rsp => {
  251. this.$message.success("更新表单成功")
  252. this.$router.push("/formsPanel")
  253. }).catch(err => {
  254. this.$message.error(err)
  255. })
  256. }
  257. })
  258. },
  259. conditionRecursion(process){
  260. if(null != process && undefined != process){
  261. if(null != process.branchs && undefined != process.branchs){
  262. process.branchs.map((item, i) => {
  263. if (i == process.branchs.length - 1) {
  264. item.typeElse = true;
  265. } else {
  266. item.typeElse = false;
  267. }
  268. if(null != item.children && undefined != item.children){
  269. this.conditionRecursion(item.children)
  270. }else{
  271. return item;
  272. }
  273. });
  274. }
  275. this.conditionRecursion(process.children)
  276. }
  277. }
  278. }
  279. }
  280. </script>
  281. <style lang="less" scoped>
  282. .layout-body {
  283. min-width: 980px;
  284. }
  285. /deep/ .el-step {
  286. .is-success {
  287. color: #2a99ff;
  288. border-color: #2a99ff;
  289. }
  290. }
  291. .err-info{
  292. max-height: 180px;
  293. overflow-y: auto;
  294. & > div{
  295. padding: 5px;
  296. margin: 2px 0;
  297. width: 220px;
  298. text-align: left;
  299. border-radius: 3px;
  300. background: rgb(242 242 242);
  301. }
  302. i{
  303. margin: 0 5px;
  304. }
  305. }
  306. ::-webkit-scrollbar {
  307. width: 2px;
  308. height: 2px;
  309. background-color: white;
  310. }
  311. ::-webkit-scrollbar-thumb {
  312. border-radius: 16px;
  313. background-color: #e8e8e8;
  314. }
  315. </style>