diff --git a/src/api/index.js b/src/api/index.js index cde818b..dab3a8f 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -1,16 +1,19 @@ import Setting from "@/setting"; -let host = Setting.apiBaseURL; -let uploadURL = "http://39.108.250.202:9000/"; +const host = Setting.apiBaseURL; +const host1 = `http://192.168.31.137:9000/` +const uploadURL = "http://39.108.250.202:9000/"; export default { host, // 登录 - logins: `users/users/user/login`, //登录 - verification: `${host}users/users/user/captcha`,// 验证码图片 + logins: `${host1}users/users/user/login`, + verification: `${host1}users/users/user/captcha`,// 验证码图片 logoDetail: `occupationlab/sys/logo/detail`, //查看系统设置信息 - isClient: `${host}users/users/user/isClient`, + isClient: `${host1}users/users/user/isClient`, + sendPhoneVerificationCode: `${host1}users/users/user/sendPhoneVerificationCode`, + getToken: `${host1}users/users/user/getToken`, platformLogList: `nakadai/log/platformLogList`, logNotification: `nakadai/log/logNotification`, @@ -81,18 +84,19 @@ export default { queryProvince: `nakadai/nakadai/province/queryProvince`, //查询省份 queryCity: `nakadai/nakadai/city/queryCity`, //查询城市 - querySchool: `nakadai/nakadai/school/querySchool`, //根据学校名称查询学校信息 + querySchool: `${host1}nakadai/nakadai/school/querySchool`, //根据学校名称查询学校信息 queryCourseDiscipline: `nakadai/nakadai/subject/courseDiscipline`, //查询课程学科 queryCourseProfessionalClass: `nakadai/nakadai/subject/courseProfessionalClass`, //查询专业类 queryCourseProfessional: `nakadai/nakadai/subject/courseProfessional`, //查询专业 // 个人中心 - uploadUserAvatars: `users/users/userAccount/updateUserAvatars`, //更改头像 + uploadUserAvatars: `${host}users/users/userAccount/updateUserAvatars`, //更改头像 queryUserInfoDetails: `users/users/userAccount/queryUserInfoDetails`,//个人中心信息展示 updatePersonCenter: `users/users/userAccount/updatePersonCenter`,//个人中心信息修改 examinePassword: `users/users/userAccount/examinePassword`,//更换密码 bindPhoneOrEmail: `users/users/userAccount/bindPhoneOrEmail`,// 绑定手机或邮箱 sendPhoneOrEmailCode: `users/users/userAccount/sendPhoneOrEmailCode`,// 更换手机号或邮箱--发送手机验证码 + unbindMobilePhone: `users/users/userAccount/unbindMobilePhone`, joinPractice: `tms/classTech/joinPractice`, //通过邀请码进入实验 queryArchievement: `tms/classTech/queryExperimentalReport`, //查看教学实验报告 diff --git a/src/layouts/header/index.vue b/src/layouts/header/index.vue index 7c8d8be..438d9ee 100644 --- a/src/layouts/header/index.vue +++ b/src/layouts/header/index.vue @@ -75,10 +75,10 @@ export default { }).catch(res => {}) }, getSystemDetail () { - this.$get(this.api.logoDetail).then(res => { - if (res.data) { - this.setTitle(res.data.title); - this.setLogoUrl(res.data.logoUrl); + this.$get(this.api.logoDetail).then(({ data }) => { + if (data) { + this.setTitle(data.title); + this.setLogoUrl(data.logoUrl); } }).catch(res => {}); }, diff --git a/src/pages/account/login/index.vue b/src/pages/account/login/index.vue index b2310b2..b1e1ca2 100644 --- a/src/pages/account/login/index.vue +++ b/src/pages/account/login/index.vue @@ -6,18 +6,18 @@ - +
-
+
+ 设置为默认学校 +
- 设置为默认学校 -
@@ -28,38 +28,51 @@ - +
- + - + + 登录
@@ -75,8 +88,7 @@
- {{ phoneBtnText }} + {{ phoneBtnText }}
@@ -101,16 +113,8 @@

该手机号已绑定以下用户信息

@@ -129,48 +133,53 @@ export default { data: function() { return { tabList: [ - { - id: 0, - label: '学号/工号登录' - }, { - id: 1, - label: '学校管理员登录' - }, { - id: 2, - label: '手机号/邮箱' - } + { + id: 0, + label: '学号/工号登录' + }, { + id: 1, + label: '学校管理员登录' + }, { + id: 2, + label: '手机号/邮箱' + } ], - setDefault: !!util.local.get('schoolId'), - verificationIMG: "", + setDefault: !!util.local.get('schoolId'), // 本地缓存里有学校id,则默认勾选 + verificationIMG: '', schoolList: [], form: { - schoolId: '', - workNumber: '', - account: '', - password: "", - code: "", // 验证码 - random: "", // 随机数 - distinguish: 0, // 区分手机号账号登录,1为账号登录,2为手机号或邮箱登录 - type: 1, // 平台端区分:0->教师端 1->学生端 2->无端 - platform: Setting.platformId + schoolId: '', + workNumber: '', + account: '', + password: '', + code: '', // 验证码 + random: '', // 随机数 + distinguish: 0, // 区分手机号账号登录,1为账号登录,2为手机号或邮箱登录 + type: 1, // 平台端区分:0->教师端 1->学生端 2->无端 + platform: Setting.platformId }, - loginRules: { - schoolId: [{ required: true, message: "请选择学校", trigger: "change" }], - workNumber: [{ required: true, message: "请输入学生学号", trigger: "blur" }], - account: [{ required: false, message: "请输入账号", trigger: "blur" }], - password: [{ required: true, message: "请输入密码", trigger: "blur" }], - code: [{ required: true, message: "请输入验证码", trigger: "blur" }] + rules: { + schoolId: [{ required: true, message: "请选择学校", trigger: "change" }], + workNumber: [{ required: true, message: "请输入学生学号", trigger: "blur" }], + account: [{ required: false, message: "请输入账号", trigger: "blur" }], + password: [{ required: true, message: "请输入密码", trigger: "blur" }], + code: [{ required: true, message: "请输入验证码", trigger: "blur" }] }, + phoneDisabledLogin: false, + phoneTimerLogin: null, + phoneBtnTextLogin: '发送验证码', + phoneVisible: false, - phone: "", - phoneCode: "", + phone: '', + phoneCode: '', phoneDisabled: false, phoneTimer: null, - phoneBtnText: "发送验证码", + phoneBtnText: '发送验证码', selectVisible: false, selectedRole: '', token: '', - userVisible: false + userVisible: false, + users: [] }; }, components: { @@ -181,8 +190,10 @@ export default { this.getSchool() // 页面离开的时候销毁手机和邮箱验证码定时器 this.$once("hook:beforeDestroy", function() { - clearInterval(this.phoneTimer); - this.phoneTimer = null; + clearInterval(this.phoneTimer) + clearInterval(this.phoneTimerLogin) + this.phoneTimer = null + this.phoneTimerLogin = null }); }, methods: { @@ -193,39 +204,49 @@ export default { "setInfo" ]), getSchool() { - this.$get(this.api.querySchool, { - provinceId: '', - cityId: '' - }).then(res => { - this.schoolList = res.list - const schoolId = util.local.get('schoolId') - if (schoolId) this.form.schoolId = schoolId - }).catch(res => {}) + this.$get(this.api.querySchool, { + provinceId: '', + cityId: '' + }).then(res => { + this.schoolList = res.list + // 取本地缓存里的学校id + const schoolId = util.local.get('schoolId') + if (schoolId) this.form.schoolId = schoolId + }).catch(res => {}) }, getVerImg() { // 获取验证码图片 - this.form.random = Math.floor(Math.random() * 999999999); - this.verificationIMG = this.api.verification + "?random=" + `${this.form.random}`; + this.form.random = Math.floor(Math.random() * 999999999); + this.verificationIMG = this.api.verification + "?random=" + `${this.form.random}`; }, // 切换标签 typeClick(tab) { const { id } = tab const form = this.form - // 切换了后,学校等清空 - form.account = '' - form.workNumber = '' - form.schoolId = '' - form.type = 1 - form.distinguish = id + // 切换了后,全部字段重置 + this.form = { + schoolId: form.schoolId, + workNumber: '', + account: '', + password: '', + code: '', + random: form.random, + distinguish: id, + type: 1, + platform: form.platform + } this.$refs.form.clearValidate() // 切换了登录方式后,校验规则要变化 - const rules = this.loginRules - rules.account[0].required = id === 1 + const rules = this.rules rules.schoolId[0].required = id === 0 rules.workNumber[0].required = id === 0 + rules.account[0].required = !!id + this.rules.account[0].message = id === 1 ? + '请输入账号' : + '请输入手机号/邮箱' }, // 学号工号切换 typeChange(id) { - this.loginRules.workNumber[0].message = id === 1 ? + this.rules.workNumber[0].message = id === 1 ? '请输入学生学号' : '请输入老师工号' }, @@ -233,6 +254,29 @@ export default { reloadIndex() { window.opener && window.opener.location.reload() }, + // 选择用户回调 + chooseUser(user) { + this.$post(`${this.api.getToken}?id=${user.id}`).then(({ data }) => { + this.queryClient(data.token) + }).catch(res => {}) + }, + // 查询是否是客户,如果是客户,则弹出选择端的页面去选择跳转到哪个端 + queryClient(token) { + this.token = token + axios.get(this.api.isClient, { + headers: { + token + } + }).then(({ data }) => { + // 如果是客户 + if (data.customer) { + this.SET_CUSTOMERNAME(data.customerName) + this.selectVisible = true + } else { + this.setLogin() + } + }).catch(res => {}) + }, // 处理登录成功 setLogin() { util.local.set(Setting.tokenKey, this.token, Setting.tokenExpires) @@ -244,8 +288,12 @@ export default { submit() { // 提交登录 this.$refs.form.validate(valid => { if (valid) { - const form = this.form - if (!form.distinguish && this.setDefault) util.local.set('schoolId', form.schoolId) + const form = JSON.parse(JSON.stringify(this.form)) + const { distinguish } = form + if (!form.distinguish && this.setDefault) util.local.set('schoolId', form.schoolId) // 选的是学号工号登录,并且勾选了默认,则存入缓存 + if (util.local.get('schoolId') && !this.setDefault) util.local.remove('schoolId') // 本地缓存了学校id,并且没有勾选默认,则删除缓存 + if (distinguish) form.schoolId = '' + if (!distinguish) form.distinguish = 1 this.$post(this.api.logins, form).then(({ status, data, message }) => { // 未绑定手机号,则弹框去绑定 if (status == 30001) { @@ -253,23 +301,13 @@ export default { this.getVerImg() form.code = '' } else if (status == 200) { - const { token } = data - this.token = token - // 查询是否是客户,如果是客户,则弹出选择端的页面去选择跳转到哪个端 - // this.setLogin() - axios.get(this.api.isClient, { - headers: { - token - } - }).then(({ data }) => { - // 如果是客户 - if (data.customer) { - this.SET_CUSTOMERNAME(data.customerName) - this.selectVisible = true - } else { - this.setLogin() - } - }).catch(res => {}) + // 如果返回的是数组,则弹框给用户选择登录哪个用户,否则,直接登录 + if (data instanceof Array) { + this.users = data + this.userVisible = true + } else { + this.queryClient(data.token) + } } else { util.errorMsg(message) } @@ -297,62 +335,101 @@ export default { `${location.origin}/admin/#/redirect?auth=${window.btoa(this.token)}` } }, + // 验证手机号 + verifyPhone(phone) { + if (!phone) { + util.warningMsg("请输入手机号") + return false + } + if (!/^1[3456789]\d{9}$/.test(phone) && !/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(phone)) { + util.warningMsg("请输入正确的手机号/邮箱") + return false + } + return true + }, + + // 验证码倒计时 + phoneCountdownLogin() { + let count = 60 + if (!this.phoneTimerLogin) { + this.phoneDisabledLogin = true + this.phoneTimerLogin = setInterval(() => { + if (count > 0) { + count-- + this.phoneBtnTextLogin = `${count}秒后重试` + } else { + this.phoneDisabledLogin = false + clearInterval(this.phoneTimerLogin) + this.phoneTimerLogin = null + this.phoneBtnTextLogin = `发送验证码` + } + }, 1000) + } + }, + // 发送验证码 + sendPhoneCodeLogin() { + const phone = this.form.account + if (!this.verifyPhone(phone)) return false + this.$post(`${this.api.sendPhoneVerificationCode}?phoneOrEmail=${phone}`).then(({ message }) => { + util.successMsg(message) + this.phoneCountdownLogin() + }).catch(res => {}) + }, + + // 验证码倒计时 phoneCountdown() { - let count = 60; - if (!this.phoneTimer) { - this.phoneDisabled = true; - this.phoneTimer = setInterval(() => { - console.log("倒计时中"); - if (count > 0) { - count--; - this.phoneBtnText = `${count}秒后重试`; - } else { - this.phoneDisabled = false; - clearInterval(this.phoneTimer); - this.phoneTimer = null; - this.phoneBtnText = `发送验证码`; - } - }, 1000); - } + let count = 60 + if (!this.phoneTimer) { + this.phoneDisabled = true + this.phoneTimer = setInterval(() => { + if (count > 0) { + count-- + this.phoneBtnText = `${count}秒后重试` + } else { + this.phoneDisabled = false + clearInterval(this.phoneTimer) + this.phoneTimer = null + this.phoneBtnText = `发送验证码` + } + }, 1000) + } }, + // 发送验证码 sendPhoneCode() { - if (!this.phone) return util.warningMsg("请输入手机号"); - if (!/^1[3456789]\d{9}$/.test(this.phone)) return util.warningMsg("请输入正确的手机号"); - let data = { - platform: Setting.platformId, - phone: this.phone, - types: 2 - }; - this.$post(this.api.sendPhoneOrEmailCode, data).then(res => { - if (res.message.opener) { - this.phoneCountdown(); - this.phoneOpener = res.message.opener; - } else { - util.errorMsg(res.message); - } - - }).catch(res => { - }); + const { phone } = this + if (!this.verifyPhone(phone)) return false + this.$post(this.api.sendPhoneOrEmailCode, { + platform: Setting.platformId, + phone, + types: 2 + }).then(({ message }) => { + if (message.opener) { + this.phoneCountdown() + this.phoneOpener = message.opener + } else { + util.errorMsg(message) + } + }).catch(res => {}) }, + // 绑定手机号 phoneSubmit() { - if (!this.phone) return util.warningMsg("请输入手机号"); - if (!/^1[3456789]\d{9}$/.test(this.phone)) return util.warningMsg("请输入正确的手机号"); - if (!this.phoneCode) return util.warningMsg("请输入验证码"); - let data = { - phone: this.phone, - types: 2, - code: this.phoneCode, - opener: this.phoneOpener, - platform: Setting.platformId, - account: this.form.workNumber - }; - this.$post(this.api.bindPhoneOrEmail, data).then(res => { - util.successMsg("绑定成功"); - this.form.phone = this.phone; - this.phoneVisible = false; - this.token = res.token - this.setLogin() - }).catch(res => {}) + const { phone, phoneCode } = this + if (!this.verifyPhone(phone)) return false + if (!phoneCode) return util.warningMsg("请输入验证码") + this.$post(this.api.bindPhoneOrEmail, { + phone, + types: 2, + code: phoneCode, + opener: this.phoneOpener, + platform: Setting.platformId, + account: this.form.workNumber + }).then(({ token }) => { + util.successMsg("绑定成功") + this.form.phone = this.phone + this.phoneVisible = false + this.token = token + this.setLogin() + }).catch(res => {}) } } }; @@ -424,9 +501,10 @@ export default { border-radius: 4px !important; } .school-select { - flex: 1; - margin-right: 10px; - margin-bottom: 0; + // margin-bottom: 10px; + } + .default-check { + text-align: right; } .el-select { width: 100%; diff --git a/src/pages/index/list/index.vue b/src/pages/index/list/index.vue index 8c78ba3..6b74dd9 100644 --- a/src/pages/index/list/index.vue +++ b/src/pages/index/list/index.vue @@ -166,7 +166,7 @@ -
+
diff --git a/src/pages/setting/person/info.vue b/src/pages/setting/person/info.vue index ee3e833..d91f001 100644 --- a/src/pages/setting/person/info.vue +++ b/src/pages/setting/person/info.vue @@ -135,9 +135,8 @@
  • - - - 编辑 + +
  • @@ -368,14 +367,16 @@ export default { 'setAvatar','setUserName' ]), getdata() { - this.$get(this.api.queryUserInfoDetails).then(res => { - let userInfo = res.result.hrUserInfo - let schoolId = userInfo.schoolId - this.form = Object.assign(userInfo, res.result.userAccountList[0]) - this.form.schoolId = schoolId - this.form.accountId = userInfo.id + this.$get(this.api.queryUserInfoDetails).then(({ result }) => { + const userInfo = result.hrUserInfo + const { userAccount } = result + userInfo.account = userAccount.account + userInfo.phone = userAccount.phone + userInfo.email = userAccount.email + userInfo.workNumber = userAccount.workNumber + this.form = userInfo this.originAccount = this.form.account - this.archivesList = res.result.personalFileList + this.archivesList = result.personalFileList this.$nextTick(() => { if(this.form.provinceId){ this.getCityData(1)