文件上传修改

This commit is contained in:
HuskyOo 2023-03-09 16:22:07 +08:00
parent 828dcd0510
commit c38bdc3ffe
6 changed files with 148 additions and 97 deletions

View File

@ -4,8 +4,8 @@ ENV = 'development'
# base api
#VUE_APP_BASE_API = '/dev-api'
#VUE_APP_BASE_API = 'http://app.rt.xianci.info/'
VUE_APP_BASE_API = 'http://office.xianci.info:18904/'
#VUE_APP_BASE_API = 'http://api.rt.myntv.cn/'
# VUE_APP_BASE_API = 'http://office.xianci.info:18904/'
VUE_APP_BASE_API = 'https://api.rt.rtrmt.cn/'
# base url
VUE_APP_BASE_URL = 'http://admin.rt.xianci.info'

BIN
convenience-prod.zip Normal file

Binary file not shown.

View File

@ -1,4 +1,4 @@
import request from "@/utils/request";
import request from '@/utils/request'
/**
* 通讯录
@ -26,8 +26,21 @@ export function staffList(data) {
*/
export function info(data) {
return request({
url: "/api/convenience/v2/staff/info",
method: "get",
url: '/api/convenience/v2/staff/info',
method: 'get',
params: data
});
})
}
/**
* 文件上传
* @param data
*/
export function upload(data) {
return request({
url: '/api/common/upload/upload',
method: 'post',
headers: { 'Content-Type': 'multipart/form-data' },
data
})
}

View File

