login.vue 29 KB

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