594 lines
14 KiB
JavaScript
Raw Normal View History

2025-07-10 16:27:08 +08:00
import * as echarts from '../../ec-canvas/echarts';
let symbolImg = '../../images/circle.png';
let App = getApp();
// 设置数据,可以增加更多的数据参数
function setOption(chart, scatterData, mapData, type) {
const option = {
layoutCenter: ['50%', '30%'],
layoutSize: '100%',
series: [{
type: 'map',
map: type,
aspectScale: 0.75,
roam: 'scale',
zoom: 0.4,
scaleLimit: {
min: 1,
max: 2.5
},
itemStyle: {
normal: {
areaColor: 'rgba(216,216,215,0.5)',
borderColor: '#fff',
borderWidth: 1,
},
emphasis: {
areaColor: null,
},
},
label: {
show: true,
fontSize: 8,
color: '#333'
},
emphasis: {
label: {
show: true,
color: '#333'
},
},
data: mapData,
markPoint: {
symbol: 'circle',
symbolSize: 5,
label: {
show: true,
fontSize: 6,
color: '#333',
position: 'right'
},
data: scatterData
}
}
],
};
chart.setOption(option);
}
Page({
data: {
ec: {
lazyLoad: true,
},
showAddMeBtn: !0,
scrollTop: 0,
showModal: false,
step: 0,
shouquan: 0,
follow: 0,
yunti: !0,
sign: !0,
indexData: {
'dhnum': 0
},
scatterData: [],
mapData: [],
activity: [],
show: 0,
today: "",
canvasShow: 0,
map:{}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
// 获取组件
this.ecComponent = this.selectComponent('#mychart-dom-area');
},
getMap(){
var that=this;
wx.request({
url: `https://minipro.luochunlvshi.com/map/${this.data.type}.js`,
success: function (res) {
console.log(res);
that.initChart(res.data);
}
});
},
// 初始化图表
initChart(mapItem) {
this.ecComponent.init((canvas, width, height, dpr) => {
// 获取组件的 canvas、width、height 后的回调函数
// 在这里初始化图表
const chart = echarts.init(canvas, null, {
width: width,
height: height,
devicePixelRatio: dpr, // new
});
console.log(this.data.mapData);
console.log(this.data.type);
// 注册中国地图数据包
echarts.registerMap(this.data.type, mapItem);
// 设置数据
setOption(chart, this.data.scatterData, this.data.mapData, this.data.type);
// 将图表实例绑定到 this 上,可以在其他成员函数(如 dispose中访问
this.chart = chart;
// 绑定点击事件
let that = this;
chart.on('click', function (params) {
that.handleChartClick(params);
});
// 注意这里一定要返回 chart 实例,否则会影响事件处理等
return chart;
});
},
handleChartClick(params) {
// 可以通过参数去数据列表中获取完整数据 params.dataIndex
console.log('chart click params:', {
name: params.name,
data: params.data,
dataIndex: params.dataIndex,
seriesIndex: params.seriesIndex,
value: params.value
});
},
onLoad: function () {
// 设置页面标题
App.setTitle();
// 设置navbar标题、颜色
App.setNavigationBar();
let user_id = wx.getStorageSync('user_id');
if (user_id) {
this.Updatestep();
this.getData();
}
},
onShow: function () {
this.setData({
showAddMeBtn: !0
})
let user_id = wx.getStorageSync('user_id');
if (!user_id) {
this.setData({
showModal: true
})
}
},
goTop: function (t) {
this.setData({
scrollTop: 0
});
},
/**
* 获取首页数据
*/
getIndexData: function () {
let _this = this;
App._get('index/page', {
user_id: wx.getStorageSync('user_id')
}, function (result) {
_this.setData(result.data);
});
},
onClickAddToMinProgramCloseBtn: function () {
wx.setStorageSync("showAddMeFlag" + this.data.time, !0), this.setData({
showAddMeBtn: !1
});
},
onShareAppMessage: function () {
return {
title: "科大工会健步走小程序",
desc: "",
path: "/pages/index/index"
};
},
goDuiHuan: async function (e) {
let _this = this;
let step = this.data.step;
let time = parseInt(new Date().getTime() / 1000);
console.log('step', this.data.step);
if (this.data.step == 0) {
var a = await this.getyundong();
console.log('运动授权结果:', a);
if (a === 1) {
// 授权成功后,立即更新步数
this.Updatestep();
}
return;
}
if (time < _this.data.activity.starttime) {
wx.showToast({
title: '活动未开始',
icon: 'none',
duration: 2000
})
return false;
}
if (time > _this.data.activity.endtime) {
wx.showToast({
title: '活动已结束',
icon: 'none',
duration: 2000
})
return false;
}
var user_id = wx.getStorageSync('user_id');
App._post_form('footchina/goDuiHuan', {
user_id: user_id,
step: step
}, function (result) {
var rdata = result.data.data;
console.log('goDuiHuan', rdata);
if (result.data.code == -1) {
wx.showToast({
title: '用户信息失效...',
icon: 'none',
duration: 2000
})
_this.setData({
showModal: true
})
return;
}
if (rdata.status) {
// let _this = this;
_this.setData({
show: 1,
today: new Date().toISOString().slice(0, 10)
})
console.log('today', _this.data.today);
// wx.showToast({
// title: '点亮成功',
// icon: 'none',
// duration: 2000
// })
_this.getData();
}
});
},
getData: function (e) {
let _this = this;
App._post_form('footchina/getData', {
user_id: wx.getStorageSync('user_id'),
}, (result) => {
var rdata = result.data.data;
console.log(rdata);
_this.setData({
indexData: rdata,
scatterData: rdata.citySub,
mapData: rdata.provinceAreaColor,
type: rdata.type,
activity: rdata.activity,
});
console.log(rdata.provinceAreaColor);
console.log(_this.data.mapData);
_this.getMap();
});
},
goDuiHuanDis: function () {
let time = parseInt(new Date().getTime() / 1000);
if (time < this.data.activity.starttime) {
wx.showToast({
title: '活动未开始',
icon: 'none',
duration: 2000
})
return false;
}
if (this.data.step < this.data.indexData.step) {
wx.showToast({
title: '步数未达标,暂不能点亮城市',
icon: 'none',
duration: 2000
})
return false;
}
if (time > this.data.activity.endtime) {
wx.showToast({
title: '活动已结束',
icon: 'none',
duration: 2000
})
return false;
}
if (this.data.indexData.dhnum == 1) {
// let _this = this;
// _this.setData({
// show:1
// })
wx.showToast({
title: '今日已点亮',
icon: 'none',
duration: 2000
})
return false;
}
},
guanzhu: function () {
this.data.follow;
this.setData({
follow: 1
});
},
xiao: function () {
let _this = this;
wx.showModal({
title: '提示',
content: '确定要保存这张图片吗?',
success: function (res) {
if (res.confirm) {
console.log('用户点击确定')
wx.getImageInfo({
src: _this.data.imageSet.index_gz_gzh,
success: function (res) {
console.log(res);
var path = res.path;
wx.saveImageToPhotosAlbum({
filePath: path,
success: function (res) {
console.log('图片已保存');
_this.data.follow;
_this.setData({
follow: 0
});
},
fail: function (res) {
console.log('保存失败');
_this.data.follow;
_this.setData({
follow: 0
});
}
})
}
});
} else if (res.cancel) {
console.log('用户点击取消');
_this.data.follow;
_this.setData({
follow: 0
});
}
}
})
},
bindIdCard: function (e) {
this.setData({
idcard: e.detail.value
})
},
checkIdCard: function () {
let _this = this;
let idCard = _this.data.idcard;
if (idCard == undefined) {
wx.showModal({
title: "提示",
content: "身份证号不能为空",
success: function (a) {
}
});
return false;
}
App.getUserInfoByIdCard(idCard, (user_id) => {
_this.getUserProfile(user_id);
_this.setData({
showModal: false
})
});
},
//取消登录
loginClose: function () {
let _this = this;
_this.setData({
showModal: false
});
},
/**
* 获取用户微信信息
*/
getUserProfile(user_id) {
if (!user_id) {
let user_id = wx.getStorageSync('user_id');
}
console.log('user_id', user_id);
const app = this
try {
wx.getUserProfile({
lang: 'zh_CN',
desc: '获取用户相关信息',
success({
userInfo
}) {
console.log('用户同意了授权')
console.log('userInfo', userInfo)
App.getUserInfo(userInfo, user_id, () => {
app.Updatestep();
});
},
fail() {
console.log('用户拒绝了授权--微信授权')
}
})
} catch (e) {
console.log('error', e.message)
if (e.message === 'wx.getUserProfile is not a function') {
App.showError('wx.getUserProfile 接口无法使用,请升级到最新版微信')
} else {
App.showError(error.message)
}
}
},
getyundong() {
return new Promise((resolve, reject) => {
// 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.werun" 这个 scope
wx.getSetting({
success(res) {
if (!res.authSetting['scope.werun']) {
wx.openSetting({
success: (authResult) => {
if (authResult.authSetting['scope.werun']) {
resolve(1);
} else {
resolve(0);
}
},
fail: (err) => {
console.error('打开设置页失败', err);
reject(err);
}
});
} else {
resolve(1);
}
},
fail: (err) => {
console.error('wx.getSetting失败', err);
reject(err);
}
})
});
},
// 读取用户的微信运动数据
Updatestep: function (t) {
var e = this;
wx.login({
success: function (t) {
var a = t.code;
e.setData({
code: a
}), wx.getWeRunData({
success: function (t) {
var a = t.encryptedData,
o = t.iv;
App._post_form('user/getStep', {
wRunEncryptedData: a,
iv: o,
code: e.data.code,
user_id: wx.getStorageSync('user_id')
}, result => {
e.getIndexData();
//wx.setStorageSync('step', result.data.data);
e.setData({
step: result.data.data
})
e.getData();
});
},
fail() {
console.log('用户拒绝了授权--微信运动')
}
});
}
});
},
guanbil: function () {
var a = this.data.yunti;
this.setData({
yunti: !a
});
},
goInfo: function () {
wx.navigateTo({
url: "/pages/rank/address"
});
},
goRili: function () {},
goRili: function () {
wx.navigateTo({
url: '/packageB/user/sign'
})
},
/**
* 拒绝授权
*/
onNotLogin() {
let _this = this;
// 跳转回原页面
_this.onNavigateBack();
},
/**
* 授权成功 跳转回原页面
*/
onNavigateBack() {
wx.navigateBack();
},
overdue: function () {
var t = this;
wx.getSetting({
success: function (a) {
if (a.authSetting["scope.userInfo"]) wx.checkSession({
success: function (a) {
},
fail: function (a) {
t.data.shouquan;
t.setData({
shouquan: 1
});
}
});
else {
t.data.shouquan;
t.setData({
shouquan: 1
});
}
}
});
},
onPullDownRefresh: function () {
let user_id = wx.getStorageSync('user_id');
if (user_id) {
this.Updatestep();
}
wx.stopPullDownRefresh()
},
/** 点亮成功 */
goSuccess() {
console.log('进来了', 111);
let _this = this;
_this.setData({
show: 1,
today: new Date().toISOString().slice(0, 10)
})
},
//关闭签到弹窗
guanbilsig: function () {
let _this = this;
_this.setData({
show: 0
})
// wx.navigateTo({
// url: "/pages/rank/address"
// });
// var a = this.data.sign;
// this.setData({
// sign: !a
// });
},
});