调整拍照上传功能

This commit is contained in:
weipengfei 2024-04-15 17:48:03 +08:00
parent d23ad0114f
commit cd8513ec02
3 changed files with 52 additions and 20 deletions

View File

@ -489,11 +489,20 @@
}); });
}, },
clk() { clk() {
let avatar = this.$refs.avatar; // let avatar = this.$refs.avatar;
avatar.fChooseImg(1, { // avatar.fChooseImg(1, {
selWidth: '350upx', // selWidth: '350upx',
selHeight: '350upx', // selHeight: '350upx',
inner: true // inner: true
// });
this.$util.uploadImageOne({
url: 'upload/image',
crop: {
width: 2000,
height: 2000,
}
},(res)=> {
this.setFormData.imageList.push(res.data.path);
}); });
}, },
doUpload(rsp) { doUpload(rsp) {

View File

@ -32,8 +32,9 @@
</view> </view>
</view> </view>
<view class="input_content_describe_textarea"> <view class="input_content_describe_textarea">
<textarea v-model="prodectContent.store_info" value="" <textarea v-model="prodectContent.store_info" value="" placeholder="请填写商品简介" placeholderClass="placeholderClass"
placeholder="请填写商品简介" placeholderClass="placeholderClass" maxlength="200" /></view> maxlength="200" />
</view>
</view> </view>
<view class="input_content_keyword" v-if="isShowDescribe"> <view class="input_content_keyword" v-if="isShowDescribe">
@ -41,7 +42,8 @@
<view class="input_content_keyword_value"><input v-model="prodectContent.keyword" type="text" value="" <view class="input_content_keyword_value"><input v-model="prodectContent.keyword" type="text" value=""
placeholder="填写关键字" /></view> placeholder="填写关键字" /></view>
</view> </view>
<avatar style="height: 1px;" @upload="doUpload" @getName="getImgName" quality="1" ref="avatar" selWidth="250upx" selHeight="250upx"> <avatar style="height: 1px;" @upload="doUpload" @getName="getImgName" quality="1" ref="avatar" selWidth="250upx"
selHeight="250upx">
</avatar> </avatar>
</view> </view>
</template> </template>
@ -81,7 +83,7 @@
data() { data() {
return { return {
uploadImg: this.prodectContent.imageList, uploadImg: this.prodectContent.imageList,
upstore : '', upstore: '',
isUpload: true, isUpload: true,
imgName: "" imgName: ""
}; };
@ -91,7 +93,7 @@
prodectContent: { prodectContent: {
handler(val) { handler(val) {
// console.log(val.store_name); // console.log(val.store_name);
this.upstore=val.store_name this.upstore = val.store_name
this.$emit('getProductContent', val); this.$emit('getProductContent', val);
}, },
@ -122,8 +124,22 @@
}); });
}, },
clk() { clk() {
let avatar = this.$refs.avatar; // let avatar = this.$refs.avatar;
avatar.fChooseImg(1, { selWidth: '350upx', selHeight: '350upx', inner: true }); // avatar.fChooseImg(1, {
// selWidth: '350upx',
// selHeight: '350upx',
// inner: true
// });
this.$util.uploadImageOne({
url: 'upload/image',
crop: {
width: 2000,
height: 2000,
}
}, (res)=> {
this.uploadImg.push(res.data.path);
this.$set(this.prodectContent, 'imageList', this.uploadImg);
});
}, },
doUpload(rsp) { doUpload(rsp) {
// console.log(rsp); // console.log(rsp);
@ -146,8 +162,9 @@
// console.log(JSON.parse(uploadFileRes.data)); // console.log(JSON.parse(uploadFileRes.data));
let imgData = JSON.parse(uploadFileRes.data) let imgData = JSON.parse(uploadFileRes.data)
// that.prodectContent.imageList.push(imgData.data.path) // that.prodectContent.imageList.push(imgData.data.path)
if(!that.prodectContent.imageList)that.prodectContent.imageList=[]; if (!that.prodectContent.imageList) that.prodectContent.imageList = [];
that.prodectContent = { imageList: [...that.prodectContent.imageList, imgData.data.path] ,store_name:this.upstore}; that.prodectContent = { imageList: [...that.prodectContent.imageList, imgData.data.path],
store_name: this.upstore };
}, },
complete(res) { complete(res) {
// console.log(res) // console.log(res)

View File

@ -590,10 +590,13 @@ export default {
*/ */
uploadImageOne: function(opt, successCallback, errorCallback) { uploadImageOne: function(opt, successCallback, errorCallback) {
let that = this; let that = this;
let obj = {};
if (typeof opt === 'string') { if (typeof opt === 'string') {
let url = opt; let url = opt;
opt = {}; opt = {};
opt.url = url; opt.url = url;
}else {
opt.crop ? obj.crop = opt.crop : null;
} }
let count = opt.count || 1, let count = opt.count || 1,
sizeType = opt.sizeType || ['compressed'], sizeType = opt.sizeType || ['compressed'],
@ -601,11 +604,14 @@ export default {
is_load = opt.is_load || true, is_load = opt.is_load || true,
uploadUrl = opt.url || '', uploadUrl = opt.url || '',
inputName = opt.name || 'field'; inputName = opt.name || 'field';
uni.chooseImage({ uni.chooseImage({
count: count, //最多可以选择的图片总数 count: count, //最多可以选择的图片总数
sizeType: sizeType, // 可以指定是原图还是压缩图,默认二者都有 sizeType: sizeType, // 可以指定是原图还是压缩图,默认二者都有
sourceType: sourceType, // 可以指定来源是相册还是相机,默认二者都有 sourceType: sourceType, // 可以指定来源是相册还是相机,默认二者都有
...obj,
success: function(res) { success: function(res) {
console.log(res);
//启动上传等待中... //启动上传等待中...
uni.showLoading({ uni.showLoading({
title: '图片上传中', title: '图片上传中',