若圖片看不清,可私信給五木大大要高清大圖哈。文章來源:http://www.zghlxwxcb.cn/news/detail-798517.html
18、常用功能-登錄
?? ?效果
?? ??? ?
?? ?wxml頁面
?? ??? ?<view class="login-container">\n\n?? ?<view class="login" wx:if="{{ !logged }}">\n\n?? ??? ?<view class="app-info">\n\n?? ??? ??? ?<image class="app-logo" src="../../images/logo.png" />\n\n?? ??? ??? ?<text class="app-name">微信登錄</text>\n\n?? ??? ?</view>\n\n?? ??? ?<view class="alert">\n\n?? ??? ??? ?<view class="alert-title">網(wǎng)頁由科技開發(fā),請確認(rèn)授權(quán)以下信息</view>\n\n?? ??? ??? ?<view class="alert-desc">\n\n?? ??? ??? ??? ?<view class="alert-text">獲得你的公開信息(昵稱、頭像等)</view>\n\n?? ??? ??? ?</view>\n\n?? ??? ?</view>\n\n?? ??? ?<button class="weui-btn" type="primary" bindtap="login">確認(rèn)登錄</button>\n\n?? ?</view>\n\n?? ?<view class="logged" wx:else>\n\n?? ??? ?<image class="logged-icon" src="../../assets/images/iconfont-weixin.png" />\n\n?? ??? ?<view class="logged-text">近期你已經(jīng)授權(quán)登陸過微信登錄</view>\n\n?? ??? ?<view class="logged-text">自動(dòng)登錄中</view>\n\n?? ?</view>\n\n</view>
?? ?wxss樣式
?? ??? ?完整看備注
?? ?js邏輯
?? ??? ?signIn(cb) {\n\n ? ?var that = this;\n\n ? ?wx.login({\n\n ? ? ? ?success: function (result) {\n\n ? ? ? ? ? ?console.log("------2這里是登錄接口-------");\n\n ? ? ? ? ? ?console.dir(result);\n\n\n\n ? ? ? ? ? ?wx.getUserInfo({\n\n ? ? ? ? ? ? ? ?success: function (res) {\n\n ? ? ? ? ? ? ? ? ? ?console.log("login success!" + res);\n\n ? ? ? ? ? ? ? ? ? ?\n\n ? ? ? ? ? ? ? ? ? ?//昵稱\n\n ? ? ? ? ? ? ? ? ? ?console.log("3++++++++"+res.userInfo.nickName);\n\n\n\n ? ? ? ? ? ? ? ? ? ?if (result.code) {\n\n ? ? ? ? ? ? ? ? ? ? ? ?//發(fā)起網(wǎng)絡(luò)請求\n\n ? ? ? ? ? ? ? ? ? ? ? ?wx.request({\n\n ? ? ? ? ? ? ? ? ? ? ? ? ? ?url: App.globalData.siteUrl + '/common/before/weixinLogin.shtml',\n\n ? ? ? ? ? ? ? ? ? ? ? ? ? ?method: "GET",\n\n ? ? ? ? ? ? ? ? ? ? ? ? ? ?data: {\n\n ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?code: result.code,\n\n ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?nickName: res.userInfo.nickName \n\n ? ? ? ? ? ? ? ? ? ? ? ? ? ?},\n\n ? ? ? ? ? ? ? ? ? ? ? ? ? ?success: function(result2){\n\n ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//token存入緩存\n\n ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?var token = result2.data.data.token;\n\n ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?console.log("4token存入緩存" + token);\n\n ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?wx.setStorageSync("token", token );\n\n\n\n ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?cb();\n\n ? ? ? ? ? ? ? ? ? ? ? ? ? ?}\n\n ? ? ? ? ? ? ? ? ? ? ? ?})\n\n ? ? ? ? ? ? ? ? ? ?} else {\n\n ? ? ? ? ? ? ? ? ? ? ? ?console.log('獲取用戶登錄態(tài)失??!' + userInfo.errMsg)\n\n ? ? ? ? ? ? ? ? ? ?}\n\n ? ? ? ? ? ? ? ?},\n\n ? ? ? ? ? ? ? ?fail: function(){\n\n ? ? ? ? ? ? ? ? ?console.log("因?yàn)榫芙^了資料,所以失敗");\n\n ? ? ? ? ? ? ? ?}\n\n ? ? ? ? ? ?})\n\n ? ? ? ?}\n\n ? ?})\n\n ?},
?? ??? ?完整看備注
?文章來源地址http://www.zghlxwxcb.cn/news/detail-798517.html
到了這里,關(guān)于【第十八節(jié):微信小程序 常用功能-登錄】微信小程序入門,以思維導(dǎo)圖的方式展開18的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!