From 0a62aaf1aae41eafa6735be7cb73fe526d0d5736 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=AE=B8=E5=85=81=E6=9E=9E?= <3422692813@qq.com>
Date: Tue, 11 Mar 2025 14:47:44 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/views/partner/api/file.js | 10 ++
src/views/partner/file/file.vue | 200 ++++++++++++++++++++++++++++++--
2 files changed, 201 insertions(+), 9 deletions(-)
diff --git a/src/views/partner/api/file.js b/src/views/partner/api/file.js
index 9c50009..a4a2049 100644
--- a/src/views/partner/api/file.js
+++ b/src/views/partner/api/file.js
@@ -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({
diff --git a/src/views/partner/file/file.vue b/src/views/partner/file/file.vue
index 0a0534e..423f0c0 100644
--- a/src/views/partner/file/file.vue
+++ b/src/views/partner/file/file.vue
@@ -37,6 +37,15 @@
>新增
+ 批量新增
+
@@ -116,12 +125,6 @@
-
-
-
-
-
-
@@ -152,6 +155,38 @@
取 消
+
+
+
+
+
+ 点击上传
+ 只能上传jpg/png文件,且不超过500kb
+
+
+
+
+
+
+
+
+
@@ -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();
+ }
+ },
}
};