This commit is contained in:
许允枞 2025-03-11 14:47:44 +08:00
parent 7523444595
commit 0a62aaf1aa
2 changed files with 201 additions and 9 deletions

View File

@ -65,6 +65,16 @@ export function addInspectionFile(data) {
})
}
// 新增inspectionFile
export function addBatchInspectionFile(data) {
return request({
url: '/inspectionFile/inspectionFile/addBatch',
method: 'post',
data: data
})
}
// 修改inspectionFile
export function updateInspectionFile(data) {
return request({

View File

@ -37,6 +37,15 @@
>新增
</el-button>
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAddBatch"
>批量新增
</el-button>
</el-col>
<el-col :span="1.5">
@ -116,12 +125,6 @@
<!-- 添加或修改inspectionFile对话框 -->
<el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<!-- <el-form-item label="店铺主键" prop="partnerId">-->
<!-- <el-input v-model="form.partnerId" placeholder="请输入店铺主键" />-->
<!-- </el-form-item>-->
<!-- <el-form-item label="父节点" prop="fatherId">-->
<!-- <el-input v-model="form.fatherId" placeholder="请输入父节点" />-->
<!-- </el-form-item>-->
<el-form-item label="文件名称" prop="fileName">
<el-input v-model="form.fileName" placeholder="请输入文件名称"/>
</el-form-item>
@ -152,6 +155,38 @@
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
<!-- 批量添加-->
<el-dialog title="批量新增" :visible.sync="openBatch" width="600px" append-to-body>
<el-form ref="formBatch" :model="form" :rules="rules" label-width="120px">
<el-form-item label="文件路径" prop="fileList">
<el-upload
class="upload-demo"
:action="uploadFileUrl"
multiple
:on-error="handleUploadError"
:on-exceed="handleExceed"
:on-success="handleUploadSuccess"
:before-upload="handleBeforeUpload"
:headers="headers"
:file-list="fileList">
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件且不超过500kb</div>
</el-upload>
</el-form-item>
<el-form-item label="提醒时间" prop="warnTime">
<el-date-picker clearable
v-model="form.warnTime"
type="date"
value-format="yyyy-MM-dd"
placeholder="请选择提醒时间">
</el-date-picker>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitBatchForm"> </el-button>
<el-button @click="cancelBatch"> </el-button>
</div>
</el-dialog>
</div>
</template>
@ -161,19 +196,29 @@ import {
getInspectionFile,
delInspectionFile,
addInspectionFile,
updateInspectionFile, listStaff, assignAuthority, getUserIdsByFileId, listByPermission, getFileRecord
updateInspectionFile,
listStaff,
assignAuthority,
getUserIdsByFileId,
listByPermission,
getFileRecord,
addBatchInspectionFile
} from "../api/file";
import inspFileUpload from '@/components/FileUpload/index.vue'
import {getAccessToken} from "@/utils/auth";
export default {
name: "InspectionFile",
components: {inspFileUpload},
data() {
return {
uploadFileUrl: process.env.VUE_APP_BASE_API + "/admin-api/infra/file/uploadDetail",
//
loading: true,
//
ids: [],
fileList:[],
headers: { Authorization: "Bearer " + getAccessToken() }, //
//
single: true,
//
@ -189,10 +234,13 @@ export default {
drawer: false,
//
open: false,
openBatch: false,
//
isShow: false,
//
daterangeWarnTime: [],
number: 0,
uploadList:[],
//
queryParams: {
pageNum: 1,
@ -205,7 +253,25 @@ export default {
//
form: {},
//
rules: {},
rules: {
fileList: [
{
required: false,
message: "文件路径不能为空",
trigger: "blur"
},
{
validator: (rule, value, callback) => {
if (!value || value.length === 0) {
callback(new Error("请至少上传一个文件"));
} else {
callback();
}
},
trigger: "change"
}
]
},
//
staffList: [],
selectStaffList: [],
@ -343,6 +409,11 @@ export default {
this.open = false;
this.reset();
},
//
cancelBatch() {
this.openBatch = false;
this.resetBatch();
},
//
reset() {
this.form = {
@ -360,6 +431,24 @@ export default {
};
this.resetForm("form");
},
//
resetBatch() {
this.form = {
id: null,
partnerId: null,
type: null,
fatherId: null,
fileName: null,
filePath: null,
warnTime: null,
createTime: null,
createBy: null,
updateTime: null,
updateBy: null
};
this.fileList = []
this.resetForm("formBatch");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
@ -383,6 +472,12 @@ export default {
this.open = true;
this.title = "新增";
},
/** 批量新增按钮操作 */
handleAddBatch() {
this.resetBatch();
this.openBatch = true;
this.title = "新增";
},
handleE(item) {
this.reset(item);
this.form = item;
@ -424,6 +519,26 @@ export default {
}
});
},
/** 提交按钮 */
submitBatchForm() {
console.log(this.form,'内容')
console.log(this.fileList,'文件')
this.$refs["formBatch"].validate(valid => {
this.fileList.forEach(item => {
item.fatherId = this.fatherId
item.type = '2'
item.fileName = this.getFileNameWithoutExtension(item.name)
item.filePath = item.url
item.warnTime = this.form.warnTime
})
addBatchInspectionFile(this.fileList).then(res => {
this.$modal.msgSuccess("新增成功");
this.openBatch = false
this.resetBatch()
this.getList();
})
});
},
/** 分配文件权限给对应用户 */
saveStaff() {
console.log(this.selectStaffList, "66666666666666")
@ -452,6 +567,10 @@ export default {
}).catch(() => {
});
},
getFileNameWithoutExtension(filename) {
if (!filename.includes('.')) return filename; //
return filename.substring(0, filename.lastIndexOf('.'));
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
@ -468,7 +587,70 @@ export default {
this.download('inspectionFile/inspectionFile/export', {
...this.queryParams
}, `inspectionFile_${new Date().getTime()}.xlsx`)
}
},
//
handleBeforeUpload(file) {
//
if (this.fileType) {
let fileExtension = "";
if (file.name.lastIndexOf(".") > -1) {
fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1);
}
const isTypeOk = this.fileType.some((type) => {
if (file.type.indexOf(type) > -1) return true;
if (fileExtension && fileExtension.indexOf(type) > -1) return true;
return false;
});
if (!isTypeOk) {
this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`);
return false;
}
}
//
if (this.fileSize) {
const isLt = file.size / 1024 / 1024 < this.fileSize;
if (!isLt) {
this.$modal.msgError(`上传文件大小不能超过 ${this.fileSize} MB!`);
return false;
}
}
this.$modal.loading("正在上传文件,请稍候...");
this.number++;
return true;
},
//
handleExceed() {
this.$modal.msgError(`上传文件数量不能超过 ${this.limit} 个!`);
},
//
handleUploadError(err) {
this.$modal.msgError("上传图片失败,请重试");
this.$modal.closeLoading()
},
//
handleUploadSuccess(res, file) {
if (res.code === 0) {
// edit by
this.uploadList.push({ name: res.data.name, url: res.data.url });
this.uploadedSuccessfully();
} else {
this.number--;
this.$modal.closeLoading();
this.$modal.msgError(res.msg);
this.$refs.fileUpload.handleRemove(file);
this.uploadedSuccessfully();
}
},
//
uploadedSuccessfully() {
if (this.number > 0 && this.uploadList.length === this.number) {
this.fileList = this.fileList.concat(this.uploadList);
this.uploadList = [];
this.number = 0;
// this.$emit("input", this.listToString(this.fileList));
this.$modal.closeLoading();
}
},
}
};
</script>