login.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  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;white-space:nowrap;">
  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: 30rpx;">
  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 + 378;
  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.SMSLOGINFROMTYPE, {
  572. "account": _self.bMobileLogin ? _self.phoneNumber : _self.mailboxNumber,
  573. "code": _self.inputCode,
  574. "type": _self.bMobileLogin ? 0 : 1
  575. }).then(res => {
  576. console.log('requestData GETCODE =====', res);
  577. uni.hideToast();
  578. if (res.code == 0) {
  579. uni.showToast({
  580. title: "登录中..",
  581. icon: "loading",
  582. mask: true,
  583. duration: 3000
  584. })
  585. //登录成功
  586. uni.setStorage({
  587. key: 'token',
  588. data: res.data.token,
  589. success: function() {
  590. _self.$store.state.bNewUser = res.data.newUser;
  591. _self.resetCountDown();
  592. _self.accountLogin(function() {
  593. uni.hideToast();
  594. if (_self.bNewUser) {
  595. uni.reLaunch({
  596. url: "../../my-page/userInfo/userInfo"
  597. })
  598. } else {
  599. uni.reLaunch({
  600. url: "../../personal-page/personal/personal"
  601. })
  602. }
  603. });
  604. }
  605. });
  606. } else {
  607. uni.showToast({
  608. title: "验证码错误",
  609. mask: true,
  610. icon: 'none',
  611. duration: 1000
  612. })
  613. }
  614. },
  615. e => {
  616. console.log(e);
  617. uni.hideToast();
  618. });
  619. },
  620. onGetCode() {
  621. //置灰状态
  622. if (this.bCodeDisabled) return;
  623. //调用store 倒计时
  624. if (this.bMobileLogin) {
  625. this.countDown({
  626. account: this.phoneNumber,
  627. type: 0
  628. });
  629. } else {
  630. this.countDown({
  631. account: this.mailboxNumber,
  632. type: 1
  633. });
  634. }
  635. },
  636. onTap() {
  637. this.bFocus = true;
  638. console.log(this.bFocus);
  639. },
  640. onFocus(e) {
  641. console.log(e);
  642. setTimeout(() => {
  643. // this.bFocus = false;
  644. }, 1000)
  645. },
  646. onInputFocus(e) {
  647. console.log(e.detail.value);
  648. this.Value = e.detail.value;
  649. },
  650. inputEvent(res) {
  651. console.log("input 1 input code components : " + res.detail.value);
  652. /* this.$emit('vueMsg',res.detail.value); */
  653. this.inputCode = res.detail.value;
  654. },
  655. onSwitchAgree(data) {
  656. console.log("=== ", data);
  657. uni.navigateTo({
  658. url: "../../login-page/userAgreement/userAgreement?type=" + data
  659. })
  660. },
  661. onAppleReg() {
  662. this.onAppleLogout(() => {
  663. this.onAppleRegEvent();
  664. })
  665. },
  666. onAppleRegEvent() {
  667. let _self = this;
  668. uni.login({
  669. provider: 'apple',
  670. success: (loginRes) => {
  671. // console.log('apple login:', loginRes);
  672. uni.getUserInfo({
  673. provider: 'apple',
  674. success(resUser) {
  675. //用户信息
  676. console.log("resUser:", resUser);
  677. uni.showToast({
  678. title: '',
  679. icon: 'loading',
  680. mask: true,
  681. duration: 10000,
  682. })
  683. reqUtil.requestData(config.URL.APPLElOGINURL, {
  684. "identityToken": resUser.userInfo.identityToken
  685. }).then(res => {
  686. console.log('requestData apple login =====', res);
  687. uni.hideToast();
  688. if (res.code == 0) {
  689. //登录成功
  690. uni.setStorage({
  691. key: 'token',
  692. data: res.data.token,
  693. success: function() {
  694. _self.$store.state.bNewUser = res
  695. .data.newUser;
  696. // console.log("apple token = ", res.data.token);
  697. //如果是新用户,则获取用户信息
  698. if (_self.bNewUser) {
  699. //获取了用户信息后
  700. let tempName = "匿名";
  701. if (resUser.userInfo.fullName
  702. .hasOwnProperty(
  703. "familyName") &&
  704. resUser.userInfo.fullName
  705. .hasOwnProperty(
  706. "givenName")) {
  707. tempName = resUser.userInfo
  708. .fullName.familyName +
  709. resUser.userInfo
  710. .fullName.givenName;
  711. }
  712. let userInfo = {
  713. username: tempName,
  714. gender: 0 //默认是男性
  715. }
  716. // console.log("苹果数据11:", resUser.userInfo);
  717. // console.log("userInfo:", userInfo);
  718. _self.appleUserInfoLogin({
  719. params: userInfo,
  720. callback: () => {
  721. //这里是记录appleid,不是微信
  722. _self
  723. .$store
  724. .state
  725. .appleid =
  726. resUser
  727. .userInfo
  728. .openId ||
  729. '';
  730. uni
  731. .hideToast();
  732. uni.reLaunch({
  733. url: "../../my-page/perfectInfo/perfectInfo"
  734. })
  735. }
  736. });
  737. } else {
  738. //如果不是新用户,直接获取用户信息
  739. _self.accountLogin(function() {
  740. uni.hideToast();
  741. uni.reLaunch({
  742. url: "../../personal-page/personal/personal"
  743. })
  744. });
  745. }
  746. }
  747. });
  748. } else {
  749. uni.showToast({
  750. title: "apple登陆失败",
  751. mask: true,
  752. icon: 'none',
  753. duration: 1000
  754. })
  755. }
  756. },
  757. e => {
  758. console.log(e);
  759. uni.hideToast();
  760. });
  761. }
  762. })
  763. },
  764. fail: (err) => {
  765. //登陆失败
  766. console.log('登陆失败:', err)
  767. uni.showToast({
  768. title: '登陆失败',
  769. icon: 'none'
  770. })
  771. }
  772. })
  773. },
  774. onAppleLogout(callback) {
  775. this.appleOauth.logout(function(e) {
  776. // plus.nativeUI.alert("注销登录认证成功!");
  777. callback(e);
  778. console.log("注销登录认证成功!");
  779. }, function(e) {
  780. // plus.nativeUI.alert("注销登录认证失败: " + JSON.stringify(e));
  781. console.log("注销登录认证失败: " + JSON.stringify(e));
  782. });
  783. },
  784. onGetAppleService() {
  785. // console.log("onGetAppleService");
  786. let _self = this;
  787. plus.oauth.getServices(function(services) {
  788. for (var i in services) {
  789. var service = services[i];
  790. // 获取苹果授权登录对象,苹果授权登录id 为 'apple' iOS13以下系统,不会返回苹果登录对应的 service
  791. if (service.id == 'apple') {
  792. _self.appleOauth = service;
  793. // console.log("this.appleOla:", _self.appleOauth);
  794. break;
  795. }
  796. // console.log("service:", service);
  797. }
  798. }, function(err) {
  799. // 获取 services 失败
  800. })
  801. }
  802. },
  803. onReady() {
  804. this.initPosition();
  805. this.initProvider();
  806. //获取apple相关服务
  807. this.onGetAppleService();
  808. }
  809. }
  810. </script>
  811. <style>
  812. .action-row {
  813. display: flex;
  814. flex-direction: row;
  815. justify-content: space-between;
  816. height: 67px;
  817. }
  818. .action-row navigator {
  819. color: #FFFFFF;
  820. font-size: 16px;
  821. /* padding: 0 20upx; */
  822. }
  823. .action-row-text {
  824. margin-top: 18px;
  825. display: flex;
  826. flex-direction: row;
  827. justify-content: center;
  828. }
  829. .action-child {
  830. /* color: #FFFFFF; */
  831. padding: 0 20upx;
  832. }
  833. .oauth-row {
  834. display: flex;
  835. flex-direction: column;
  836. justify-content: center;
  837. align-content: center;
  838. text-align: center;
  839. position: absolute;
  840. top: 0;
  841. left: 0;
  842. width: 100%;
  843. right: 0;
  844. z-index: -1;
  845. /* border: 1rpx solid #000000; */
  846. }
  847. .oauth-image {
  848. width: 76rpx;
  849. height: 76rpx;
  850. /* border: 1upx solid #dddddd; */
  851. /* border-radius: 100upx; */
  852. margin: 0 40upx;
  853. /* background-color: #ffffff; */
  854. }
  855. .oauth-image image {
  856. width: 76rpx;
  857. height: 76rpx;
  858. /* margin: 20upx; */
  859. }
  860. .input-group {
  861. background-color: #ffffff;
  862. margin-top: 40upx;
  863. position: relative;
  864. }
  865. .input-group::before {
  866. position: absolute;
  867. right: 0;
  868. top: 0;
  869. left: 0;
  870. height: 1upx;
  871. content: '';
  872. -webkit-transform: scaleY(.5);
  873. transform: scaleY(.5);
  874. background-color: #c8c7cc;
  875. }
  876. .input-group::after {
  877. position: absolute;
  878. right: 0;
  879. bottom: 0;
  880. left: 0;
  881. height: 1upx;
  882. content: '';
  883. -webkit-transform: scaleY(.5);
  884. transform: scaleY(.5);
  885. background-color: #c8c7cc;
  886. }
  887. .input-row {
  888. display: flex;
  889. flex-direction: row;
  890. position: relative;
  891. }
  892. .main-title {
  893. width: 20%;
  894. height: 50upx;
  895. min-height: 50upx;
  896. padding: 15upx 0;
  897. padding-left: 30upx;
  898. line-height: 50upx;
  899. }
  900. .main-info {
  901. width: 20%;
  902. height: 50upx;
  903. min-height: 50upx;
  904. padding: 15upx 0;
  905. padding-left: 30upx;
  906. line-height: 50upx;
  907. }
  908. .btn-row {
  909. display: flex;
  910. justify-content: center;
  911. align-items: center;
  912. }
  913. .container {
  914. position: absolute;
  915. top: 0;
  916. bottom: 0;
  917. left: 0;
  918. right: 0;
  919. background-color: #FFFFFF;
  920. }
  921. .bg-image {
  922. position: absolute;
  923. top: 0;
  924. left: 0;
  925. width: 100%;
  926. height: calc(25% + 67px);
  927. opacity: 1;
  928. }
  929. .up {
  930. position: absolute;
  931. z-index: 1;
  932. width: 100%;
  933. height: 100%;
  934. }
  935. .input-container {
  936. border-bottom: 1rpx solid #e7e9eb;
  937. }
  938. .btn-confirm {
  939. width: 636rpx;
  940. height: 102rpx;
  941. background-color: rgba(151, 151, 255, 1);
  942. border-radius: 10px;
  943. display: flex;
  944. justify-content: center;
  945. align-items: center;
  946. font-size: 17px;
  947. color: #FFFFFF;
  948. }
  949. .btn-apple-confirm {
  950. width: 380rpx;
  951. height: 64rpx;
  952. /* background-color: rgba(151, 151, 255, 1); */
  953. border: 1px solid #000000;
  954. border-radius: 8px;
  955. display: flex;
  956. justify-content: center;
  957. align-items: center;
  958. font-size: 12px;
  959. font-weight: bold;
  960. color: #000000;
  961. margin-top: 7px;
  962. }
  963. .disabledBtn {
  964. background-color: rgba(221, 221, 221, 1.0);
  965. }
  966. .code-input-main {
  967. display: flex;
  968. flex-direction: column;
  969. width: 100%;
  970. /* border: 1rpx solid #000000; */
  971. height: 150px;
  972. position: relative;
  973. }
  974. .input-item {
  975. width: 106rpx;
  976. height: 118rpx;
  977. font-size: 20px;
  978. line-height: 118rpx;
  979. background-color: rgba(244, 241, 244, 255);
  980. /* border: 1rpx solid #ddd; */
  981. text-align: center;
  982. border-radius: 8px;
  983. margin-left: 44rpx;
  984. /* margin-right: 40upx; */
  985. color: rgba(86, 86, 86, 1);
  986. font-weight: bold;
  987. }
  988. .inputLine {
  989. display: flex;
  990. justify-content: flex-start;
  991. width: 100%;
  992. top: 80rpx;
  993. left: 52rpx;
  994. position: absolute;
  995. z-index: 1;
  996. }
  997. .code-input-input {
  998. height: 150px;
  999. position: absolute;
  1000. width: 100%;
  1001. outline: none;
  1002. color: transparent;
  1003. text-shadow: 0 0 0 transparent;
  1004. width: 300%;
  1005. left: -100%;
  1006. top: 0;
  1007. /* background: #000000; */
  1008. /* border: 1rpx solid #007AFF; */
  1009. z-index: 10;
  1010. }
  1011. .ipt {
  1012. width: 0;
  1013. height: 0;
  1014. }
  1015. .text-decoration {
  1016. margin: 0 1rpx;
  1017. border-bottom: 1rpx solid rgba(0, 0, 0, 0.3);
  1018. padding-bottom: 1rpx;
  1019. }
  1020. </style>