|
@@ -8,12 +8,8 @@ Page({
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
- dataPositionObj: { //正面数据
|
|
|
- top: 184,
|
|
|
- left: 305,
|
|
|
- width: 218,
|
|
|
- height: 218,
|
|
|
- },
|
|
|
+ dataPositionObj1: {},
|
|
|
+ dataPositionObj2: {},
|
|
|
imgTouch: {
|
|
|
isActive: "1",
|
|
|
src: "https://dlz.info666.com//temp/d945bfb0-5cc6-406d-a814-cf63b099041f.jpg",
|
|
@@ -40,27 +36,15 @@ Page({
|
|
|
height: 132
|
|
|
},
|
|
|
rpx: 1,
|
|
|
- obverseImgObject: ['', '/customized/images/customized/cup_black_big.png', '/customized/images/customized/cup_black_side.png', '/customized/images/customized/cup_black_handle.png', '/customized/images/customized/cup_black_bottom.png', '/customized/images/customized/box_white_big_1.png', '/customized/images/customized/box_white_big_2.png'],
|
|
|
- // obverseImgObject: {
|
|
|
- // '1': ,
|
|
|
- // /*正面 */
|
|
|
- // '2': '/customized/images/customized/cup_black_side.png',
|
|
|
- // /*侧面面 */
|
|
|
- // '3': '/customized/images/customized/cup_black_handle.png',
|
|
|
- // /*手柄 */
|
|
|
- // '4': '/customized/images/customized/cup_black_bottom.png',
|
|
|
- // /*底部 */
|
|
|
- // },
|
|
|
+ obverseImgObject: {},
|
|
|
+
|
|
|
imgSrcArray: [],
|
|
|
buildSrcArrayText: {
|
|
|
'1': '正面',
|
|
|
'2': '背面',
|
|
|
},
|
|
|
- boxImg: {
|
|
|
- '5': '/customized/images/customized/box_white_big_1_out.png',
|
|
|
- '6': '/customized/images/customized/box_white_big_2_out.png',
|
|
|
- },
|
|
|
buildSrcArray: [],
|
|
|
+ dataId:[],
|
|
|
customGoodsImg: "",
|
|
|
|
|
|
},
|
|
@@ -68,7 +52,16 @@ Page({
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
- onLoad: function (options) {},
|
|
|
+ onLoad: function (options) {
|
|
|
+ if ('dataId' in options) {
|
|
|
+ this.setData({
|
|
|
+ obverseImgObject: util.changeImg,//素材
|
|
|
+ dataPositionObj1: util.changeCup(options.dataId.split(',')[0].toString()).dataPositionObj,
|
|
|
+ dataPositionObj2: util.changeCup(options.dataId.split(',')[1].toString()).dataPositionObj,
|
|
|
+ dataId: options.dataId.split(',')
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
@@ -79,13 +72,14 @@ Page({
|
|
|
title: '图片合成中...'
|
|
|
})
|
|
|
let that = this,
|
|
|
- result = true;
|
|
|
+ result = true,
|
|
|
+ dataId = that.data.dataId;
|
|
|
|
|
|
- if (wx.getStorageSync('madeCupImgData5') || wx.getStorageSync('madeCupFontData5')) {
|
|
|
- that.getCombImg(that, 5);
|
|
|
+ if (wx.getStorageSync('madeCupImgData' + dataId[0]) || wx.getStorageSync('madeCupFontData' + dataId[0])) {
|
|
|
+ that.getCombImg(that, dataId[0],1);
|
|
|
result = false
|
|
|
- } else if (wx.getStorageSync('madeCupImgData6') || wx.getStorageSync('madeCupFontData6')) {
|
|
|
- that.getCombImg(that, 6);
|
|
|
+ } else if (wx.getStorageSync('madeCupImgData' + dataId[1]) || wx.getStorageSync('madeCupFontData' + dataId[1])) {
|
|
|
+ that.getCombImg(that, dataId[1],2);
|
|
|
result = false
|
|
|
}
|
|
|
|
|
@@ -135,7 +129,7 @@ Page({
|
|
|
onShareAppMessage: function () {
|
|
|
|
|
|
},
|
|
|
- getCombImg(that, i) {
|
|
|
+ getCombImg(that, i,id) {
|
|
|
let imgTouch = null,
|
|
|
dataPositionObj = null;
|
|
|
that.setData({ // imgSrcArray 初始化
|
|
@@ -162,7 +156,7 @@ Page({
|
|
|
let dWidth = dataPositionObj.width / imgTouch.width;
|
|
|
// canvas截图区域与图片的高度比例
|
|
|
let dHeight = dataPositionObj.height / imgTouch.height;
|
|
|
- const ctx = wx.createCanvasContext('comb-img' + i);
|
|
|
+ const ctx = wx.createCanvasContext('comb-img' + id);
|
|
|
//画布中点坐标转移到图片中心
|
|
|
let movex = imgTouch.x + imgTouch.width * rpx / 2;
|
|
|
let movey = imgTouch.y + imgTouch.height * rpx / 2;
|
|
@@ -179,7 +173,7 @@ Page({
|
|
|
that.setData({
|
|
|
imgSrcArray: imgArray
|
|
|
})
|
|
|
- that.getCombFont(that, i, true);
|
|
|
+ that.getCombFont(that, i, true,id);
|
|
|
}
|
|
|
}, that)
|
|
|
})
|
|
@@ -190,13 +184,14 @@ Page({
|
|
|
},
|
|
|
})
|
|
|
} else {
|
|
|
- that.getCombFont(that, i, false);
|
|
|
+ that.getCombFont(that, i, false,id);
|
|
|
+ console.log("没有图片往下执行")
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
- getCombFont(that, i, _static) {
|
|
|
+ getCombFont(that, i, _static,id) {
|
|
|
let fontTouch = null,
|
|
|
dataPositionObj = null,
|
|
|
simulationFont = null;
|
|
@@ -204,7 +199,9 @@ Page({
|
|
|
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' + id);
|
|
|
+ console.log(id, ctx,"console.log(id,)")
|
|
|
// ctx.textBaseline = 'top';
|
|
|
ctx.setFontSize(fontTouch.fontSize);
|
|
|
ctx.setFillStyle(fontTouch.isColor);
|
|
@@ -220,19 +217,20 @@ Page({
|
|
|
ctx.restore()
|
|
|
ctx.draw(false, function () {
|
|
|
wx.canvasToTempFilePath({
|
|
|
- canvasId: 'comb-font' + i,
|
|
|
+ canvasId: 'comb-font' + id,
|
|
|
success: function (res) {
|
|
|
console.log(res)
|
|
|
- that.getCombFontImg(that, res.tempFilePath, fontTouch, i)
|
|
|
+ that.getCombFontImg(that, res.tempFilePath, fontTouch, i,id)
|
|
|
}
|
|
|
}, that)
|
|
|
})
|
|
|
} else {
|
|
|
- that.getComb(that, that.data.imgSrcArray, i, _static)
|
|
|
+ that.getComb(that, that.data.imgSrcArray, i, _static,id)
|
|
|
}
|
|
|
|
|
|
},
|
|
|
- getCombFontImg(that, img, fontTouch, i) { // 生产字体图片后在进行处理一次
|
|
|
+ getCombFontImg(that, img, fontTouch, i,id) { // 生产字体图片后在进行处理一次
|
|
|
+ let dataPositionObj = util.changeCup(i.toString()).dataPositionObj;
|
|
|
wx.getSystemInfo({
|
|
|
success: function (res) {
|
|
|
let rpx = res.windowWidth / 750;
|
|
@@ -242,16 +240,16 @@ Page({
|
|
|
// 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
|
|
|
console.log(res)
|
|
|
// canvas截图区域与图片的宽度比例
|
|
|
- const ctx = wx.createCanvasContext('comb-font' + i + '-2');
|
|
|
+ const ctx = wx.createCanvasContext('comb-font' + id + '-2');
|
|
|
//画布中点坐标转移到图片中心
|
|
|
- let movex = fontTouch.x + 536 * rpx / 2;
|
|
|
- let movey = fontTouch.y + 712 * rpx / 2;
|
|
|
+ let movex = fontTouch.x + dataPositionObj.width * rpx / 2;
|
|
|
+ let movey = fontTouch.y + dataPositionObj.height * 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.drawImage(img, -dataPositionObj.width * rpx / 2, -dataPositionObj.height * rpx / 2, dataPositionObj.width * rpx, dataPositionObj.height * rpx)
|
|
|
ctx.draw(false, function () {
|
|
|
wx.canvasToTempFilePath({
|
|
|
- canvasId: 'comb-font' + i + '-2',
|
|
|
+ canvasId: 'comb-font' + id + '-2',
|
|
|
success: function (res) {
|
|
|
console.log(res)
|
|
|
let imgArray = that.data.imgSrcArray;
|
|
@@ -259,75 +257,104 @@ Page({
|
|
|
that.setData({
|
|
|
imgSrcArray: imgArray
|
|
|
})
|
|
|
- that.getComb(that, that.data.imgSrcArray, i, true)
|
|
|
+ that.getComb(that, that.data.imgSrcArray, i, true,id)
|
|
|
}
|
|
|
}, that)
|
|
|
})
|
|
|
},
|
|
|
})
|
|
|
},
|
|
|
- getComb(that, imgSrcArray, i, _static) {
|
|
|
+ getComb(that, imgSrcArray, i, _static,id) {
|
|
|
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];
|
|
|
- console.log(canvasBg)
|
|
|
- wx.getSystemInfo({
|
|
|
- success: function (res) {
|
|
|
- let rpx = res.windowWidth / 750;
|
|
|
- that.setData({
|
|
|
- rpx: rpx
|
|
|
- });
|
|
|
- const ctx = wx.createCanvasContext('comb-canvas' + i);
|
|
|
- ctx.drawImage(canvasBg, 0, 0, 750 * rpx, 800 * rpx);
|
|
|
- // 设置背景
|
|
|
- ctx.draw(true)
|
|
|
- imgSrcArray.forEach((res) => {
|
|
|
- ctx.drawImage(res, dataPositionObj.left * rpx, dataPositionObj.top * rpx, dataPositionObj.width * rpx, dataPositionObj.height * rpx);
|
|
|
- })
|
|
|
- console.log('开始执行叠加')
|
|
|
- ctx.drawImage(that.data.boxImg[i], 0, 0, 750 * rpx, 800 * rpx)
|
|
|
-
|
|
|
- ctx.draw(true, function () {
|
|
|
- wx.canvasToTempFilePath({
|
|
|
- canvasId: 'comb-canvas' + i,
|
|
|
+ wx.downloadFile({
|
|
|
+ url: that.data.obverseImgObject[i],
|
|
|
+ success(res){
|
|
|
+ if (res.statusCode === 200) {
|
|
|
+ let canvasBg = res.tempFilePath;
|
|
|
+ wx.getSystemInfo({
|
|
|
success: function (res) {
|
|
|
- that.uploadFile(res.tempFilePath, that, function (data) {
|
|
|
- console.log(res, "合成成功");
|
|
|
-
|
|
|
- let buildSrcArray = that.data.buildSrcArray;
|
|
|
-
|
|
|
- buildSrcArray.push({
|
|
|
- src: res.tempFilePath,
|
|
|
- isActive: i,
|
|
|
- });
|
|
|
- console.log(buildSrcArray, "buildSrcArray")
|
|
|
- that.setData({
|
|
|
- buildSrcArray: buildSrcArray,
|
|
|
- })
|
|
|
- console.log(that.data.buildSrcArray, "buildSrcArray")
|
|
|
- if (i < 7) {
|
|
|
- i = i + 1
|
|
|
- that.getCombImg(that, i);
|
|
|
- } else {
|
|
|
- wx.hideLoading()
|
|
|
+ let rpx = res.windowWidth / 750;
|
|
|
+ that.setData({
|
|
|
+ rpx: rpx
|
|
|
+ });
|
|
|
+ const ctx = wx.createCanvasContext('comb-canvas' + id);
|
|
|
+ ctx.drawImage(canvasBg, 0, 0, 750 * rpx, 800 * rpx);
|
|
|
+ // 设置背景
|
|
|
+ ctx.draw(true)
|
|
|
+ imgSrcArray.forEach((res) => {
|
|
|
+ ctx.drawImage(res, dataPositionObj.left * rpx, dataPositionObj.top * rpx, dataPositionObj.width * rpx, dataPositionObj.height * rpx);
|
|
|
+ })
|
|
|
+ wx.downloadFile({
|
|
|
+ url: that.data.obverseImgObject[i+'_2'],
|
|
|
+ success(file){
|
|
|
+ if (file.statusCode === 200) {
|
|
|
+ ctx.drawImage(file.tempFilePath, 0, 0, 750 * rpx, 800 * rpx);
|
|
|
+ ctx.draw(true, function () {
|
|
|
+ wx.canvasToTempFilePath({
|
|
|
+ canvasId: 'comb-canvas' + id,
|
|
|
+ success: function (res) {
|
|
|
+ that.uploadFile(res.tempFilePath, that, function (data) {
|
|
|
+ console.log(res, "合成成功");
|
|
|
+
|
|
|
+ let buildSrcArray = that.data.buildSrcArray;
|
|
|
+
|
|
|
+ buildSrcArray.push({
|
|
|
+ src: res.tempFilePath,
|
|
|
+ isActive: i,
|
|
|
+ });
|
|
|
+ console.log(buildSrcArray, "buildSrcArray")
|
|
|
+ that.setData({
|
|
|
+ buildSrcArray: buildSrcArray,
|
|
|
+ })
|
|
|
+ console.log('第一张图片合成结束,i='+i)
|
|
|
+ if (i < that.data.dataId[1]) {
|
|
|
+ i = i*1 + 1
|
|
|
+ that.getCombImg(that, i,2);
|
|
|
+ } else {
|
|
|
+ wx.hideLoading()
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ },
|
|
|
+ fail: function (err) {
|
|
|
+ console.log(err, "合成失败")
|
|
|
+ wx.hideLoading();
|
|
|
+ }
|
|
|
+ }, that)
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: '合成资源图片不存在,请联系客服',
|
|
|
+ icon: 'error'
|
|
|
+ })
|
|
|
+ wx.hideLoading();
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
|
|
|
+
|
|
|
},
|
|
|
- fail: function (err) {
|
|
|
- console.log(err, "合成失败")
|
|
|
- wx.hideLoading();
|
|
|
- }
|
|
|
- }, that)
|
|
|
- })
|
|
|
- },
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: '合成资源图片不存在,请联系客服',
|
|
|
+ icon:'error'
|
|
|
+ })
|
|
|
+ wx.hideLoading();
|
|
|
+ }
|
|
|
+ }
|
|
|
})
|
|
|
+
|
|
|
+
|
|
|
} else {
|
|
|
- if (i < 4) {
|
|
|
- i = i + 1
|
|
|
- that.getCombImg(that, i);
|
|
|
+ console.log("走了这里哈,i值等于",i)
|
|
|
+ if (i < that.data.dataId[1]) {
|
|
|
+ i = i*1 + 1
|
|
|
+ that.getCombImg(that, i,2);
|
|
|
} else {
|
|
|
wx.hideLoading()
|
|
|
}
|
|
@@ -346,7 +373,7 @@ Page({
|
|
|
},
|
|
|
data: {
|
|
|
customGoodsImg: that.data.customGoodsImg.substring(0, that.data.customGoodsImg.length - 1),
|
|
|
- customGoodsName: '拉杆箱-银灰色',
|
|
|
+ customGoodsName: wx.getStorageSync('detail').customgoodsName,
|
|
|
customGoodsNum: 1,
|
|
|
userId: app.globalData.user_id,
|
|
|
customGoodsId:wx.getStorageSync('detail').id,
|
|
@@ -357,7 +384,6 @@ Page({
|
|
|
wx.showModal({
|
|
|
title: '提示',
|
|
|
content: '加入购物车成功,是否去购物车结算商品?',
|
|
|
-
|
|
|
success: function (res) {
|
|
|
if (res.confirm) {
|
|
|
console.log('用户点击确定')
|