@ -20,6 +20,8 @@
import OSS from '@/utils/aliOSS'
import UUID from 'uuidjs'
import { upload } from '@/api/staff'
export default {
props: {
value: {
@ -58,10 +60,18 @@ export default {
const suffix = item.name.substr(item.name.lastIndexOf('.')+1)
const fileName = UUID.generate() + '.' + suffix
item.name = fileName
OSS(item.raw, fileName).then(res => {
this.$emit('input', 'http://storage.myntv.cn/'+res.name)
item.url = 'http://storage.myntv.cn/'+res.name
const formData = new FormData()
formData.append('file', item.raw, fileName)
upload(formData).then(res => {
console.log(res)
// OSS(item.raw, fileName).then(res => {
// this.$emit('input', 'http://storage.myntv.cn/'+res.name)
// item.url = 'http://storage.myntv.cn/'+res.name
this.$emit('input', res.d)
item.url = res.d
item.status = 'success'
const list = fileList.filter(item => item.status === 'success').map(item => item.url)
console.log(list);
@ -70,13 +80,17 @@ export default {
}
})
} else {
// const suffix = file.name.split('.')[0]
const suffix = item.name.substr(item.name.lastIndexOf('.')+1)
const suffix = file.name.split('.')[0]
const fileName = UUID.generate() + '.' + suffix
file.name = fileName
this.fileList = [file]
OSS(file.raw, fileName).then(res => {
this.$emit('input', 'http://storage.myntv.cn/'+res.name)
const formData = new FormData()
formData.append('file', file.raw, fileName)
upload(formData).then(res => {
// OSS(file.raw, fileName).then(res => {
// this.$emit('input', 'http://storage.myntv.cn/'+res.name)
this.$emit('input', res.d)
})
}
},

View File

@ -41,6 +41,8 @@ import { Loading } from 'element-ui'
import OSS from '@/utils/aliOSS'
import UUID from 'uuidjs'
import { upload } from '@/api/staff'
export default {
components: { Preview },
props: {
@ -178,8 +180,13 @@ export default {
file = item
})
const suffix = file.name.split('.')[1]
OSS(file, UUID.generate() + '.' + suffix).then(res => {
resolve(res.url)
const form = new FormData()
form.append('file', file)
upload(form).then(res => {
// OSS(file, UUID.generate() + '.' + suffix).then(res => {
// resolve(res.url)
resolve(res.d)
loadingInstance.close()
}).catch(() => {
console.log('文件上传失败!')

View File

@ -32,7 +32,7 @@
:style="{ width: width + 'px', height: height + 'px' }"
@mouseenter="mouseEnter"
@mouseleave="mouseLeave"
/>
>
<i
v-else
class="el-icon-plus avatar-uploader-icon"
@ -101,7 +101,7 @@
</el-upload>
<!-- 多图片预览弹窗 -->
<el-dialog :visible.sync="dialogVisible" append-to-body>
<img width="100%" :src="dialogImageUrl" alt="" />
<img width="100%" :src="dialogImageUrl" alt="">
</el-dialog>
<!-- 剪裁组件弹窗 -->
<el-dialog
@ -121,13 +121,15 @@
</div>
</template>
<script>
import Cropper from "@/components/uploader/cropper";
import Cropper from '@/components/uploader/cropper'
// import axios from 'axios'
import OSS from "@/utils/aliOSS";
import UUID from "uuidjs";
import OSS from '@/utils/aliOSS'
import UUID from 'uuidjs'
import { upload } from '@/api/staff'
export default {
name: "Uploader",
name: 'Uploader',
components: {
Cropper
},
@ -135,7 +137,7 @@ export default {
targetUrl: {
//
type: String,
default: "http://120.77.82.246:6789/api/postUpLoadFiles"
default: 'http://120.77.82.246:6789/api/postUpLoadFiles'
},
multiple: {
//
@ -144,12 +146,12 @@ export default {
},
initUrl: {
//
default: ""
default: ''
},
fixedNumber: {
//
default: function() {
return [3, 1];
return [3, 1]
}
},
news: {
@ -169,66 +171,66 @@ export default {
},
data() {
return {
file: "", //
imageUrl: "", //
dialogImageUrl: "", //
file: '', //
imageUrl: '', //
dialogImageUrl: '', //
uploadList: [], //
reupload: true, // ""
dialogVisible: false, //
cropperModel: false, //
reuploadWidth: this.height * 0.7 //
};
}
},
watch: {
initUrl: function(val) {
//
console.info("watch");
console.info(val);
console.info('watch')
console.info(val)
if (val) {
if (typeof this.initUrl === "string") {
this.imageUrl = val;
if (typeof this.initUrl === 'string') {
this.imageUrl = val
} else {
this.uploadList = this.formatImgArr(val);
this.uploadList = this.formatImgArr(val)
}
} else {
this.imageUrl = "";
this.uploadList = [];
this.imageUrl = ''
this.uploadList = []
}
}
},
updated() {
if (this.$refs.vueCropper) {
this.$refs.vueCropper.Update();
this.$refs.vueCropper.Update()
}
},
mounted() {
if (typeof this.initUrl === "string") {
this.imageUrl = this.initUrl;
if (typeof this.initUrl === 'string') {
this.imageUrl = this.initUrl
} else {
this.uploadList = this.formatImgArr(this.initUrl);
this.uploadList = this.formatImgArr(this.initUrl)
}
},
methods: {
/** **************************** multiple多图情况 **************************************/
handlePreview(file) {
//
this.dialogImageUrl = file.url;
this.dialogVisible = true;
this.dialogImageUrl = file.url
this.dialogVisible = true
},
handleRemove(file, fileList) {
//
this.uploadList = fileList;
this.$emit("imgupload", this.formatImgArr(this.uploadList));
this.uploadList = fileList
this.$emit('imgupload', this.formatImgArr(this.uploadList))
},
handlePicRemove(file) {
this.imageUrl = "";
this.$emit("imgupload", this.imageUrl);
this.imageUrl = ''
this.$emit('imgupload', this.imageUrl)
},
consoleFL(file, fileList) {
//
this.cropperModel = true;
this.file = file;
this.uploadList = fileList;
this.cropperModel = true
this.file = file
this.uploadList = fileList
},
/** **********************************************************************************/
@ -236,28 +238,28 @@ export default {
handlePreviewSingle(file) {
//
// this.dialogImageUrl = this.file.url
this.dialogImageUrl = this.imageUrl;
this.dialogVisible = true;
this.dialogImageUrl = this.imageUrl
this.dialogVisible = true
},
mouseEnter() {
//
this.$refs.reupload.style.display = "block";
if (this.$refs.failUpload.style.display === "block") {
this.$refs.failUpload.style.display = "none";
this.$refs.reupload.style.display = 'block'
if (this.$refs.failUpload.style.display === 'block') {
this.$refs.failUpload.style.display = 'none'
}
this.$refs.singleImg.style.opacity = "0.6";
this.$refs.singleImg.style.opacity = '0.6'
},
mouseLeave() {
//
this.$refs.reupload.style.display = "none";
this.$refs.singleImg.style.opacity = "1";
this.$refs.reupload.style.display = 'none'
this.$refs.singleImg.style.opacity = '1'
},
handleCrop(file, files) {
file.url = URL.createObjectURL(file.raw);
file.url = URL.createObjectURL(file.raw)
// console.log(file)
//
this.cropperModel = true;
this.file = file;
this.cropperModel = true
this.file = file
// this.imageUrl = file.url
},
/** **********************************************************************************/
@ -266,70 +268,85 @@ export default {
// upload
if (!this.multiple) {
//
this.$refs.uploading.style.display = "block";
this.$refs.uploading.style.display = 'block'
}
// const formData = new FormData()
// formData.append('file', data, '123.png')
// axios.defaults.withCredentials = false
// axios.post(this.targetUrl, formData, { headers: { 'Content-Type': 'multipart/form-data' }}).then(res => {
const name = UUID.generate() + ".png";
OSS(data, name).then(res => {
const name = UUID.generate() + '.png'
const formData = new FormData()
formData.append('file', data, name)
upload(formData).then(res => {
// OSS(data, name).then(res => {
if (!this.multiple) {
//
this.$refs.uploading.style.display = "none";
this.$refs.uploading.style.display = 'none'
}
// console.log(res)
if (res.res.status === 200) {
//
const currentPic = res.url;
if (this.multiple) {
this.uploadList.pop();
this.uploadList.push({
url: currentPic,
uid: "111"
});
// console.log(this.formatImgArr(this.uploadList))
this.$emit("imgupload", this.formatImgArr(this.uploadList));
} else {
this.$emit("imgupload", currentPic);
}
// if (res.res.status === 200) {
//
const currentPic = res.d
if (this.multiple) {
this.uploadList.pop()
this.uploadList.push({
url: currentPic,
uid: '111'
})
// console.log(this.formatImgArr(this.uploadList))
this.$emit('imgupload', this.formatImgArr(this.uploadList))
} else {
this.$message({
type: "warning",
message: "上传失败!"
});
//
if (!this.multiple) {
this.$refs.failUpload.style.display = "block";
} else {
this.uploadList.pop();
}
this.$emit('imgupload', currentPic)
}
});
this.cropperModel = false;
// } else {
// this.$message({
// type: "warning",
// message: "!"
// });
// //
// if (!this.multiple) {
// this.$refs.failUpload.style.display = "block";
// } else {
// this.uploadList.pop();
// }
// }
}).catch(() => {
this.$message({
type: 'warning',
message: '上传失败!'
})
//
if (!this.multiple) {
this.$refs.failUpload.style.display = 'block'
} else {
this.uploadList.pop()
}
})
this.cropperModel = false
},
formatImgArr(arr) {
// console.log(arr);
if (arr) {
const result = arr.map((item, index) => {
if (typeof item === "string") {
if (typeof item === 'string') {
return {
url: item,
uid: `index${index}`
};
}
} else {
return item.url;
return item.url
}
});
return result;
})
return result
}
},
beforeClose(done) {
this.uploadList.pop();
this.cropperModel = false;
this.uploadList.pop()
this.cropperModel = false
}
}
};
}
</script>
<style>
.avatar-uploader .el-upload {