1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177 |
- <template>
- <view class="container">
- <image class="bg-image" src="../../../static/loginBg.png" mode="aspectFill"></image>
- <view class="up">
- <!-- 258px -->
- <view id="HeadArea" style="height: 25%;"></view>
- <view id="MidArea">
- <view class="action-row align-center position-relative"
- style="background-color: rgba(146, 146, 255, 0.15); padding: 29px 104rpx 29px 104rpx;">
- <view class="text-white " :class="bMobileLogin?'text-22px':'text-16px'" @tap="onSwitchLogin(true)">
- 手机登录</view>
- <view class="text-white " :class="!bMobileLogin?'text-22px':'text-16px'"
- @tap="onSwitchLogin(false)">邮箱登录</view>
- <view class="position-absolute-center"
- style="height: 29px ;width: 1px; background-color: rgba(255, 255, 255, 0.25);"></view>
- </view>
- <!-- bMobileLogin -->
- <view v-if="bPhoneNumberAndPasswordLogin">
-
- <view class="input-container" style="margin: 10px 102rpx 0 68rpx;">
- <view class="input-row padding align-center" style="width: 318px;">
- <view class="text-18px text-regular " style="width: 72rpx;white-space:nowrap;">
- {{bMobileLogin?' +86':'邮箱'}}
- </view>
- <view class="margin-left-sm margin-right-sm"
- style="width: 2rpx; height: 25rpx; background-color: rgba(209, 209, 209, 1);">
- </view>
- <m-input :focus="true" :inputmode="bMobileLogin?'numeric':'email'" focus="true" :type="bMobileLogin?'number':'text'" :maxlength="bMobileLogin?'11':'32'"
- clearable v-model="account" :placeholder="bMobileLogin?'请填写11位手机号码':'请输入邮箱'"></m-input>
- </view>
-
- </view>
- <input type="text" style="width: 0;height: 0;min-height: 0;"/>
- <view class="input-container" style="margin: 8px 102rpx 0 68rpx;">
- <view class="input-row padding align-center" style="width: 318px;">
- <view class="text-18px text-regular " style="width: 72rpx;white-space:nowrap;">
- 密码
- </view>
- <view class="margin-left-sm margin-right-sm"
- style="width: 2rpx; height: 25rpx; background-color: rgba(209, 209, 209, 1);">
- </view>
- <m-input inputmode="text" type="password" maxlength="16" displayable v-model="password" placeholder="请输入密码">
- </m-input>
- </view>
- </view>
-
- <view @click="onSwitchGetCode" class="make-text-bPurple text-14px text-right text-regular"
- style="margin: 40rpx 96rpx 0 0;">{{bPhoneNumberAndPasswordLogin?'验证码登录':'密码登录'}} </view>
- <view class="btn-row" style="margin: 32rpx 0 0 0;">
- <view class="btn-confirm" @tap="bindLogin">登录</view>
- </view>
- </view>
- <!-- 手机端登录或者邮箱,获取验证码 -->
- <view v-else-if="bGetCode">
- <view class="input-container" style="margin: 32px 102rpx 0 68rpx;">
- <view class="input-row padding align-center" style="width: 318px;">
- <view class="text-18px text-regular " style="width: 72rpx;white-space:nowrap;">
- {{bMobileLogin?' +86':'邮箱'}}
- </view>
- <view class="margin-left-sm margin-right-sm"
- style="width: 2rpx; height: 25rpx; background-color: rgba(209, 209, 209, 1);">
- </view>
- <m-input :inputmode="bMobileLogin?'numeric':'email'" :type="bMobileLogin?'number':'text'" :maxlength="bMobileLogin?'11':'32'"
- clearable v-model="account" :placeholder="bMobileLogin?'请填写11位手机号码':'请输入邮箱'"></m-input>
- </view>
- </view>
- <view @click="onSwitchGetCode" class="make-text-bPurple text-14px text-right text-regular "
- style="margin: 40rpx 96rpx 0 0; ">{{bPhoneNumberAndPasswordLogin?'验证码登录':'密码登录'}} </view>
- <view class="btn-row" style="margin: 28rpx 0 0 0;">
- <view class="btn-confirm" @tap="onNavToReg">获取验证码</view>
- </view>
- </view>
- <view v-else>
- <!-- 手机端登录 -->
- <view class="text-22px make-text-bPurple" style="margin: 34px 0 0 96rpx;">输入验证码</view>
- <view v-if="bMobileLogin" class="text-16px text-gray text-lines2"
- style="margin: 20px 96rpx 0 96rpx; word-wrap: break-word;">已发送4位验证码至 +86
- {{phoneNumber}}
- </view>
- <view v-else class="text-16px text-gray text-lines2"
- style="margin: 20px 96rpx 0 96rpx;word-wrap: break-word;">已发送4位验证码至 {{mailboxNumber}}</view>
- <view class="code-input-main">
- <view class="inputLine">
- <!-- <view class="input-item" maxlength="1" :value="inputCode[0]">{{inputCode[0]}}</input> -->
- <view class="input-item">{{inputCode[0]}}</view>
- <view class="input-item">{{inputCode[1]}}</view>
- <view class="input-item">{{inputCode[2]}}</view>
- <view class="input-item">{{inputCode[3]}}</view>
- </view>
- <!-- @input="inputEvent" -->
- <input class="code-input-input" v-model="inputCode" maxlength="4" type="number" />
- </view>
- <view class="btn-row">
- <!-- :disabled="inputCode.length<4" -->
- <view class="btn-confirm " :class="inputCode.length<4?'disabledBtn':''" @tap="onConfirm">确认
- </view>
- </view>
- <view v-if="bCodeDisabled" class="action-row-text">
- <view class="action-child text-gray">重新获取({{count}})</view>
- </view>
- <view v-else class="action-row-text">
- <view class="action-child text-gray" @tap="onGetCode">重新发送验证码</view>
- </view>
- <input class='ipt' type="number" :maxlength="Length" :focus="bFocus" @input="onInputFocus"
- @focus="onFocus"></input>
- </view>
- </view>
- <view v-if="bGetCode">
- <view class="action-row-text " style="margin-top: 25rpx;">
- <checkbox-group style="transform: scale(0.7,0.7);" @change="CheckboxChange">
- <checkbox class='round red' :class="checkbox[0].checked?'checked':''"
- :checked="checkbox[0].checked?true:false" value="A"></checkbox>
- </checkbox-group>
- <!-- 登录即代表同意哔蹦 我已阅读并同意-->
- <view class="text-gray" style="margin-top: 2px;">我已阅读并同意</view>
- <view class="text-bold text-decoration make-text-bPurple" style="margin-top: 2px;" @tap="onSwitchAgree('agreement')">用户协议
- </view>
- <view class="text-gray" style="margin-top: 2px;">和</view>
- <view class="text-bold text-decoration make-text-bPurple" style="margin-top: 2px;" @tap="onSwitchAgree('privacy')">隐私政策
- </view>
- </view>
- </view>
- <!-- v-if="hasProvider" style="border: 1rpx solid #000000;"-->
- <view class="oauth-row" v-if="bGetCode" v-bind:style="{top: positionTop + 'px'}">
- <view v-if="hasProvider&&providerList.length>0">
- <view v-if="(bInstallWechat&&!bHideWeixin)||appleOauth" class="text-14px text-gray">其他登录方式</view>
- <!-- <view v-else style="height: 50px;"></view> -->
- <view class="flex justify-center align-center margin-top-sm flex-direction">
- <!-- <view class="oauth-image" v-for="provider in providerList" :key="provider.value">
- <image :src="provider.image" @tap="oauth(provider.value)"></image>
- </view> -->
- <view v-if="bInstallWechat&&!bHideWeixin" v-for="provider in providerList"
- :key="provider.value">
- <view class="btn-apple-confirm" @tap="oauth(provider.value)">
- <image style="width: 48rpx;height: 48rpx;margin-right: 5px;" :src="provider.image">
- </image>
- <view>通过微信注册</view>
- </view>
- </view>
- <view v-if="appleOauth" class="btn-apple-confirm" @tap="onAppleReg">
- <image style="width: 48rpx;height: 48rpx;margin-right: 5px;"
- src="../../../static/img/apple.png"></image>
- <view>通过Apple注册</view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import config from '../../../common/config.js';
- import service from '../../../util/util-js/service.js';
- import reqUtil from "@/util/util-js/requstUtil.js";
- import verify from '../../../util/util-js/verify.js'
- import {
- mapState,
- mapMutations
- } from 'vuex'
- import mInput from '../../../components/m-input.vue'
- export default {
- components: {
- mInput
- },
- data() {
- return {
- //获取验证码页面
- bGetCode: true,
- //默认手机号和密码登录
- bPhoneNumberAndPasswordLogin: true,
- bMobileLogin: true,
- providerList: [],
- hasProvider: true,
- account: '',
- password: '',
- positionTop: 0,
- //输入框参数
- Length: 4, //输入框个数
- bFocus: false, //聚焦
- Value: "", //输入的内容
- inputCode: '',
- //苹果服务
- appleOauth: null,
- checkbox: [{
- value: 'A',
- checked: false
- }],
- }
- },
- computed: mapState(['bNewUser', 'forcedLogin', 'phoneNumber', 'mailboxNumber', 'bCodeDisabled', 'count',
- 'bInstallWechat',
- 'bHideWeixin', 'clientName'
- ]),
- methods: {
- ...mapMutations(['login', 'addUserAvatarAndLogin', 'appleUserInfoLogin', 'accountLogin', 'countDown',
- 'resetCountDown'
- ]),
- CheckboxChange(e) {
- console.log(11);
- var items = this.checkbox,
- values = e.detail.value;
- for (var i = 0, lenI = items.length; i < lenI; ++i) {
- items[i].checked = false;
- for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
- if (items[i].value == values[j]) {
- items[i].checked = true;
- break
- }
- }
- }
- },
- initProvider() {
- // const filters = ['weixin', 'qq', 'sinaweibo'];
- const filters = ['weixin'];
- uni.getProvider({
- service: 'oauth',
- success: (res) => {
- if (res.provider && res.provider.length) {
- for (let i = 0; i < res.provider.length; i++) {
- if (~filters.indexOf(res.provider[i])) {
- this.providerList.push({
- value: res.provider[i],
- image: '../../../static/img/' + res.provider[i] + '.png'
- });
- }
- }
- this.hasProvider = true;
- }
- },
- fail: (err) => {
- console.error('获取服务供应商失败:' + JSON.stringify(err));
- }
- });
- },
- initPosition() {
- let _self = this;
- let headView = uni.createSelectorQuery().in(this).select('#HeadArea');
- headView.fields({
- size: true,
- }, data => {
- // console.log("得到节点信息1" + JSON.stringify(data));
- let headHeight = data.height;
- if (_self.clientName.indexOf('iPad') > -1) {
- _self.positionTop = headHeight + 390;
- } else {
- _self.positionTop = headHeight + 378;
- }
- // let midView = uni.createSelectorQuery().in(this).select('#MidArea');
- // midView.fields({
- // size: true,
- // }, data => {
- // console.log("得到节点信息2" + JSON.stringify(data));
- // let midHeight = data.height;
- // /**
- // * 使用 absolute 定位,并且设置 bottom 值进行定位。软键盘弹出时,底部会因为窗口变化而被顶上来。
- // * 反向使用 top 进行定位,可以避免此问题。
- // * uni.getSystemInfoSync().windowHeight - 220
- // */
- // _self.positionTop = headHeight + midHeight;
- // }).exec();
- }).exec();
- },
- bindLogin() {
- let _self = this;
- if(!_self.checkbox[0].checked){
- uni.showToast({
- icon: 'none',
- title: '请阅读并勾选下方协议'
- });
- return;
- }
- uni.showToast({
- icon: 'loading',
- title: '',
- mask: true,
- duration: 10000
- });
- /**
- * 密码登录的情况下
- * 处理手机号码和邮箱号码验证。
- */
- if (this.bMobileLogin) {
- if (!verify.checkPhone(this.account)) {
- uni.showToast({
- icon: 'none',
- title: '请输入正确手机号'
- });
- return;
- }
- } else {
- //todo 后面要验证邮箱
- if (!verify.checkEMail(this.account)) {
- uni.showToast({
- icon: 'none',
- title: '请输入正确邮箱号'
- });
- return;
- }
- }
- // if (this.account.length < 11) {
- // uni.showToast({
- // icon: 'none',
- // title: '账号最短为 11 个字符'
- // });
- // return;
- // }
- if (this.password.length < 6) {
- uni.showToast({
- icon: 'none',
- title: '密码最短为 6 个字符'
- });
- return;
- }
- reqUtil.requestData(config.URL.LOGINPASSWORDBASEDONTHETYPE, {
- "account": this.account,
- "password": this.password,
- "type": this.bMobileLogin ? 0 : 1
- }).then(res => {
- console.log('requestData PASSWORDlOGIN =====', res);
- if (res.code == 0) {
- uni.showToast({
- title: "登陆中..",
- mask: true,
- duration: 3000
- })
- //密码登录成功
- uni.setStorageSync('token', res.data.token);
- _self.$store.state.bNewUser = res.data.newUser;
- _self.accountLogin(function() {
- console.log("_self.bNewUser=", _self.bNewUser);
- if (_self.bNewUser) {
- uni.reLaunch({
- url: "../../my-page/userInfo/userInfo",
- complete() {
- uni.hideToast();
- }
- })
- } else {
- uni.reLaunch({
- url: "../../personal-page/personal/personal",
- complete() {
- uni.hideToast();
- }
- })
- }
- });
- } else {
- uni.showToast({
- title: "用户密码错误",
- icon: 'none',
- mask: true,
- duration: 1000
- })
- }
- },
- e => {
- console.log(e)
- });
- },
- oauth(value) {
- let _self = this;
- if(!_self.checkbox[0].checked){
- uni.showToast({
- icon: 'none',
- title: '请阅读并勾选下方协议'
- });
- return;
- }
- uni.showToast({
- title: "",
- icon: "loading",
- duration: 10000
- })
- uni.login({
- provider: value,
- success: (res) => {
- // console.log('code11:', res);
- // #ifdef APP-PLUS
- // android 端微信登录
- uni.request({
- url: config.URL.ANDROIDLOGINURL,
- data: {
- openid: res.authResult.openid,
- unionid: res.authResult.unionid,
- },
- success: (res) => {
- // console.log('ANDROIDLOGINURL请求返回:', res);
- let resData = res.data;
- uni.hideToast();
- if (resData.code == 0) {
- uni.showToast({
- title: "登录中..",
- icon: "loading",
- mask: true,
- duration: 10000
- })
- //登录成功
- uni.setStorage({
- key: 'token',
- data: resData.data.token,
- success: function() {
- _self.$store.state.bNewUser = resData.data
- .newUser;
- console.log("wx token = ", resData.data
- .token);
- //如果是新用户,则获取用户信息
- if (_self.bNewUser) {
- uni.getUserInfo({
- provider: value,
- success: (infoRes) => {
- //获取了用户信息后
- let userInfo = {
- username: infoRes
- .userInfo
- .nickName,
- gender: 0 //默认是男性
- }
- //服务器0是男,1是女
- //微信的2 对应的女
- if (infoRes
- .userInfo
- .gender == 2) {
- //服务器记录的是1
- userInfo
- .gender =
- 1;
- }
- console.log(
- "微信数据:",
- infoRes,
- userInfo);
- uni.downloadFile({
- url: infoRes
- .userInfo
- .avatarUrl,
- success: (
- res
- ) => {
- // if (res.statusCode === 200) {
- // console.log('下载成功');
- // }
- // console.log(res.tempFilePath);
- _self
- .addUserAvatarAndLogin({
- params: userInfo,
- filePath: res
- .tempFilePath,
- callback: () => {
- _self
- .$store
- .state
- .openid =
- infoRes
- .userInfo
- .openId ||
- '';
-
- uni.reLaunch({
- url: "../../my-page/perfectInfo/perfectInfo",
- complete() {
- uni.hideToast();
- }
- })
- }
- });
- }
- });
- },
- fail: (failRes) => {
- uni.hideToast();
- console.log(
- 'getUserInfo failRes:',
- failRes);
- }
- })
- } else {
- //如果不是新用户,直接获取用户信息
- _self.accountLogin(function() {
- uni.reLaunch({
- url: "../../personal-page/personal/personal",
- complete() {
- uni.hideToast();
- }
- })
- });
- }
- }
- });
- } else {
- uni.showToast({
- title: "微信登陆失败",
- mask: true,
- icon: 'none',
- duration: 1000
- })
- }
- }
- })
- // #endif
- // #ifdef MP-WEIXIN
- uni.request({
- url: config.URL.USERlOGINURL,
- data: {
- appid: 'wxd6dfd60729d33d17',
- code: res.code,
- source: 1,
- },
- success: (res) => {
- // console.log('请求返回:', res, res.cookies[0]);
- // return;
- uni.getUserInfo({
- provider: value,
- success: (infoRes) => {
- /**
- * 实际开发中,获取用户信息后,需要将信息上报至服务端。
- * 服务端可以用 userInfo.openId 作为用户的唯一标识新增或绑定用户信息。
- */
- // this.toMain(infoRes.userInfo.nickName);
- console.log('getUserInfo infoRes:', infoRes)
- uni.request({
- url: config.URL.WXGETUSERINFO,
- data: {
- appid: 'wxd6dfd60729d33d17',
- encryptedData: infoRes
- .encryptedData,
- iv: infoRes.iv,
- signature: infoRes.signature,
- rawData: infoRes.rawData
- },
- success: (wxInfoRes) => {
- console.log(
- 'WXGETUSERINFO 请求返回:',
- wxInfoRes);
- }
- })
- },
- fail: (failRes) => {
- console.log('getUserInfo failRes:', failRes)
- }
- });
- }
- })
- // #endif
- },
- fail: (err) => {
- console.error('授权登录失败:' + JSON.stringify(err));
- }
- });
- },
- callbackUserInfo(userinfo) {
- console.log('callbackUserInfo:', userinfo);
- },
- onSwitchLogin(bMobileLogin) {
- //切换就重置
- this.account = '';
- this.password = '';
- this.bMobileLogin = bMobileLogin;
- //如果是已获取的验证码页面,返回获取验证码界面
- if (!this.bGetCode)
- this.bGetCode = true;
- },
- onSwitchGetCode() {
- this.bPhoneNumberAndPasswordLogin = !this.bPhoneNumberAndPasswordLogin;
- },
- onNavToReg() {
-
- if(!this.checkbox[0].checked){
- uni.showToast({
- icon: 'none',
- title: '请阅读并勾选下方协议'
- });
- return;
- }
-
- if (this.bMobileLogin) {
- if (!verify.checkPhone(this.account)) {
- uni.showToast({
- icon: 'none',
- title: '请输入正确手机号'
- });
- return;
- }
- this.$store.state.phoneNumber = this.account;
- } else {
- //todo 后面要验证邮箱
- if (!verify.checkEMail(this.account)) {
- uni.showToast({
- icon: 'none',
- title: '请输入正确邮箱号'
- });
- return;
- }
- this.$store.state.mailboxNumber = this.account;
- }
- // uni.showToast({
- // icon: 'none',
- // title: '账号:'+ this.account
- // });
- // return;
- this.bGetCode = false;
- this.onGetCode();
- },
- //验证码操作
- //注册
- onConfirm() {
- var _self = this;
- if (_self.inputCode.length < 4) {
- uni.showToast({
- title: "请输入4位验证码",
- icon: "none",
- duration: 2000,
- mask: true
- })
- return;
- }
- uni.showToast({
- title: "",
- icon: "loading",
- duration: 10000,
- mask: true
- })
- reqUtil.requestData(config.URL.SMSLOGINFROMTYPE, {
- "account": _self.bMobileLogin ? _self.phoneNumber : _self.mailboxNumber,
- "code": _self.inputCode,
- "type": _self.bMobileLogin ? 0 : 1
- }).then(res => {
- console.log('requestData GETCODE =====', res);
- uni.hideToast();
- if (res.code == 0) {
- uni.showToast({
- title: "登录中..",
- icon: "loading",
- mask: true,
- duration: 3000
- })
- //登录成功
- uni.setStorage({
- key: 'token',
- data: res.data.token,
- success: function() {
- _self.$store.state.bNewUser = res.data.newUser;
- _self.resetCountDown();
- _self.accountLogin(function() {
- if (_self.bNewUser) {
- uni.reLaunch({
- url: "../../my-page/userInfo/userInfo",
- complete() {
- uni.hideToast();
- }
- })
- } else {
- uni.reLaunch({
- url: "../../personal-page/personal/personal",
- complete() {
- uni.hideToast();
- }
- })
- }
- });
- }
- });
- } else {
- uni.showToast({
- title: "验证码错误",
- mask: true,
- icon: 'none',
- duration: 1000
- })
- }
- },
- e => {
- console.log(e);
- uni.hideToast();
- });
- },
- onGetCode() {
- //置灰状态
- if (this.bCodeDisabled) return;
- //调用store 倒计时
- if (this.bMobileLogin) {
- this.countDown({
- account: this.phoneNumber,
- type: 0
- });
- } else {
- this.countDown({
- account: this.mailboxNumber,
- type: 1
- });
- }
- },
- onTap() {
- this.bFocus = true;
- console.log(this.bFocus);
- },
- onFocus(e) {
- console.log(e);
- setTimeout(() => {
- // this.bFocus = false;
- }, 1000)
- },
- onInputFocus(e) {
- console.log(e.detail.value);
- this.Value = e.detail.value;
- },
- inputEvent(res) {
- console.log("input 1 input code components : " + res.detail.value);
- /* this.$emit('vueMsg',res.detail.value); */
- this.inputCode = res.detail.value;
- },
- onSwitchAgree(data) {
- console.log("=== ", data);
- uni.navigateTo({
- url: "../../login-page/userAgreement/userAgreement?type=" + data
- })
- },
- onAppleReg() {
- if(!this.checkbox[0].checked){
- uni.showToast({
- icon: 'none',
- title: '请阅读并勾选下方协议'
- });
- return;
- }
- this.onAppleLogout(() => {
- this.onAppleRegEvent();
- })
- },
- onAppleRegEvent() {
- let _self = this;
- uni.login({
- provider: 'apple',
- success: (loginRes) => {
- // console.log('apple login:', loginRes);
- uni.getUserInfo({
- provider: 'apple',
- success(resUser) {
- //用户信息
- console.log("resUser:", resUser);
- uni.showToast({
- title: '登录中..',
- icon: 'loading',
- mask: true,
- duration: 10000,
- })
- reqUtil.requestData(config.URL.APPLElOGINURL, {
- "identityToken": resUser.userInfo.identityToken
- }).then(res => {
- console.log('requestData apple login =====', res);
- uni.hideToast();
- if (res.code == 0) {
- uni.showToast({
- title: "登录中..",
- icon: "loading",
- mask: true,
- duration: 3000
- })
- //登录成功
- uni.setStorage({
- key: 'token',
- data: res.data.token,
- success: function() {
- _self.$store.state.bNewUser = res
- .data.newUser;
- // console.log("apple token = ", res.data.token);
- //如果是新用户,则获取用户信息
- if (_self.bNewUser) {
- //获取了用户信息后
- let tempName = "匿名";
- if (resUser.userInfo.fullName
- .hasOwnProperty(
- "familyName") &&
- resUser.userInfo.fullName
- .hasOwnProperty(
- "givenName")) {
- tempName = resUser.userInfo
- .fullName.familyName +
- resUser.userInfo
- .fullName.givenName;
- }
- let userInfo = {
- username: tempName,
- gender: 0 //默认是男性
- }
- // console.log("苹果数据11:", resUser.userInfo);
- // console.log("userInfo:", userInfo);
- _self.appleUserInfoLogin({
- params: userInfo,
- callback: () => {
- //这里是记录appleid,不是微信
- _self
- .$store
- .state
- .appleid =
- resUser
- .userInfo
- .openId ||
- '';
-
- uni.reLaunch({
- url: "../../my-page/perfectInfo/perfectInfo",
- complete() {
- uni.hideToast();
- }
- })
- }
- });
- } else {
- //如果不是新用户,直接获取用户信息
- _self.accountLogin(function() {
- uni.reLaunch({
- url: "../../personal-page/personal/personal",
- complete() {
- uni.hideToast();
- }
- })
- });
- }
- }
- });
- } else {
- uni.showToast({
- title: "apple登陆失败",
- mask: true,
- icon: 'none',
- duration: 1000
- })
- }
- },
- e => {
- console.log(e);
- uni.hideToast();
- });
- }
- })
- },
- fail: (err) => {
- //登陆失败
- console.log('登陆失败:', err)
- uni.showToast({
- title: '登陆失败',
- icon: 'none'
- })
- }
- })
- },
- onAppleLogout(callback) {
- this.appleOauth.logout(function(e) {
- // plus.nativeUI.alert("注销登录认证成功!");
- callback(e);
- console.log("注销登录认证成功!");
- }, function(e) {
- // plus.nativeUI.alert("注销登录认证失败: " + JSON.stringify(e));
- console.log("注销登录认证失败: " + JSON.stringify(e));
- });
- },
- onGetAppleService() {
- // console.log("onGetAppleService");
- let _self = this;
- plus.oauth.getServices(function(services) {
- for (var i in services) {
- var service = services[i];
- // 获取苹果授权登录对象,苹果授权登录id 为 'apple' iOS13以下系统,不会返回苹果登录对应的 service
- if (service.id == 'apple') {
- _self.appleOauth = service;
- // console.log("this.appleOla:", _self.appleOauth);
- break;
- }
- // console.log("service:", service);
- }
- }, function(err) {
- // 获取 services 失败
- })
- }
- },
- onReady() {
- this.initPosition();
- this.initProvider();
- //获取apple相关服务
- this.onGetAppleService();
- }
- }
- </script>
- <style>
- .action-row {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- height: 67px;
- }
- .action-row navigator {
- color: #FFFFFF;
- font-size: 16px;
- /* padding: 0 20upx; */
- }
- .action-row-text {
- margin-top: 18px;
- display: flex;
- flex-direction: row;
- justify-content: center;
- }
- .action-child {
- /* color: #FFFFFF; */
- padding: 0 20upx;
- }
- .oauth-row {
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-content: center;
- text-align: center;
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- right: 0;
- z-index: -1;
- /* border: 1rpx solid #000000; */
- }
- .oauth-image {
- width: 76rpx;
- height: 76rpx;
- /* border: 1upx solid #dddddd; */
- /* border-radius: 100upx; */
- margin: 0 40upx;
- /* background-color: #ffffff; */
- }
- .oauth-image image {
- width: 76rpx;
- height: 76rpx;
- /* margin: 20upx; */
- }
- .input-group {
- background-color: #ffffff;
- margin-top: 40upx;
- position: relative;
- }
- .input-group::before {
- position: absolute;
- right: 0;
- top: 0;
- left: 0;
- height: 1upx;
- content: '';
- -webkit-transform: scaleY(.5);
- transform: scaleY(.5);
- background-color: #c8c7cc;
- }
- .input-group::after {
- position: absolute;
- right: 0;
- bottom: 0;
- left: 0;
- height: 1upx;
- content: '';
- -webkit-transform: scaleY(.5);
- transform: scaleY(.5);
- background-color: #c8c7cc;
- }
- .input-row {
- display: flex;
- flex-direction: row;
- position: relative;
- }
- .main-title {
- width: 20%;
- height: 50upx;
- min-height: 50upx;
- padding: 15upx 0;
- padding-left: 30upx;
- line-height: 50upx;
- }
- .main-info {
- width: 20%;
- height: 50upx;
- min-height: 50upx;
- padding: 15upx 0;
- padding-left: 30upx;
- line-height: 50upx;
- }
- .btn-row {
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .container {
- position: absolute;
- top: 0;
- bottom: 0;
- left: 0;
- right: 0;
- background-color: #FFFFFF;
- }
- .bg-image {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: calc(25% + 67px);
- opacity: 1;
- }
- .up {
- position: absolute;
- z-index: 1;
- width: 100%;
- height: 100%;
- }
- .input-container {
- border-bottom: 1rpx solid #e7e9eb;
- }
- .btn-confirm {
- width: 636rpx;
- height: 102rpx;
- background-color: rgba(151, 151, 255, 1);
- border-radius: 10px;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 17px;
- color: #FFFFFF;
- }
- .btn-apple-confirm {
- width: 380rpx;
- height: 64rpx;
- /* background-color: rgba(151, 151, 255, 1); */
- border: 1px solid #000000;
- border-radius: 8px;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 12px;
- font-weight: bold;
- color: #000000;
- margin-top: 7px;
- }
- .disabledBtn {
- background-color: rgba(221, 221, 221, 1.0);
- }
- .code-input-main {
- display: flex;
- flex-direction: column;
- width: 100%;
- /* border: 1rpx solid #000000; */
- height: 150px;
- position: relative;
- }
- .input-item {
- width: 106rpx;
- height: 118rpx;
- font-size: 20px;
- line-height: 118rpx;
- background-color: rgba(244, 241, 244, 255);
- /* border: 1rpx solid #ddd; */
- text-align: center;
- border-radius: 8px;
- margin-left: 44rpx;
- /* margin-right: 40upx; */
- color: rgba(86, 86, 86, 1);
- font-weight: bold;
- }
- .inputLine {
- display: flex;
- justify-content: flex-start;
- width: 100%;
- top: 80rpx;
- left: 52rpx;
- position: absolute;
- z-index: 1;
- }
- .code-input-input {
- height: 150px;
- position: absolute;
- width: 100%;
- outline: none;
- color: transparent;
- text-shadow: 0 0 0 transparent;
- width: 300%;
- left: -100%;
- top: 0;
- /* background: #000000; */
- /* border: 1rpx solid #007AFF; */
- z-index: 10;
- }
- .ipt {
- width: 0;
- height: 0;
- }
- .text-decoration {
- margin: 0 1rpx;
- border-bottom: 1rpx solid rgba(0, 0, 0, 0.3);
- padding-bottom: 1rpx;
- }
- </style>
|