123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- // pages/signIn/index.js
- import SignIn from '../../../api/signIn'
- import { isEmpty } from '../../../utils/util'
-
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- showPage: false,
- activity: {},
- signInNodes: [{ pos: 1, text: '星期一' },
- { pos: 2, text: '星期二' },
- { pos: 3, text: '星期三' },
- { pos: 4, text: '星期四' },
- { pos: 5, text: '星期五' },
- { pos: 6, text: '星期六' }],
- lastSignInNode: { pos: 7, text: '星期天' }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- SignIn.getActivityData("").then(res => {
- console.log(res)
- if (res.code == 200) {
- this.setData({
- activity: res.data
- })
- this.mapToView(res.data)
- }
- }).catch(_ => {
- }).finally(_ => {
- this.setData({
- showPage: true
- })
- })
- this.setPageStyle();
- },
- setPageStyle() {
- let dwObj = wx.getMenuButtonBoundingClientRect()
- let navHeight_ = (dwObj.top + dwObj.height)
- let capsuleTop_ = dwObj.top
- let windowHeight = wx.getSystemInfoSync().windowHeight
- this.setData({
- navHeight: navHeight_,
- capsuleTop:capsuleTop_,
- capHeight: dwObj.height,
- bodyHeight: windowHeight - navHeight_,
- });
- },
- mapToView(data) {
- if (data.dayAwardList && data.dayAwardList.length > 0) {
- data.dayAwardList.forEach(item => {
- if (item.dayNo == 7) {
- Object.assign(this.data.lastSignInNode, item);
- } else {
- if (this.data.signInNodes[item.dayNo - 1]) {
- Object.assign(this.data.signInNodes[item.dayNo - 1], item)
- }
- }
- });
- this.setData({
- signInNodes: this.data.signInNodes,
- lastSignInNode: this.data.lastSignInNode
- })
- }
- this.setColors(data.color)
- },
- setColors(color) {
- if (isEmpty(color)) {
- color = "#EE5A5A"
- }
- if (color.length == 4) {
- color = color.replace(/#(.)(.)(.)$/, "#$1$1$2$2$3$3")
- }
- for (let i = 1; i <= 6; i++) {
- console.log(color.charAt(i))
- }
- },
- tapSignIn: function() {
- SignIn.triggerSignIn(5, "16602120168").then(res => {
- console.log(res)
- }).catch(_ => {})
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|