Commit a1e3e972 by 黄燕娟

fix:文件上传

parent a2415598
# 开发环境配置 # 开发环境配置
VUE_APP_MODE = 'test' VUE_APP_MODE = 'test'
VUE_APP_BASE_API = '/api' VUE_APP_BASE_API = 'http://sz-tianma.meiqicloud.com/api'
VITE_AXIOS_API_PRIMARY = 'http://rapidplatform.meiqicloud.com/api' VITE_AXIOS_API_PRIMARY = 'http://rapidplatform.meiqicloud.com/api'
VUE_APP_SERVER_URL = 'http://sz-tianma.meiqicloud.com/api' VUE_APP_SERVER_URL = 'http://sz-tianma.meiqicloud.com/api'
...@@ -46,7 +46,7 @@ axios.interceptors.response.use( ...@@ -46,7 +46,7 @@ axios.interceptors.response.use(
(response) => { (response) => {
console.log('response', response) console.log('response', response)
let { code } = response.data; let { code } = response.data;
if (code === 501) { if (code === 113) {
window.parent.postMessage( window.parent.postMessage(
{ text: "子页面发消息给父页面", type: "token-past-due" }, { text: "子页面发消息给父页面", type: "token-past-due" },
"*" "*"
...@@ -61,9 +61,9 @@ axios.interceptors.response.use( ...@@ -61,9 +61,9 @@ axios.interceptors.response.use(
(error) => { (error) => {
console.log('error', error) console.log('error', error)
if (!error.response) return Promise.reject(error); if (!error.response) return Promise.reject(error);
const { code, data, config } = error.response; const { status, data, config } = error.response;
switch (code) { switch (status) {
// 需要重新登录 // 需要重新登录
case 401: { case 401: {
break; break;
......
...@@ -27,7 +27,7 @@ export function userGroupPage(params) { ...@@ -27,7 +27,7 @@ export function userGroupPage(params) {
// 文件上传 // 文件上传
export function sysUpload(params) { export function sysUpload(params) {
return request({ return request({
url: `/a/sys/upload`, url: `/a/sys/file/uploadFile`,
method: 'post', method: 'post',
data: params data: params
}) })
......
...@@ -85,20 +85,15 @@ export default { ...@@ -85,20 +85,15 @@ export default {
let formData = new FormData(); let formData = new FormData();
formData.append("file", blobInfo.blob(), blobInfo.filename()); formData.append("file", blobInfo.blob(), blobInfo.filename());
formData.append("isImg", true); formData.append("isImg", true);
axios
.post(this.uploadUrl, formData, { sysUpload(formData)
"Content-type": "multipart/form-data", .then((res) => {
this.$message.success("上传成功");
success(this.$getRes(res.data.fullPath));
}) })
.then( .catch(() => {
(res) => { Toast.fail("上传失败");
this.$message.success("上传成功"); });
success(this.$getRes(res.data.url));
},
(err) => {
this.$message.error("上传失败");
console.log(err);
}
);
}, },
setup: (editor) => { setup: (editor) => {
editor.on("init", (e) => { editor.on("init", (e) => {
...@@ -112,22 +107,6 @@ export default { ...@@ -112,22 +107,6 @@ export default {
}; };
}, },
computed: { computed: {
uploadUrl() {
let mode = sessionStorage.getItem("mode");
if (process.env.VUE_APP_MODE === "development") {
if (mode !== "PC") {
return "/a/wflow/res";
} else {
return process.env.VUE_APP_BASE_API + "/a/wflow/res";
}
} else {
if (mode !== "PC") {
return "/a/wflow/res";
} else {
return process.env.VUE_APP_SERVER_URL + "/a/wflow/res";
}
}
},
_value: { _value: {
get() { get() {
return this.value; return this.value;
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
<div v-else-if="mode === 'PC' && !readonly" v-loading="loading"> <div v-else-if="mode === 'PC' && !readonly" v-loading="loading">
<el-upload <el-upload
:file-list="fileList" :file-list="fileList"
:action="uploadUrl" action=""
:http-request="uploadFile"
:limit="maxNumber" :limit="maxNumber"
with-credentials with-credentials
:multiple="maxNumber > 1" :multiple="maxNumber > 1"
...@@ -100,7 +101,7 @@ ...@@ -100,7 +101,7 @@
import componentMinxins from "../ComponentMinxins"; import componentMinxins from "../ComponentMinxins";
import { Uploader, Toast } from "vant"; import { Uploader, Toast } from "vant";
import axios from "axios"; import axios from "axios";
import { CONDITION_PROPS } from "../../../admin/layout/process/DefaultNodeProps"; import { sysUpload } from "@/api/sys.js";
export default { export default {
mixins: [componentMinxins], mixins: [componentMinxins],
name: "FileUpload", name: "FileUpload",
...@@ -132,22 +133,6 @@ export default { ...@@ -132,22 +133,6 @@ export default {
}, },
}, },
computed: { computed: {
uploadUrl() {
let mode = sessionStorage.getItem("mode");
if (process.env.VUE_APP_MODE === "development") {
if (mode !== "PC") {
return "/a/wflow/res";
} else {
return process.env.VUE_APP_BASE_API + "/a/wflow/res";
}
} else {
if (mode !== "PC") {
return "/a/wflow/res";
} else {
return process.env.VUE_APP_SERVER_URL + "/a/wflow/res";
}
}
},
sizeTip() { sizeTip() {
if (this.fileTypes.length > 0) { if (this.fileTypes.length > 0) {
return ` | 只允许上传[${String(this.fileTypes).replaceAll( return ` | 只允许上传[${String(this.fileTypes).replaceAll(
...@@ -189,7 +174,6 @@ export default { ...@@ -189,7 +174,6 @@ export default {
uploadParams: { isImg: false }, uploadParams: { isImg: false },
headers: { headers: {
token: localStorage.getItem("token"), token: localStorage.getItem("token"),
factoryId: localStorage.getItem("factoryId"),
}, },
}; };
}, },
...@@ -225,13 +209,7 @@ export default { ...@@ -225,13 +209,7 @@ export default {
return size + "B"; return size + "B";
} }
}, },
removeFile(fileId) {
axios
.delete(`${process.env.VUE_APP_BASE_API}/a/wflow/res/${fileId}`)
.then((rsp) => {
this.$message.success("移除文件成功");
});
},
uploadSuccess(response, file, fileList) { uploadSuccess(response, file, fileList) {
this.loading = false; this.loading = false;
console.log(response, this._value); console.log(response, this._value);
...@@ -261,27 +239,28 @@ export default { ...@@ -261,27 +239,28 @@ export default {
this.uploadFile(file); this.uploadFile(file);
} }
}, },
uploadFile(file) { uploadFile(params) {
//上传文件 //上传文件
const formData = new FormData(); const formData = new FormData();
formData.append("file", file.file); formData.append("file", params.file);
formData.append("isImg", false); formData.append("isImg", false);
Toast.loading({ message: "上传中...", forbidClick: true });
axios sysUpload(formData)
.post(this.uploadUrl, formData, { .then((res) => {
"Content-type": "multipart/form-data", this._value.push({
...res.data,
url: res.data.fullPath,
name: res.data.originalName,
});
console.log(7886, res.data);
this.$emit("input", this._value);
Toast.success("上传成功");
this.loading = false;
}) })
.then( .catch(() => {
(res) => { Toast.fail("上传失败");
this._value.push(res.data); this.loading = false;
this.$emit("input", this._value); });
Toast.success("上传成功");
},
(err) => {
Toast.fail("上传失败");
console.log(err);
}
);
}, },
onOversize(file) { onOversize(file) {
Toast.fail("文件过大"); Toast.fail("文件过大");
...@@ -289,7 +268,6 @@ export default { ...@@ -289,7 +268,6 @@ export default {
handleRemove(file, fileList) { handleRemove(file, fileList) {
let i = this._value.findIndex((v) => v.name === file.name); let i = this._value.findIndex((v) => v.name === file.name);
if (i > -1) { if (i > -1) {
//this.removeFile(this._value[i].id)
this._value.splice(i, 1); this._value.splice(i, 1);
this.$emit("input", this._value); this.$emit("input", this._value);
console.log("删除文件", file); console.log("删除文件", file);
......
...@@ -9,10 +9,11 @@ ...@@ -9,10 +9,11 @@
<div v-else-if="mode === 'PC' && !readonly"> <div v-else-if="mode === 'PC' && !readonly">
<el-upload <el-upload
:file-list="fileList" :file-list="fileList"
:action="uploadUrl" action=""
:limit="maxNumber" :limit="maxNumber"
with-credentials with-credentials
:multiple="maxNumber > 1" :multiple="maxNumber > 1"
:http-request="uploadFile"
:headers="headers" :headers="headers"
:data="uploadParams" :data="uploadParams"
:on-success="uploadSuccess" :on-success="uploadSuccess"
...@@ -24,7 +25,6 @@ ...@@ -24,7 +25,6 @@
auto-upload auto-upload
:before-upload="beforeUpload" :before-upload="beforeUpload"
> >
<!-- :http-request="uploadImg" -->
<i slot="default" class="el-icon-plus"></i> <i slot="default" class="el-icon-plus"></i>
<div slot="tip" class="el-upload__tip"> <div slot="tip" class="el-upload__tip">
{{ placeholder }} {{ sizeTip }} {{ placeholder }} {{ sizeTip }}
...@@ -66,7 +66,7 @@ import { Uploader, Toast } from "vant"; ...@@ -66,7 +66,7 @@ import { Uploader, Toast } from "vant";
import componentMinxins from "../ComponentMinxins"; import componentMinxins from "../ComponentMinxins";
import axios from "@/api/request"; import axios from "@/api/request";
import { deepClone } from "@/utils/common.js"; import { deepClone } from "@/utils/common.js";
import { sysUpload } from "@/api/sys.js";
export default { export default {
mixins: [componentMinxins], mixins: [componentMinxins],
name: "ImageUpload", name: "ImageUpload",
...@@ -96,22 +96,6 @@ export default { ...@@ -96,22 +96,6 @@ export default {
}, },
}, },
computed: { computed: {
uploadUrl() {
let mode = sessionStorage.getItem("mode");
if (process.env.VUE_APP_MODE === "development") {
if (mode !== "PC") {
return "/a/wflow/res";
} else {
return process.env.VUE_APP_BASE_API + "/a/wflow/res";
}
} else {
if (mode !== "PC") {
return "/a/wflow/res";
} else {
return process.env.VUE_APP_SERVER_URL + "/a/wflow/res";
}
}
},
sizeTip() { sizeTip() {
return this.maxSize > 0 ? `| 每张图不超过${this.maxSize}MB` : ""; return this.maxSize > 0 ? `| 每张图不超过${this.maxSize}MB` : "";
}, },
...@@ -169,24 +153,16 @@ export default { ...@@ -169,24 +153,16 @@ export default {
} }
return false; return false;
}, },
removeFile(fileId) {
axios
.delete(`${process.env.VUE_APP_BASE_API}/a/wflow/res/${fileId}`)
.then((rsp) => {
this.$message.success("移除文件成功");
});
},
uploadSuccess(response, file, fileList) { uploadSuccess(response, file, fileList) {
console.log(4444, response); console.log("uploadSuccess", response);
this.loading = false; this.loading = false;
this.catchList.push(response); this.catchList.push({ ...response.data, url: response.data.fullPath });
let ft = fileList.filter((f) => f.size !== undefined); let ft = fileList.filter((f) => f.size !== undefined);
if (this.catchList.length === ft.length) { if (this.catchList.length === ft.length) {
this._value.push(...this.catchList); this._value.push(...this.catchList);
this.$emit("input", this._value); this.$emit("input", this._value);
} }
this.$message.success(response.name + "上传成功"); this.$message.success("图片上传成功");
}, },
uploadFail(err) { uploadFail(err) {
this.loading = false; this.loading = false;
...@@ -201,28 +177,25 @@ export default { ...@@ -201,28 +177,25 @@ export default {
this.uploadFile(file); this.uploadFile(file);
} }
}, },
// uploadImg(params) {},
uploadFile(file) { uploadFile(params) {
//上传文件 //上传文件
const formData = new FormData(); const formData = new FormData();
formData.append("file", file.file); formData.append("file", params.file);
formData.append("isImg", true); formData.append("isImg", true);
console.log(5555, this.uploadUrl); sysUpload(formData)
axios .then((res) => {
.post(this.uploadUrl, formData, { this._value.push({
"Content-type": "multipart/form-data", ...res.data,
url: res.data.fullPath,
name: res.data.originalName,
});
this.$emit("input", this._value);
Toast.success("上传成功");
}) })
.then( .catch(() => {
(res) => { Toast.fail("上传失败");
this._value.push(res.data); });
this.$emit("input", this._value);
Toast.success("上传成功");
},
(err) => {
Toast.fail("上传失败");
console.log(err);
}
);
}, },
overLimit() { overLimit() {
if (this.mode === "PC") { if (this.mode === "PC") {
...@@ -237,7 +210,6 @@ export default { ...@@ -237,7 +210,6 @@ export default {
handleRemove(file, fileList) { handleRemove(file, fileList) {
let i = this._value.findIndex((v) => v.name === file.name); let i = this._value.findIndex((v) => v.name === file.name);
if (i > -1) { if (i > -1) {
//this.removeFile(this._value[i].id)
this._value.splice(i, 1); this._value.splice(i, 1);
this.$emit("input", this._value); this.$emit("input", this._value);
} }
......
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 sign in to comment