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