123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- // index.ts
- import { ConstsData } from "../../utils/const";
- import { loginType } from "../../utils/loginType"
- import { httpUtil } from "../../utils/restful";
- import { storage } from "../../utils/storageUtil";
- Page({
- data: {
- login_check_tab: 0,
- loginType: 0,
- showAccPwd: true,
- showUpdatePassWordLayout: false,
- //短信验证码登录参数
- inputPhoneNum: '',
- inputVCodeNum: '',
- inputPhonePwdLoginNum: '',
- inputPwdText: '',
- hasGetVCode: false,
- getVCodeText: "获取验证码",
- getvcodeInter: -5,
- teacherEnable: false,
- installerEnable: false,
- repairmanEnable: false,
- itEnable: false
- },
- onLoad(opention: any) {
- console.log("opention.loginType:", opention.loginType)
- this.setData({
- login_check_tab: 0,
- loginType: opention.loginType
- })
- },
- // 点击短信验证码登录
- clickPhoneNumLogin: function (event: any) {
- console.log("短信验证码登录")
- console.log(event)
- this.setData({
- login_check_tab: 0,
- // inputPhoneNum: '',
- // inputPhonePwdLoginNum: ''
- })
- },
- // 点击账号密码登录
- clicAccountPasswordLogin: function (event: any) {
- console.log("账号密码登录")
- console.log(event)
- this.setData({
- login_check_tab: 1,
- // inputPhoneNum: '',
- // inputPhonePwdLoginNum: ''
- })
- },
- // 获取验证码
- clickGetVCode: function () {
- console.log("账号密码登录")
- if (this.data.hasGetVCode) {
- this.showToast("请勿频繁点击")
- return;
- }
- if (!this.data.inputPhoneNum) {
- this.showToast("请输入手机号")
- return;
- }
- let that = this;
- let time = 60;
- this.data.getvcodeInter = setInterval(function () {
- if (time <= 1) {
- clearInterval(that.data.getvcodeInter)
- that.setData({
- hasGetVCode: false,
- getVCodeText: '获取验证码',
- getvcodeInter: -5
- })
- return;
- }
- time--;
- that.setData({
- getVCodeText: time.toString() + "秒",
- hasGetVCode: true
- })
- }, 1000)
- let params = {
- mobileNo: this.data.inputPhoneNum
- }
- httpUtil.wxGet(httpUtil.interfaces.getVerifyCode, params).then((res) => {
- console.log("获取验证码成功:", res)
- }).catch((res) => {
- console.log("获取验证码失败:", res)
- })
- },
- //账号密码登录——---------------------------
- showAccountPwd: function () {
- if (this.data.showAccPwd) {
- this.setData({
- showAccPwd: false
- })
- } else {
- this.setData({
- showAccPwd: true
- })
- }
- },
- //显示修改密码的框
- showUpdatePwdLayout: function () {
- if (this.data.showUpdatePassWordLayout) {
- this.setData({
- showUpdatePassWordLayout: false
- })
- } else {
- this.setData({
- showUpdatePassWordLayout: true
- })
- }
- },
- //跳转注册界面
- toRegisterPage: function () {
- wx.navigateTo({
- url: '../register/register',
- })
- },
- //判断是短信登录还是账号密码登录进行相应登录
- toTabIndex: function () {
- switch (Number(this.data.login_check_tab)) {
- case 0:
- //短信验证码登录
- this.phoneVCodeLogin();
- break;
- case 1:
- //账号密码登录
- this.pwdPhoneLogin();
- break;
- }
- // this.toNextPage();
- },
- //短信验证码登录
- phoneVCodeLogin: function () {
- if (!this.data.inputPhoneNum) {
- this.showToast('请输入手机号')
- return;
- }
- if (!this.data.inputVCodeNum) {
- this.showToast('请输入验证码')
- }
- let params = {
- mobile: this.data.inputPhoneNum,
- verifyCode: this.data.inputVCodeNum
- }
- httpUtil.wxPost(httpUtil.interfaces.phoneRegister, params).then((res: any) => {
- if (res.data.success) {
- console.log("登录成功:", res)
- httpUtil.httpData.userId = res.data.data.id;
- ConstsData.AppData.myInfoData = res.data.data
- storage.saveStorage(storage.storageKey.userId, res.data.data.id).then((res) => {
- console.log("保存成功:", res)
- }).catch((res) => {
- console.log("保存失败:", res)
- })
- if (ConstsData.AppData.myInfoData.type == 3) {
- this.setData({
- teacherEnable: true
- })
- //是老师,并且点击进入的也是老师
- if (Number(this.data.loginType) == loginType.Teacher) {
- this.toNextPage()
- }
- } else {
- if (!res.data.data.role) {
- let arr = res.data.data.role.split(",")
- this.choseType(arr)
- }
- }
- } else {
- console.log("登录失败:", res)
- this.showToast(res.data.message)
- }
- }).catch((res) => {
- console.log("登录失败:", res)
- })
- },
- //账号密码登录
- pwdPhoneLogin: function () {
- if (!this.data.inputPhonePwdLoginNum) {
- this.showToast('请输入手机号')
- return;
- }
- if (!this.data.inputPwdText) {
- this.showToast('请输入密码')
- }
- let params = {
- password: this.data.inputPwdText,
- userName: this.data.inputPhonePwdLoginNum
- }
- httpUtil.wxPost(httpUtil.interfaces.pwdPhoneLogin, params).then((res: any) => {
- if (res.data.success) {
- httpUtil.httpData.userId = res.data.data.id
- ConstsData.AppData.myInfoData = res.data.data
- storage.saveStorage(storage.storageKey.userId, res.data.data.id).then((res) => {
- console.log("保存成功:", res)
- }).catch((res) => {
- console.log("保存失败:", res)
- })
- if (Number(ConstsData.AppData.myInfoData.type) == 3) {
- //走了3里面
- this.setData({
- teacherEnable: true
- })
- //是老师,并且点击进入的也是老师
- if (Number(this.data.loginType) == loginType.Teacher) {
- this.toNextPage()
- } else {
- this.goBack()
- }
- } else {
- console.log("走了不是3")
- if (!res.data.data.role) {
- let arr = res.data.data.role.split(",")
- this.choseType(arr)
- } else {
- this.goBack()
- wx.navigateBack()
- }
- }
- } else {
- this.showToast(res.data.message)
- }
- }).catch((res) => {
- console.log(res)
- })
- },
- bindPhoneInput: function (event: any) {
- this.setData({
- inputPhoneNum: event.detail.value
- })
- },
- bindPwdLoginPhoneInput: function (event: any) {
- this.setData({
- inputPhonePwdLoginNum: event.detail.value
- })
- },
- bindVCodeInput: function (event: any) {
- this.setData({
- inputVCodeNum: event.detail.value
- })
- },
- bindPwdInput: function (event: any) {
- this.setData({
- inputPwdText: event.detail.value
- })
- },
- choseType: function (arr: any[]) {
- arr.forEach((item: any) => {
- switch (Number(item)) {
- case 1:
- //安装员
- this.setData({
- installerEnable: true
- })
- //如果是安装员,又从安装员进来的
- if (this.data.loginType == loginType.Installer) {
- this.toNextPage();
- } else {
- this.goBack()
- }
- break;
- case 2:
- //IT管理员
- this.setData({
- itEnable: true
- })
- if (this.data.loginType == loginType.Installer) {
- this.toNextPage();
- } else {
- this.goBack()
- }
- break;
- case 3:
- //维修员
- this.setData({
- repairmanEnable: true
- })
- if (this.data.loginType == loginType.Repairman) {
- this.toNextPage();
- } else {
- this.goBack()
- }
- break;
- }
- });
- },
- //登录成功后跳转界面
- toNextPage: function () {
- let toUrl = '';
- switch (Number(this.data.loginType)) {
- case loginType.Teacher:
- //教师(去教师的index页面)
- toUrl = "../teacher/index/index"
- break;
- case loginType.Installer:
- //安装员(去安装员的index页面)
- toUrl = "../installer/index/index"
- break;
- case loginType.Repairman:
- //维修员(去维修员的index页面)
- toUrl = "../repairman/index/index"
- break;
- case loginType.IT:
- //IT管理员(去IT管理员的index页面)
- toUrl = "../itadministrator/index/index"
- break;
- }
- wx.navigateTo({
- url: toUrl,
- })
- },
- goBack: function () {
- wx.showToast({
- title: '身份选择错误',
- icon: 'none',
- duration: 1000
- })
- setTimeout(function () {
- wx.navigateBack()
- }, 1000)
- },
- showToast: function (message: string) {
- wx.showToast({
- title: message,
- icon: 'none'
- })
- },
- onUnload() {
- if (this.data.getvcodeInter != -5) {
- clearInterval(this.data.getvcodeInter)
- }
- }
- })
|