login.vue 27 KB

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