Commit 4574999c authored by caimeng's avatar caimeng

更换oss 图片上传的方式为sts

parent 40c14068
...@@ -45,17 +45,17 @@ ...@@ -45,17 +45,17 @@
<el-form-item label="相关凭证" required> <el-form-item label="相关凭证" required>
<el-upload <el-upload
:file-list="fileList"
class="upload-demo" class="upload-demo"
action="" list-type="picture-card"
:on-preview="handlePreview" :action="oss.action"
:on-remove="handleRemove" :data="oss.data"
:before-remove="beforeRemove" :multiple="oss.multiple"
multiple accept=".jpeg,.jpg,.png"
:limit="3" :http-request="uploadSectionFile"
:http-request="handleUpload" :before-upload="handleBeforeApplyUpload"
:on-exceed="handleExceed" :on-remove="handleLoanApplyRemove">
:file-list="fileList"> <i class="el-icon-plus"></i>
<el-button size="small" type="primary">点击上传</el-button>
</el-upload> </el-upload>
</el-form-item> </el-form-item>
...@@ -70,6 +70,7 @@ ...@@ -70,6 +70,7 @@
<script type="text/ecmascript-6"> <script type="text/ecmascript-6">
import Axios from 'axios'
export default { export default {
name: 'AddUserServiceDialog', name: 'AddUserServiceDialog',
...@@ -95,13 +96,13 @@ export default { ...@@ -95,13 +96,13 @@ export default {
}, },
visible: this.$props.dialogVisible, visible: this.$props.dialogVisible,
ruleForm: { ruleForm: {
feedNo:'', feedNo: '',
feedType: '', feedType: '',
feedStatus: '', feedStatus: '',
feedContent: '', feedContent: '',
clientNo: '', clientNo: '',
creater: '', creater: '',
loanNo:'', loanNo: '',
productName: '', productName: '',
feedVoucher: [] feedVoucher: []
}, },
...@@ -114,7 +115,7 @@ export default { ...@@ -114,7 +115,7 @@ export default {
], ],
feedContent: [ feedContent: [
{required: true, message: '请输入反馈问题描述', trigger: 'blur'} {required: true, message: '请输入反馈问题描述', trigger: 'blur'}
] ],
}, },
optionsStatus: [ optionsStatus: [
{ {
...@@ -156,13 +157,19 @@ export default { ...@@ -156,13 +157,19 @@ export default {
label: '其它' label: '其它'
} }
], ],
oss: {
action: '',
data: {},
multiple: false,
},
file: null
} }
}, },
created() { created() {
console.log(this.params,'888888888888'); console.log(this.params, '888888888888');
const {clientNo, feedNo, feedType,feedStatus,feedContent,feedVoucher, feedProduct,loanNo} = this.params; const {clientNo, feedNo, feedType, feedStatus, feedContent, feedVoucher, feedProduct, loanNo} = this.params;
const list = []; const list = [];
feedVoucher.forEach(item=>{ feedVoucher.forEach(item => {
const o = {}; const o = {};
o.name = item; o.name = item;
o.url = item; o.url = item;
...@@ -185,60 +192,75 @@ export default { ...@@ -185,60 +192,75 @@ export default {
} }
}, },
mounted() {
this.client = new OSS({
region: 'oss-cn-hangzhou',
accessKeyId: 'LTAI5tGDFPU1dnToV9jAatw1',
accessKeySecret: 'gHW0vHhSDh3GVis8H1dT5kkDJVldRJ',
bucket: 'w-loan-static'
});
},
methods: { methods: {
handleUpload(file) { handleBeforeApplyUpload(file) {
this.upload(file) const attachType = 'LOESS_TRANSFER_APPLY';
return this.$$get(`/oss/signature/?fileType=` + attachType + "&fileName=" + file.name).then(res => {
if (res.data.code !== '200') {
this.$message.error(res.data.message);
return false
}
const result = res.data.result.result;
const data = {};
const tempOss = {};
data.OSSAccessKeyId = result.accessId;
data.policy = result.policy;
data.Signature = result.signature;
data.key = result.dir;
tempOss.action = result.host;
tempOss.data = data;
this.oss = tempOss;
});
}, },
upload(file) {
console.log(file, '文件') uploadSectionFile(params) {
const key = file.file.name; const {action, data} = this.oss
const client = this.client; console.log(params, '图片信息')
const that = this; const d = new FormData();
const timeNum=new Date().getTime(); d.append("key", data.key);
client.multipartUpload('customer/feed/' +timeNum+'-'+key, file.file) d.append("policy", data.policy);
.then((res) => { d.append("OSSAccessKeyId", data.OSSAccessKeyId);
console.log(res, '返回结果'); d.append("success_action_status", "200");
const fileList = that.fileList; d.append("Signature", data.Signature);
d.append("file", params.file);
const imgSrc = `https://file.jqtianxia.com/${res.name}`; const baseUrl = action;
const o = {name: res.name, url: imgSrc};
fileList.push(o);
Axios({
that.$message.success('上传成功'); url: baseUrl,
method: 'post',
data: d,
headers: {'Content-Type': 'multipart/form-data'}
}).then((res) => {
if (res.status === 200) {
const imgUrl = `${baseUrl}/${data.key}`;
this.$notify({title: '成功', message: params.file.name + ",上传成功", type: 'success'});
this.fileList.push({
name: params.file.name,
url: imgUrl
}) })
.catch((err) => { }
console.log(err, '错误信息'); }).catch((e) => {
this.$message.error('上传失败'); console.log(e, '错误')
}); });
}, },
handleRemove(file, fileList) {
console.log(file, fileList);
this.fileList = fileList; handleLoanApplyRemove(file, fileList) {
}, console.log(file, 'r2')
handlePreview(file) { console.log(fileList, 'r3')
console.log(file);
},
handleExceed(files, fileList) {
this.$message.warning(`当前限制选择 3 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
}, },
beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}?`); httpRequest() {
}, },
/** 提交点击 */ /** 提交点击 */
submitForm() { submitForm() {
console.log(this.fileList,'文件列表'); console.log(this.fileList, '文件列表');
const feedVoucher = []; const feedVoucher = [];
this.fileList.forEach(item=>{ this.fileList.forEach(item => {
feedVoucher.push(item.url); feedVoucher.push(item.url);
}) })
...@@ -246,9 +268,9 @@ export default { ...@@ -246,9 +268,9 @@ export default {
if (!valid) { if (!valid) {
return false return false
} }
if(this.ruleForm.feedNo){ if (this.ruleForm.feedNo) {
this.$$post('/feed/updateClientFeed', { this.$$post('/feed/updateClientFeed', {
feedNo:this.ruleForm.feedNo, feedNo: this.ruleForm.feedNo,
feedType: this.ruleForm.feedType, feedType: this.ruleForm.feedType,
feedSource: 'CUSTOMER', feedSource: 'CUSTOMER',
feedStatus: this.ruleForm.feedStatus, feedStatus: this.ruleForm.feedStatus,
...@@ -264,7 +286,7 @@ export default { ...@@ -264,7 +286,7 @@ export default {
this.$message({message: '反馈问题修改成功', type: 'success'}); this.$message({message: '反馈问题修改成功', type: 'success'});
this.$emit('callback') this.$emit('callback')
this.handleClose(); this.handleClose();
}else { } else {
this.$message.error(res.data.message); this.$message.error(res.data.message);
} }
...@@ -272,7 +294,7 @@ export default { ...@@ -272,7 +294,7 @@ export default {
.catch(err => { .catch(err => {
alert("error!") alert("error!")
}) })
}else{ } else {
this.$$post('/feed/createClientFeed', { this.$$post('/feed/createClientFeed', {
creater: localStorage.getItem("userName"), creater: localStorage.getItem("userName"),
feedType: this.ruleForm.feedType, feedType: this.ruleForm.feedType,
...@@ -289,7 +311,7 @@ export default { ...@@ -289,7 +311,7 @@ export default {
this.$message({message: '反馈问题新增成功', type: 'success'}); this.$message({message: '反馈问题新增成功', type: 'success'});
this.$emit('callback') this.$emit('callback')
this.handleClose(); this.handleClose();
}else { } else {
this.$message.error(res.data.message); this.$message.error(res.data.message);
} }
...@@ -300,7 +322,6 @@ export default { ...@@ -300,7 +322,6 @@ export default {
} }
}) })
}, },
......
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 to comment