Browse Source

增加自动化产生的工作流form页面

pixel 4 years ago
parent
commit
7e33276e0c

+ 4 - 4
server/initialize/workflow.go

@@ -2,14 +2,14 @@ package initialize
 
 import "gin-vue-admin/model"
 
-func initWkModel() {
+func initWorkflowModel() {
 	model.WorkflowBusinessStruct = make(map[string]func() model.GVA_Workflow)
 	model.WorkflowBusinessStruct["leave"] = func() model.GVA_Workflow {
 		return new(model.ExaWfLeaveWorkflow)
 	}
 }
 
-func initWkTable() {
+func initWorkflowTable() {
 	model.WorkflowBusinessTable = make(map[string]func() interface{})
 	model.WorkflowBusinessTable["leave"] = func() interface{} {
 		return new(model.ExaWfLeave)
@@ -17,6 +17,6 @@ func initWkTable() {
 }
 
 func InitWkMode() {
-	initWkModel()
-	initWkTable()
+	initWorkflowModel()
+	initWorkflowTable()
 }

+ 1 - 1
server/model/exa_wf_leave.go

@@ -20,6 +20,6 @@ type ExaWfLeaveWorkflow struct {
 	ExaWfLeave   `json:"business"`
 }
 
-func (e ExaWfLeave) TableName() string {
+func (ExaWfLeave) TableName() string {
 	return "exa_wf_leaves"
 }

+ 24 - 1
server/resource/template/server/model.go.tpl

@@ -19,4 +19,27 @@ type {{.StructName}} struct {
 func ({{.StructName}}) TableName() string {
   return "{{.TableName}}"
 }
-{{ end }}
+{{ end }}
+
+// 如果使用工作流功能 需要打开下方注释 并到initialize的workflow中进行注册 且必须指定TableName
+// type {{.StructName}}Workflow struct {
+// 	// 工作流操作结构体
+// 	WorkflowBase      `json:"wf"`
+// 	{{.StructName}}   `json:"business"`
+// }
+
+// func ({{.StructName}}) TableName() string {
+// 	return "{{.TableName}}"
+// }
+
+// 工作流注册代码
+
+// initWorkflowModel内部注册
+// model.WorkflowBusinessStruct["{{.Abbreviation}}"] = func() model.GVA_Workflow {
+//   return new(model.{{.StructName}}Workflow)
+// }
+
+// initWorkflowTable内部注册
+// model.WorkflowBusinessTable["{{.Abbreviation}}"] = func() interface{} {
+// 	return new(model.{{.StructName}})
+// }

+ 171 - 0
server/resource/template/web/workflowForm.vue.tpl

@@ -0,0 +1,171 @@
+<template>
+<div>
+    <el-form :model="formData" label-position="right" label-width="80px">
+        {{- range .Fields}}
+             <el-form-item label="{{.FieldDesc}}:">
+          {{- if eq .FieldType "bool" }}
+                <el-switch active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" v-model="formData.{{.FieldJson}}" clearable ></el-switch>
+          {{ end -}}
+          {{- if eq .FieldType "string" }}
+                <el-input v-model="formData.{{.FieldJson}}" clearable placeholder="请输入" ></el-input>
+          {{ end -}}
+          {{- if eq .FieldType "int" }}
+          {{- if .DictType}}
+                 <el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" clearable>
+                     <el-option v-for="(item,key) in {{ .DictType }}Options" :key="key" :label="item.label" :value="item.value"></el-option>
+                 </el-select>
+          {{ else -}}
+                 <el-input v-model.number="formData.{{ .FieldJson }}" clearable placeholder="请输入"></el-input>
+          {{ end -}}
+          {{ end -}}
+          {{- if eq .FieldType "time.Time" }}
+                  <el-date-picker type="date" placeholder="选择日期" v-model="formData.{{ .FieldJson }}" clearable></el-date-picker>
+           {{ end -}}
+           {{- if eq .FieldType "float64" }}
+                  <el-input-number v-model="formData.{{ .FieldJson }}" :precision="2" clearable></el-input-number>
+           {{ end -}}
+              </el-form-item>
+           {{ end -}}
+
+           <el-form-item>
+           <el-button v-if="this.wf.clazz == 'start'" @click="start" type="primary">启动</el-button>
+           // complete传入流转参数 决定下一步会流转到什么位置 此处可以设置多个按钮来做不同的流转
+           <el-button v-if="this.wf.clazz == 'userTask'" @click="complete('yes')" type="primary">提交</el-button>
+           <el-button @click="back" type="primary">返回</el-button>
+           </el-form-item>
+    </el-form>
+</div>
+</template>
+
+<script>
+import {
+    startWorkflow,
+    completeWorkflowMove
+} from "@/api/workflowProcess";
+import infoList from "@/mixins/infoList";
+import { mapGetters } from "vuex";
+export default {
+  name: "{{.StructName}}",
+  mixins: [infoList],
+  props:{
+      business:{
+         type:Object,
+        default:function(){return null}
+      },
+      wf:{
+        type:Object,
+        default:function(){return{}}
+      },
+      workflowMoveID:{
+        type:Number,
+        default:0
+      }
+   },
+  data() {
+    return {
+      {{- range .Fields}}
+          {{- if .DictType }}
+      {{ .DictType }}Options:[],
+          {{ end -}}
+      {{end -}}
+
+      formData: {
+            {{range .Fields}}
+            {{- if eq .FieldType "bool" -}}
+               {{.FieldJson}}:false,
+            {{ end -}}
+            {{- if eq .FieldType "string" -}}
+               {{.FieldJson}}:"",
+            {{ end -}}
+            {{- if eq .FieldType "int" -}}
+               {{.FieldJson}}:0,
+            {{ end -}}
+            {{- if eq .FieldType "time.Time" -}}
+               {{.FieldJson}}:new Date(),
+            {{ end -}}
+            {{- if eq .FieldType "float64" -}}
+               {{.FieldJson}}:0,
+            {{ end -}}
+            {{ end }}
+      }
+    };
+  },
+  computed:{
+      canShow(){
+        if(this.wf.assignType == "user"){
+          if(this.wf.assginValue.indexOf(","+this.userInfo.ID+",")>0){
+            return true
+          }else{
+            return false
+          }
+        }else if(this.wf.assign_type == "authority"){
+          if(this.wf.assginValue.indexOf(","+this.userInfo.authorityId+",")>0){
+            return true
+          }else{
+            return false
+          }
+        }
+      },
+      ...mapGetters("user", ["userInfo"])
+  },
+  methods: {
+    async start() {
+      const res = await startWorkflow({
+            business:this.formData,
+            wf:{
+              workflowMoveID:this.workflowMoveID,
+              businessId:0,
+              businessType:"{{.Abbreviation}}",
+              workflowProcessID:this.wf.workflowProcessID,
+              workflowNodeID:this.wf.id,
+              promoterID:this.userInfo.ID,
+              operatorID:this.userInfo.ID,
+              action:"create",
+              param:""
+              }
+          });
+      if (res.code == 0) {
+        this.$message({
+          type:"success",
+          message:"启动成功"
+        })
+       this.back()
+      }
+    },
+    async complete(param){
+     const res = await completeWorkflowMove({
+            business:this.formData,
+            wf:{
+              workflowMoveID:this.workflowMoveID,
+              businessID:this.formData.ID,
+              businessType:"{{.Abbreviation}}",
+              workflowProcessID:this.wf.workflowProcessID,
+              workflowNodeID:this.wf.id,
+              promoterID:this.userInfo.ID,
+              operatorID:this.userInfo.ID,
+              action:"complete",
+              param:param
+              }
+     })
+     if(res.code == 0){
+       this.$message({
+          type:"success",
+          message:"提交成功"
+       })
+       this.back()
+     }
+    },
+    back(){
+        this.$router.go(-1)
+    }
+  },
+  async created() {
+    if(this.business){
+     this.formData = this.business
+    }
+}
+};
+</script>
+
+<style>
+</style>

+ 2 - 0
server/service/sys_auto_code.go

@@ -201,6 +201,8 @@ func addAutoMoveFile(data *tplData) {
 	} else if strings.Contains(data.autoCodePath, "web") {
 		if strings.Contains(data.autoCodePath, "js") {
 			data.autoMoveFilePath = filepath.Join("../", "web", "src", dir, base)
+		} else if strings.Contains(data.autoCodePath, "workflowForm") {
+			data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), strings.TrimSuffix(base, filepath.Ext(base))+"WorkflowForm.vue")
 		} else if strings.Contains(data.autoCodePath, "form") {
 			data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), strings.TrimSuffix(base, filepath.Ext(base))+"Form.vue")
 		} else if strings.Contains(data.autoCodePath, "table") {