|
|
@@ -0,0 +1,561 @@
|
|
|
+<template>
|
|
|
+ <view class="wrap">
|
|
|
+ <view class="logo">
|
|
|
+ <image :src="topImage || 'https://xy.wenlvti.net/app_static/yunexamine/imgs/login_top_loading.jpg'" mode="widthFix"></image>
|
|
|
+ </view>
|
|
|
+ <view class="main">
|
|
|
+ <template v-if="loginMethod === 'name_code'">
|
|
|
+ <view class="form">
|
|
|
+ <view class="b-row">
|
|
|
+ <view class="b-input">
|
|
|
+ <view class="s-icon iconfont icon-account"></view>
|
|
|
+ <input type="text" :value="form.name" @input="onInputName" placeholder="请输入姓名" />
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view class="b-row">
|
|
|
+ <view class="b-input">
|
|
|
+ <view class="s-icon iconfont icon-password"></view>
|
|
|
+ <input type="text" :value="form.code" @input="onInputCode" placeholder="请输入登录码" />
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view class="submit" :class="{ disable: disable.submit }" @click="onLoginByNameCode">立即登录</view>
|
|
|
+ </template>
|
|
|
+ <template v-else-if="loginMethod === 'number_code'">
|
|
|
+ <view class="form">
|
|
|
+ <view class="b-row">
|
|
|
+ <view class="b-input">
|
|
|
+ <view class="s-icon iconfont icon-card"></view>
|
|
|
+ <input type="text" :value="form.number" @input="onInputNumber" placeholder="请输入编号" />
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view class="b-row">
|
|
|
+ <view class="b-input">
|
|
|
+ <view class="s-icon iconfont icon-password"></view>
|
|
|
+ <input type="text" :value="form.code" @input="onInputCode" placeholder="请输入登录码" />
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view class="submit" :class="{ disable: disable.submit }" @click="onLoginByNumberCode">立即登录</view>
|
|
|
+ </template>
|
|
|
+ <template v-else-if="loginMethod === 'phone_captcha'">
|
|
|
+ <view class="form">
|
|
|
+ <view class="b-row">
|
|
|
+ <view class="b-input">
|
|
|
+ <view class="s-icon iconfont icon-phone"></view>
|
|
|
+ <input type="text" :value="form.phone" @input="onInputPhone" placeholder="请输入手机号" />
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view class="b-row">
|
|
|
+ <view class="b-input">
|
|
|
+ <view class="s-icon iconfont icon-password"></view>
|
|
|
+ <input type="text" :value="form.captcha" @input="onInputCaptcha" placeholder="请输入验证码" />
|
|
|
+ <view class="s-captcha" :class="{ disable: captcha.second > 0 }" @click="onPhoneCaptcha">
|
|
|
+ <text v-if="!captcha.retry && !captcha.second">获取验证码</text>
|
|
|
+ <text v-else-if="captcha.second > 0">重新获取 {{ captcha.second }}秒</text>
|
|
|
+ <text v-else-if="captcha.retry">重新获取</text>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view class="submit" :class="{ disable: disable.submit }" @click="onLoginByPhoneCaptcha">立即登录</view>
|
|
|
+ </template>
|
|
|
+ <!-- #ifdef MP-WEIXIN -->
|
|
|
+ <button class="submit f-wechat open-data-btn" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber"
|
|
|
+ v-if="loginMethods.length === 1 && loginMethod === 'wechat_phone'">手机号快捷登录</button>
|
|
|
+ <!-- #endif -->
|
|
|
+ <view class="other" v-if="showOtherMethods">
|
|
|
+ <view class="split">
|
|
|
+ <view class="s-line"></view>
|
|
|
+ <view class="s-text">其他登录方式</view>
|
|
|
+ <view class="s-line"></view>
|
|
|
+ </view>
|
|
|
+ <view class="login-method">
|
|
|
+ <view class="b-method f-name"
|
|
|
+ v-if="loginMethods.indexOf('name_code') !== -1 && loginMethod !== 'name_code'"
|
|
|
+ @click="onChangeMethod('name_code')">
|
|
|
+ <view class="iconfont icon-key"></view>
|
|
|
+ <view class="s-text">姓名登录码</view>
|
|
|
+ </view>
|
|
|
+ <view class="b-method f-number"
|
|
|
+ v-if="loginMethods.indexOf('number_code') !== -1 && loginMethod !== 'number_code'"
|
|
|
+ @click="onChangeMethod('number_code')">
|
|
|
+ <view class="iconfont icon-key"></view>
|
|
|
+ <view class="s-text">编号登录码</view>
|
|
|
+ </view>
|
|
|
+ <view class="b-method f-phone"
|
|
|
+ v-if="loginMethods.indexOf('phone_captcha') !== -1 && loginMethod !== 'phone_captcha'"
|
|
|
+ @click="onChangeMethod('phone_captcha')">
|
|
|
+ <view class="iconfont icon-verify-fill"></view>
|
|
|
+ <view class="s-text">手机验证码</view>
|
|
|
+ </view>
|
|
|
+ <!-- #ifdef MP-WEIXIN -->
|
|
|
+ <button class="b-method f-wechat open-data-btn" open-type="getPhoneNumber"
|
|
|
+ @getphonenumber="onGetPhoneNumber" v-if="loginMethods.indexOf('wechat_phone') !== -1">
|
|
|
+ <view class="iconfont icon-phone"></view>
|
|
|
+ <view class="s-text">手机号快捷登录</view>
|
|
|
+ </button>
|
|
|
+ <!-- #endif -->
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view class="auth-tips" v-if="openRegister">
|
|
|
+ <view class="s-text" @click="onJumpRegister">还没有账号?立即注册</view>
|
|
|
+ </view>
|
|
|
+ <view class="tips">{{loginNote}}</view>
|
|
|
+ </view>
|
|
|
+ <view class="select-activity" v-if="selectActivity" @click="onJumpActivity">
|
|
|
+ <view class="iconfont icon-dashboard"></view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+ import {
|
|
|
+ loginByNameCode,
|
|
|
+ loginByNumberCode,
|
|
|
+ loginByPhoneCaptcha,
|
|
|
+ loginByWechatPhone,
|
|
|
+ sendPhoneCaptcha
|
|
|
+ } from '../../service/api/user.js'
|
|
|
+ import {
|
|
|
+ smartLogin
|
|
|
+ } from '../../service/request/main.js'
|
|
|
+ import {
|
|
|
+ decodeRedirectUrl,
|
|
|
+ showToast
|
|
|
+ } from './../common/util'
|
|
|
+ import mixinsCommon from '../../mixins/common.js'
|
|
|
+ import { useAppStore } from '../../store/index.js'
|
|
|
+ export default {
|
|
|
+ mixins: [mixinsCommon],
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ form: {
|
|
|
+ name: '',
|
|
|
+ number: '',
|
|
|
+ code: '',
|
|
|
+ phone: '',
|
|
|
+ captcha: '',
|
|
|
+ },
|
|
|
+ loginMethod: '',
|
|
|
+ disable: {
|
|
|
+ captcha: false,
|
|
|
+ submit: false
|
|
|
+ },
|
|
|
+ captcha: {
|
|
|
+ retry: false,
|
|
|
+ second: 0,
|
|
|
+ },
|
|
|
+ appStore: useAppStore()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onLoad(options) {
|
|
|
+ this.returnPage = options.from ? decodeRedirectUrl(options.from) : 'pages/home/index'
|
|
|
+ console.log('login returnPage', this.returnPage)
|
|
|
+ smartLogin('', true) // 判断是否扫码或进入活动列表页,因为当前页没有接口请求和权限校验
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ selectActivity() {
|
|
|
+ return this.appStore.getGlobalConfig.select_activity
|
|
|
+ },
|
|
|
+ topImage() {
|
|
|
+ return this.appStore.getGlobalConfig.login_top_img
|
|
|
+ },
|
|
|
+ loginNote() {
|
|
|
+ return this.appStore.getGlobalConfig.login_note || '注:仅内部使用,请选择合适的方式登录参加答题竞赛活动。'
|
|
|
+ },
|
|
|
+ loginMethods() {
|
|
|
+ // ['name_code','number_code',phone_captcha','wechat_phone']
|
|
|
+ let loginMethods = this.appStore.getGlobalConfig.login_methods || []
|
|
|
+ if (loginMethods.length > 0) {
|
|
|
+ this.loginMethod = loginMethods[0]
|
|
|
+ console.log('this.loginMethod')
|
|
|
+ }
|
|
|
+
|
|
|
+ return loginMethods
|
|
|
+ },
|
|
|
+ openRegister() {
|
|
|
+ return this.appStore.getGlobalConfig.open_register
|
|
|
+ },
|
|
|
+ showOtherMethods() {
|
|
|
+ let show = this.loginMethods.length >= 2
|
|
|
+ // #ifndef MP-WEIXIN
|
|
|
+ show = this.loginMethods.length >= 3 ||
|
|
|
+ (this.loginMethods.length === 2 && this.loginMethods.indexOf('wechat_phone') === -1)
|
|
|
+ // #endif
|
|
|
+
|
|
|
+ return show
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ onInputName(e) {
|
|
|
+ // console.log('onInputName', e)
|
|
|
+ this.form.name = e.detail.value
|
|
|
+ },
|
|
|
+ onInputNumber(e) {
|
|
|
+ // console.log('onInputName', e)
|
|
|
+ this.form.number = e.detail.value
|
|
|
+ },
|
|
|
+ onInputCode(e) {
|
|
|
+ // console.log('onInputCode', e)
|
|
|
+ this.form.code = e.detail.value
|
|
|
+ },
|
|
|
+ onInputPhone(e) {
|
|
|
+ // console.log('onInputPhone', e)
|
|
|
+ this.form.phone = e.detail.value;
|
|
|
+ },
|
|
|
+ onInputCaptcha(e) {
|
|
|
+ // console.log('onInputCaptcha', e)
|
|
|
+ this.form.captcha = e.detail.value
|
|
|
+ },
|
|
|
+ onChangeMethod(method) {
|
|
|
+ this.loginMethod = method
|
|
|
+ },
|
|
|
+ onPhoneCaptcha() {
|
|
|
+ if (this.disable.captcha) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.disable.captcha = true
|
|
|
+ uni.login().then(([err, res]) => {
|
|
|
+ console.log('uni.login', err, res)
|
|
|
+ sendPhoneCaptcha(this.form.phone, res ? res.code : '', true).then(([err, res]) => {
|
|
|
+ console.log('sendPhoneCaptcha', err, res)
|
|
|
+ if (!err) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '发送成功'
|
|
|
+ })
|
|
|
+
|
|
|
+ // 验证码倒计时
|
|
|
+ this.captcha.second = 60
|
|
|
+ var interval = setInterval(() => {
|
|
|
+ this.captcha.second--
|
|
|
+ }, 1000)
|
|
|
+ setTimeout(() => {
|
|
|
+ clearInterval(interval)
|
|
|
+ this.captcha.retry = true
|
|
|
+ this.captcha.second = 0
|
|
|
+ this.disable.captcha = false
|
|
|
+ }, this.captcha.second * 1000)
|
|
|
+ } else {
|
|
|
+ this.disable.captcha = false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onLoginByNameCode() {
|
|
|
+ if (this.disable.submit) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!this.form.name) {
|
|
|
+ return showToast('姓名不能为空')
|
|
|
+ }
|
|
|
+ if (!this.form.code) {
|
|
|
+ return showToast('登录码不能为空')
|
|
|
+ }
|
|
|
+ this.disable.submit = true;
|
|
|
+ uni.login().then(([err, res]) => {
|
|
|
+ console.log('uni.login', err, res)
|
|
|
+ loginByNameCode(this.form.name, this.form.code, res ? res.code : '').then(([err, res]) => {
|
|
|
+ console.log('loginByNameCode', err, res)
|
|
|
+ this.disable.submit = false
|
|
|
+ if (!err) {
|
|
|
+ this.appStore.setAccessToken(res.token)
|
|
|
+ this.appStore.setActivityId(res.activity_id)
|
|
|
+ showToast('登录成功').then(([err, res]) => {
|
|
|
+ uni.reLaunch({
|
|
|
+ url: '/' + this.returnPage
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onLoginByNumberCode() {
|
|
|
+ if (this.disable.submit) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!this.form.number) {
|
|
|
+ return showToast('编号不能为空')
|
|
|
+ }
|
|
|
+ if (!this.form.code) {
|
|
|
+ return showToast('登录码不能为空')
|
|
|
+ }
|
|
|
+ this.disable.submit = true;
|
|
|
+ uni.login().then(([err, res]) => {
|
|
|
+ console.log('uni.login', err, res)
|
|
|
+ loginByNumberCode(this.form.number, this.form.code, res ? res.code : '').then(([err, res]) => {
|
|
|
+ console.log('loginByNumberCode', err, res)
|
|
|
+ this.disable.submit = false
|
|
|
+ if (!err) {
|
|
|
+ this.appStore.setAccessToken(res.token)
|
|
|
+ this.appStore.setActivityId(res.activity_id)
|
|
|
+ showToast('登录成功').then(([err, res]) => {
|
|
|
+ uni.reLaunch({
|
|
|
+ url: '/' + this.returnPage
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onLoginByPhoneCaptcha() {
|
|
|
+ if (this.disable.submit) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!this.form.phone) {
|
|
|
+ return showToast('手机号不能为空')
|
|
|
+ }
|
|
|
+ if (!this.form.captcha) {
|
|
|
+ return showToast('验证码不能为空')
|
|
|
+ }
|
|
|
+ this.disable.submit = true
|
|
|
+ uni.login().then(([err, res]) => {
|
|
|
+ console.log('uni.login', err, res)
|
|
|
+ loginByPhoneCaptcha(this.form.phone, this.form.captcha, res ? res.code : '').then(([err,
|
|
|
+ res
|
|
|
+ ]) => {
|
|
|
+ console.log('loginByPhoneCaptcha', err, res)
|
|
|
+ this.disable.submit = false
|
|
|
+ if (!err) {
|
|
|
+ this.appStore.setAccessToken(res.token)
|
|
|
+ this.appStore.setActivityId(res.activity_id)
|
|
|
+ showToast('登录成功').then(([err, res]) => {
|
|
|
+ uni.reLaunch({
|
|
|
+ url: '/' + this.returnPage
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onGetPhoneNumber(e) {
|
|
|
+ console.log('onGetPhoneNumber', e)
|
|
|
+ if (e.detail.errMsg.indexOf(':ok') === -1) {
|
|
|
+ // fail user deny
|
|
|
+ // showToast(e.detail.errMsg.replace('getPhoneNumber:', ''))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ uni.showLoading({
|
|
|
+ title: '尝试登录中'
|
|
|
+ })
|
|
|
+ uni.login().then(([err, res]) => {
|
|
|
+ console.log('uni.login', err, res)
|
|
|
+ loginByWechatPhone(e.detail.encryptedData, e.detail.iv, e.detail.code || '', res.code).then(([
|
|
|
+ err, res
|
|
|
+ ]) => {
|
|
|
+ console.log('loginByWechatPhone', err, res)
|
|
|
+ uni.hideLoading()
|
|
|
+ if (!err) {
|
|
|
+ this.appStore.setAccessToken(res.token)
|
|
|
+ this.appStore.setActivityId(res.activity_id)
|
|
|
+ showToast('登录成功').then(([err, res]) => {
|
|
|
+ uni.reLaunch({
|
|
|
+ url: '/' + this.returnPage
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onJumpActivity() {
|
|
|
+ uni.redirectTo({
|
|
|
+ url: '/pages/third/yunexamine/pages/home/dashboard'
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onJumpRegister() {
|
|
|
+ uni.redirectTo({
|
|
|
+ url: '/pages/third/yunexamine/pages/user/register'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss">
|
|
|
+ page {
|
|
|
+ padding-bottom: env(safe-area-inset-bottom);
|
|
|
+ background: #ffffff;
|
|
|
+ }
|
|
|
+
|
|
|
+ .wrap {}
|
|
|
+
|
|
|
+ .logo {
|
|
|
+ image {
|
|
|
+ width: 100%;
|
|
|
+ height: 460upx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .main {
|
|
|
+ padding: 50upx;
|
|
|
+ }
|
|
|
+
|
|
|
+ .form {
|
|
|
+ .b-row {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: space-between;
|
|
|
+ margin-bottom: 30upx;
|
|
|
+ border-bottom: 1upx solid #E5E5E5;
|
|
|
+ }
|
|
|
+
|
|
|
+ .b-input {
|
|
|
+ flex: 1;
|
|
|
+ padding: 0 20upx;
|
|
|
+ width: 100%;
|
|
|
+ height: 90upx;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+
|
|
|
+ .s-icon {
|
|
|
+ color: #ccc;
|
|
|
+ font-size: 40upx;
|
|
|
+ }
|
|
|
+
|
|
|
+ input {
|
|
|
+ margin-left: 30upx;
|
|
|
+ flex: 1;
|
|
|
+ color: #333;
|
|
|
+ font-size: 28upx;
|
|
|
+ }
|
|
|
+
|
|
|
+ .s-captcha {
|
|
|
+ padding: 0 30upx;
|
|
|
+ background: #fff;
|
|
|
+ border: 2upx #ccc solid;
|
|
|
+ height: 64upx;
|
|
|
+ line-height: 64upx;
|
|
|
+ border-radius: 32upx;
|
|
|
+ color: #808080;
|
|
|
+ font-size: 24upx;
|
|
|
+
|
|
|
+ &.disable {
|
|
|
+ color: #999;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .submit {
|
|
|
+ margin-top: 80upx;
|
|
|
+ height: 100upx;
|
|
|
+ line-height: 100upx;
|
|
|
+ text-align: center;
|
|
|
+ color: #fff;
|
|
|
+ font-size: 32upx;
|
|
|
+ background: #DA5650;
|
|
|
+ border-radius: 50upx;
|
|
|
+ letter-spacing: 10upx;
|
|
|
+
|
|
|
+ &.f-wechat {
|
|
|
+ background: #35C773;
|
|
|
+ }
|
|
|
+
|
|
|
+ &.disable {
|
|
|
+ background: rgba($color: #DA5650, $alpha: 0.2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .split {
|
|
|
+ margin-top: 50upx;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: space-between;
|
|
|
+
|
|
|
+ .s-line {
|
|
|
+ width: 200upx;
|
|
|
+ height: 1upx;
|
|
|
+ background: #eee;
|
|
|
+ }
|
|
|
+
|
|
|
+ .s-text {
|
|
|
+ font-size: 28upx;
|
|
|
+ color: #808080;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .login-method {
|
|
|
+ margin-top: 30upx;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ flex-wrap: wrap;
|
|
|
+
|
|
|
+ .b-method {
|
|
|
+ margin: 0 20upx 20upx 20upx;
|
|
|
+ width: 250upx;
|
|
|
+ // padding: 0 20upx;
|
|
|
+ height: 80upx;
|
|
|
+ border-radius: 10upx;
|
|
|
+ background: #808080;
|
|
|
+ display: flex;
|
|
|
+ justify-content: center;
|
|
|
+ align-items: center;
|
|
|
+ color: #fff;
|
|
|
+
|
|
|
+ &.f-name {
|
|
|
+ background: #64A2FA;
|
|
|
+ }
|
|
|
+
|
|
|
+ &.f-number {
|
|
|
+ background: #EE6C77;
|
|
|
+ }
|
|
|
+
|
|
|
+ &.f-phone {
|
|
|
+ background: #FF9C45;
|
|
|
+ }
|
|
|
+
|
|
|
+ &.f-wechat {
|
|
|
+ background: #35C773;
|
|
|
+ }
|
|
|
+
|
|
|
+ .iconfont {
|
|
|
+ margin-right: 10upx;
|
|
|
+ font-size: 40upx;
|
|
|
+ }
|
|
|
+
|
|
|
+ .s-text {
|
|
|
+ font-size: 26upx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .auth-tips {
|
|
|
+ margin-top: 50upx;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+
|
|
|
+ .s-text {
|
|
|
+ font-size: 28upx;
|
|
|
+ color: #808080;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .tips {
|
|
|
+ margin-top: 50upx;
|
|
|
+ width: 100%;
|
|
|
+ color: #383838;
|
|
|
+ font-size: 24upx;
|
|
|
+ text-align: center;
|
|
|
+ }
|
|
|
+
|
|
|
+ .select-activity {
|
|
|
+ position: absolute;
|
|
|
+ bottom: 50upx;
|
|
|
+ right: 50upx;
|
|
|
+ background: #fff;
|
|
|
+ border: 2upx solid #ddd;
|
|
|
+ width: 100upx;
|
|
|
+ height: 100upx;
|
|
|
+ border-radius: 50upx;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+
|
|
|
+ .iconfont {
|
|
|
+ font-size: 50upx;
|
|
|
+ color: #DA5650;
|
|
|
+ }
|
|
|
+ }
|
|
|
+</style>
|