123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- <template>
- <view class="register">
- <view class="content">
- <!-- 头部logo -->
- <view class="header">
- <image src="https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/loginlogo.png"></image>
- </view>
- <!-- 主体 -->
- <view class="main">
- <wInput v-model="phoneData" type="number" maxlength="11" placeholder="手机号"></wInput>
- <wInput v-model="verCode" type="number" maxlength="6" placeholder="验证码" isShowCode ref="runCode" @setCode="getVerCode()"></wInput>
- </view>
- <wButton class="wbutton" text="登 录" :rotate="isRotate" @click.native="startReg()" bgColor="linear-gradient(to right, rgba(11,115,185,0.7), rgba(11,115,185,0.6))"></wButton>
- <view class="flex justify-between align-center" style="margin-top: 60rpx;">
- <button v-if="!isphoneNum" style="margin-top: 20rpx;" :class="['buttonBorder',!istrue?'dlbutton':'dlbutton_loading']"
- open-type="getPhoneNumber" @getphonenumber="getphone">
- <view :class="istrue?'rotate_loop':''">
- <text v-if="istrue" class="cuIcon cuIcon-loading1"></text>
- <view v-if="!istrue">
- <slot name="text">微信授权一键登录</slot>
- </view>
- </view>
- </button>
- <button v-else style="margin-top: 20rpx;" :class="['buttonBorder',!istrue?'dlbutton':'dlbutton_loading']" open-type="getUserInfo"
- @getuserinfo="wxLogin">
- <view :class="istrue?'rotate_loop':''">
- <text v-if="istrue" class="cuIcon cuIcon-loading1"></text>
- <view v-if="!istrue">
- <slot name="text">微信授权一键登录</slot>
- </view>
- </view>
- </button>
- <button style="margin-top: 20rpx;color:#0B73B9 ;" class="buttonBorder dlbutton" @click="toindex()">
- <slot name="text">游客登录</slot>
- </button>
- </view>
- <u-popup v-model="show" mode="center" :mask-close-able="false" border-radius="16">
- <view style="width: 500rpx;height: 400rpx;position: relative;" class="flex flex-direction align-center justify-center">
- <view class="text-xl text-bold" style="position: absolute;top:30rpx">
- 提示
- </view>
- <view class="text-gray margin-top-sm text-lg padding-lr-sm">
- 需要获取用户个人信息及资料方便后续注册
- </view>
- <button open-type="getUserInfo" style="width: 100%;font-size: 32rpx;position: absolute;bottom: 0;" @getuserinfo="wxLogin">确认授权</button>
- </view>
- </u-popup>
- <!-- 底部信息 -->
- <view class="footer">
- <view class="flex align-center" @click="isqueren">
- <image :src="imgitem.name" mode="" style="width: 30rpx;height: 30rpx;"></image>
- <text style="color: #0B73B9;">《熙宝HMO》</text>
- <text style="color: #999999;">服务协议</text>
- </view>
- </view>
- </view>
- <u-no-network></u-no-network>
- </view>
- </template>
- <script>
- var _this;
- import wInput from '../../components/watch-input.vue' //input
- import wButton from '../../components/watch-button.vue' //button
- var user = require('../../common/user.js');
- import {
- mapState,
- mapMutations,
- mapGetters,
- mapActions
- } from 'vuex';
- import IMService from "../../common/goeasyimutil.js";
- import store from '@/store'
- export default {
- computed: {
- ...mapGetters({
- hasLogin: 'verifyJwt'
- }),
- ...mapState(['user'])
- },
- data() {
- return {
- //logo图片 base64
- phoneData: '', // 用户/电话
- verCode: "", //验证码
- showAgree: true, //协议是否选择
- isRotate: false, //是否加载旋转
- istrue: false,
- num: 1,
- imgitem: {
- istrue: false,
- name: "https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/xieyi.png"
- },
- show: false,
- isphoneNum: false
- }
- },
- // onShow() {
- // uni.checkSession({
- // success() {
- // console.log("已登录")
- // return;
- // },
- // fail() {
- // uni.navigateTo({
- // url: "../doctor_related/doctor_info"
- // })
- // }
- // })
- // },
- components: {
- wInput,
- wButton,
- },
- mounted() {
- _this = this;
- },
- onLoad() {
- this.isphone()
- },
- methods: {
- isShowAgree() {
- //是否选择协议
- _this.showAgree = !_this.showAgree;
- },
- getVerCode: async function() {
- //获取验证码
- if (_this.phoneData.length != 11) {
- uni.showToast({
- icon: 'none',
- position: 'bottom',
- title: '手机号不正确'
- });
- return false;
- }
- if (!_this.$util.isNum(_this.phoneData)) {
- uni.showToast({
- title: "手机号不正确",
- icon: "none",
- position: "bottom"
- })
- return false
- }
- if (!_this.$util.isPhoneNumber(_this.phoneData)) {
- uni.showToast({
- title: "手机号不正确",
- icon: "none",
- position: "bottom"
- })
- return false
- }
- let res = await this.$request.post("/api/v1/common/sendVerifyCode", {
- phone: this.phoneData,
- type: 1
- })
- console.log(res)
- if (res.status == 0) {
- this.$refs.runCode.$emit('runCode'); //触发倒计时(一般用于请求成功验证码后调用)
- }
- // _this.$refs.runCode.$emit('runCode', 0); //假装模拟下需要 终止倒计时
- },
- startReg: function() {
- //注册
- if (this.isRotate) {
- //判断是否加载中,避免重复点击请求
- return false;
- }
- if (!this.imgitem.istrue) {
- uni.showToast({
- icon: 'none',
- position: 'bottom',
- title: '请先同意协议'
- });
- return false;
- }
- if (this.phoneData.length != 11) {
- uni.showToast({
- icon: 'none',
- position: 'bottom',
- title: '手机号不正确'
- });
- return false;
- }
- if (this.verCode.length != 6) {
- uni.showToast({
- icon: 'none',
- position: 'bottom',
- title: '验证码不正确'
- });
- return false;
- }
- uni.login({
- success: (res) => {
- _this.isRotate = true
- this.$request.post("/api/v1/common/wxLogin", {
- wechat_code: res.code,
- phone: this.phoneData,
- verify_code: this.verCode
- }).then(res => {
- console.log(res)
- if (res.status == 0) {
- if (res.data.token) {
- store.commit('setJwt', res.data.token);
- store.commit('setUser', res.data);
- store.commit('login');
- let loginResult = getApp().globalData.imService.login({
- flag: "member_" + res.data.id,
- nickname: res.data.nickname,
- avatar: res.data.avatar
- });
- if (loginResult) {
- //连接IM
- getApp().globalData.imService.connectIM();
- }
- uni.showToast({
- title: "登录成功",
- icon: "none"
- }, 1500)
- setTimeout(() => {
- uni.navigateBack({
- delta: 1
- })
- }, 1500)
- }
- } else {
- uni.showToast({
- title: res.message,
- icon: "none"
- })
- _this.isRotate = false
- }
- }).catch(err => {
- })
- }
- })
- },
- isphone: async function() {
- uni.login({
- success: (re) => {
- this.$request.post("/api/v1/common/getUserByCode", {
- wechat_code: re.code
- }).then(data => {
- console.log(data)
- if (data.data != null && data.data.phone != "") {
- uni.setStorageSync('phone', data.data.phone)
- this.isphoneNum = true
- }
- }).catch(err => {
- })
- }
- })
- },
- getphone: async function(e) {
- if (this.imgitem.istrue) {
- _this.istrue = true
- uni.login({
- success: (res) => {
- console.log(res)
- this.$request.post("/api/v1/common/getPhoneNumber", {
- wechat_code: res.code,
- iv: e.detail.iv,
- encryptData: e.detail.encryptedData
- }).then(data => {
- console.log(data)
- if (data.status == 0) {
- this.show = true
- } else {
- _this.istrue = false
- uni.showToast({
- title: "授权失败",
- icon: "none"
- })
- }
- }).catch(err => {
- })
- }
- })
- } else {
- uni.showToast({
- title: "请先同意协议",
- icon: "none"
- })
- }
- },
- wxLogin: async function(e) {
- if (e.detail.errMsg == "getUserInfo:fail auth deny") {
- uni.showToast({
- title: '微信登录失败',
- icon: "none"
- });
- return;
- }
- if (this.imgitem.istrue) {
- user.loginByWeixin(e.detail.userInfo)
- .then(res => {
- this.show = false
- if (res.status == 0) {
- console.log(res.data)
- store.commit('setJwt', res.data.token);
- store.commit('setUser', res.data);
- console.log("进来了")
- store.commit('login');
- getApp().globalData.imService = new IMService();
- let loginResult = getApp().globalData.imService.login(res.data);
- if (loginResult) {
- //连接IM
- getApp().globalData.imService.connectIM();
- }
- uni.showToast({
- title: "登录成功",
- icon: "none",
- duration: 2000
- })
- }
- setTimeout(function() {
- _this.istrue = false
- uni.navigateBack({
- delta: 1
- })
- }, 2000)
- })
- .catch(res => {
- uni.showToast({
- title: '微信登录失败',
- icon: "none"
- });
- });
- } else {
- uni.showToast({
- title: "请先同意协议",
- icon: "none"
- })
- }
- },
- toindex() {
- uni.switchTab({
- url: "../index/index"
- })
- },
- isqueren() {
- this.num++
- if (this.num % 2 == 0) {
- this.imgitem.name = "https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/xieyixuan.png"
- this.imgitem.istrue = true
- } else {
- this.imgitem.name = "https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/xieyi.png"
- this.imgitem.istrue = false
- }
- }
- }
- }
- </script>
- <style>
- @import url("../../components/colorui/icon.css");
- @import url("./css/main.css");
- page {
- background-color: #fff;
- }
- .dlbutton {
- display: flex;
- justify-content: center;
- align-items: center;
- color: #84BB43;
- font-size: 30rpx;
- white-space: nowrap;
- overflow: hidden;
- width: 294rpx;
- height: 88rpx;
- background: linear-gradient(to right, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 255.6));
- box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.4);
- border-radius: 2.5rem;
- margin-top: 0rpx;
- }
- .dlbutton_loading {
- display: flex;
- justify-content: center;
- align-items: center;
- color: #84BB43;
- font-size: 30rpx;
- width: 100rpx;
- height: 100rpx;
- background: linear-gradient(to right, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 255.6));
- box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.4);
- border-radius: 2.5rem;
- margin-top: 0rpx;
- }
- .buttonBorder {
- border: none;
- border-radius: 2.5rem;
- -webkit-box-shadow: 0 0 60rpx 0 rgba(0, 0, 0, .2);
- box-shadow: 0 0 60rpx 0 rgba(0, 0, 0, .2);
- -webkit-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
- -moz-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
- -ms-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
- -o-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
- transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
- }
- /* 旋转动画 */
- .rotate_loop {
- -webkit-transition-property: -webkit-transform;
- -webkit-transition-duration: 1s;
- -moz-transition-property: -moz-transform;
- -moz-transition-duration: 1s;
- -webkit-animation: rotate 1s linear infinite;
- -moz-animation: rotate 1s linear infinite;
- -o-animation: rotate 1s linear infinite;
- animation: rotate 1s linear infinite;
- }
- @-webkit-keyframes rotate {
- from {
- -webkit-transform: rotate(0deg)
- }
- to {
- -webkit-transform: rotate(360deg)
- }
- }
- @-moz-keyframes rotate {
- from {
- -moz-transform: rotate(0deg)
- }
- to {
- -moz-transform: rotate(359deg)
- }
- }
- @-o-keyframes rotate {
- from {
- -o-transform: rotate(0deg)
- }
- to {
- -o-transform: rotate(359deg)
- }
- }
- @keyframes rotate {
- from {
- transform: rotate(0deg)
- }
- to {
- transform: rotate(359deg)
- }
- }
- button::after {
- border: none;
- }
- </style>
|