login.vue 31 KB

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