Commit 9f3be329 by 穆启卓

1

parent f8f35299
......@@ -36,56 +36,7 @@ Page({
},
onReady() {
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 {
// 重画
}
});
this.initCanvas();
},
getPageData() {
......@@ -266,40 +217,48 @@ Page({
},
method: 'POST',
success:(res) => {
this.data.isFirstReq = false;
const resData = res.data.data;
// 数据处理,结合!!两个数组!!判断是否显示打卡角标和状态
const joinDate = [];
resData.records_info.forEach(item => {
joinDate.push(item.period);
});
resData.step_data.forEach(item => {
if (joinDate.indexOf(item.period) > -1) {
if (resData.records_info[joinDate.indexOf(item.period)].daka_done) {
item.status = 1; // 打卡成功
wx.hideLoading();
if (res.data.code === 0) {
this.data.isFirstReq = false;
const resData = res.data.data;
// 数据处理,结合!!两个数组!!判断是否显示打卡角标和状态
const joinDate = [];
resData.records_info.forEach(item => {
joinDate.push(item.period);
});
resData.step_data.forEach(item => {
if (joinDate.indexOf(item.period) > -1) {
if (resData.records_info[joinDate.indexOf(item.period)].daka_done) {
item.status = 1; // 打卡成功
} else {
item.status = 2; // 打卡失败
}
} 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 {
item.status = 0; // 未参与打卡
setData.currentSteps = (resData.step_data && resData.step_data[0]) ? resData.step_data[0].step : 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);
this.setData(setData);
this.showToast();
} 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: () => {
wx.hideLoading();
......@@ -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
......
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