123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- import http from '../../base/httputil'
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- isShowAccoutDialog : false,
- isBindSuccess : false,
- userInfo:null,
- userName :"点击登录",
- password: null,
- openid: null
- },
- inputUserName(e){
- this.userName = e.detail.value
- },
- inputPassword(e){
- this.password = e.detail.value
- },
- init_userInfo() {
- let that = this
- if (app.globalToken == null) {
- http.showLoading()
- wx.getUserProfile({
- desc: 'desc',
- success: (res) => {
- this.getSysUserInfo(res.userInfo)
- that.setData({
- userInfo : res.userInfo
- })
- },
- fail: res => {
- console.log(res)
- },
- })
- }
- },
- getSysUserInfo(info) {
- let that = this
- wx.login({
- success(res) {
- var code = res.code
- var data = {
- wxCode: code,
- wxNickName: info.nickName,
- wxAvatarUrl: info.avatarUrl
- }
-
- http.send_post("/auth/applogin", data, that.loginSuccess)
- },
- fail(res) {
- console.log("ffff", res)
- }
- })
- },
- loginSuccess(res) {
- console.log(res)
- let that = this
- if (res.data.code != 200) {
- that.openid = res.data.data
- wx.showToast({
- title: res.data.msg,
- icon: "none"
- })
- http.hideLoading()
- that.setData({
- isShowAccoutDialog : true
- })
-
- } else {
- app.globalToken = res.data.data.access_token
- console.log("我的令牌:",app.globalToken )
- //登录成功,获取首页数据
- http.hideLoading()
- this.setData({
- isBindSuccess : true
- })
- }
- },
- clear(){
- wx.clearStorage({
- success: (res) => {
- wx.showToast({
- title: '清理成功',
- })
- wx.removeStorageSync('userInfo');
- wx.removeStorageSync('openid');
- app.globalToken=null;
- this.setData({
- isShowAccoutDialog : false,
- isBindSuccess : false,
- userInfo:null,
-
- userName :"游客",
- password: null,
- openid: null
-
- })
- wx.reLaunch({
- url: '../index/index'
- })
- },
- })
- },
- modalCancel(){
- this.setData({
- isShowAccoutDialog : false
- })
- },
- modalSubmit(){
- let obj = new Object()
- obj.openid = this.openid
- obj.userName = this.userName
- obj.password = this.password
- http.send_post("/system/minapp/AppLoginController/bindWxUser",obj,this.modalSubmitSuccess)
- },
- modalSubmitSuccess(res){
- wx.showToast({
- title: res.data.msg,
- icon: "none"
- })
- if (res.data.code == 200) {
- this.setData({
- isShowAccoutDialog : false,
- isBindSuccess : true
- })
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
-
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|