123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- // pages/sign/sign.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- code:"",//储存微信传过来的code
- number:"",
- },
- verification:function(e){
- var that = this
- that.data.number = e.detail.value
- },
- //登录功能
- sign:function(){
- var that = this
- var trys = /^1[3-9][0-9]{9}$/
- var number = that.data.number
- if(number == "") {
- wx.showModal({
- title:'提示',
- showCancel:false,
- content:'请输入手机号'
- })
- }
- else if(trys.test(number) == false){
- wx.showModal({
- title:'提示',
- showCancel:false,
- content:'请输入正确的手机号'
- })
- }
- else {
- wx.login({
- success:function(e){
- console.log(e.code)
- wx.request({
- url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/login',
- method:'POST',
- data:{
- code:e.code,
- phone:that.data.number
- },
- header:{"Content-Type": "application/json"},
- success:function(res){
- if(res.data.code == 200){
- wx.setStorageSync('token', res.data.data.access_token)
- let creatime = new Date()
- wx.setStorageSync('time',creatime)
- wx.switchTab({
- url: '/pages/scene/scene',
- })
- }
- else{
- console.log('登录失败')
- }
- }
- })
- }
- })
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|