From a25a8b14c892994e68812b607bb446ec1176c13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E9=A1=BA=E7=92=9E?= Date: Tue, 22 Jun 2021 16:30:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=88=E6=9D=83=E6=8E=A5=E5=8F=A3=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 51 ++++++++-- app.wxss | 1 + assets/.DS_Store | Bin 6148 -> 6148 bytes assets/images/.DS_Store | Bin 0 -> 8196 bytes pages/auth/auth.js | 205 ++++++++++++++++++++++------------------ pages/auth/auth.wxml | 4 +- pages/auth/auth.wxss | 39 ++++++++ utils/api.js | 19 ++-- 8 files changed, 206 insertions(+), 113 deletions(-) create mode 100644 assets/images/.DS_Store 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 8d97eeab408497acb54fe06a894dbd30fbdb5f45..a0c44dca1740678f8064d51f7ad75c65bb0f7c15 100644 GIT binary patch delta 242 zcmZoMXffCj&8i_LDlQ=^DJ3NnFCd(hn4FznlwX>c;+&t8U*wcini`RroSzq*S(Q4u zhc!SpUVy(ixhOv;Cm_E#vm`S=FETp4C^N-BEv-1UWb#i|Um=i+jQny>pss+T)UwRf z^2z>eqV>uS0SsWE?4SW*2rwu^7z_-`4xR_VYz_g&ki7i7R8CH12XCk>2ZJ_)BZC)1 zFhd4IIYS@AEQU1c;+&t8U*wcini?;_U!0L&?wOpQ z7f_U1mYG^UxtTRUHafj1GsQnGtvIzL5~L)#C_g7BAip@XBr`v6@&{I5&WKE)mf*~) z)XDyAqV=504jK$#Ai$suVK6W#J7hF~*&G6lA$j?EsX$c$5J_bRZ>TB`25kmMhG2#m zhC+r0hUpB88P+o#WH`t0nBgnKe@0$LF-9duZAKkNQ$}+}2S!guFGe56K*k`(Xo!9$ MMi9OEF`J?w0I^Cq?*IS* diff --git a/assets/images/.DS_Store b/assets/images/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..fd8fd36c141dbcf31bfe3d5bbcf54d8ea6d13b5b GIT binary patch literal 8196 zcmeHM!EVzq82-JDHEp-i0}{I+<-%>7)@=fDKq_S%c0($H1E4Kgqb;IKrlzHArBm-b z0UUS*o`WagEx2=n@Bf_@FHOpALYf`fpBsN)ZGZmj)GZOIX1`r0S|uU}nXy(yk(0Qc z^HiEk@7x0_=!s4#qNBY|eCT(k*!G5Xz&c9Vp}o09?RrNvPu-AR0HtMv7yNBE@^^(}PN-Dm`K-El0b{bYLUJ zu|_Q?rRAj3o>h86QPMkfuFy#}G}_WSU>%rtfY0tF@~Dk#!#uyoK3e$0^aOe1w1D!ifKUWP%%aY+HVYo2H3(w6>-=OKzZ{j zjN0*_8TX@hBJb1E4USWG%KNp|;qc+k_L{r1T_3Hv!$(`2Tz@bcm7Tly>yP&iPR`DU zA4eCT5zt5~{XRjr_3KIb1+|PR?_1rd6Gyxyu&RczNhJK&VKi@`983wW+y$0EGEH1I z^fNah2`5vzh%NU+K`$KQKd*$tIYO?F5k|CMwDn5xnLSj=R26K&5_-jb6>P;4dZub( zxvgBU1M|AORX+beLp(FuWF4>$+$;yw!ftD~i8)_B3$xSbv$l(TfXs<`V~rv~A;)o` q9LIr^KMYZKL1j%N#j!@*LAv%I0_^ku@1L}nU-0bnUt;kl6@LJHJ1#;1 literal 0 HcmV?d00001 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