index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div>
  3. <v-form-designer ref="vfDesigner" :designer-config="designerConfig">
  4. <!-- 保存按钮 -->
  5. <template #customSaveButton>
  6. <el-button type="text" @click="saveFormJson"><i class="el-icon-s-promotion" />保存</el-button>
  7. </template>
  8. </v-form-designer>
  9. <!--系统表单信息-->
  10. <el-dialog :title="formTitle" :visible.sync="formOpen" width="500px" append-to-body>
  11. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  12. <el-form-item label="表单名称" prop="formName">
  13. <el-input v-model="form.formName" placeholder="请输入表单名称" />
  14. </el-form-item>
  15. <el-form-item label="备注" prop="remark">
  16. <el-input v-model="form.remark" placeholder="请输入备注" />
  17. </el-form-item>
  18. </el-form>
  19. <div slot="footer" class="dialog-footer">
  20. <el-button type="primary" @click="submitForm">确 定</el-button>
  21. <el-button @click="cancel">取 消</el-button>
  22. </div>
  23. </el-dialog>
  24. </div>
  25. </template>
  26. <script>
  27. import { addForm, getForm, updateForm } from '@/api/flowable/form'
  28. import { StrUtil } from '@/utils/StrUtil'
  29. export default {
  30. name: 'flowForm',
  31. data() {
  32. return {
  33. formTitle: '',
  34. formOpen: false,
  35. // 表单校验
  36. rules: {
  37. formName: [
  38. { required: true, message: '表单名称不能为空', trigger: 'blur' }
  39. ]
  40. },
  41. // 表单参数
  42. form: {
  43. formId: null,
  44. formName: null,
  45. formContent: null,
  46. remark: null
  47. },
  48. designerConfig: {
  49. generateSFCButton: false,
  50. exportCodeButton: false, // 是否显示导出代码按钮
  51. toolbarMaxWidth: 320,
  52. toolbarMinWidth: 300, // 设计器工具按钮栏最小宽度(单位像素)
  53. formHeader: false
  54. }
  55. }
  56. },
  57. mounted() {
  58. const formId = this.$route.query && this.$route.query.formId
  59. if (StrUtil.isNotBlank(formId)) {
  60. getForm(formId).then(res => {
  61. this.$nextTick(() => {
  62. // 加载表单json数据
  63. this.$refs.vfDesigner.setFormJson(JSON.parse(res.data.formContent))
  64. })
  65. this.form = res.data
  66. })
  67. } else {
  68. this.$nextTick(() => {
  69. // 加载表单json数据
  70. this.$refs.vfDesigner.setFormJson({ 'widgetList': [], 'formConfig': { 'modelName': 'formData', 'refName': 'vForm', 'rulesName': 'rules', 'labelWidth': 80, 'labelPosition': 'left', 'size': '', 'labelAlign': 'label-left-align', 'cssCode': '', 'customClass': '', 'functions': '', 'layoutType': 'PC', 'onFormCreated': '', 'onFormMounted': '', 'onFormDataChange': '', 'onFormValidate': '' }})
  71. })
  72. }
  73. },
  74. methods: {
  75. // 保存表单数据
  76. saveFormJson() {
  77. const formJson = this.$refs.vfDesigner.getFormJson()
  78. this.form.formContent = JSON.stringify(formJson)
  79. this.formOpen = true
  80. },
  81. /** 提交按钮 */
  82. submitForm() {
  83. this.$refs['form'].validate(valid => {
  84. if (valid) {
  85. if (this.form.formId != null) {
  86. updateForm(this.form).then(response => {
  87. this.$modal.msgSuccess('修改成功')
  88. this.formOpen = false
  89. })
  90. } else {
  91. addForm(this.form).then(response => {
  92. this.$modal.msgSuccess('新增成功')
  93. this.formOpen = false
  94. })
  95. }
  96. // 关闭当前标签页并返回上个页面
  97. const obj = { path: '/flowable/form', query: { t: Date.now() }}
  98. this.$tab.closeOpenPage(obj)
  99. }
  100. })
  101. },
  102. // 取消按钮
  103. cancel() {
  104. this.formOpen = false
  105. this.reset()
  106. }
  107. }
  108. }
  109. </script>
  110. <style lang="scss" scoped>
  111. body {
  112. margin: 0; /* 如果页面出现垂直滚动条,则加入此行CSS以消除之 */
  113. }
  114. .el-container.main-container{
  115. background: #fff;
  116. margin-left: 0 !important;
  117. }
  118. </style>