Commit 10de5790 authored by liwei's avatar liwei

修改了上传逻辑

parent 8425705d
...@@ -88,3 +88,11 @@ export function deleteComment(data) { ...@@ -88,3 +88,11 @@ export function deleteComment(data) {
data:data data:data
}) })
} }
//查看动态详情
export function getUploadType(){
return request({
url: '/app/opmArticle/getUploadType',
method: 'GET',
})
}
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
</template> </template>
<script> <script>
import {publishArticle} from '../api/article/index' import {publishArticle,getUploadType} from '../api/article/index'
import ELM from '@/components/elm-toast/index.vue'; import ELM from '@/components/elm-toast/index.vue';
import {getDict} from "../api/system/dict/data"; import {getDict} from "../api/system/dict/data";
export default { export default {
...@@ -49,6 +49,8 @@ ...@@ -49,6 +49,8 @@
articleOptions:{}, articleOptions:{},
//话题id //话题id
topicId:null, topicId:null,
// oss上传类型 aliYun local
uploadType: 'aliYun'
} }
}, },
components: { components: {
...@@ -60,10 +62,17 @@ ...@@ -60,10 +62,17 @@
} }
}, },
onLoad(value){ onLoad(value){
this.getUploadType()
this.topicId = value.topicId this.topicId = value.topicId
this.getArticleDict() this.getArticleDict()
}, },
methods: { methods: {
// 获取上传类型 判断当前是oss上传还是本地上传
getUploadType(){
getUploadType().then( res=>{
this.uploadType = res.data.data
})
},
//发布 //发布
submit() { submit() {
if (!this.content && !this.fileList.length) { if (!this.content && !this.fileList.length) {
...@@ -133,7 +142,14 @@ ...@@ -133,7 +142,14 @@
}) })
for (let i = 0; i < lists.length; i++) { for (let i = 0; i < lists.length; i++) {
this.uploadFilePromise(lists[i]).then( res => { this.uploadFilePromise(lists[i]).then( res => {
if (res.data.ossInfoId !== null && res.data.ossInfoId !== '' && res.data.ossInfoId !== undefined){
// oss上传
// res.data.ossInfoId转成数字
this.uploadImgJSON.id.push(Number(res.data.ossInfoId))
} else {
// 本地上传
this.uploadImgJSON.id.push(res.data.businessId) this.uploadImgJSON.id.push(res.data.businessId)
}
}) })
let item = this.fileList[fileListLen] let item = this.fileList[fileListLen]
this.fileList.splice(fileListLen, 1, Object.assign(item, { this.fileList.splice(fileListLen, 1, Object.assign(item, {
...@@ -146,13 +162,63 @@ ...@@ -146,13 +162,63 @@
//上传图片 //上传图片
uploadFilePromise(file) { uploadFilePromise(file) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (this.uploadType === 'aliYun'){
uni.uploadFile({ uni.uploadFile({
// url: 'http://192.168.1.18:8082/common/aliyunOssFileUploadByWx',
url: this.$BASE_URL + '/common/aliyunOssFileUploadByWx',
filePath: file.url,
formData: {
file: file,//你要传的临时文件
temp: 'opmArticle',
},
header: {
Authorization: 'Bearer ' + uni.getStorageSync("token"),
},
name: 'file',
success: (res) => {
let response = JSON.parse(res.data)
const formData = {
key: response.data.url, //上传文件名称
policy: response.data.policy, //表单域
'x-oss-signature-version': response.data.x_oss_signature_version, //指定签名的版本和算法
'x-oss-credential': response.data.x_oss_credential, //指明派生密钥的参数集
'x-oss-date': response.data.x_oss_date, //请求的时间
'x-oss-signature': response.data.signature, //签名认证描述信息
'x-oss-security-token': response.data.security_token, //安全令牌
success_action_status: "200" //上传成功后响应状态码
};
wx.uploadFile({
url: response.data.ossDomainName, // 此域名仅作示例,实际Bucket域名,请替换为您的目标Bucket域名。
filePath: file.url,
name: 'file', //固定值为file
formData: formData,
success(res1) {
console.log('上传响应:', res1);
if (res1.statusCode === 200) {
callback(null, res1.data); // 上传成功
} else {
console.error('上传失败,状态码:', res1.statusCode);
console.error('失败响应:', res1);
callback(res1); // 上传失败,返回响应
}
},
fail(err) {
console.error('上传失败:', err); // 输出错误信息
wx.showToast({ title: '上传失败,请重试!', icon: 'none' });
callback(err); // 调用回调处理错误
}
});
resolve(response);
},
});
} else {
uni.uploadFile({
// url: 'http://192.168.1.18:8082/common/fileUpload',
url: this.$BASE_URL + '/common/fileUpload', url: this.$BASE_URL + '/common/fileUpload',
filePath: file.url, filePath: file.url,
formData: { formData: {
file: file,//你要传的临时文件 file: file,//你要传的临时文件
temp: 'opmArticle', temp: 'opmArticle',
bucket:'cust-91isoft'
}, },
header: { header: {
Authorization: 'Bearer ' + uni.getStorageSync("token"), Authorization: 'Bearer ' + uni.getStorageSync("token"),
...@@ -163,6 +229,7 @@ ...@@ -163,6 +229,7 @@
resolve(data) resolve(data)
}, },
}); });
}
}) })
}, },
payConfirm(){ payConfirm(){
......
...@@ -2,21 +2,11 @@ ...@@ -2,21 +2,11 @@
<view style="padding-bottom: 100rpx"> <view style="padding-bottom: 100rpx">
<!-- 头像部分--> <!-- 头像部分-->
<view class="w-100 pt30 pb60"> <view class="w-100 pt30 pb60">
<!-- <view class="pr40 pl72 pt40 rowa" v-if="userInfo.avatarUrl == null">-->
<!-- <view class="mw32 mt8 h32 bc000 cfff br-50 tc lh32 fs24">!</view>-->
<!-- <view class="ml14 c333 fs28 lh44">-->
<!-- 请上传个人的真实照片,通过后这样才能匹配到高质量好友哦~-->
<!-- </view>-->
<!-- </view>-->
<!-- 个人资料 顶部头像--> <!-- 个人资料 顶部头像-->
<view class="pr32 pl32 rowa"> <view class="pr32 pl32 rowa">
<!-- 大头像--> <!-- 大头像-->
<view class="relative" @click="showSingleNoPopup(9)"> <view class="relative" @click="showSingleNoPopup(9)">
<image class="w328 br24 h328 blc " :src="userInfo.avatarUrl != null ? userInfo.avatarUrl : baseUrl + '/user/defaultAvatar.png'" mode="aspectFill"></image> <image class="w328 br24 h328 blc " :src="userInfo.avatarUrl != null ? userInfo.avatarUrl : baseUrl + '/user/defaultAvatar.png'" mode="aspectFill"></image>
<!-- <view v-else class="absolute w328 h328 rowjcic top0">-->
<!-- <view class="w186 h52 lh52 tc cfff fs28 br10" style="background-color: rgba(0,0,0,0.3);">头像/封面-->
<!-- </view>-->
<!-- </view>-->
</view> </view>
<!-- 4个小头像--> <!-- 4个小头像-->
<view class="h328 crowjb"> <view class="h328 crowjb">
...@@ -243,7 +233,7 @@ ...@@ -243,7 +233,7 @@
import {getUserInfo, updateUser, userDetail} from "../../api/user"; import {getUserInfo, updateUser, userDetail} from "../../api/user";
import {calculateAge, parseDate} from "../../common"; import {calculateAge, parseDate} from "../../common";
import {getCity, getValue} from "../../common/options"; import {getCity, getValue} from "../../common/options";
import {getOssUrl} from "../../api/article"; import {getOssUrl, getUploadType} from "../../api/article";
export default { export default {
data() { data() {
...@@ -264,6 +254,8 @@ import {getOssUrl} from "../../api/article"; ...@@ -264,6 +254,8 @@ import {getOssUrl} from "../../api/article";
singleNoShow: false, singleNoShow: false,
singleIndex: 0, singleIndex: 0,
waitApprovedImg: [], waitApprovedImg: [],
// oss上传类型 aliYun local
uploadType: 'aliYun'
} }
}, },
computed: { computed: {
...@@ -279,8 +271,15 @@ import {getOssUrl} from "../../api/article"; ...@@ -279,8 +271,15 @@ import {getOssUrl} from "../../api/article";
}, },
onShow() { onShow() {
this.getUserInfo() this.getUserInfo()
this.getUploadType()
}, },
methods: { methods: {
// 获取上传类型 判断当前是oss上传还是本地上传
getUploadType(){
getUploadType().then( res=>{
this.uploadType = res.data.data
})
},
gotomation() { gotomation() {
uni.navigateTo({ uni.navigateTo({
url: "/pagesme/me/doubleauth" url: "/pagesme/me/doubleauth"
...@@ -325,14 +324,55 @@ import {getOssUrl} from "../../api/article"; ...@@ -325,14 +324,55 @@ import {getOssUrl} from "../../api/article";
}) })
//接收cropper页面传递的图片路径 //接收cropper页面传递的图片路径
uni.$on('Cropper', path => { uni.$on('Cropper', path => {
if(path){ if (this.uploadType === 'aliYun'){
uni.uploadFile({
// url: 'http://192.168.1.18:8082/common/aliyunOssFileUploadByWx',
url: this.$BASE_URL + '/common/aliyunOssFileUploadByWx',
filePath: path,
formData: {
file: path,//你要传的临时文件
temp: 'opmMember',
},
header: {
Authorization: 'Bearer ' + uni.getStorageSync("token"),
},
name: 'file',
success: (res) => {
let response = JSON.parse(res.data)
const formData = {
key: response.data.url, //上传文件名称
policy: response.data.policy, //表单域
'x-oss-signature-version': response.data.x_oss_signature_version, //指定签名的版本和算法
'x-oss-credential': response.data.x_oss_credential, //指明派生密钥的参数集
'x-oss-date': response.data.x_oss_date, //请求的时间
'x-oss-signature': response.data.signature, //签名认证描述信息
'x-oss-security-token': response.data.security_token, //安全令牌
success_action_status: "200" //上传成功后响应状态码
};
wx.uploadFile({
url: response.data.ossDomainName, // 此域名仅作示例,实际Bucket域名,请替换为您的目标Bucket域名。
filePath: path,
name: 'file', //固定值为file
formData: formData,
success:(res1) =>{
console.log('上传响应:', res1);
this.updateImage(type,response.data.ossInfoId);
},
fail(err) {
console.error('上传失败:', err); // 输出错误信息
wx.showToast({ title: '上传失败,请重试!', icon: 'none' });
}
});
},
});
} else {
uni.uploadFile({ uni.uploadFile({
// url: 'http://192.168.1.18:8082/common/fileUpload',
url: this.$BASE_URL + '/common/fileUpload', url: this.$BASE_URL + '/common/fileUpload',
filePath: path, filePath: path,
formData: { formData: {
file: path, file: path,//你要传的临时文件
temp: 'opmArticle', temp: 'opmArticle',
bucket:'cust-91isoft'
}, },
header: { header: {
Authorization: 'Bearer ' + uni.getStorageSync("token"), Authorization: 'Bearer ' + uni.getStorageSync("token"),
...@@ -346,7 +386,7 @@ import {getOssUrl} from "../../api/article"; ...@@ -346,7 +386,7 @@ import {getOssUrl} from "../../api/article";
} }
}); });
}, },
async updateImage(type,businessId) { updateImage(type,businessId) {
var that = this; var that = this;
if (type == 'add') { if (type == 'add') {
let memPictureIdArray = this.userInfo.memPictureId ? JSON.parse(this.userInfo.memPictureId) : { id: [] }; let memPictureIdArray = this.userInfo.memPictureId ? JSON.parse(this.userInfo.memPictureId) : { id: [] };
......
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