login.vue 30 KB

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