login.vue 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. <template>
  2. <view class="container">
  3. <image class="bg-image" src="../../../static/loginBg.png" mode="aspectFill"></image>
  4. <view class="up">
  5. <!-- 258px -->
  6. <view id="HeadArea" style="height: 25%;"></view>
  7. <view id="MidArea">
  8. <view class="action-row align-center " style="background-color: rgba(0, 0, 0, 0.2); padding: 29px 104rpx 29px 104rpx;">
  9. <!-- <view class="text-white text-22px text-center" style="width: 100%;" @tap="onSwitchLogin(true)">手机登录</view> -->
  10. <view class=" text-white " :class="bMobileLogin?'text-22px':'text-16px'" @tap="onSwitchLogin(true)">手机登录</view>
  11. <view class="text-bold text-white">|</view>
  12. <view class=" text-white " :class="!bMobileLogin?'text-22px':'text-16px'" @tap="onSwitchLogin(false)">账号登录</view>
  13. </view>
  14. <view v-if="bMobileLogin">
  15. <!-- 手机端登录,获取验证码 -->
  16. <view v-if="bGetCode">
  17. <view class="input-container" style="margin: 32px 102rpx 0 68rpx;">
  18. <view class="input-row padding" style="width: 318px;">
  19. <m-input type="number" maxlength="11" clearable v-model="account" placeholder="请填写11位手机号码"></m-input>
  20. </view>
  21. </view>
  22. <view class="btn-row" style="margin: 32px 0 0 0;">
  23. <view class="btn-confirm" @tap="onNavToReg">获取验证码</view>
  24. </view>
  25. <!-- <view v-if="appleOauth" class="btn-row" style="margin: 5px 0 0 0;">
  26. <view class="btn-apple-confirm" @tap="onAppleReg">
  27. <image style="width: 48rpx;height: 48rpx;margin-right: 5px;" src="../../../static/img/apple.png"></image>
  28. <view>通过Apple注册</view>
  29. </view>
  30. </view> -->
  31. </view>
  32. <view v-else>
  33. <!-- 手机端登录 -->
  34. <view class="text-22px make-text-bPurple" style="margin: 34px 0 0 96rpx;">输入验证码</view>
  35. <view class="text-16px text-gray" style="margin: 20px 0 0 96rpx;">已发送4位验证码至 +86 {{phoneNumber}}</view>
  36. <view class="code-input-main">
  37. <view class="inputLine">
  38. <!-- <view class="input-item" maxlength="1" :value="inputCode[0]">{{inputCode[0]}}</input> -->
  39. <view class="input-item">{{inputCode[0]}}</view>
  40. <view class="input-item">{{inputCode[1]}}</view>
  41. <view class="input-item">{{inputCode[2]}}</view>
  42. <view class="input-item">{{inputCode[3]}}</view>
  43. </view>
  44. <!-- @input="inputEvent" -->
  45. <input class="code-input-input" v-model="inputCode" maxlength="4" type="number" />
  46. </view>
  47. <view class="btn-row">
  48. <!-- :disabled="inputCode.length<4" -->
  49. <view class="btn-confirm " :class="inputCode.length<4?'disabledBtn':''" @tap="onConfirm">确认</view>
  50. </view>
  51. <view v-if="bCodeDisabled" class="action-row-text">
  52. <view class="action-child text-gray">重新获取({{count}})</view>
  53. <!-- <text style="color: #FFFFFF;">|</text>
  54. <navigator url="../pwd/pwd">忘记密码</navigator> -->
  55. </view>
  56. <view v-else class="action-row-text">
  57. <view class="action-child text-gray" @tap="onGetCode">重新发送验证码</view>
  58. <!-- <text style="color: #FFFFFF;">|</text>
  59. <navigator url="../pwd/pwd">忘记密码</navigator> -->
  60. </view>
  61. <input class='ipt' type="number" :maxlength="Length" :focus="bFocus" @input="onInputFocus" @focus="onFocus"></input>
  62. </view>
  63. </view>
  64. <view v-else>
  65. <!-- 密码登录 -->
  66. <!-- <view class="text-26px text-white" style="margin: 116px 0 0 58rpx;">密码登录</view>
  67. <view class="text-16px text-white" style="margin: 32px 0 0 58rpx;">记录你的运动轨迹,呵护你的身体健康</view> -->
  68. <view class="input-container" style="margin: 10px 102rpx 0 68rpx;">
  69. <view class="input-row padding" style="width: 318px;">
  70. <m-input type="number" clearable v-model="account" placeholder="输入手机号码"></m-input>
  71. </view>
  72. </view>
  73. <view class="input-container" style="margin: 8px 102rpx 0 68rpx;">
  74. <view class="input-row padding" style="width: 318px;">
  75. <m-input type="password" maxlength="14" displayable v-model="password" placeholder="请输入密码"></m-input>
  76. </view>
  77. </view>
  78. <!-- border: 1rpx solid #007AFF; -->
  79. <view class="btn-row" style="margin: 20px 0 0 0;">
  80. <view class="btn-confirm" @tap="bindLogin">登录</view>
  81. </view>
  82. <!-- <view class="action-row " style="margin: 29px 58rpx 0 58rpx;">
  83. <view class="text-14px text-gray">
  84. <text class="cuIcon-roundcheck "></text>
  85. 我已阅读并同意使用<span style="color: rgba(151, 151, 255, 1);">服务协议</span></view>
  86. <view class="text-14px" style="color: rgba(151, 151, 255, 1);">忘记密码?</view>
  87. </view> -->
  88. </view>
  89. </view>
  90. <!-- v-if="hasProvider" style="border: 1rpx solid #000000;"-->
  91. <view class="oauth-row" v-if="bGetCode" v-bind:style="{top: positionTop + 'px'}" >
  92. <view v-if="hasProvider&&providerList.length>0">
  93. <view v-if="(bInstallWechat&&!bHideWeixin)||appleOauth" class="text-14px text-gray">其他登录方式</view>
  94. <!-- <view v-else style="height: 50px;"></view> -->
  95. <view class="flex justify-center align-center margin-top-sm flex-direction">
  96. <!-- <view class="oauth-image" v-for="provider in providerList" :key="provider.value">
  97. <image :src="provider.image" @tap="oauth(provider.value)"></image>
  98. </view> -->
  99. <view v-if="bInstallWechat&&!bHideWeixin" v-for="provider in providerList" :key="provider.value">
  100. <view class="btn-apple-confirm" @tap="oauth(provider.value)">
  101. <image style="width: 48rpx;height: 48rpx;margin-right: 5px;" :src="provider.image"></image>
  102. <view>通过微信注册</view>
  103. </view>
  104. </view>
  105. <view v-if="appleOauth" class="btn-apple-confirm" @tap="onAppleReg">
  106. <image style="width: 48rpx;height: 48rpx;margin-right: 5px;" src="../../../static/img/apple.png"></image>
  107. <view>通过Apple注册</view>
  108. </view>
  109. </view>
  110. </view>
  111. <view class="action-row-text">
  112. <view class=" ">登录即代表同意哔蹦</view>
  113. <view class="text-bold text-decoration" @tap="onSwitchAgree('agreement')">用户协议</view>
  114. <view class=" ">和</view>
  115. <view class="text-bold text-decoration" @tap="onSwitchAgree('privacy')">隐私政策</view>
  116. </view>
  117. </view>
  118. </view>
  119. </view>
  120. </template>
  121. <script>
  122. import config from '../../../common/config.js';
  123. import service from '../../../util/util-js/service.js';
  124. import reqUtil from "@/util/util-js/requstUtil.js";
  125. import verify from '../../../util/util-js/verify.js'
  126. import {
  127. mapState,
  128. mapMutations
  129. } from 'vuex'
  130. import mInput from '../../../components/m-input.vue'
  131. export default {
  132. components: {
  133. mInput
  134. },
  135. data() {
  136. return {
  137. //获取验证码页面
  138. bGetCode: true,
  139. bMobileLogin: true,
  140. providerList: [],
  141. hasProvider: true,
  142. account: '',
  143. password: '',
  144. positionTop: 0,
  145. //输入框参数
  146. Length: 4, //输入框个数
  147. bFocus: false, //聚焦
  148. Value: "", //输入的内容
  149. inputCode: '',
  150. //苹果服务
  151. appleOauth: null,
  152. }
  153. },
  154. computed: mapState(['bNewUser', 'forcedLogin', 'phoneNumber', 'bCodeDisabled', 'count', 'bInstallWechat',
  155. 'bHideWeixin','clientName'
  156. ]),
  157. methods: {
  158. ...mapMutations(['login', 'addUserAvatarAndLogin', 'appleUserInfoLogin', 'accountLogin', 'countDown',
  159. 'resetCountDown'
  160. ]),
  161. initProvider() {
  162. // const filters = ['weixin', 'qq', 'sinaweibo'];
  163. const filters = ['weixin'];
  164. uni.getProvider({
  165. service: 'oauth',
  166. success: (res) => {
  167. if (res.provider && res.provider.length) {
  168. for (let i = 0; i < res.provider.length; i++) {
  169. if (~filters.indexOf(res.provider[i])) {
  170. this.providerList.push({
  171. value: res.provider[i],
  172. image: '../../../static/img/' + res.provider[i] + '.png'
  173. });
  174. }
  175. }
  176. this.hasProvider = true;
  177. }
  178. },
  179. fail: (err) => {
  180. console.error('获取服务供应商失败:' + JSON.stringify(err));
  181. }
  182. });
  183. },
  184. initPosition() {
  185. let _self = this;
  186. let headView = uni.createSelectorQuery().in(this).select('#HeadArea');
  187. headView.fields({
  188. size: true,
  189. }, data => {
  190. // console.log("得到节点信息1" + JSON.stringify(data));
  191. let headHeight = data.height;
  192. if(_self.clientName.indexOf('iPad')>-1){
  193. _self.positionTop = headHeight + 390;
  194. }else{
  195. _self.positionTop = headHeight + 280;
  196. }
  197. // let midView = uni.createSelectorQuery().in(this).select('#MidArea');
  198. // midView.fields({
  199. // size: true,
  200. // }, data => {
  201. // console.log("得到节点信息2" + JSON.stringify(data));
  202. // let midHeight = data.height;
  203. // /**
  204. // * 使用 absolute 定位,并且设置 bottom 值进行定位。软键盘弹出时,底部会因为窗口变化而被顶上来。
  205. // * 反向使用 top 进行定位,可以避免此问题。
  206. // * uni.getSystemInfoSync().windowHeight - 220
  207. // */
  208. // _self.positionTop = headHeight + midHeight;
  209. // }).exec();
  210. }).exec();
  211. if (plus.runtime.isApplicationExist({
  212. pname: 'com.tencent.mm',
  213. action: 'weixin://'
  214. })) {
  215. //安装了微信
  216. // console.log("安装了微信");
  217. _self.$store.state.bInstallWechat = true;
  218. } else {
  219. //未安装微信
  220. // console.log("未安装微信");
  221. _self.$store.state.bInstallWechat = false;
  222. }
  223. },
  224. bindLogin() {
  225. let _self = this;
  226. /**
  227. * 客户端对账号信息进行一些必要的校验。
  228. * 这里先简单处理
  229. */
  230. if (this.account.length < 11) {
  231. uni.showToast({
  232. icon: 'none',
  233. title: '账号最短为 11 个字符'
  234. });
  235. return;
  236. }
  237. if (this.password.length < 6) {
  238. uni.showToast({
  239. icon: 'none',
  240. title: '密码最短为 6 个字符'
  241. });
  242. return;
  243. }
  244. reqUtil.requestData(config.URL.PASSWORDlOGIN, {
  245. "phoneNumber": this.account,
  246. "password": this.password
  247. }).then(res => {
  248. console.log('requestData PASSWORDlOGIN =====', res);
  249. if (res.code == 0) {
  250. uni.showToast({
  251. title: "成功",
  252. mask: true,
  253. duration: 1000
  254. })
  255. //密码登录成功
  256. uni.setStorageSync('token', res.data.token);
  257. _self.$store.state.bNewUser = res.data.newUser;
  258. _self.accountLogin(function() {
  259. console.log("_self.bNewUser=", _self.bNewUser);
  260. if (_self.bNewUser) {
  261. uni.reLaunch({
  262. url: "../../my-page/userInfo/userInfo"
  263. })
  264. } else {
  265. uni.reLaunch({
  266. url: "../../personal-page/personal/personal"
  267. })
  268. }
  269. });
  270. } else {
  271. uni.showToast({
  272. title: "用户密码错误",
  273. icon: 'none',
  274. mask: true,
  275. duration: 1000
  276. })
  277. }
  278. },
  279. e => {
  280. console.log(e)
  281. });
  282. },
  283. oauth(value) {
  284. let _self = this;
  285. uni.showToast({
  286. title: "",
  287. icon: "loading",
  288. duration: 10000
  289. })
  290. uni.login({
  291. provider: value,
  292. success: (res) => {
  293. // console.log('code11:', res);
  294. // #ifdef APP-PLUS
  295. // android 端微信登录
  296. uni.request({
  297. url: config.URL.ANDROIDLOGINURL,
  298. data: {
  299. openid: res.authResult.openid,
  300. unionid: res.authResult.unionid,
  301. },
  302. success: (res) => {
  303. // console.log('ANDROIDLOGINURL请求返回:', res);
  304. let resData = res.data;
  305. uni.hideToast();
  306. if (resData.code == 0) {
  307. uni.showToast({
  308. title: "登录中..",
  309. icon: "loading",
  310. mask: true,
  311. duration: 10000
  312. })
  313. //登录成功
  314. uni.setStorage({
  315. key: 'token',
  316. data: resData.data.token,
  317. success: function() {
  318. _self.$store.state.bNewUser = resData.data.newUser;
  319. console.log("wx token = ", resData.data.token);
  320. //如果是新用户,则获取用户信息
  321. if (_self.bNewUser) {
  322. uni.getUserInfo({
  323. provider: value,
  324. success: (infoRes) => {
  325. //获取了用户信息后
  326. let userInfo = {
  327. username: infoRes.userInfo.nickName,
  328. gender: 0 //默认是男性
  329. }
  330. //服务器0是男,1是女
  331. //微信的2 对应的女
  332. if (infoRes.userInfo.gender == 2) {
  333. //服务器记录的是1
  334. userInfo.gender = 1;
  335. }
  336. console.log("微信数据:", infoRes, userInfo);
  337. uni.downloadFile({
  338. url: infoRes.userInfo.avatarUrl,
  339. success: (res) => {
  340. // if (res.statusCode === 200) {
  341. // console.log('下载成功');
  342. // }
  343. // console.log(res.tempFilePath);
  344. _self.addUserAvatarAndLogin({
  345. params: userInfo,
  346. filePath: res.tempFilePath,
  347. callback: () => {
  348. _self.$store.state.openid = infoRes.userInfo.openId || '';
  349. uni.hideToast();
  350. uni.reLaunch({
  351. url: "../../my-page/perfectInfo/perfectInfo"
  352. })
  353. }
  354. });
  355. }
  356. });
  357. },
  358. fail: (failRes) => {
  359. uni.hideToast();
  360. console.log('getUserInfo failRes:', failRes);
  361. }
  362. })
  363. } else {
  364. //如果不是新用户,直接获取用户信息
  365. _self.accountLogin(function() {
  366. uni.hideToast();
  367. uni.reLaunch({
  368. url: "../../personal-page/personal/personal"
  369. })
  370. });
  371. }
  372. }
  373. });
  374. } else {
  375. uni.showToast({
  376. title: "验证码错误",
  377. mask: true,
  378. icon: 'none',
  379. duration: 1000
  380. })
  381. }
  382. }
  383. })
  384. // #endif
  385. // #ifdef MP-WEIXIN
  386. uni.request({
  387. url: config.URL.USERlOGINURL,
  388. data: {
  389. appid: 'wxd6dfd60729d33d17',
  390. code: res.code,
  391. source: 1,
  392. },
  393. success: (res) => {
  394. // console.log('请求返回:', res, res.cookies[0]);
  395. // return;
  396. uni.getUserInfo({
  397. provider: value,
  398. success: (infoRes) => {
  399. /**
  400. * 实际开发中,获取用户信息后,需要将信息上报至服务端。
  401. * 服务端可以用 userInfo.openId 作为用户的唯一标识新增或绑定用户信息。
  402. */
  403. // this.toMain(infoRes.userInfo.nickName);
  404. console.log('getUserInfo infoRes:', infoRes)
  405. uni.request({
  406. url: config.URL.WXGETUSERINFO,
  407. data: {
  408. appid: 'wxd6dfd60729d33d17',
  409. encryptedData: infoRes.encryptedData,
  410. iv: infoRes.iv,
  411. signature: infoRes.signature,
  412. rawData: infoRes.rawData
  413. },
  414. success: (wxInfoRes) => {
  415. console.log('WXGETUSERINFO 请求返回:', wxInfoRes);
  416. }
  417. })
  418. },
  419. fail: (failRes) => {
  420. console.log('getUserInfo failRes:', failRes)
  421. }
  422. });
  423. }
  424. })
  425. // #endif
  426. },
  427. fail: (err) => {
  428. console.error('授权登录失败:' + JSON.stringify(err));
  429. }
  430. });
  431. },
  432. callbackUserInfo(userinfo) {
  433. console.log('callbackUserInfo:', userinfo);
  434. },
  435. onSwitchLogin(bMobileLogin) {
  436. // console.log(bMobileLogin);
  437. this.bMobileLogin = bMobileLogin;
  438. //如果是已获取的验证码页面,返回获取验证码界面
  439. if (this.bGetCode == false)
  440. this.bGetCode = true;
  441. // this.bMobileLogin = !this.bMobileLogin;
  442. },
  443. onNavToReg() {
  444. if (!verify.checkPhone(this.account)) {
  445. uni.showToast({
  446. icon: 'none',
  447. title: '输入手机号错误'
  448. });
  449. return;
  450. }
  451. // console.log("手机号正确:",this.account);
  452. // return;
  453. this.$store.state.phoneNumber = this.account;
  454. this.bGetCode = false;
  455. this.onGetCode();
  456. },
  457. //验证码操作
  458. //注册
  459. onConfirm() {
  460. var _self = this;
  461. if (_self.inputCode.length < 4) {
  462. uni.showToast({
  463. title: "请输入4位验证码",
  464. icon: "none",
  465. duration: 2000,
  466. mask: true
  467. })
  468. return;
  469. }
  470. uni.showToast({
  471. title: "",
  472. icon: "loading",
  473. duration: 10000,
  474. mask: true
  475. })
  476. reqUtil.requestData(config.URL.SMSLOGIN, {
  477. "phoneNumber": _self.phoneNumber,
  478. "code": _self.inputCode
  479. }).then(res => {
  480. console.log('requestData GETCODE =====', res);
  481. uni.hideToast();
  482. if (res.code == 0) {
  483. uni.showToast({
  484. title: "登录中..",
  485. icon: "loading",
  486. mask: true,
  487. duration: 3000
  488. })
  489. //登录成功
  490. uni.setStorage({
  491. key: 'token',
  492. data: res.data.token,
  493. success: function() {
  494. _self.$store.state.bNewUser = res.data.newUser;
  495. _self.resetCountDown();
  496. _self.accountLogin(function() {
  497. uni.hideToast();
  498. if (_self.bNewUser) {
  499. uni.reLaunch({
  500. url: "../../my-page/userInfo/userInfo"
  501. })
  502. } else {
  503. uni.reLaunch({
  504. url: "../../personal-page/personal/personal"
  505. })
  506. }
  507. });
  508. }
  509. });
  510. } else {
  511. uni.showToast({
  512. title: "验证码错误",
  513. mask: true,
  514. icon: 'none',
  515. duration: 1000
  516. })
  517. }
  518. },
  519. e => {
  520. console.log(e);
  521. uni.hideToast();
  522. });
  523. },
  524. onGetCode() {
  525. //置灰状态
  526. if (this.bCodeDisabled) return;
  527. //调用store 倒计时
  528. this.countDown(this.phoneNumber);
  529. },
  530. onTap() {
  531. this.bFocus = true;
  532. console.log(this.bFocus);
  533. },
  534. onFocus(e) {
  535. console.log(e);
  536. setTimeout(() => {
  537. // this.bFocus = false;
  538. }, 1000)
  539. },
  540. onInputFocus(e) {
  541. console.log(e.detail.value);
  542. this.Value = e.detail.value;
  543. },
  544. inputEvent(res) {
  545. console.log("input 1 input code components : " + res.detail.value);
  546. /* this.$emit('vueMsg',res.detail.value); */
  547. this.inputCode = res.detail.value;
  548. },
  549. onSwitchAgree(data) {
  550. console.log("=== ", data);
  551. uni.navigateTo({
  552. url: "../../login-page/userAgreement/userAgreement?type=" + data
  553. })
  554. },
  555. onAppleReg() {
  556. this.onAppleLogout(() => {
  557. this.onAppleRegEvent();
  558. })
  559. },
  560. onAppleRegEvent() {
  561. let _self = this;
  562. uni.login({
  563. provider: 'apple',
  564. success: (loginRes) => {
  565. // console.log('apple login:', loginRes);
  566. uni.getUserInfo({
  567. provider: 'apple',
  568. success(resUser) {
  569. //用户信息
  570. console.log("resUser:", resUser);
  571. uni.showToast({
  572. title: '',
  573. icon: 'loading',
  574. mask: true,
  575. duration: 10000,
  576. })
  577. reqUtil.requestData(config.URL.APPLElOGINURL, {
  578. "identityToken": resUser.userInfo.identityToken
  579. }).then(res => {
  580. console.log('requestData apple login =====', res);
  581. uni.hideToast();
  582. if (res.code == 0) {
  583. //登录成功
  584. uni.setStorage({
  585. key: 'token',
  586. data: res.data.token,
  587. success: function() {
  588. _self.$store.state.bNewUser = res.data.newUser;
  589. // console.log("apple token = ", res.data.token);
  590. //如果是新用户,则获取用户信息
  591. if (_self.bNewUser) {
  592. //获取了用户信息后
  593. let tempName = "匿名";
  594. if (resUser.userInfo.fullName.hasOwnProperty("familyName") &&
  595. resUser.userInfo.fullName.hasOwnProperty("givenName")) {
  596. tempName = resUser.userInfo.fullName.familyName + resUser.userInfo.fullName.givenName;
  597. }
  598. let userInfo = {
  599. username: tempName,
  600. gender: 0 //默认是男性
  601. }
  602. // console.log("苹果数据11:", resUser.userInfo);
  603. // console.log("userInfo:", userInfo);
  604. _self.appleUserInfoLogin({
  605. params: userInfo,
  606. callback: () => {
  607. //这里是记录appleid,不是微信
  608. _self.$store.state.appleid = resUser.userInfo.openId || '';
  609. uni.hideToast();
  610. uni.reLaunch({
  611. url: "../../my-page/perfectInfo/perfectInfo"
  612. })
  613. }
  614. });
  615. } else {
  616. //如果不是新用户,直接获取用户信息
  617. _self.accountLogin(function() {
  618. uni.hideToast();
  619. uni.reLaunch({
  620. url: "../../personal-page/personal/personal"
  621. })
  622. });
  623. }
  624. }
  625. });
  626. } else {
  627. uni.showToast({
  628. title: "apple登陆失败",
  629. mask: true,
  630. icon: 'none',
  631. duration: 1000
  632. })
  633. }
  634. },
  635. e => {
  636. console.log(e);
  637. uni.hideToast();
  638. });
  639. }
  640. })
  641. },
  642. fail: (err) => {
  643. //登陆失败
  644. console.log('登陆失败:', err)
  645. uni.showToast({
  646. title: '登陆失败',
  647. icon: 'none'
  648. })
  649. }
  650. })
  651. },
  652. onAppleLogout(callback) {
  653. this.appleOauth.logout(function(e) {
  654. // plus.nativeUI.alert("注销登录认证成功!");
  655. callback(e);
  656. console.log("注销登录认证成功!");
  657. }, function(e) {
  658. // plus.nativeUI.alert("注销登录认证失败: " + JSON.stringify(e));
  659. console.log("注销登录认证失败: " + JSON.stringify(e));
  660. });
  661. },
  662. onGetAppleService() {
  663. // console.log("onGetAppleService");
  664. let _self = this;
  665. plus.oauth.getServices(function(services) {
  666. for (var i in services) {
  667. var service = services[i];
  668. // 获取苹果授权登录对象,苹果授权登录id 为 'apple' iOS13以下系统,不会返回苹果登录对应的 service
  669. if (service.id == 'apple') {
  670. _self.appleOauth = service;
  671. // console.log("this.appleOla:", _self.appleOauth);
  672. break;
  673. }
  674. // console.log("service:", service);
  675. }
  676. }, function(err) {
  677. // 获取 services 失败
  678. })
  679. }
  680. },
  681. onReady() {
  682. this.initPosition();
  683. this.initProvider();
  684. //获取apple相关服务
  685. this.onGetAppleService();
  686. }
  687. }
  688. </script>
  689. <style>
  690. .action-row {
  691. display: flex;
  692. flex-direction: row;
  693. justify-content: space-between;
  694. height: 67px;
  695. }
  696. .action-row navigator {
  697. color: #FFFFFF;
  698. font-size: 16px;
  699. /* padding: 0 20upx; */
  700. }
  701. .action-row-text {
  702. margin-top: 25px;
  703. display: flex;
  704. flex-direction: row;
  705. justify-content: center;
  706. }
  707. .action-child {
  708. /* color: #FFFFFF; */
  709. padding: 0 20upx;
  710. }
  711. .oauth-row {
  712. display: flex;
  713. flex-direction: column;
  714. justify-content: center;
  715. align-content: center;
  716. text-align: center;
  717. position: absolute;
  718. top: 0;
  719. left: 0;
  720. width: 100%;
  721. right: 0;
  722. z-index: -1;
  723. /* border: 1rpx solid #000000; */
  724. }
  725. .oauth-image {
  726. width: 76rpx;
  727. height: 76rpx;
  728. /* border: 1upx solid #dddddd; */
  729. /* border-radius: 100upx; */
  730. margin: 0 40upx;
  731. /* background-color: #ffffff; */
  732. }
  733. .oauth-image image {
  734. width: 76rpx;
  735. height: 76rpx;
  736. /* margin: 20upx; */
  737. }
  738. .input-group {
  739. background-color: #ffffff;
  740. margin-top: 40upx;
  741. position: relative;
  742. }
  743. .input-group::before {
  744. position: absolute;
  745. right: 0;
  746. top: 0;
  747. left: 0;
  748. height: 1upx;
  749. content: '';
  750. -webkit-transform: scaleY(.5);
  751. transform: scaleY(.5);
  752. background-color: #c8c7cc;
  753. }
  754. .input-group::after {
  755. position: absolute;
  756. right: 0;
  757. bottom: 0;
  758. left: 0;
  759. height: 1upx;
  760. content: '';
  761. -webkit-transform: scaleY(.5);
  762. transform: scaleY(.5);
  763. background-color: #c8c7cc;
  764. }
  765. .input-row {
  766. display: flex;
  767. flex-direction: row;
  768. position: relative;
  769. }
  770. .main-title {
  771. width: 20%;
  772. height: 50upx;
  773. min-height: 50upx;
  774. padding: 15upx 0;
  775. padding-left: 30upx;
  776. line-height: 50upx;
  777. }
  778. .main-info {
  779. width: 20%;
  780. height: 50upx;
  781. min-height: 50upx;
  782. padding: 15upx 0;
  783. padding-left: 30upx;
  784. line-height: 50upx;
  785. }
  786. .btn-row {
  787. /* margin-top: 50upx; */
  788. /* padding: 20upx; */
  789. display: flex;
  790. justify-content: center;
  791. align-items: center;
  792. }
  793. .container {
  794. position: absolute;
  795. top: 0;
  796. bottom: 0;
  797. left: 0;
  798. right: 0;
  799. background-color: #FFFFFF;
  800. }
  801. .bg-image {
  802. position: absolute;
  803. top: 0;
  804. left: 0;
  805. width: 100%;
  806. height: calc(25% + 67px);
  807. opacity: 1;
  808. }
  809. .up {
  810. position: absolute;
  811. z-index: 1;
  812. width: 100%;
  813. height: 100%;
  814. }
  815. .input-container {
  816. border-bottom: 1rpx solid #e7e9eb;
  817. }
  818. .btn-confirm {
  819. width: 636rpx;
  820. height: 102rpx;
  821. background-color: rgba(151, 151, 255, 1);
  822. border-radius: 10px;
  823. display: flex;
  824. justify-content: center;
  825. align-items: center;
  826. font-size: 17px;
  827. color: #FFFFFF;
  828. }
  829. .btn-apple-confirm {
  830. width: 636rpx;
  831. height: 102rpx;
  832. /* background-color: rgba(151, 151, 255, 1); */
  833. border: 1px solid #000000;
  834. border-radius: 10px;
  835. display: flex;
  836. justify-content: center;
  837. align-items: center;
  838. font-size: 17px;
  839. color: #000000;
  840. margin-top: 7px;
  841. }
  842. .disabledBtn {
  843. background-color: rgba(221, 221, 221, 1.0);
  844. }
  845. .code-input-main {
  846. display: flex;
  847. flex-direction: column;
  848. width: 100%;
  849. /* border: 1rpx solid #000000; */
  850. height: 150px;
  851. position: relative;
  852. }
  853. .input-item {
  854. width: 106rpx;
  855. height: 118rpx;
  856. font-size: 20px;
  857. line-height: 118rpx;
  858. background-color: rgba(244, 241, 244, 255);
  859. /* border: 1rpx solid #ddd; */
  860. text-align: center;
  861. border-radius: 8px;
  862. margin-left: 44rpx;
  863. /* margin-right: 40upx; */
  864. color: rgba(86, 86, 86, 1);
  865. font-weight: bold;
  866. }
  867. .inputLine {
  868. display: flex;
  869. justify-content: flex-start;
  870. width: 100%;
  871. top: 80rpx;
  872. left: 52rpx;
  873. position: absolute;
  874. z-index: 1;
  875. }
  876. .code-input-input {
  877. height: 150px;
  878. position: absolute;
  879. width: 100%;
  880. outline: none;
  881. color: transparent;
  882. text-shadow: 0 0 0 transparent;
  883. width: 300%;
  884. left: -100%;
  885. top: 0;
  886. /* background: #000000; */
  887. /* border: 1rpx solid #007AFF; */
  888. z-index: 10;
  889. }
  890. .ipt {
  891. width: 0;
  892. height: 0;
  893. }
  894. .text-decoration {
  895. margin: 0 1rpx;
  896. border-bottom: 1rpx solid rgba(0, 0, 0, 0.3);
  897. padding-bottom: 1rpx;
  898. }
  899. </style>