Browse Source

优化商品详情页生成海报

threedate
邓平艺 5 years ago
parent
commit
6652ce1dc9
  1. 102
      pages/goodsDetail/index.vue

102
pages/goodsDetail/index.vue

@ -163,19 +163,22 @@
methods: {
getBackground() {
let _this = this
_this.$http(_this.API.API_BILLBACKGROUND, {
type: 'goods'
}).then(res => {
let img = res.data.img_url
if (img) {
wx.getImageInfo({
src: img,
success: function(sres) {
_this.backgroundImg = sres.path;
_this.isShowButtonCount++;
}
})
}
return new Promise((resolve, reject) => {
_this.$http(_this.API.API_BILLBACKGROUND, {
type: 'goods'
}).then(res => {
let img = res.data.img_url
if (img) {
wx.getImageInfo({
src: img,
success: function(sres) {
_this.backgroundImg = sres.path;
_this.isShowButtonCount++;
resolve(); //
}
})
}
}).catch(err => reject(err));
})
},
//
@ -220,33 +223,36 @@
})
},
getWxCode() {
const token = this.$shared.createToken({
user_id: this.userInfo.id,
goods_id: this.goods_id
});
let options = {
route: 'goods',
pt: 2,
id: this.goods_id,
share_id: this.userInfo.id,
scene_code: this.$scene.V2_GOODS_SHAREPOSTER
}
this.generateKooken(token, options); // token
this.$http(this.API.API_WXBILL, {
scene: token,
page: 'pages/route/index',
width: '2800'
}).then(res => {
this.wxCode = res.data.base_url
if (this.wxCode) {
this.getwxCodeImg()
let that = this;
return new Promise((resolve, reject) => {
const token = that.$shared.createToken({
user_id: that.userInfo.id,
goods_id: that.goods_id
});
let options = {
route: 'goods',
pt: 2,
id: that.goods_id,
share_id: that.userInfo.id,
scene_code: that.$scene.V2_GOODS_SHAREPOSTER
}
that.generateKooken(token, options); // token
that.$http(that.API.API_WXBILL, {
scene: token,
page: 'pages/route/index',
width: '2800'
}).then(res => {
that.wxCode = res.data.base_url
if (that.wxCode) {
that.getwxCodeImg(resolve, reject); // /
}
}).catch(err => reject());
})
},
//
//
getwxCodeImg() {
getwxCodeImg(resolve, reject) {
var imgSrc = this.wxCode; //base64
var save = wx.getFileSystemManager();
var number = Math.random();
@ -257,10 +263,12 @@
success: res => {
this.onceCode = wx.env.USER_DATA_PATH + '/pic' + number + '.jpg';
this.isShowButtonCount++;
resolve(); //
console.log('二维码临时路径',this.onceCode)
},
fail: err => {
console.log(err)
console.log(err);
reject(); //
}
})
},
@ -317,7 +325,7 @@
context.draw();
//
setTimeout(function() {
wx.hideToast();
uni.hideLoading(); // loading
wx.canvasToTempFilePath({
canvasId: 'mycanvas',
success: function(res) {
@ -361,13 +369,19 @@
},
formSubmit() {
var that = this;
that.getWxCode()
that.getBackground()
if(that.isShowButtonCount >= 2) {
that.createNewImg()
}else {
this.$msg('请稍后重试!')
}
uni.showLoading({title: '正在生成中'});
Promise.all([that.getWxCode(), that.getBackground()]).then(res => {
that.createNewImg();
}).catch(err => {
this.$msg('生成失败,请稍后重试!');
})
// if(that.isShowButtonCount >= 2) {
// }else {
// this.$msg('!')
// }
// that.$u.throttle(() => {
// wx.showToast({
// title: '...',

Loading…
Cancel
Save