item.name === this.activeMenu)?.key;
+ return notDetailMode && (showAlways || ((editMode || addMode) && permission)) && currentMenuKey === "info";
},
+
resetForm(excludeId = false, immediate = false) {
setTimeout(
() => {
@@ -399,7 +412,7 @@ export default {
},
/** init **/
- init(id, detailMode) {
+ init(id, detailMode, menu) {
// this.dialogVisible = true;
if (this.$refs.dataForm && this.$refs.dataForm.length) {
// 当不是首次渲染dialog的时候,一开始就清空验证信息,本组件的循环里只有一个 dataForm 所以只用取 [0] 即可
@@ -434,6 +447,10 @@ export default {
}
}
this.loadingStatus = false;
+ // 是否要跳转到附件页
+ if (menu && menu.key === "attachment") {
+ this.activeMenu = this.configs.menu.find((item) => item.key === menu.key)?.name;
+ }
});
} else {
// 如果不是编辑
@@ -445,31 +462,97 @@ export default {
/** handlers */
handleFileClick(type, file) {
switch (type) {
- case "view":
- break;
- case "download": {
- /** 通知 */
- this.$notify({
- title: "成功",
- message: "开始下载",
- type: "success",
- });
+ case "view": {
+ // 加载图片
+ this.$http
+ .get("/pms/attachment/downloadFile", {
+ params: {
+ attachmentId: file.id,
+ type: 0, // 0 预览,1 下载
+ },
+ responseType: "blob",
+ })
+ .then(({ data: res }) => {
+ console.log("preivew", res);
+ if (/image/i.test(res.type)) {
+ // 显示图片
+ this.currentImgUrl = URL.createObjectURL(res);
+ this.imgPreviewDialogVisible = true;
+ } else {
+ this.$message({
+ message: "非图片文件请下载后预览",
+ type: "error",
+ duration: 1500,
+ });
+ }
+ });
break;
}
- case "delete": {
- console.log("deleting", file);
- const { id } = file;
- this.fileList = this.fileList.filter((f) => f.id !== id);
- this.updateRemoteFiles().then((res) => {
- /** 通知 */
- this.$notify({
- title: "成功",
- message: "已删除",
- type: "success",
+
+ case "download": {
+ // 下载图片
+ this.$http
+ .get("/pms/attachment/downloadFile", {
+ params: {
+ attachmentId: file.id,
+ type: 1, // 0 预览,1 下载
+ },
+ responseType: "blob",
+ })
+ .then(({ data: res }) => {
+ const blob = new Blob([res]);
+
+ /** 通知 */
+ this.$notify({
+ title: "成功",
+ message: "开始下载",
+ type: "success",
+ duration: 1200,
+ });
+
+ if ("download" in document.createElement("a")) {
+ const alink = document.createElement("a");
+ alink.download = file.name;
+ alink.style.display = "none";
+ alink.target = "_blank";
+ alink.href = URL.createObjectURL(blob);
+ document.body.appendChild(alink);
+ alink.click();
+ URL.revokeObjectURL(alink.href);
+ document.body.removeChild(alink);
+ } else {
+ navigator.msSaveBlob(blob, fileName);
+ }
});
- });
+
break;
}
+
+ case "delete": {
+ return this.$confirm(`确定删除图片: ${file.name}`, "提示", {
+ confirmButtonText: "确认",
+ cancelButtonText: "我再想想",
+ type: "warning",
+ })
+ .then(() => {
+ this.loadingStatus = true;
+ const newFilelist = this.fileList.filter((f) => f.id !== file.id);
+ this.updateRemoteFiles(newFilelist).then((msg) => {
+ if (msg && msg === "success") {
+ this.fileList = newFilelist;
+ this.loadingStatus = false;
+ /** 通知 */
+ this.$notify({
+ title: "成功",
+ message: "已删除",
+ type: "success",
+ duration: 1200,
+ });
+ }
+ });
+ })
+ .catch((err) => {});
+ }
}
},
@@ -485,31 +568,47 @@ export default {
typeCode: file.typeCode,
};
- this.fileList.push(fileItem);
- /** 通知 */
- this.$notify({
- title: "成功",
- message: "上传成功",
- type: "success",
+ this.loadingStatus = true;
+ this.updateRemoteFiles([...this.fileList, fileItem]).then((msg) => {
+ if (msg && msg === "success") {
+ this.fileList.push(fileItem);
+ this.loadingStatus = false;
+ /** 通知 */
+ this.$notify({
+ title: "成功",
+ message: "上传成功",
+ type: "success",
+ duration: 1200,
+ });
+ }
});
-
- this.updateRemoteFiles();
}
},
- updateRemoteFiles() {
+ updateRemoteFiles(filelist) {
return this.$http
.put("/pms/product", {
id: "id" in this.dataForm ? this.dataForm.id : "DEFAULT_ID",
- // code: "code" in this.dataForm ? this.dataForm.code : "DEFAULT_CODE",
- // ...this.dataForm,
- fileIds: this.fileList.map((f) => f.id),
+ fileIds: filelist.map((f) => f.id),
})
.then(({ data: res }) => {
- console.log("updateFileList", this.fileList, res);
+ if (res.code === 0) return "success";
});
},
+ handleUploadCheck(file) {
+ console.log("[before upload]", file);
+ const LIMIT = 2 * 1024 * 1024; // bytes
+ if (file.size > LIMIT) {
+ this.$message({
+ message: "文件大小不能超过 2MB",
+ type: "error",
+ duration: 1500,
+ });
+ return false;
+ } else return true;
+ },
+
handleComponentModelUpdate(propName, { subject, payload: { data } }) {
this.dataForm[propName] = JSON.stringify(data);
console.log("[DialogJustForm] handleComponentModelUpdate", this.dataForm[propName]);
@@ -538,6 +637,15 @@ export default {
// 如果通过验证
this.loadingStatus = true;
const method = payload.name === "add" ? "POST" : "PUT";
+
+ // 判断是否有附件选项
+ const hasAttachment = !!this.configs.menu.find((item) => item.key === "attachment");
+ if (hasAttachment) {
+ const fileIds = this.fileList.map((item) => item.id);
+ this.$set(this.dataForm, "fileIds", fileIds);
+ }
+
+ // 实际发送请求
this.$http({
url: this.urls.base,
method,
@@ -555,15 +663,11 @@ export default {
if (this.loadingStatus) this.loadingStatus = false;
});
} else {
- // 没有通过验证
- // this.$message.error(JSON.stringify(result));
this.$message.error("请核查字段信息");
}
});
}
}
- } else {
- console.log("[x] 不是这么用的! 缺少name属性");
}
},
handleTabClick(payload) {
@@ -764,4 +868,7 @@ ul.file-list > li:hover {
width: 16px;
height: 16px;
}
+
+/* .image-preview-dialog {
+} */
diff --git a/src/components/README.config.md b/src/components/README.config.md
deleted file mode 100644
index af95d2e..0000000
--- a/src/components/README.config.md
+++ /dev/null
@@ -1,2 +0,0 @@
-配置文件选项总结
-
diff --git a/src/components/noTemplateComponents/textBtn.js b/src/components/noTemplateComponents/textBtn.js
deleted file mode 100644
index 5cf2ac1..0000000
--- a/src/components/noTemplateComponents/textBtn.js
+++ /dev/null
@@ -1,2 +0,0 @@
-// 表格中的可点击文本
-export default {}
\ No newline at end of file
diff --git a/src/components/uploadBtn/components/FileList.vue b/src/components/uploadBtn/components/FileList.vue
index db7751a..dba512a 100644
--- a/src/components/uploadBtn/components/FileList.vue
+++ b/src/components/uploadBtn/components/FileList.vue
@@ -53,8 +53,8 @@ export default {
},
detailMode: {
type: Boolean,
- default: false
- }
+ default: false,
+ },
},
data() {
return {
@@ -83,9 +83,19 @@ export default {
attachmentId: file.id,
type: 1,
},
+ responseType: "blob",
})
.then(({ data: res }) => {
const blob = new Blob([res]);
+
+ /** 通知 */
+ this.$notify({
+ title: "成功",
+ message: "开始下载",
+ type: "success",
+ duration: 1200,
+ });
+
if ("download" in document.createElement("a")) {
const alink = document.createElement("a");
alink.download = file.name;
diff --git a/src/components/uploadBtn/index.vue b/src/components/uploadBtn/index.vue
index c78fc85..61b6204 100644
--- a/src/components/uploadBtn/index.vue
+++ b/src/components/uploadBtn/index.vue
@@ -8,6 +8,7 @@
:show-file-list="false"
:headers="uploadHeaders"
:on-success="handleUploadSuccess"
+ :before-upload="handleUploadCheck"
>
{{ buttonText }}
@@ -42,7 +43,7 @@ export default {
tips: {
type: Object,
default: () => ({
- hint: "只能上传jpg/png文件, 且不超过500kb",
+ hint: "文件大小不超过 2MB",
success: "上传成功!",
}),
},
@@ -64,14 +65,9 @@ export default {
return { showMsg: false, uploadedFileList: [] };
},
watch: {
- // fileList: {
- // handler: (arr) => {
- // if (arr && arr.length > 0) {
- // this.uploadedFileList = arr;
- // }
- // },
- // immediate: true,
- // },
+ fileList(val) {
+ this.uploadedFileList = val ?? [];
+ }
},
computed: {
uploadHeaders() {
@@ -103,6 +99,18 @@ export default {
.catch(() => {});
},
+ handleUploadCheck(file) {
+ const LIMIT = 2 * 1024 * 1024; // bytes
+ if (file.size > LIMIT) {
+ this.$message({
+ message: "文件大小不能超过 2MB",
+ type: "error",
+ duration: 1500,
+ });
+ return false;
+ } else return true;
+ },
+
handleUploadSuccess(response, file, fileList) {
console.log("[UploadBtn] uploadedFileList", response, file, fileList, this.uploadedFileList);
@@ -115,13 +123,6 @@ export default {
typeCode: file.typeCode,
};
- /** 通知 */
- this.$notify({
- title: "成功",
- message: "上传成功",
- type: "success",
- });
-
this.uploadedFileList.push(fileItem);
this.$emit("update-file-list", this.uploadedFileList);
// this.showMsg = true;
diff --git a/src/views/atomViews/ListViewWithHead.vue b/src/views/atomViews/ListViewWithHead.vue
index c887529..896901e 100644
--- a/src/views/atomViews/ListViewWithHead.vue
+++ b/src/views/atomViews/ListViewWithHead.vue
@@ -224,12 +224,12 @@ export default {
break;
}
case "status": {
- console.log('status', data)
+ console.log("status", data);
// TODO: 类似于这种字符串,可以统一集中到一个文件里
const { id, code } = data;
const queryCondition = { id, code };
- if ("enabled" in data) queryCondition.enabled = data['enabled'];
- if ("status" in data) queryCondition.status = data['status'];
+ if ("enabled" in data) queryCondition.enabled = data["enabled"];
+ if ("status" in data) queryCondition.status = data["status"];
// 更改状态,更改状态需要 id 和 code 然后是 状态 enabled
this.$http.put(this.urls.base, queryCondition).then(({ data: res }) => {
if (res.code === 0) {
@@ -238,6 +238,9 @@ export default {
});
break;
}
+ case "view-attachment": {
+ this.openDialog(data, false, { key: "attachment" });
+ }
}
},
@@ -268,11 +271,11 @@ export default {
},
/** 打开对话框 */
- openDialog(row_id, detail_mode) {
+ openDialog(row_id, detail_mode, tag_info) {
this.dialogVisible = true;
this.$nextTick(() => {
- this.$refs["edit-dialog"].init(/** some args... */ row_id, detail_mode);
+ this.$refs["edit-dialog"].init(/** some args... */ row_id, detail_mode, tag_info);
});
},
},
diff --git a/src/views/modules/pms/product/config.js b/src/views/modules/pms/product/config.js
index 6f17e23..f4fc98b 100644
--- a/src/views/modules/pms/product/config.js
+++ b/src/views/modules/pms/product/config.js
@@ -15,7 +15,7 @@ export default function () {
{ prop: "weight", label: "重量", filter: (val) => (val ? val + " kg" : "-") },
{ prop: "processTime", label: "产线完成单位产品用时", width: 200, filter: (val) => val + " s" },
{ prop: "remark", label: "备注" },
- { prop: "description", label: "附件信息", subcomponent: TableTextComponent, buttonContent: "查看附件" },
+ { prop: "description", label: "附件信息", subcomponent: TableTextComponent, buttonContent: "查看附件", actionName: 'view-attachment' },
{
prop: "operations",
name: "操作",