Commit 9f3be329 by 穆启卓

1

parent f8f35299
...@@ -36,56 +36,7 @@ Page({ ...@@ -36,56 +36,7 @@ Page({
}, },
onReady() { onReady() {
const rate = wx.getSystemInfoSync().screenWidth / 750, this.initCanvas();
context = wx.createCanvasContext('progressCanvas');
context.translate(375 * rate, 255 * rate);
this.data.progressCanvasContext = context;
this.data.progressCanvasRate = rate;
// 画进度条总长
context.setStrokeStyle('rgba(255, 255, 255, 0.4)');
context.setLineWidth(4 * rate);
context.setLineCap('round');
context.beginPath();
context.arc(0, 0, 245 * rate, 0.90625 * Math.PI, 2.09375 * Math.PI, false);
context.stroke();
// 画刻度
context.setStrokeStyle('#ffffff');
context.setLineWidth(4 * rate);
context.rotate(-0.09375 * Math.PI);
context.beginPath();
const keduLeft = -230 * rate,
keduRight = -220 * rate,
oneKedu = 0.03125 * Math.PI;
context.moveTo(keduLeft, 0);
context.lineTo(keduRight, 0);
context.stroke();
for (let i = 0; i < 38; i++) {
context.rotate(oneKedu);
context.beginPath();
context.moveTo(keduLeft, 0);
context.lineTo(keduRight, 0);
context.stroke();
}
// 画当前圆球
context.setFillStyle('#ffffff');
context.rotate(2.544);
context.arc(-245 * rate, 0, 7 * rate, 0, 2 * Math.PI, false);
context.fill();
// 画
context.draw(false, drawRes => {
if (drawRes.errMsg === 'drawCanvas:ok') {
wx.canvasToTempFilePath({
canvasId: 'progressCanvas',
success:(ImageRes) => {
this.setData({
progressCanvasImage: ImageRes.tempFilePath
});
}
});
} else {
// 重画
}
});
}, },
getPageData() { getPageData() {
...@@ -266,40 +217,48 @@ Page({ ...@@ -266,40 +217,48 @@ Page({
}, },
method: 'POST', method: 'POST',
success:(res) => { success:(res) => {
this.data.isFirstReq = false; wx.hideLoading();
const resData = res.data.data; if (res.data.code === 0) {
// 数据处理,结合!!两个数组!!判断是否显示打卡角标和状态 this.data.isFirstReq = false;
const joinDate = []; const resData = res.data.data;
resData.records_info.forEach(item => { // 数据处理,结合!!两个数组!!判断是否显示打卡角标和状态
joinDate.push(item.period); const joinDate = [];
}); resData.records_info.forEach(item => {
resData.step_data.forEach(item => { joinDate.push(item.period);
if (joinDate.indexOf(item.period) > -1) { });
if (resData.records_info[joinDate.indexOf(item.period)].daka_done) { resData.step_data.forEach(item => {
item.status = 1; // 打卡成功 if (joinDate.indexOf(item.period) > -1) {
if (resData.records_info[joinDate.indexOf(item.period)].daka_done) {
item.status = 1; // 打卡成功
} else {
item.status = 2; // 打卡失败
}
} else { } else {
item.status = 2; // 打卡失败 item.status = 0; // 未参与打卡
} }
});
// wx.setStorageSync('getStepLoading', Date.now());
// 避免没有目标步数,不好比较是否达标
const setData = {
targetSteps: resData.total_step,
stepRecordList: resData.step_data
};
if (resData.total_step > 0) {
// this.changeShowPopup();
const realCurrentSteps = (resData.step_data && resData.step_data[0]) ? resData.step_data[0].step : 0;
this.dynamicDrawCanvas(realCurrentSteps, (realCurrentSteps > resData.total_step ? resData.total_step : realCurrentSteps) / 100);
} else { } else {
item.status = 0; // 未参与打卡 setData.currentSteps = (resData.step_data && resData.step_data[0]) ? resData.step_data[0].step : 0;
} }
}); this.setData(setData);
// wx.setStorageSync('getStepLoading', Date.now()); this.showToast();
// 避免没有目标步数,不好比较是否达标
const setData = {
targetSteps: resData.total_step,
stepRecordList: resData.step_data
};
if (resData.total_step > 0) {
// this.changeShowPopup();
const realCurrentSteps = (resData.step_data && resData.step_data[0]) ? resData.step_data[0].step : 0;
this.dynamicDrawCanvas(realCurrentSteps, (realCurrentSteps > resData.total_step ? resData.total_step : realCurrentSteps) / 100);
} else { } else {
setData.currentSteps = (resData.step_data && resData.step_data[0]) ? resData.step_data[0].step : 0; wx.showToast({
title: '同步步数失败,请联系客服处理',
icon: 'none',
duration: 2000
});
} }
this.setData(setData);
wx.hideLoading();
this.showToast();
}, },
fail: () => { fail: () => {
wx.hideLoading(); wx.hideLoading();
...@@ -616,6 +575,60 @@ Page({ ...@@ -616,6 +575,60 @@ Page({
} }
}, },
// 初始化仪表盘
initCanvas() {
const rate = wx.getSystemInfoSync().screenWidth / 750,
context = wx.createCanvasContext('progressCanvas');
context.translate(375 * rate, 255 * rate);
this.data.progressCanvasContext = context;
this.data.progressCanvasRate = rate;
// 画进度条总长
context.setStrokeStyle('rgba(255, 255, 255, 0.4)');
context.setLineWidth(4 * rate);
context.setLineCap('round');
context.beginPath();
context.arc(0, 0, 245 * rate, 0.90625 * Math.PI, 2.09375 * Math.PI, false);
context.stroke();
// 画刻度
context.setStrokeStyle('#ffffff');
context.setLineWidth(4 * rate);
context.rotate(-0.09375 * Math.PI);
context.beginPath();
const keduLeft = -230 * rate,
keduRight = -220 * rate,
oneKedu = 0.03125 * Math.PI;
context.moveTo(keduLeft, 0);
context.lineTo(keduRight, 0);
context.stroke();
for (let i = 0; i < 38; i++) {
context.rotate(oneKedu);
context.beginPath();
context.moveTo(keduLeft, 0);
context.lineTo(keduRight, 0);
context.stroke();
}
// 画当前圆球
context.setFillStyle('#ffffff');
context.rotate(2.544);
context.arc(-245 * rate, 0, 7 * rate, 0, 2 * Math.PI, false);
context.fill();
// 画
context.draw(false, drawRes => {
if (drawRes.errMsg === 'drawCanvas:ok') {
wx.canvasToTempFilePath({
canvasId: 'progressCanvas',
success:(ImageRes) => {
this.setData({
progressCanvasImage: ImageRes.tempFilePath
});
}
});
} else {
// 重画
}
});
},
// 暂留================================================================== // 暂留==================================================================
// 通过code2session方式拿unionid // 通过code2session方式拿unionid
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment