Commit c410240ed545374375c6073e3f74ddf39ad41878
1 parent
2b4ff2ae
修复 form generator 组件上传文件、图片报错的问题
Showing
5 changed files
with
50 additions
and
7 deletions
yudao-ui-admin/src/components/generator/config.js
| @@ -499,7 +499,8 @@ export const selectComponents = [ | @@ -499,7 +499,8 @@ export const selectComponents = [ | ||
| 499 | __slot__: { | 499 | __slot__: { |
| 500 | 'list-type': true | 500 | 'list-type': true |
| 501 | }, | 501 | }, |
| 502 | - action: process.env.VUE_APP_BASE_API + "/admin-api/infra/file/upload", // 请求地址 | 502 | + // action: process.env.VUE_APP_BASE_API + "/admin-api/infra/file/upload", // 请求地址 |
| 503 | + action: '/infra/file/upload', // 请求地址 | ||
| 503 | disabled: false, | 504 | disabled: false, |
| 504 | accept: '', | 505 | accept: '', |
| 505 | name: 'file', | 506 | name: 'file', |
yudao-ui-admin/src/components/parser/Parser.vue
| 1 | <script> | 1 | <script> |
| 2 | import { deepClone } from '@/utils/index' | 2 | import { deepClone } from '@/utils/index' |
| 3 | import render from '@/components/render/render.js' | 3 | import render from '@/components/render/render.js' |
| 4 | +import {getAccessToken} from "@/utils/auth"; | ||
| 4 | 5 | ||
| 5 | const ruleTrigger = { | 6 | const ruleTrigger = { |
| 6 | 'el-input': 'blur', | 7 | 'el-input': 'blur', |
| @@ -79,10 +80,51 @@ function formBtns(h) { | @@ -79,10 +80,51 @@ function formBtns(h) { | ||
| 79 | } | 80 | } |
| 80 | 81 | ||
| 81 | function renderFormItem(h, elementList) { | 82 | function renderFormItem(h, elementList) { |
| 83 | + const that = this | ||
| 84 | + const data = this[this.formConf.formModel] | ||
| 85 | + // const formRef = that.$refs[that.formConf.formRef] // 这里直接添加有问题,此时还找不到表单 $refs | ||
| 82 | return elementList.map(scheme => { | 86 | return elementList.map(scheme => { |
| 83 | const config = scheme.__config__ | 87 | const config = scheme.__config__ |
| 84 | const layout = layouts[config.layout] | 88 | const layout = layouts[config.layout] |
| 85 | 89 | ||
| 90 | + // edit by 芋道源码,解决 el-upload 上传的问题 | ||
| 91 | + // 参考 https://github.com/JakHuang/form-generator/blob/master/src/components/parser/example/Index.vue 实现 | ||
| 92 | + const vModel = scheme.__vModel__ | ||
| 93 | + const val = data[vModel] | ||
| 94 | + if (scheme.__config__.tag === 'el-upload') { | ||
| 95 | + // 回显图片 | ||
| 96 | + scheme['file-list'] = (val || []).map(url => ({ name: url, url })) | ||
| 97 | + // 上传地址 + 请求头 | ||
| 98 | + scheme.action = process.env.VUE_APP_BASE_API + "/admin-api/infra/file/upload" | ||
| 99 | + scheme.headers = { Authorization: "Bearer " + getAccessToken() } | ||
| 100 | + // 注意 on-success 不能绑定箭头函数!!! | ||
| 101 | + scheme['on-success'] = function (response, file, fileList) { | ||
| 102 | + if (response.code !== 0) { | ||
| 103 | + return; | ||
| 104 | + } | ||
| 105 | + // 添加到 data 中 | ||
| 106 | + const prev = data[vModel] || [] | ||
| 107 | + this.$set(data, vModel, [ | ||
| 108 | + ...prev, | ||
| 109 | + response.data | ||
| 110 | + ]) | ||
| 111 | + // 发起表单校验 | ||
| 112 | + that.$refs[that.formConf.formRef].validateField(vModel) | ||
| 113 | + } | ||
| 114 | + // 注意 on-remove 不能绑定箭头函数!!! | ||
| 115 | + scheme['on-remove'] = function (file, fileList) { | ||
| 116 | + // 移除从 data 中 | ||
| 117 | + const prev = data[vModel] || [] | ||
| 118 | + const index = prev.indexOf(file.response.data) | ||
| 119 | + if (index === -1) { | ||
| 120 | + return | ||
| 121 | + } | ||
| 122 | + prev.splice(index, 1) // 直接移除即可,无需重复 set,因为 array 是引用 | ||
| 123 | + // 发起表单校验 | ||
| 124 | + that.$refs[that.formConf.formRef].validateField(vModel) | ||
| 125 | + } | ||
| 126 | + } | ||
| 127 | + | ||
| 86 | if (layout) { | 128 | if (layout) { |
| 87 | return layout.call(this, h, scheme) | 129 | return layout.call(this, h, scheme) |
| 88 | } | 130 | } |
yudao-ui-admin/src/main.js
| @@ -69,8 +69,9 @@ import "bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css"; | @@ -69,8 +69,9 @@ import "bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css"; | ||
| 69 | import Tinymce from '@/components/tinymce/index.vue' | 69 | import Tinymce from '@/components/tinymce/index.vue' |
| 70 | Vue.component('tinymce', Tinymce) | 70 | Vue.component('tinymce', Tinymce) |
| 71 | import '@/icons' | 71 | import '@/icons' |
| 72 | -import axios from 'axios' | ||
| 73 | -Vue.prototype.$axios = axios | 72 | +import request from "@/utils/request" // 实现 form generator 使用自己定义的 axios request 对象 |
| 73 | +console.log(request) | ||
| 74 | +Vue.prototype.$axios = request | ||
| 74 | import '@/styles/index.scss' | 75 | import '@/styles/index.scss' |
| 75 | 76 | ||
| 76 | /** | 77 | /** |
yudao-ui-admin/src/views/bpm/model/index.vue
| @@ -429,7 +429,7 @@ export default { | @@ -429,7 +429,7 @@ export default { | ||
| 429 | this.$modal.confirm('是否删除该流程!!').then(function() { | 429 | this.$modal.confirm('是否删除该流程!!').then(function() { |
| 430 | deleteModel(row.id).then(response => { | 430 | deleteModel(row.id).then(response => { |
| 431 | that.getList(); | 431 | that.getList(); |
| 432 | - that.msgSuccess("删除成功"); | 432 | + that.$modal.msgSuccess("删除成功"); |
| 433 | }) | 433 | }) |
| 434 | }).catch(() => {}); | 434 | }).catch(() => {}); |
| 435 | }, | 435 | }, |
| @@ -439,7 +439,7 @@ export default { | @@ -439,7 +439,7 @@ export default { | ||
| 439 | this.$modal.confirm('是否部署该流程!!').then(function() { | 439 | this.$modal.confirm('是否部署该流程!!').then(function() { |
| 440 | deployModel(row.id).then(response => { | 440 | deployModel(row.id).then(response => { |
| 441 | that.getList(); | 441 | that.getList(); |
| 442 | - that.msgSuccess("部署成功"); | 442 | + that.$modal.msgSuccess("部署成功"); |
| 443 | }) | 443 | }) |
| 444 | }).catch(() => {}); | 444 | }).catch(() => {}); |
| 445 | }, | 445 | }, |
yudao-ui-admin/src/views/bpm/processInstance/create.vue
| @@ -55,10 +55,9 @@ | @@ -55,10 +55,9 @@ | ||
| 55 | <script> | 55 | <script> |
| 56 | import {getProcessDefinitionBpmnXML, getProcessDefinitionList} from "@/api/bpm/definition"; | 56 | import {getProcessDefinitionBpmnXML, getProcessDefinitionList} from "@/api/bpm/definition"; |
| 57 | import {DICT_TYPE, getDictDatas} from "@/utils/dict"; | 57 | import {DICT_TYPE, getDictDatas} from "@/utils/dict"; |
| 58 | -import {getForm} from "@/api/bpm/form"; | ||
| 59 | import {decodeFields} from "@/utils/formGenerator"; | 58 | import {decodeFields} from "@/utils/formGenerator"; |
| 60 | import Parser from '@/components/parser/Parser' | 59 | import Parser from '@/components/parser/Parser' |
| 61 | -import {createProcessInstance, getMyProcessInstancePage} from "@/api/bpm/processInstance"; | 60 | +import {createProcessInstance} from "@/api/bpm/processInstance"; |
| 62 | 61 | ||
| 63 | // 流程实例的发起 | 62 | // 流程实例的发起 |
| 64 | export default { | 63 | export default { |