198 lines
6.0 KiB
JavaScript
198 lines
6.0 KiB
JavaScript
;
|
|
|
|
// #region
|
|
|
|
class Utils {
|
|
static request = (url, type = "GET",
|
|
data, isAsync = true,
|
|
success = () => {
|
|
}, error = (err) => {
|
|
console.log(err)
|
|
}, complete = () => {
|
|
},
|
|
contentType = 'application/json',
|
|
beforeSend = () => {
|
|
}) => {
|
|
let options = {
|
|
url,
|
|
type,
|
|
dataType: "json",
|
|
contentType,
|
|
async: isAsync,
|
|
data,
|
|
beforeSend,
|
|
success,
|
|
error,
|
|
complete,
|
|
}
|
|
if (contentType === 'application/json') {
|
|
options.data = JSON.stringify(data)
|
|
}
|
|
return $.ajax(options)
|
|
}
|
|
}
|
|
|
|
class CopyMultipleFile {
|
|
|
|
configuration = {
|
|
browseBox: "",
|
|
detailList: [{
|
|
modeFile: "",
|
|
workflowFile: ""
|
|
}],
|
|
modeTable: "",
|
|
workflowType: ""
|
|
}
|
|
oldBrowseBoxValue = null
|
|
baseInfo = {
|
|
f_weaver_belongto_userid: "1",
|
|
f_weaver_belongto_usertype: "0",
|
|
formid: 0,
|
|
isbill: "1",
|
|
languageid: 7,
|
|
nodeid: 0,
|
|
requestid: "-1",
|
|
workflowid: 0,
|
|
}
|
|
|
|
constructor(_configuration) {
|
|
this.configuration = _configuration
|
|
this.baseInfo = WfForm.getBaseInfo()
|
|
}
|
|
|
|
/**
|
|
* 转换字段名为字段id
|
|
* @param fieldName 字段名
|
|
* @returns {*} 字段id
|
|
*/
|
|
convertField2Id(fieldName) {
|
|
return WfForm.convertFieldNameToId(fieldName)
|
|
}
|
|
|
|
/**
|
|
* 绑定浏览框改变触发事件
|
|
* @param listenerField 浏览框字段
|
|
*/
|
|
bindBrowseBoxChangeEvent() {
|
|
WfForm.bindFieldChangeEvent(this.convertField2Id(this.configuration.browseBox), async (elem, id, value) => {
|
|
await this.copyFile(value)
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 复制文件逻辑
|
|
* @param value 浏览框的值
|
|
* @returns {Promise<void>}
|
|
*/
|
|
async copyFile(value) {
|
|
//为空,清除其他模板字段数据,TODO 删除文件
|
|
if ((value ?? '') === '') {
|
|
let deleteArr = []
|
|
this.configuration.detailList.forEach(item => {
|
|
let fieldId = this.convertField2Id(item.workflowFile)
|
|
deleteArr = [...wfform.getFieldValue(fieldId).split(","), ...deleteArr]
|
|
WfForm.changeFieldValue(fieldId, {
|
|
value: '',
|
|
specialobj: {
|
|
filedatas: []
|
|
}
|
|
})
|
|
})
|
|
Utils.request(`/api/browseBox/copyMultipleFile/delete/${deleteArr.join(",")}`).then((res) => {
|
|
// console.log(res)
|
|
})
|
|
return
|
|
}
|
|
//判断是否和原来的数据不同,不同则进行文件复制带出
|
|
if (value !== this.oldBrowseBoxValue) {
|
|
let copyFileParam = {
|
|
workflowType: this.baseInfo.workflowid,
|
|
requestId: this.baseInfo.requestid,
|
|
browseValue: value,
|
|
modeTable: this.configuration.modeTable,
|
|
fileMapperList: this.configuration.detailList,
|
|
queryFileInfoMap: {
|
|
listType: "list",
|
|
requestid: this.baseInfo.requestid,
|
|
desrequestid: -1,
|
|
isprint: 0,
|
|
f_weaver_belongto_userid: this.baseInfo.f_weaver_belongto_userid,
|
|
f_weaver_belongto_usertype: this.baseInfo.f_weaver_belongto_usertype,
|
|
authStr: '',
|
|
authSignatureStr: ''
|
|
},
|
|
}
|
|
ecCom.WeaLoadingGlobal.start({
|
|
tip: "文件模板复制中"
|
|
})
|
|
let result = await Utils.request("/api/browseBox/copyMultipleFile/copy", "POST", copyFileParam)
|
|
ecCom.WeaLoadingGlobal.destroy()
|
|
// console.log(result)
|
|
if (result && result.code == 200) {
|
|
let copyResult = result.data
|
|
copyResult.forEach(item => {
|
|
// 设置模板字段值
|
|
WfForm.changeFieldValue(this.convertField2Id(item.workflowFile), {
|
|
value: item.fileId,
|
|
specialobj: {
|
|
filedatas: item.fileInfo ? item.fileInfo.filedatas : []
|
|
}
|
|
})
|
|
})
|
|
} else {
|
|
antd.message.error("复制模板文件失败!")
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 强制触发一次复制
|
|
*/
|
|
mandatoryCopy() {
|
|
let browseBoxValue = WfForm.getFieldValue(this.convertField2Id(this.configuration.browseBox))
|
|
this.copyFile(browseBoxValue)
|
|
}
|
|
|
|
}
|
|
|
|
|
|
class CopyMultipleFileBuilder {
|
|
|
|
configuration = []
|
|
copyMultipleFileArr = []
|
|
|
|
|
|
constructor() {
|
|
this.workflowId = WfForm.getBaseInfo().workflowid
|
|
this.init()
|
|
}
|
|
|
|
async init() {
|
|
// 获取配置信息
|
|
let result = await Utils.request(`/api/browseBox/copyMultipleFile/getConfig/${this.workflowId}`, "GET");
|
|
if (result && result.code == 200) {
|
|
this.configuration = result.data
|
|
this.configuration.forEach(item => {
|
|
let copyMultipleFile = new CopyMultipleFile(item);
|
|
copyMultipleFile.bindBrowseBoxChangeEvent()
|
|
this.copyMultipleFileArr.push(copyMultipleFile)
|
|
})
|
|
} else {
|
|
antd.message.error("请求模板复制信息失败!")
|
|
console.log(result)
|
|
}
|
|
}
|
|
}
|
|
|
|
$(() => {
|
|
let copyMultipleFileBuilder = new CopyMultipleFileBuilder()
|
|
//绑定强制触发
|
|
window.mandatoryCopy = function () {
|
|
copyMultipleFileBuilder.copyMultipleFileArr.forEach(item => {
|
|
item.mandatoryCopy()
|
|
})
|
|
}
|
|
})
|
|
|
|
|