FormProcessDesign.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. // console.log(this.$route.query)
  84. //判断传参,决定是新建还是加载原始数据
  85. this.loadInitFrom()
  86. if (this.isNotEmpty(formId)) {
  87. this.isNew = false
  88. this.loadFormInfo(formId)
  89. }
  90. let group = this.$route.query.group
  91. this.setup.groupId = this.$isNotEmpty(group) ? parseInt(group) : null
  92. },
  93. beforeDestroy() {
  94. this.stopTimer()
  95. },
  96. methods: {
  97. loadFormInfo(formId) {
  98. getFormDetail(formId).then(rsp => {
  99. console.log(rsp.data)
  100. let form = rsp.data;
  101. form.logo = JSON.parse(form.logo)
  102. form.settings = JSON.parse(form.settings)
  103. form.formItems = JSON.parse(form.formItems)
  104. form.process = JSON.parse(form.process)
  105. this.$store.commit('loadForm', form)
  106. }).catch(err => {
  107. this.$message.error(err)
  108. })
  109. },
  110. loadInitFrom() {
  111. this.$store.commit('loadForm', {
  112. formId: null,
  113. formName: "未命名表单",
  114. logo: {
  115. icon: "el-icon-eleme",
  116. background: "#1e90ff"
  117. },
  118. settings: {
  119. commiter: [],
  120. admin: [],
  121. sign: false,
  122. notify: {
  123. types: ["APP"],
  124. title: "消息通知标题"
  125. }
  126. },
  127. groupId: undefined,
  128. formItems: [],
  129. process: {
  130. id: "root",
  131. parentId: null,
  132. type: "ROOT",
  133. name: "发起人",
  134. desc: "任何人",
  135. props: {
  136. assignedUser: [],
  137. formPerms: []
  138. },
  139. children: {}
  140. },
  141. remark: "备注说明"
  142. })
  143. },
  144. validateDesign() {
  145. console.log('000')
  146. this.validVisible = true
  147. this.validStep = 0
  148. this.showValiding()
  149. this.stopTimer()
  150. this.timer = setInterval(() => {
  151. this.validResult.errs = this.$refs[this.validComponents[this.validStep]].validate()
  152. if (Array.isArray(this.validResult.errs) && this.validResult.errs.length === 0) {
  153. this.validStep++;
  154. if (this.validStep >= this.validOptions.length) {
  155. this.stopTimer()
  156. this.showValidFinish(true)
  157. }
  158. } else {
  159. this.stopTimer()
  160. this.validOptions[this.validStep].status = 'error'
  161. this.showValidFinish(false, this.getDefaultValidErr())
  162. }
  163. }, 300)
  164. },
  165. getDefaultValidErr() {
  166. switch (this.validStep) {
  167. case 0:
  168. return '请检查基础设置项';
  169. case 1:
  170. return '请检查审批表单相关设置'
  171. case 2:
  172. return '请检查审批流程,查看对应标注节点错误信息'
  173. case 3:
  174. return '请检查扩展设置'
  175. default:
  176. return '未知错误'
  177. }
  178. },
  179. showValidFinish(success, err) {
  180. this.validResult.success = success
  181. this.validResult.finished = true
  182. this.validResult.title = success ? '校验完成 😀' : '校验失败 '
  183. this.validResult.desc = success ? '设置项校验成功,是否提交?' : err
  184. this.validResult.action = success ? '提 交' : '去修改'
  185. },
  186. showValiding() {
  187. this.validResult = {
  188. errs: [],
  189. finished: false,
  190. success: false,
  191. title: '检查中...',
  192. action: '处理',
  193. desc: '正在检查设置项'
  194. }
  195. this.validStep = 0
  196. this.validOptions.forEach(op => {
  197. op.status = ''
  198. op.icon = ''
  199. op.description = ''
  200. })
  201. },
  202. doAfter() {
  203. if (this.validResult.success) {
  204. this.doPublish()
  205. } else {
  206. this.activeSelect = this.validComponents[this.validStep]
  207. this.validVisible = false
  208. }
  209. },
  210. stopTimer() {
  211. if (this.timer) {
  212. clearInterval(this.timer)
  213. }
  214. },
  215. preview() {
  216. this.validateDesign()
  217. },
  218. publishProcess() {
  219. this.validateDesign()
  220. },
  221. doPublish() {
  222. this.$confirm('如果您只想预览请选择预览,确认发布后流程立即生效,是否继续?', '提示', {
  223. confirmButtonText: '发布',
  224. cancelButtonText: '取消',
  225. type: 'warning'
  226. }).then(() => {
  227. console.log(this.setup)
  228. let processNew = JSON.parse(JSON.stringify(this.setup.process));
  229. //判断条件分支
  230. this.conditionRecursion(processNew);
  231. let template = {
  232. formId: this.setup.formId,
  233. formName: this.setup.formName,
  234. logo: JSON.stringify(this.setup.logo),
  235. settings: JSON.stringify(this.setup.settings),
  236. groupId: this.setup.groupId,
  237. formItems: JSON.stringify(this.setup.formItems),
  238. process: JSON.stringify(processNew),
  239. remark: this.setup.remark
  240. }
  241. console.log(template);
  242. // return;
  243. if (this.isNew || !this.$isNotEmpty(this.setup.formId)) {
  244. createForm(template).then(rsp => {
  245. this.$message.success("创建表单成功")
  246. this.$router.push("/formsPanel")
  247. }).catch(err => {
  248. this.$message.error(err)
  249. })
  250. } else {
  251. updateFormDetail(template).then(rsp => {
  252. this.$message.success("更新表单成功")
  253. this.$router.push("/formsPanel")
  254. }).catch(err => {
  255. this.$message.error(err)
  256. })
  257. }
  258. })
  259. },
  260. conditionRecursion(process){
  261. if(null != process && undefined != process){
  262. if(null != process.branchs && undefined != process.branchs){
  263. process.branchs.map((item, i) => {
  264. if (i == process.branchs.length - 1) {
  265. item.typeElse = true;
  266. } else {
  267. item.typeElse = false;
  268. }
  269. if(null != item.children && undefined != item.children){
  270. this.conditionRecursion(item.children)
  271. }else{
  272. return item;
  273. }
  274. });
  275. }
  276. this.conditionRecursion(process.children)
  277. }
  278. }
  279. }
  280. }
  281. </script>
  282. <style lang="less" scoped>
  283. .layout-body {
  284. min-width: 980px;
  285. }
  286. /deep/ .el-step {
  287. .is-success {
  288. color: #2a99ff;
  289. border-color: #2a99ff;
  290. }
  291. }
  292. .err-info{
  293. max-height: 180px;
  294. overflow-y: auto;
  295. & > div{
  296. padding: 5px;
  297. margin: 2px 0;
  298. width: 220px;
  299. text-align: left;
  300. border-radius: 3px;
  301. background: rgb(242 242 242);
  302. }
  303. i{
  304. margin: 0 5px;
  305. }
  306. }
  307. ::-webkit-scrollbar {
  308. width: 2px;
  309. height: 2px;
  310. background-color: white;
  311. }
  312. ::-webkit-scrollbar-thumb {
  313. border-radius: 16px;
  314. background-color: #e8e8e8;
  315. }
  316. </style>