Commit 61b8125f authored by tianhongyang's avatar tianhongyang

fix

parent a3b5c1bc
......@@ -50,6 +50,11 @@ export default {
fileList: {
type: Array,
default: () => []
},
// 是否是演示模式
presentationModel: {
type: Boolean,
default: false
}
},
model: {
......@@ -70,6 +75,15 @@ export default {
//可访问data属性
created() {
},
beforeDestroy() {
if (this.presentationModel) {
this.comFileList.forEach(item => {
if (item?.url?.indexOf("localhost") > -1) {
URL.revokeObjectURL(item.url);
}
});
}
},
//计算集
computed: {
......@@ -92,9 +106,14 @@ export default {
if (!this.allowTypes.includes(fileType.toLowerCase())) {
return this.$message.warning(`只支持上传${this.allowTypes.join(" , ")}类型文件`);
}
// 验证通过进行上传
await this.uploadHandle(new File([file.raw], encodeURIComponent(fileName)), fileType);
this.$message.success("上传成功");
// 是否是演示模式
if (this.presentationModel) {
await this.uploadHandleLocal(file, fileType);
} else {
// 验证通过进行上传
await this.uploadHandle(new File([file.raw], encodeURIComponent(fileName)), fileType);
}
} catch (error) {
console.log(error);
} finally {
......@@ -121,9 +140,25 @@ export default {
fileName: result.data.fileName
});
this.$emit("update:fileList", this.comFileList);
this.$message.success("上传成功");
}
} catch (error) {
console.log(error);
}
},
async uploadHandleLocal(file, fileType) {
try {
const localUrl = URL.createObjectURL(file.raw);
this.comFileList.push({
url: localUrl,
type: fileType,
id: `${new Date().getTime()}${generateRandomLowerCaseLetter()}`,
fileName: file.name
});
this.$emit("update:fileList", this.comFileList);
this.$message.success("上传成功");
} catch (error) {
console.log(error);
}
},
showFileListDialog() {
......@@ -140,6 +175,9 @@ export default {
},
removeImg(row) {
if (row.id) {
if (this.presentationModel) {
return this.removeLocalImg(row.id);
}
this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
......@@ -159,6 +197,19 @@ export default {
}
}).catch(() => { });
}
},
removeLocalImg(id) {
const index = this.comFileList.findIndex(item => item.id == id);
if (index > -1) {
const url = this.comFileList[index].url;
URL.revokeObjectURL(url);
this.comFileList.splice(index, 1);
this.$emit("update:fileList", this.comFileList);
this.$message({
type: 'success',
message: '删除成功!'
});
}
}
},
}
......
......@@ -43,6 +43,7 @@
<script>
import { uploadFileToOssApi, removeFileFromOssApi } from "@/api/consultingOrgManagement";
import { elementMessageSingleton } from "@/utils";
import { generateRandomLowerCaseLetter } from "@/utils/";
export default {
name: "dskPhotoInput",
props: {
......@@ -56,6 +57,11 @@ export default {
fileList: {
type: Array,
default: () => []
},
// 是否是演示模式
presentationModel: {
type: Boolean,
default: false
}
},
model: {
......@@ -78,6 +84,15 @@ export default {
//可访问data属性
created() {
},
beforeDestroy() {
if (this.presentationModel) {
this.comFileList.forEach(item => {
if (item?.url?.indexOf("localhost") > -1) {
URL.revokeObjectURL(item.url);
}
});
}
},
//计算集
computed: {
......@@ -100,9 +115,14 @@ export default {
if (!this.allowTypes.includes(fileType.toLowerCase())) {
return this.$message.warning(`只支持上传${this.allowTypes.join(" , ")}类型图片`);
}
// 验证通过进行上传
await this.uploadHandle(new File([file.raw], encodeURIComponent(fileName)), fileType);
this.$message.success("上传成功");
// 是否是演示模式
if (this.presentationModel) {
await this.uploadHandleLocal(file, fileType);
} else {
// 验证通过进行上传
await this.uploadHandle(new File([file.raw], encodeURIComponent(fileName)), fileType);
}
} catch (error) {
console.log(error);
} finally {
......@@ -129,11 +149,27 @@ export default {
fileName: result.data.fileName
});
this.$emit("update:fileList", this.comFileList);
this.$message.success("上传成功");
}
} catch (error) {
}
},
async uploadHandleLocal(file, fileType) {
try {
const localUrl = URL.createObjectURL(file.raw);
this.comFileList.push({
url: localUrl,
type: fileType,
id: `${new Date().getTime()}${generateRandomLowerCaseLetter()}`,
fileName: file.name
});
this.$emit("update:fileList", this.comFileList);
this.$message.success("上传成功");
} catch (error) {
console.log(error);
}
},
showFileListDialog() {
this.fileListDialog = true;
},
......@@ -152,6 +188,9 @@ export default {
},
removeImg(row) {
if (row.id) {
if (this.presentationModel) {
return this.removeLocalImg(row.id);
}
this.$confirm('此操作将永久删除该图片, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
......@@ -171,6 +210,19 @@ export default {
}
}).catch(() => { });
}
},
removeLocalImg(id) {
const index = this.comFileList.findIndex(item => item.id == id);
if (index > -1) {
const url = this.comFileList[index].url;
URL.revokeObjectURL(url);
this.comFileList.splice(index, 1);
this.$emit("update:fileList", this.comFileList);
this.$message({
type: 'success',
message: '删除成功!'
});
}
}
},
}
......
......@@ -1020,3 +1020,13 @@ export function replaceDomTags(str) {
const reg = /<[^>]*>/gmi;
return str.replace(reg, "");
}
/**
* 生成随机字母
* @returns
*/
export function generateRandomLowerCaseLetter() {
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
const randomIndex = Math.floor(Math.random() * alphabet.length);
return alphabet[randomIndex];
}
......@@ -29,10 +29,10 @@
:clearable="true" :disabled="isDisabled" v-if="comChildModuleInfo.comType == 'email'"></dsk-email-input>
<!-- 图片类型 -->
<dsk-photo-input v-model="comChildModuleInfo.componentAttribute.value" :disabled="isDisabled" v-if="comChildModuleInfo.comType == 'photo'"
:limit="comChildModuleInfo.formAttribute.limit"></dsk-photo-input>
:limit="comChildModuleInfo.formAttribute.limit" :presentationModel="true"></dsk-photo-input>
<!-- 文件类型 -->
<dsk-file-input v-model="comChildModuleInfo.componentAttribute.value" :disabled="isDisabled" v-if="comChildModuleInfo.comType == 'file'"
:limit="comChildModuleInfo.formAttribute.limit"></dsk-file-input>
:limit="comChildModuleInfo.formAttribute.limit" :presentationModel="true"></dsk-file-input>
</el-form-item>
<img src="@/assets/images/consultingAgencyManagement/customForm/icon_delete@2x.png" alt="" class="remove-subfield-item-icon"
......
......@@ -314,23 +314,25 @@ export default {
}
},
hasCustomFormDataHandle(formTemplate, formData) {
// console.log(formTemplate);
// console.log(formData);
formTemplate.forEach(item => {
this.interComTemplateParent(formData, item);
const _template = cloneDeep(formTemplate);
const _result = _template.map(moduleItem => {
return this.interComTemplateParent(formData, moduleItem);
});
return cloneDeep(formTemplate);
return cloneDeep(_result);
},
interComTemplateParent(formData, module) {
const hasTemplateModule = formData.find(item => item.pid === module.uid);
// 数据能找到关联模块
if (hasTemplateModule) {
const index = module.children.findIndex(child => child.uid === hasTemplateModule.uid);
// 找到模板 插入数据
if (index > -1) {
module.children[index].componentAttribute.value = hasTemplateModule.componentAttribute.value;
}
const hasTemplateModuleArray = formData.filter(item => item.pid === module.uid);
// 找到当前模板下 关联的数据
if (hasTemplateModuleArray?.length) {
hasTemplateModuleArray.forEach(dataItem => {
const index = module.children.findIndex(child => child.uid === dataItem.uid);
// 找到模板 插入数据
if (index > -1) {
module.children[index].componentAttribute.value = dataItem.componentAttribute.value;
}
});
}
return module;
},
renderTemplate(template) {
const table = this.createTemplateTable(template);
......@@ -678,6 +680,9 @@ export default {
border-radius: unset;
border-color: transparent;
color: #232323;
font-size: 12px;
font-weight: 400;
font-family: Arial, Helvetica, sans-serif;
&:focus {
border: 1px solid #0081ff;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment