| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- // loifn//index.js
- //获取应用实例
- const app = getApp()
- Page({
- data: {
- text: "This is page data.",
- windowHeight: app.globalData.windowHeight
- },
- onLoad: function (options) {
- var that = this;
- wx.login({
- success: function (res) {
- console.log(res.code)
- if (res.code) {
- //将保存在本地的用户名取出
- wx.getStorage({
- key: 'login',
- success(res) {
- //发起网络请求
- // 页面创建时执行
- wx.request({
- url: 'https://wx.yfzhwlw.com/wechat_user_info',
- header: {
- "Content-Type": "application/x-www-form-urlencoded"
- },
- method: "post",
- data: {
- req: "info",
- username: res.data
- },
- success: function (res) {
- if (res.statusCode != 200) {
- wx.showToast({ //这里提示失败原因
- title: res.data.message,
- icon: 'loading',
- duration: 1500
- })
- } else {
- wx.showToast({
- title: '登陆成功', //这里成功
- icon: 'success',
- duration: 1000
- });
- that.setData({
- isLogin: true,
- redata: res.data
- })
- }
- },
- fail: function (res) {
- console.log(res)
- wx.showToast({
- title: '请求失败',
- icon: 'none',
- duration: 1500
- })
- }
- });
- }
- })
- } else {
- console.log('登录失败!' + res.errMag)
- }
- }
- })
- },
- onShow: function () {
- // 页面出现在前台时执行
- },
- onReady: function () {
- // 页面首次渲染完毕时执行
- },
- onHide: function () {
- // 页面从前台变为后台时执行
- },
- onUnload: function () {
- // 页面销毁时执行
- },
- onPullDownRefresh: function () {
- // 触发下拉刷新时执行
- },
- onReachBottom: function () {
- // 页面触底时执行
- },
- onShareAppMessage: function () {
- // 页面被用户分享时执行
- },
- onPageScroll: function () {
- // 页面滚动时执行
- },
- onResize: function () {
- // 页面尺寸变化时执行
- },
- onTabItemTap(item) {
- // tab 点击时执行
- // console.log(item.index)
- // console.log(item.pagePath)
- // console.log(item.text)
- },
- // 事件响应函数
- viewTap: function () {
- this.setData({
- text: 'Set some data for updating view.'
- }, function () {
- // this is setData callback
- })
- },
- // 自由数据
- customData: {
- hi: 'MINA'
- },
- //点击退出登录
- outBtn: function () {
- wx.showModal({
- title: '提示',
- content: '是否退出当前账号',
- success(res) {
- if (res.confirm) {
- wx.removeStorage({
- key: 'login',
- success(res) {}
- })
- wx.reLaunch({
- url: '../login/login'
- })
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- }
- })
|