微信小程序:转盘抽奖

微信小程序:转盘抽奖

更新: 2017-01-18

阅读:1125

开源:GitHub

## 简介 

用微信小程序开发的Canvas绘制可配置的转盘抽奖。

# 微信小程序转盘抽奖效果图


## 其它

微信小程序感觉是个半成品,代码移植过程比较繁琐麻烦。`canvas` API 部分都被重写了

##部分代码

app.js

//app.js
App({
  onLaunch: function () {
    //调用API从本地缓存中获取数据
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
  },
  getUserInfo:function(cb){
    var that = this
    if(this.globalData.userInfo){
      typeof cb == "function" && cb(this.globalData.userInfo)
    }else{
      //调用登录接口
      wx.login({
        success: function () {
          wx.getUserInfo({
            success: function (res) {
              that.globalData.userInfo = res.userInfo
              typeof cb == "function" && cb(that.globalData.userInfo)
            }
          })
        }
      })
    }
  },
  globalData:{
    userInfo:null,
    awardsConfig: {}
  }
})


app.wxss

/**app.wxss**/

* {
	box-sizing: border-box;
}

.container {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 200rpx 0;
  box-sizing: border-box;
} 

.red {
	color: red;
}


app.json

{
  "pages":[
    "pages/list/list",
    "pages/canvas/canvas",
    "pages/logs/logs"
  ],
  "window":{
    "backgroundTextStyle":"light",
    "navigationBarBackgroundColor": "#000",
    "navigationBarTitleText": "oWong",
    "navigationBarTextStyle":"white",
    "backgroundColor": "#ffffff",
    "enablePullDownRefresh": true
  },
  "tabBar": {
    "color": "#666",
    "selectedColor": "#3cc51f",
    "backgroundColor": "#eee",
    "borderStyle": "white",
    "list": [{
      "pagePath": "pages/canvas/canvas",
      "text": "去抽奖",
      "iconPath": "image/icon.png",
      "selectedIconPath": "image/icon-HL.png"  
    }, {
      "pagePath": "pages/list/list",
      "text": "中奖记录",
      "iconPath": "image/icon.png",
      "selectedIconPath": "image/icon-HL.png"
    }]
  }
}

热门推荐