|
@@ -52,24 +52,23 @@ Page({
|
|
|
|
|
|
|
|
|
imgSrcArray: [],
|
|
|
- buildSrcArrayText:{
|
|
|
- '1':'正面',
|
|
|
- '2':'背面',
|
|
|
+ buildSrcArrayText: {
|
|
|
+ '1': '正面',
|
|
|
+ '2': '背面',
|
|
|
},
|
|
|
- boxImg:{
|
|
|
+ boxImg: {
|
|
|
'5': '/customized/images/customized/box_white_big_1_out.png',
|
|
|
'6': '/customized/images/customized/box_white_big_2_out.png',
|
|
|
},
|
|
|
buildSrcArray: [],
|
|
|
- customGoodsImg:"",
|
|
|
+ customGoodsImg: "",
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
- onLoad: function (options) {
|
|
|
- },
|
|
|
+ onLoad: function (options) {},
|
|
|
|
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
@@ -79,7 +78,8 @@ Page({
|
|
|
wx.showLoading({
|
|
|
title: '图片合成中...'
|
|
|
})
|
|
|
- let that = this, result = true;
|
|
|
+ let that = this,
|
|
|
+ result = true;
|
|
|
|
|
|
if (wx.getStorageSync('madeCupImgData5') || wx.getStorageSync('madeCupFontData5')) {
|
|
|
that.getCombImg(that, 5);
|
|
@@ -135,16 +135,17 @@ Page({
|
|
|
onShareAppMessage: function () {
|
|
|
|
|
|
},
|
|
|
- getCombImg(that,i) {
|
|
|
- let imgTouch = null, dataPositionObj=null;
|
|
|
+ getCombImg(that, i) {
|
|
|
+ let imgTouch = null,
|
|
|
+ dataPositionObj = null;
|
|
|
that.setData({
|
|
|
- imgSrcArray:[],
|
|
|
+ imgSrcArray: [],
|
|
|
})
|
|
|
- console.log(wx.getStorageSync('madeCupImgData' + i),"wx.getStorageSync('madeCupImgData' + i)")
|
|
|
- if(wx.getStorageSync('madeCupImgData' + i)){
|
|
|
- imgTouch = wx.getStorageSync('madeCupImgData'+i);
|
|
|
+ console.log(wx.getStorageSync('madeCupImgData' + i), "wx.getStorageSync('madeCupImgData' + i)")
|
|
|
+ if (wx.getStorageSync('madeCupImgData' + i)) {
|
|
|
+ imgTouch = wx.getStorageSync('madeCupImgData' + i);
|
|
|
dataPositionObj = util.changeCup(i.toString()).dataPositionObj;
|
|
|
- console.log(dataPositionObj,"dataPositionObj")
|
|
|
+ console.log(dataPositionObj, "dataPositionObj")
|
|
|
wx.getSystemInfo({
|
|
|
success: function (res) {
|
|
|
let rpx = res.windowWidth / 750;
|
|
@@ -161,16 +162,16 @@ Page({
|
|
|
let dWidth = dataPositionObj.width / imgTouch.width;
|
|
|
|
|
|
let dHeight = dataPositionObj.height / imgTouch.height;
|
|
|
- const ctx = wx.createCanvasContext('comb-img'+i);
|
|
|
+ const ctx = wx.createCanvasContext('comb-img' + i);
|
|
|
|
|
|
let movex = imgTouch.x + imgTouch.width * rpx / 2;
|
|
|
let movey = imgTouch.y + imgTouch.height * rpx / 2;
|
|
|
ctx.translate(movex, movey);
|
|
|
ctx.rotate(imgTouch.angle * Math.PI / 180);
|
|
|
ctx.drawImage(res.tempFilePath, -imgTouch.width * rpx / 2, -imgTouch.height * rpx / 2, imgTouch.width * rpx, imgTouch.height * rpx)
|
|
|
- ctx.draw(false,function () {
|
|
|
+ ctx.draw(false, function () {
|
|
|
wx.canvasToTempFilePath({
|
|
|
- canvasId: 'comb-img'+i,
|
|
|
+ canvasId: 'comb-img' + i,
|
|
|
success: function (res) {
|
|
|
console.log(res)
|
|
|
let imgArray = that.data.imgSrcArray;
|
|
@@ -178,7 +179,7 @@ Page({
|
|
|
that.setData({
|
|
|
imgSrcArray: imgArray
|
|
|
})
|
|
|
- that.getCombFont(that,i,true);
|
|
|
+ that.getCombFont(that, i, true);
|
|
|
}
|
|
|
}, that)
|
|
|
})
|
|
@@ -189,25 +190,27 @@ Page({
|
|
|
},
|
|
|
})
|
|
|
} else {
|
|
|
- that.getCombFont(that,i,false);
|
|
|
+ that.getCombFont(that, i, false);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
},
|
|
|
- getCombFont(that,i,_static) {
|
|
|
- let fontTouch = null, dataPositionObj = null, simulationFont=null;
|
|
|
+ getCombFont(that, i, _static) {
|
|
|
+ let fontTouch = null,
|
|
|
+ dataPositionObj = null,
|
|
|
+ simulationFont = null;
|
|
|
if (wx.getStorageSync('madeCupFontData' + i)) {
|
|
|
fontTouch = wx.getStorageSync('madeCupFontData' + i);
|
|
|
simulationFont = wx.getStorageSync('simulationFont' + i);
|
|
|
dataPositionObj = util.changeCup(i.toString()).dataPositionObj;
|
|
|
- const ctx = wx.createCanvasContext('comb-font'+i);
|
|
|
+ const ctx = wx.createCanvasContext('comb-font' + i);
|
|
|
|
|
|
ctx.setFontSize(fontTouch.fontSize);
|
|
|
ctx.setFillStyle(fontTouch.isColor);
|
|
|
- if(fontTouch.bold){
|
|
|
+ if (fontTouch.bold) {
|
|
|
ctx.fillText(fontTouch.fontContent, -1, simulationFont.height / 5 * 4)
|
|
|
- ctx.fillText(fontTouch.fontContent, 0, simulationFont.height / 5 * 4 -1)
|
|
|
+ ctx.fillText(fontTouch.fontContent, 0, simulationFont.height / 5 * 4 - 1)
|
|
|
}
|
|
|
ctx.fillText(fontTouch.fontContent, 0, simulationFont.height / 5 * 4)
|
|
|
if (fontTouch.bold) {
|
|
@@ -215,57 +218,57 @@ Page({
|
|
|
ctx.fillText(fontTouch.fontContent, 0, simulationFont.height / 5 * 4 + 1)
|
|
|
}
|
|
|
ctx.restore()
|
|
|
- ctx.draw(false,function () {
|
|
|
+ ctx.draw(false, function () {
|
|
|
wx.canvasToTempFilePath({
|
|
|
- canvasId: 'comb-font'+i,
|
|
|
+ canvasId: 'comb-font' + i,
|
|
|
success: function (res) {
|
|
|
console.log(res)
|
|
|
- that.getCombFontImg(that, res.tempFilePath, fontTouch,i)
|
|
|
+ that.getCombFontImg(that, res.tempFilePath, fontTouch, i)
|
|
|
}
|
|
|
}, that)
|
|
|
})
|
|
|
} else {
|
|
|
that.getComb(that, that.data.imgSrcArray, i, _static)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
},
|
|
|
- getCombFontImg(that, img, fontTouch,i){
|
|
|
+ getCombFontImg(that, img, fontTouch, i) {
|
|
|
wx.getSystemInfo({
|
|
|
success: function (res) {
|
|
|
let rpx = res.windowWidth / 750;
|
|
|
that.setData({
|
|
|
rpx: rpx
|
|
|
});
|
|
|
-
|
|
|
- console.log(res)
|
|
|
-
|
|
|
- const ctx = wx.createCanvasContext('comb-font' + i + '-2');
|
|
|
-
|
|
|
- let movex = fontTouch.x + 536 * rpx / 2;
|
|
|
- let movey = fontTouch.y + 712 * rpx / 2;
|
|
|
- ctx.translate(movex, movey);
|
|
|
- ctx.rotate(fontTouch.angle * Math.PI / 180);
|
|
|
- ctx.drawImage(img, -536 * rpx / 2, -712 * rpx / 2, 536 * rpx, 712 * rpx)
|
|
|
- ctx.draw(false, function () {
|
|
|
- wx.canvasToTempFilePath({
|
|
|
- canvasId: 'comb-font' + i + '-2',
|
|
|
- success: function (res) {
|
|
|
- console.log(res)
|
|
|
- let imgArray = that.data.imgSrcArray;
|
|
|
- imgArray.push(res.tempFilePath)
|
|
|
- that.setData({
|
|
|
- imgSrcArray: imgArray
|
|
|
- })
|
|
|
- that.getComb(that, that.data.imgSrcArray,i,true)
|
|
|
- }
|
|
|
- }, that)
|
|
|
+
|
|
|
+ console.log(res)
|
|
|
+
|
|
|
+ const ctx = wx.createCanvasContext('comb-font' + i + '-2');
|
|
|
+
|
|
|
+ let movex = fontTouch.x + 536 * rpx / 2;
|
|
|
+ let movey = fontTouch.y + 712 * rpx / 2;
|
|
|
+ ctx.translate(movex, movey);
|
|
|
+ ctx.rotate(fontTouch.angle * Math.PI / 180);
|
|
|
+ ctx.drawImage(img, -536 * rpx / 2, -712 * rpx / 2, 536 * rpx, 712 * rpx)
|
|
|
+ ctx.draw(false, function () {
|
|
|
+ wx.canvasToTempFilePath({
|
|
|
+ canvasId: 'comb-font' + i + '-2',
|
|
|
+ success: function (res) {
|
|
|
+ console.log(res)
|
|
|
+ let imgArray = that.data.imgSrcArray;
|
|
|
+ imgArray.push(res.tempFilePath)
|
|
|
+ that.setData({
|
|
|
+ imgSrcArray: imgArray
|
|
|
})
|
|
|
+ that.getComb(that, that.data.imgSrcArray, i, true)
|
|
|
+ }
|
|
|
+ }, that)
|
|
|
+ })
|
|
|
},
|
|
|
})
|
|
|
},
|
|
|
- getComb(that, imgSrcArray,i,_static) {
|
|
|
- console.log(imgSrcArray,"imgSrcArray")
|
|
|
- if(_static){
|
|
|
+ getComb(that, imgSrcArray, i, _static) {
|
|
|
+ console.log(imgSrcArray, "imgSrcArray")
|
|
|
+ if (_static) {
|
|
|
let imgTouch = wx.getStorageSync('madeCupImgData' + i);
|
|
|
let dataPositionObj = util.changeCup(i.toString()).dataPositionObj;
|
|
|
let canvasBg = that.data.obverseImgObject[i];
|
|
@@ -285,12 +288,12 @@ Page({
|
|
|
})
|
|
|
console.log('开始执行叠加')
|
|
|
ctx.drawImage(that.data.boxImg[i], 0, 0, 750 * rpx, 800 * rpx)
|
|
|
-
|
|
|
+
|
|
|
ctx.draw(true, function () {
|
|
|
wx.canvasToTempFilePath({
|
|
|
canvasId: 'comb-canvas' + i,
|
|
|
success: function (res) {
|
|
|
- that.uploadFile(res.tempFilePath,that,function(data){
|
|
|
+ that.uploadFile(res.tempFilePath, that, function (data) {
|
|
|
console.log(res, "合成成功");
|
|
|
|
|
|
let buildSrcArray = that.data.buildSrcArray;
|
|
@@ -311,7 +314,7 @@ Page({
|
|
|
wx.hideLoading()
|
|
|
}
|
|
|
})
|
|
|
-
|
|
|
+
|
|
|
},
|
|
|
fail: function (err) {
|
|
|
console.log(err, "合成失败")
|
|
@@ -329,32 +332,32 @@ Page({
|
|
|
wx.hideLoading()
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
},
|
|
|
- addImgRouter(){
|
|
|
- let that = this;
|
|
|
- console.log(that.data.customGoodsImg,"that.data.customGoodsImg")
|
|
|
-
|
|
|
+ addImgRouter() {
|
|
|
+ let that = this;
|
|
|
+ console.log(that.data.customGoodsImg, "that.data.customGoodsImg")
|
|
|
+
|
|
|
wx.request({
|
|
|
url: host + '/addShopCar',
|
|
|
- method:'post',
|
|
|
+ method: 'post',
|
|
|
header: {
|
|
|
'content-type': 'application/x-www-form-urlencoded'
|
|
|
},
|
|
|
- data:{
|
|
|
- customGoodsImg: that.data.customGoodsImg.substring(0, that.data.customGoodsImg.length-1),
|
|
|
- customGoodsName:'奶缸-黑色 350ml',
|
|
|
+ data: {
|
|
|
+ customGoodsImg: that.data.customGoodsImg.substring(0, that.data.customGoodsImg.length - 1),
|
|
|
+ customGoodsName: '拉杆箱-银灰色',
|
|
|
customGoodsNum: 1,
|
|
|
userId: app.globalData.user_id,
|
|
|
},
|
|
|
- success:function(res){
|
|
|
- console.log(res,"加入购物车")
|
|
|
- if(res.data ==='success'){
|
|
|
+ success: function (res) {
|
|
|
+ console.log(res, "加入购物车")
|
|
|
+ if (res.data === 'success') {
|
|
|
wx.showModal({
|
|
|
title: '提示',
|
|
|
content: '加入购物车成功,是否去购物车结算商品?',
|
|
|
-
|
|
|
- success:function(res){
|
|
|
+
|
|
|
+ success: function (res) {
|
|
|
if (res.confirm) {
|
|
|
console.log('用户点击确定')
|
|
|
wx.redirectTo({
|
|
@@ -369,7 +372,7 @@ Page({
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- uploadFile(path,that,cb){
|
|
|
+ uploadFile(path, that, cb) {
|
|
|
let customGoodsImg = that.data.customGoodsImg;
|
|
|
wx.uploadFile({
|
|
|
url: host + 'fileUpload',
|
|
@@ -378,11 +381,11 @@ Page({
|
|
|
formData: {
|
|
|
file: path,
|
|
|
userId: app.globalData.user_id,
|
|
|
- imgStatus: 1,
|
|
|
+ imgStatus: 1,
|
|
|
},
|
|
|
success: function (res) {
|
|
|
console.log(res, "rrrr");
|
|
|
- customGoodsImg += res.data+',';
|
|
|
+ customGoodsImg += res.data + ',';
|
|
|
that.setData({
|
|
|
customGoodsImg: customGoodsImg
|
|
|
})
|