123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- // pages/login/login.js
- const app=getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- showEyes: false,
- form: {
- phone: "",
- password: ''
- },
- phone: ''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- const token = wx.getStorageSync('token')
- console.log(token);
- if (!token || token == '') {
- wx.setNavigationBarTitle({
- title: '分拣系统',
- })
- }else{
- wx.switchTab({
- url: '/pages/tabber/home/index',
- })
- }
- },
- onReady(){
-
- },
- close() {
- this.data.form.phone = ''
- this.setData({
- phone: ''
- })
- console.log(this.data.phone);
- },
- inputValue1(e) {
- let { value } = e.detail
- this.data.form.phone = value
- this.setData({
- phone: value
- })
- console.log(this.data.phone);
- },
- inputValue2(e) {
- let { value } = e.detail
- this.data.form.password = value
- },
- changeEyes() {
- this.setData({
- showEyes: !this.data.showEyes
- })
- },
- login() {
- var that=this;
- var phone=this.data.form.phone
- var password=this.data.form.password
- if(!phone){
- wx.showLoading({
- title: '手机号必填',
- })
- setTimeout(function () {
- wx.hideLoading();
-
- }, 1000);
- return false;
- }
- if(!password){
- wx.showLoading({
- title: '密码必填',
- })
- setTimeout(function () {
- wx.hideLoading();
-
- }, 1000);
- return false;
- }
- app.api.useApi(app.globalData.baseAppUrl + "api/admin/login", {
- phone:this.data.form.phone,
- password: this.data.form.password,
- appid:wx.getAccountInfoSync().miniProgram.appId
- }, "post").then(function (res) {
- wx.showLoading({
- title: '登录中',
- })
- console.log(res);
- if (res.code != 200) {
-
- wx.showLoading({
- title: '登录失败',
- })
- setTimeout(function () {
- wx.hideLoading();
- }, 2000);
- } else {
- wx.hideLoading();
- wx.setStorageSync('token', res.message.data.access_token);
- wx.switchTab({
- url: '/pages/tabber/home/index',
- })
- }
- }).catch(function (err) {
-
- console.log(222);
- })
-
- }
- })
|