| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518 |
- <template>
- <view class="wrap">
- <view class="logo">
- <image :src="topImage || '/static/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-account"></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="loginMethods.length >= 3 || (loginMethods.length === 2 && loginMethods.indexOf('wechat_phone') === -1)">
- <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-phone"></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-wechat"></view>
- <view class="s-text">微信快捷登录</view>
- </button>
- <!-- #endif -->
- </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 mixinsCommon from '@/mixins/common.js';
- import { decodeRedirectUrl } from '../../common/util';
- export default {
- mixins: [mixinsCommon],
- data() {
- return {
- form: {
- name: '',
- number: '',
- code: '',
- phone: '',
- captcha: ''
- },
- loginMethod: '',
- disable: {
- captcha: false,
- submit: false
- },
- captcha: {
- retry: false,
- second: 0
- }
- };
- },
- onLoad(options) {
- this.returnPage = options.from ? decodeRedirectUrl(options.from) : 'pages/home/index';
- console.log('login returnPage', this.returnPage);
- smartLogin('', true); // 判断是否扫码或进入活动列表页,因为当前页没有接口请求和权限校验
- },
- computed: {
- selectActivity() {
- return this.$store.getters.globalConfig.select_activity;
- },
- topImage() {
- return this.$store.getters.globalConfig.login_top_img;
- },
- loginNote() {
- return this.$store.getters.globalConfig.login_note || '欢迎参加答题竞赛活动。';
- },
- loginMethods() {
- // ['name_code','number_code',phone_captcha','wechat_phone']
- let loginMethods = this.$store.getters.globalConfig.login_methods || [];
- if (loginMethods.length > 0) {
- this.loginMethod = loginMethods[0];
- console.log('this.loginMethod');
- }
- return loginMethods;
- }
- },
- 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 this.$logic.showToast('成员姓名不能为空');
- }
- if (!this.form.code) {
- return this.$logic.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.$store.commit('setAccessToken', res.token);
- this.$store.commit('setActivityId', res.activity_id);
- this.$logic.showToast('登录成功').then(([err, res]) => {
- uni.reLaunch({
- url: '/' + this.returnPage
- });
- });
- }
- });
- });
- },
- onLoginByNumberCode() {
- if (this.disable.submit) {
- return;
- }
- if (!this.form.number) {
- return this.$logic.showToast('成员编号不能为空');
- }
- if (!this.form.code) {
- return this.$logic.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.$store.commit('setAccessToken', res.token);
- this.$store.commit('setActivityId', res.activity_id);
- this.$logic.showToast('登录成功').then(([err, res]) => {
- uni.reLaunch({
- url: '/' + this.returnPage
- });
- });
- }
- });
- });
- },
- onLoginByPhoneCaptcha() {
- if (this.disable.submit) {
- return;
- }
- if (!this.form.phone) {
- return this.$logic.showToast('手机号不能为空');
- }
- if (!this.form.captcha) {
- return this.$logic.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.$store.commit('setAccessToken', res.token);
- this.$store.commit('setActivityId', res.activity_id);
- this.$logic.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
- this.$logic.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[1].code).then(([err, res]) => {
- console.log('loginByWechatPhone', err, res);
- uni.hideLoading();
- if (!err) {
- this.$store.commit('setAccessToken', res.token);
- this.$store.commit('setActivityId', res.activity_id);
- this.$logic.showToast('登录成功').then(([err, res]) => {
- uni.reLaunch({
- url: '/' + this.returnPage
- });
- });
- }
- });
- });
- },
- onJumpActivity() {
- uni.redirectTo({
- url: '/answer_pages/home/dashboard'
- });
- }
- }
- };
- </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;
- }
- }
- }
- .tips {
- margin-top: 50upx;
- width: 100%;
- color: #383838;
- font-size: 24upx;
- }
- .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>
|