Browse Source

优化商品详情页代码

threedate
邓平艺 4 years ago
parent
commit
4628b8d13b
  1. 28
      pages/goodsDetail/index.vue

28
pages/goodsDetail/index.vue

@ -142,7 +142,6 @@
backgroundImg: '', backgroundImg: '',
goodShare: '', goodShare: '',
s_id: '', s_id: '',
isShowButtonCount: 0,
userInfo: {} userInfo: {}
} }
}, },
@ -169,11 +168,10 @@
}).then(res => { }).then(res => {
let img = res.data.img_url let img = res.data.img_url
if (img) { if (img) {
wx.getImageInfo({
uni.getImageInfo({
src: img, src: img,
success: function(sres) { success: function(sres) {
_this.backgroundImg = sres.path; _this.backgroundImg = sres.path;
_this.isShowButtonCount++;
resolve(); // resolve(); //
} }
}) })
@ -186,7 +184,7 @@
let _this = this let _this = this
let goods = _this.goods_detail; let goods = _this.goods_detail;
let imageUrl = goods.share_cover || goods.cover; let imageUrl = goods.share_cover || goods.cover;
wx.getImageInfo({
uni.getImageInfo({
src: imageUrl, src: imageUrl,
success: function(sres) { success: function(sres) {
_this.goodShare = sres.path _this.goodShare = sres.path
@ -251,18 +249,18 @@
}) })
}, },
// //
//
//
getwxCodeImg(resolve, reject) { getwxCodeImg(resolve, reject) {
var imgSrc = this.wxCode; //base64 var imgSrc = this.wxCode; //base64
var save = wx.getFileSystemManager();
var save = uni.getFileSystemManager();
var number = Math.random(); var number = Math.random();
var filePath = wx.env.USER_DATA_PATH + '/pic' + number + '.jpg';
save.writeFile({ save.writeFile({
filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.jpg',
filePath: filePath,
data: imgSrc, data: imgSrc,
encoding: 'base64', encoding: 'base64',
success: res => { success: res => {
this.onceCode = wx.env.USER_DATA_PATH + '/pic' + number + '.jpg';
this.isShowButtonCount++;
this.onceCode = filePath;
resolve(); // resolve(); //
console.log('二维码临时路径',this.onceCode) console.log('二维码临时路径',this.onceCode)
}, },
@ -274,7 +272,7 @@
}, },
createNewImg() { createNewImg() {
var that = this; var that = this;
var context = wx.createCanvasContext('mycanvas');
var context = uni.createCanvasContext('mycanvas');
let goods = that.goods_detail; let goods = that.goods_detail;
let title = goods.name; let title = goods.name;
let price = '¥'+goods.specs[0].selling_price; let price = '¥'+goods.specs[0].selling_price;
@ -326,7 +324,7 @@
// //
setTimeout(function() { setTimeout(function() {
uni.hideLoading(); // loading uni.hideLoading(); // loading
wx.canvasToTempFilePath({
uni.canvasToTempFilePath({
canvasId: 'mycanvas', canvasId: 'mycanvas',
success: function(res) { success: function(res) {
that.imagePath = res.tempFilePath; that.imagePath = res.tempFilePath;
@ -334,7 +332,7 @@
that.canvasHidden = true that.canvasHidden = true
that.maskHidden = true that.maskHidden = true
} }
wx.hideToast()
uni.hideToast()
console.log('海报生成成功') console.log('海报生成成功')
console.log(res) console.log(res)
console.log('图片链接', that.imagePath) console.log('图片链接', that.imagePath)
@ -347,10 +345,10 @@
}, },
saveBill() { saveBill() {
var that = this var that = this
wx.saveImageToPhotosAlbum({
uni.saveImageToPhotosAlbum({
filePath: that.imagePath, filePath: that.imagePath,
success(res) { success(res) {
wx.showModal({
uni.showModal({
content: '图片已保存到相册,赶紧晒一下吧~', content: '图片已保存到相册,赶紧晒一下吧~',
showCancel: false, showCancel: false,
confirmText: '好的', confirmText: '好的',
@ -370,7 +368,7 @@
}, },
formSubmit() { formSubmit() {
var that = this; var that = this;
wx.showToast({
uni.showToast({
title: '生成海报中...', title: '生成海报中...',
icon: 'loading', icon: 'loading',
duration: 100000 duration: 100000

Loading…
Cancel
Save