| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- // pages/login/index.js
- const api = require('../../api/index.js');
-
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- // 状态栏高度
- statusBarHeight: wx.getStorageSync('statusBarHeight'),
- // 导航栏高度
- navBarHeight: wx.getStorageSync('navBarHeight'),
- // 导航栏和状态栏高度
- navStatusBarHeight: wx.getStorageSync('navStatusBarHeight'),
- // 胶囊
- menu:wx.getStorageSync('menu'),
- account:'',
- password:'',
- passwordtype:true,
- checked:false,
- isChecked: false, // 单选框是否被勾选
- shakeClass: '', // 控制晃动动画的类名
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
-
- },
- onpassword(){
- console.log(111);
- this.setData({
- passwordtype:!this.data.passwordtype
- })
- },
- checkboxChange(e) {
- console.log('checkbox发生change事件,携带value值为:', e.currentTarget.dataset.value)
- this.setData({
- checked:!e.currentTarget.dataset.value
- })
- },
- // 处理单选框状态变化
- onRadioChange(e) {
- this.setData({
- isChecked: e.detail.value === 'agree',
- });
- },
- bindKeyInput1: function (e) {
- this.setData({
- account: e.detail.value
- })
- },
- bindKeyInput2: function (e) {
- this.setData({
- password: e.detail.value
- })
- },
- // 处理登录按钮点击
- onLogin() {
- // let obj = {
- // userName:'admin',
- // password:'admin'
- // }
- // api.request(`/user/login`, 'post',obj)
- // .then((res) => {
- // console.log(res);
- // })
- // .catch((err) => {
- // console.error('请求失败:', err);
- // });
- // return
- if (!this.data.checked) {
- return wx.showToast({
- title: '请勾选同意',
- icon: 'none',
-
- });
- }
- let data ={
- username:this.data.account,
- password:this.data.password,
- rememberMe:true,
- tenantNo: ''
- }
- console.log(data);
- api.request('/platform/login', 'POST',data).then((res) => {
- console.log(res);
- if (res.code==0) {
- // 设置数据到本地存储
- wx.setStorage({
- key: 'cookies', // 存储的key值
- data:res.msg,
- success: function(ress) {
- console.log(ress);
- // 获取本地存储的数据
- wx.reLaunch({
- url: '/pages/index/index'
- });
- wx.showToast({
- title: '登录成功',
- icon: 'success',
- });
- }
- });
- }else{
- wx.showToast({
- title: res.msg,
- icon: 'none',
- });
- }
-
-
-
- // 在这里处理返回的数据
- })
- .catch((err) => {
- wx.showToast({
- title: "账户或密码输入不正确",
- icon: 'none',
- });
- // 在这里处理请求失败的情况
- });
-
-
- },
- onprivacy(e){
- console.log(e.target.dataset.name);
- wx.navigateTo({
- url: `/pages/privacy/index?name=${e.target.dataset.name}`,
- })
-
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
-
- }
- })
|