diff --git a/app.js b/app.js index ed3e243..02cf30b 100644 --- a/app.js +++ b/app.js @@ -2,21 +2,60 @@ const $api = require('./utils/api').API; App({ onLaunch() { - // 展示本地存储能力 - const logs = wx.getStorageSync('logs') || [] - logs.unshift(Date.now()) - wx.setStorageSync('logs', logs) + let that = this; + let token = wx.getStorageSync('access_token') + let userInfo = wx.getStorageSync('userInfo') + if(token&&userInfo)return; wx.login({ success (res) { if (res.code) { //发起网络请求 - $api.getUserAuth(res.code) + $api.getUserAuth(res.code).then(data=>{ + if(data.access_token){ + wx.setStorage({ + key:"access_token", + data:data.access_token + }) + that.queryUsreInfo(); + }else if(data.code==2){ + that.registerBind(res.code) + }else{ + + } + }).catch(err=>{ + console.log('err',err) + }) } else { console.log('登录失败!' + res.errMsg) } } }) - + }, + registerBind(code){ + let that = this; + let params = { + state:'MINI', + code, + phone:'18280395620', + phoneCode:'', + nickName:'', + avatar:'', + legalName:'' + }; + $api.registerBind(params).then(data=>{ + wx.setStorage({ + key:"access_token", + data:data.access_token + }) + that.queryUsreInfo(); + }) + }, + queryUsreInfo(){ + $api.getUserInfo().then(res=>{ + if(res.code===0){ + wx.setStorageSync('userInfo', res.data.sysUser) + } + }) }, globalData: { userInfo: null diff --git a/app.wxss b/app.wxss index d65a6c7..34f392d 100644 --- a/app.wxss +++ b/app.wxss @@ -6,6 +6,7 @@ display: flex; flex-direction: column; background-color: #F8F8F8; + font-size: 24rpx; } .main { diff --git a/assets/.DS_Store b/assets/.DS_Store index 8d97eea..a0c44dc 100644 Binary files a/assets/.DS_Store and b/assets/.DS_Store differ diff --git a/assets/images/.DS_Store b/assets/images/.DS_Store new file mode 100644 index 0000000..fd8fd36 Binary files /dev/null and b/assets/images/.DS_Store differ diff --git a/pages/auth/auth.js b/pages/auth/auth.js index 1592348..a212a5b 100644 --- a/pages/auth/auth.js +++ b/pages/auth/auth.js @@ -2,115 +2,132 @@ const $api = require('../../utils/api').API; Page({ - /** - * 页面的初始数据 - */ - data: { - - }, - - bindGetUserInfo: function (e){ - if (e.detail.userInfo) { - //用户按了允许授权按钮 - var that = this; - let info = e.detail.userInfo; - that.queryUsreInfo(); - console.log(info); - return; - //授权成功后,跳转进入小程序首页 - wx.switchTab({ - url: '/pages/index/index' - }) - } else { - //用户按了拒绝按钮 - wx.showModal({ - title:'警告', - content:'您点击了拒绝授权,将无法进入小程序,请授权之后再进入!!!', - showCancel:false, - confirmText:'返回授权', - success:function(res){ - if (res.confirm) { - console.log('用户点击了“返回授权”') - } - } - }) - } - }, - - /** - * 生命周期函数--监听页面加载 - */ - onLoad: function (options) { - var that = this; - // 查看是否授权 - wx.getSetting({ - success: function (res) { - if (res.authSetting['scope.userInfo']) { - wx.getUserInfo({ - success: function (res) { - //从数据库获取用户信息 - that.queryUsreInfo(); - //用户已经授权过 - // wx.switchTab({ - // url: '/pages/index/index' - // }) + /** + * 页面的初始数据 + */ + data: { + agree: false + }, + + setAgree() { + let { + agree + } = this.data; + this.setData({ + agree: !agree + }) + }, + + bindGetUserInfo: function (e) { + let { + agree + } = this.data; + if (agree===false) { + wx.showToast({ + title: '请勾选隐私政策', + icon: 'none', + duration: 2000 + }) + return; + } + if (e.detail.userInfo) { + wx.switchTab({ + url: '/pages/index/index' + }) + //用户按了允许授权按钮 + // var that = this; + // let info = e.detail.userInfo; + // that.queryUsreInfo(); + } else { + //用户按了拒绝按钮 + wx.showModal({ + title: '警告', + content: '您点击了拒绝授权,将无法进入小程序,请授权之后再进入!!!', + showCancel: false, + confirmText: '返回授权', + success: function (res) { + if (res.confirm) { + console.log('用户点击了“返回授权”') } - }); - } + } + }) } - }) - }, + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + var that = this; + // 查看是否授权 + wx.getSetting({ + success: function (res) { + if (res.authSetting['scope.userInfo']) { + wx.getUserInfo({ + success: function (res) { + //从数据库获取用户信息 + that.queryUsreInfo(); + //用户已经授权过 + // wx.switchTab({ + // url: '/pages/index/index' + // }) + } + }); + } + } + }) + }, + + queryUsreInfo() { - queryUsreInfo(){ - - }, + }, - /** - * 生命周期函数--监听页面初次渲染完成 - */ - onReady: function () { + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { - }, + }, - /** - * 生命周期函数--监听页面显示 - */ - onShow: function () { + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { - }, + }, - /** - * 生命周期函数--监听页面隐藏 - */ - onHide: function () { + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { - }, + }, - /** - * 生命周期函数--监听页面卸载 - */ - onUnload: function () { + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { - }, + }, - /** - * 页面相关事件处理函数--监听用户下拉动作 - */ - onPullDownRefresh: function () { + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { - }, + }, - /** - * 页面上拉触底事件的处理函数 - */ - onReachBottom: function () { + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { - }, + }, - /** - * 用户点击右上角分享 - */ - onShareAppMessage: function () { + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { - } + } }) \ No newline at end of file diff --git a/pages/auth/auth.wxml b/pages/auth/auth.wxml index a2b0512..cbacd1a 100644 --- a/pages/auth/auth.wxml +++ b/pages/auth/auth.wxml @@ -6,8 +6,8 @@ - - + + 已阅读并同意 diff --git a/pages/auth/auth.wxss b/pages/auth/auth.wxss index d96eb7c..f956031 100644 --- a/pages/auth/auth.wxss +++ b/pages/auth/auth.wxss @@ -31,4 +31,43 @@ .wx-log { width: 40rpx; height: 40rpx; +} + +.tag-icon { + width: 24rpx; + height: 24rpx; + border: 1px solid #EFB952; + border-radius: 50%; +} + +.msg{ + margin-top: 116rpx; + margin-bottom: 46rpx; +} + +.tag-yes{ + display: none; + width: 100%; + height: 100%; +} + +.tag-active { + background: #FFAA22; +} + +.tag-active .tag-yes{ + display: block; +} + +.tag-text{ + color: #AAA9A9; + text-indent: 10rpx; +} + +.tag-text .text{ + color: #FFAA22; +} + +.bottom{ + color: #999999; } \ No newline at end of file diff --git a/utils/api.js b/utils/api.js index fe0b7d5..dc210e0 100644 --- a/utils/api.js +++ b/utils/api.js @@ -6,11 +6,13 @@ const FORM = 'FORM'; const DELETE = 'DELETE'; -function request(method, url, data) { +function request(method, url, data,hasToke=true) { + let token = wx.getStorageSync('access_token') + let Authorization =token&&hasToke?`Bearer ${token}`:'Basic YXBwOmFwcA==' return new Promise(function (resolve, reject) { let header = { 'content-type': 'application/json', - 'Authorization': 'Basic YXBwOmFwcA==', + 'Authorization': Authorization, }; wx.request({ url: baseURL + url, @@ -18,14 +20,7 @@ function request(method, url, data) { data: method === POST ? JSON.stringify(data) : data, header: header, success(res) { - //请求成功 - //判断状态码---errCode状态根据后端定义来判断 - if (res.data.errCode == 0) { - resolve(res); - } else { - //其他异常 - reject('运行时错误,请稍后再试'); - } + resolve(res.data); }, fail(err) { //请求失败 @@ -38,7 +33,9 @@ function request(method, url, data) { const API = { getOpenid: (data) => request(GET, `oauth/token?grant_type=password&username=${data.admin}&password=${data.password}`), - getUserAuth: (data) => request(POST, `social/token?code=MINI@${data}`) + getUserAuth: (data) => request(POST, `social/token?code=MINI@${data}`,'',false), + registerBind: (data) => request(POST, `social/register-bind`, data,false), + getUserInfo: () => request(GET, `user/info`), }; module.exports = { API: API