|
@@ -1,31 +1,104 @@
|
|
|
+import WxValidate from '../../utils/wxValidate'
|
|
|
const app = getApp()
|
|
|
Page({
|
|
|
data: {
|
|
|
- info: {}
|
|
|
+ form: {},
|
|
|
+ current: 1,
|
|
|
+ // 用户类别
|
|
|
+ typeList: [],
|
|
|
},
|
|
|
- toPath(e) {
|
|
|
- let data = e.detail;
|
|
|
- let url = `/${data.route}`;
|
|
|
- if (data.type == '0') wx.navigateTo({ url })
|
|
|
- else if (data.type == '1') wx.redirectTo({ url })
|
|
|
- else if (data.type == '2') wx.relaunch({ url })
|
|
|
- else if (data.type == '3') wx.switchTab({ url })
|
|
|
+ // 登陆注册监听
|
|
|
+ click(e) {
|
|
|
+ const that = this;
|
|
|
+ let index = e.currentTarget.dataset.code;
|
|
|
+ that.setData({ current: index })
|
|
|
+ },
|
|
|
+ // 验证表单
|
|
|
+ initValidate() {
|
|
|
+ const rules = { account: { required: true }, password: { required: true, } }
|
|
|
+ // 验证字段的提示信息,若不传则调用默认的信息
|
|
|
+ const messages = { account: { required: '请输入账号', }, password: { required: '请输入密码', } };
|
|
|
+ this.WxValidate = new WxValidate(rules, messages)
|
|
|
+ },
|
|
|
+ // 选择用户类别
|
|
|
+ typeChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let index = e.detail.value;
|
|
|
+ let data = that.data.typeList[index];
|
|
|
+ if (data) that.setData({ 'form.type': data.value });
|
|
|
+ that.setData({ 'form.type_name': data.label });
|
|
|
+ },
|
|
|
+ // 提交登录
|
|
|
+ onSubmit: async function (e) {
|
|
|
+ const params = e.detail.value;
|
|
|
+ if (!this.WxValidate.checkForm(params)) {
|
|
|
+ const error = this.WxValidate.errorList[0];
|
|
|
+ wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ const res = await app.$api('user/login', 'POST', params);
|
|
|
+ if (res.errcode === 0) {
|
|
|
+ app.globalData.userInfo = res.data;//存用户信息到app.js
|
|
|
+ wx.setStorage({ key: "token", data: res.data })// 存用户信息到storage,以便之后判断用户是否登录
|
|
|
+ wx.showToast({ title: `账号登录成功`, icon: 'success', duration: 2000 }) //登录成功提示
|
|
|
+ wx.redirectTo({ url: '/pagesHome/home/index' })
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: res.errmsg, icon: 'none', duration: 2000 })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 提交注册
|
|
|
+ reSubmit: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ const params = e.detail.value;
|
|
|
+ if (!this.WxValidate.checkForm(params)) {
|
|
|
+ const error = this.WxValidate.errorList[0];
|
|
|
+ wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ if (params.password !== params.is_password) {
|
|
|
+ wx.showToast({ title: '密码输入不一致', duration: 2000, icon: 'error', })
|
|
|
+ } else {
|
|
|
+ delete params.is_password
|
|
|
+ const res = await app.$api('user', 'POST', params);
|
|
|
+ if (res.errcode === 0) {
|
|
|
+ wx.showToast({ title: `账号注册成功`, icon: 'success', duration: 2000 }) //登录成功提示
|
|
|
+ that.setData({ current: 1 })
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: res.errmsg, icon: 'none', duration: 2000 })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 忘记密码
|
|
|
+ forgot() {
|
|
|
+ wx.showToast({ title: `暂未开放`, icon: 'error', duration: 2000 })
|
|
|
},
|
|
|
-
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
- onLoad(options) {
|
|
|
+ async onLoad(options) {
|
|
|
const that = this;
|
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
|
- that.search()
|
|
|
+ //验证规则函数
|
|
|
+ await that.initValidate()
|
|
|
+ await that.searchOther()
|
|
|
+ await that.search()
|
|
|
wx.hideLoading()
|
|
|
},
|
|
|
+ async searchOther() {
|
|
|
+ const that = this;
|
|
|
+ let res;
|
|
|
+ // 类别
|
|
|
+ res = await app.$api('dictData', 'GET', { type: 'type', is_use: '0' })
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ that.setData({ typeList: res.data })
|
|
|
+ }
|
|
|
+ },
|
|
|
// 查询通知
|
|
|
async search() {
|
|
|
const that = this;
|
|
|
},
|
|
|
-
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
@@ -36,9 +109,7 @@ Page({
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
- onShow() {
|
|
|
-
|
|
|
- },
|
|
|
+ onShow() { },
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面隐藏
|