| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531 |
- <template>
- <view class="page">
- <view class="content">
- <view class="pageTop x-c">
- <view class="loginBox">
- <view class="login-item">
- <view class="input-account">
- <input v-model="userName" placeholder="手机号" type="number" maxlength="11" />
- </view>
- <view class="line"></view>
- </view>
- <view class="login-item">
- <view class="input-pwd">
- <input v-model="password" placeholder="密码(6-15个字符)" type="password" />
- </view>
- <view class="line"></view>
- </view>
- <view class="login-item">
- <view class="input-pwd">
- <input v-model="password1" placeholder="确认密码" type="password" />
- </view>
- <view class="line"></view>
- </view>
- <view class="login-item" v-if="isSms">
- <view class="input-yzcode x-bc">
- <input v-model="code" placeholder="验证码" type="number"></input>
- <view style="color:#666;flex-shrink: 0;" @click="sendSms">
- {{coolDown==0 ? '获取验证码': `${coolDown}秒后重试`}}
- </view>
- </view>
- <view class="line"></view>
- </view>
- <view class="btns">
- <view class="login-btn" @click="doRegister">注册</view>
- </view>
- </view>
- <view class="checkbox">
- <view class="checkbox-icon" @tap="handleAgree">
- <image src="../../static/image/login/radio_default.png" v-show="!agree"></image>
- <image src="../../static/image/login/radio_choose.png" v-show="agree"></image>
- </view>
- <view>我已阅读并同意<text @tap="goToWeb(0)">《用户协议》</text><text @tap="goToWeb(1)">《隐私政策》</text> 并使用本机号码登录
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import {
- register,
- login,
- registerByPhone,
- registerSendCode,
- isSmsVerification
- } from '@/api/user'
- import {
- goPage,
- quickWechatLogin
- } from "@/utils/login.js"
- import {
- vipPop
- } from '@/utils/vipPop.js'
- export default {
- data() {
- return {
- //userName:"CEadmin01",
- //password:"ADMIN01",
- userName: "",
- password: "",
- password1: "",
- registrationID: "",
- code: "",
- aback: true,
- agree: false,
- source: '',
- coolDown: 0,
- timer: null,
- isSms: false,
- }
- },
- onLoad(option) {
- let that = this;
- // #ifdef APP-PLUS
- this.source = plus.os.name == "iOS" ? "iOS" : plus.runtime.channel || 'app';
- // #endif
- uni.$on('getRegistrationID', function(data) {
- that.registrationID = data;
- });
- },
- onShow() {
- this.$getRegistrationID();
- this.isSmsVerificationFun()
- },
- onUnload() {
- uni.$off('getRegistrationID');
- },
- mounted() {
- },
- methods: {
- async isSmsVerificationFun() {
- const res = await isSmsVerification()
- if (res.code == 200) {
- this.isSms = res.isSmsVerification == 1 ? true : false
- } else {
- if (!res.msg) return
- uni.showToast({
- icon: 'none',
- title: res.msg
- })
- }
- },
- sendSms() {
- if (this.coolDown > 0) {
- return
- }
- if (!uni.$u.test.mobile(this.userName)) {
- uni.showToast({
- title: "请输入正确的手机号",
- icon: 'none',
- });
- return
- }
- this.coolDown = 60;
- registerSendCode({
- phone: this.userName
- }).then(res => {
- if (res.code == 200) {
- uni.showToast({
- title: '验证码已发送',
- icon: 'none',
- });
- this.coolDown = 60;
- this.timer = setInterval(() => {
- this.coolDown--;
- if (this.coolDown === 0) {
- clearInterval(this.timer);
- this.timer = null;
- }
- }, 1000);
- } else {
- this.timer && clearInterval(this.timer);
- this.coolDown = 0
- uni.showToast({
- title: res.msg,
- icon: 'none',
- });
- }
- },
- rej => {
- this.timer && clearInterval(this.timer);
- this.coolDown = 0;
- }).catch(() => {
- this.timer && clearInterval(this.timer);
- this.coolDown = 0;
- })
- },
- doRegister() {
- if (!uni.$u.test.mobile(this.userName)) {
- uni.showToast({
- title: "请输入正确的手机号",
- icon: 'none',
- });
- return
- }
- if (this.$isEmpty(this.password)) {
- uni.showToast({
- title: "请输入密码",
- icon: 'none',
- });
- return
- }
- if (this.password.length < 6 || this.password.length > 15) {
- uni.showToast({
- title: "密码长度应该在6到15个字符",
- icon: 'none',
- });
- return
- }
- if (this.password != this.password1) {
- uni.showToast({
- title: "两次输入密码不一致",
- icon: 'none'
- });
- }
- if (this.$isEmpty(this.code) && this.isSms) {
- uni.showToast({
- title: "请输入验证码",
- icon: 'none',
- });
- return
- }
- if (!this.agree) {
- uni.showToast({
- title: "请同意相关协议",
- icon: 'none'
- });
- return
- }
- var data = {
- phone: this.userName,
- password: this.password,
- jpushId: this.registrationID || uni.getStorageSync("registrationID"),
- source: this.source,
- code: this.code
- };
- var that = this;
- uni.showLoading({
- title: "注册中..."
- });
- if (this.isSms) {
- registerByPhone(data).then(res => {
- if (res.code == 200) {
- this.doLogin();
- } else {
- uni.hideLoading()
- uni.showToast({
- title: res.msg,
- icon: 'none'
- });
- }
- },
- rej => {}
- );
- return
- }
- data['loginType'] = 1
- register(data).then(res => {
- if (res.code == 200) {
- this.doLogin();
- } else {
- uni.hideLoading()
- uni.showToast({
- title: res.msg,
- icon: 'none'
- });
- }
- })
- },
- doLogin() {
- let data = {
- phone: this.userName,
- password: this.password,
- jpushId: this.registrationID || uni.getStorageSync("registrationID"),
- loginType: 1
- };
- let that = this;
- login(data).then(res => {
- uni.hideLoading()
- if (res.code == 200 && res.users && Object.prototype.toString.call(res.users) ==
- '[object Array]') {
- uni.setStorageSync('requestParam', data)
- uni.setStorageSync('wechatList', res.users)
- goPage();
- return
- }
- if (res.code == 200) {
- // #ifdef APP-PLUS
- if (res.isNew) {
- quickWechatLogin(true, res.phone);
- return;
- }
- // #endif
- if (res.alert) {
- vipPop({
- alert: res.alert,
- alert1: res.alert1
- }, e => {
- uni.switchTab({
- url: '/pages_im/pages/conversation/conversationList/index',
- // url: '/pages/course/index'
- });
- })
- }
- uni.setStorageSync('AppToken', res.token);
- uni.setStorageSync('userInfo', JSON.stringify(res.user));
- uni.$emit('refreshIM');
- uni.$emit('showHealthButler');
- uni.reLaunch({
- url: '/pages_im/pages/conversation/conversationList/index',
- // url: '../index/index',
- animationType: 'pop-in',
- animationDuration: 100
- })
- } else {
- uni.showToast({
- title: res.msg,
- icon: 'none'
- });
- }
- },
- rej => {}
- );
- },
- getRegistrationID() {
- // #ifdef APP-PLUS
- // #endif
- },
- handleAgree() { // 同意
- this.agree = !this.agree
- },
- goToWeb(index) {
- uni.setStorageSync('url', index == 0 ? "https://userapp.zkhj6.com/web/userAgreement" :
- "https://userapp.zkhj6.com/web/privacyPolicy");
- uni.navigateTo({
- url: "/pages/index/h5"
- })
- },
- },
- beforeDestroy() { // 组件卸载时清掉定时器,防止内存泄漏
- this.timer && clearInterval(this.timer);
- }
- }
- </script>
- <style lang="scss">
- page {
- background-color: #ffffff;
- }
- .content {
- display: flex;
- flex-direction: column;
- align-items: center;
- height: calc(100vh);
- width: 100%;
- justify-content: space-between;
- //padding-top: calc(100% - 32vh);
- }
- .pageTop {
- display: flex;
- flex-direction: column;
- width: 100%;
- }
- .content .head {
- text-align: center;
- width: 100%;
- height: 100rpx;
- background-size: cover;
- box-sizing: border-box;
- font-size: 36rpx;
- font-weight: bold;
- color: #666;
- }
- .content .head image {
- width: 150rpx;
- height: 150rpx;
- border-radius: 10rpx;
- box-shadow: 0px 0px 20rpx rgba(0, 0, 0, 0.2);
- }
- .title {
- color: #141414;
- margin: 50upx 0upx 30upx 0rpx;
- font-size: 38rpx;
- font-weight: 500;
- }
- .desc {
- color: #686866;
- padding: 0 0 30rpx 0rpx;
- font-size: 28rpx;
- }
- .loginBox {
- padding: 10px 10px 30rpx;
- width: calc(100% - 20px);
- margin-top: 0rpx;
- background: #FDFDFD;
- //box-shadow: 0rpx 4rpx 27rpx 0rpx rgba(155,155,155,0.25);
- border-radius: 7rpx;
- }
- .login-item p {
- text-align: left;
- }
- .line {
- height: 0.5rpx;
- background-color: #efefef;
- margin-top: 10rpx;
- }
- .input-account {
- margin-top: 20rpx;
- margin-bottom: 0rpx;
- border-radius: 40rpx;
- border: solid 0rpx #efefef;
- height: 80rpx;
- width: 100%;
- background: url(/static/account.png) no-repeat 0 center;
- background-size: 30rpx 30rpx;
- background-position: 30rpx;
- }
- .input-yzcode {
- margin-top: 20rpx;
- margin-bottom: 0rpx;
- border-radius: 40rpx;
- border: solid 0rpx #efefef;
- height: 80rpx;
- width: 100%;
- background: url(/static/image/login/cz_icon.png) no-repeat 0 center;
- background-size: 30rpx 30rpx;
- background-position: 30rpx;
- }
- .input-pwd {
- margin-top: 40rpx;
- margin-bottom: 20rpx;
- border-radius: 40rpx;
- border: solid 0rpx #efefef;
- height: 80rpx;
- width: 100%;
- background: url(/static/password.png) no-repeat 0 center;
- background-size: 30rpx 30rpx;
- background-position: 30rpx;
- }
- input {
- margin-left: 80rpx;
- height: 80rpx;
- line-height: 80rpx
- }
- .footer {
- color: #686866;
- width: 100%;
- position: fixed;
- text-align: center;
- bottom: 60upx;
- font-size: 28rpx;
- }
- .btns {
- margin: 50rpx 0rpx;
- margin-bottom: 0rpx;
- }
- .login-btn {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 100%;
- height: 80rpx;
- background: linear-gradient(to right, #FF5C03 0%, #FF5C03 100%);
- background: -moz-linear-gradient(to right, #FF5C03 0%, #FF5C03 100%);
- box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
- border-radius: 40rpx;
- font-size: 30rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: rgba(255, 255, 255, 1);
- }
- .reg-box {
- padding-bottom: 20rpx;
- margin: 0 10px;
- .reg-btn {
- font-size: 16px;
- color: #FF5C03;
- }
- }
- .pageBottom {
- height: 260rpx;
- width: 75%;
- display: flex;
- flex-direction: column;
- }
- .tips {
- color: #999;
- font-size: 36rpx;
- }
- .menu {
- margin-top: 30rpx;
- image {
- width: 78rpx;
- height: 78rpx;
- }
- }
- .checkbox {
- margin: 20rpx;
- margin-top: 16rpx;
- display: flex;
- flex-direction: row;
- align-items: flex-start;
- justify-content: flex-start;
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- font-size: 26rpx;
- color: #999999;
- line-height: 38rpx;
- text-align: left;
- text {
- color: #FF5C03;
- }
- &-icon {
- flex-shrink: 0;
- margin-right: 12rpx;
- image {
- height: 24rpx;
- width: 24rpx;
- }
- }
- }
- </style>
|