login.vue 30 KB

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