123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- import Toast from '@vant/weapp/toast/toast';
- const _Http = getApp().globalData.http;
- const md5 = require("../../utils/md5");
- const loginMsg = require("./modules/login");
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- isAgree: true,
- accountno: "",
- password: "",
- inputType: "password", //密码输入框类型
- focus: false,
- memory: true, //记忆
- disabled: true, //是否禁用
- loading: false, //登陆中
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.setData({
- ...wx.getStorageSync('loginMsg')
- })
- wx.getUserProfile({
- desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
- success: (res) => {
- console.log("用户信息",res)
- /* this.setData({
- userInfo: res.userInfo,
- hasUserInfo: true
- }) */
- }
- })
- this.allowOrNot()
- },
- /* 微信登录 */
- wechatLogin() {
- if (!this.data.isAgree) return Toast({
- message: '请阅读并勾选用户协议',
- position: 'bottom'
- });
- wx.login({
- success(res) {
- if (res.code) {
- _Http.loginbywechat({
- wechat_code: res.code,
- "systemclient": "wechatsaletool"
- }).then(res => {
- console.log(res)
- if (res.code == 0) return wx.showToast({
- title: res.msg,
- icon: "none"
- })
- loginMsg.loginMsg(res);
- })
- } else {
- console.log('登录失败!' + res.errMsg)
- }
- }
- })
- },
- /* 用户登录 */
- userLogin() {
- if (this.data.loading || this.data.disabled) return;
- if (!this.data.isAgree) return Toast({
- message: '请阅读并勾选用户协议',
- position: 'bottom'
- });
- this.setData({
- loading: true
- })
- _Http.login({
- "accountno": this.data.accountno,
- "password": md5.hexMD5(this.data.password),
- "systemclient": "wechatsaletool"
- }).then(res => {
- console.log("登录", res)
- this.setData({
- loading: false
- })
- if (res.msg != '成功') return wx.showToast({
- title: res.msg,
- icon: "none"
- })
- wx.setStorageSync('loginMsg', {
- accountno: this.data.accountno,
- password: (this.data.memory) ? this.data.password : ''
- })
- loginMsg.loginMsg(res);
- })
- },
- /* 改变密码输入框类型 */
- changePasswordType() {
- this.setData({
- inputType: this.data.inputType == "text" ? 'password' : 'text'
- })
- },
- /* 授权 */
- agreementChange({
- detail
- }) {
- this.setData({
- isAgree: detail
- })
- },
- /* 手机号 */
- inputPhone(e) {
- this.setData({
- accountno: e.detail.value.trim()
- })
- this.allowOrNot()
- },
- /* 密码 */
- inputPassword(e) {
- this.setData({
- password: e.detail.value.trim()
- })
- this.allowOrNot()
- },
- /* 验证是否允许登录 */
- allowOrNot() {
- this.setData({
- disabled: (this.data.accountno.length > 0 && this.data.password.length > 5) ? false : true
- })
- },
- /* 是否记忆密码 */
- isMemory() {
- this.setData({
- memory: !this.data.memory
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|