login.vue 30 KB

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