login.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. <template>
  2. <view class="login">
  3. <!-- 小程序状态下登录 -->
  4. <!-- #ifdef MP-WEIXIN -->
  5. <view class="mp_wxBox">
  6. <view>
  7. <view class="headers">
  8. <image src="../../static/logo.png" style="border-radius: 50%;"></image>
  9. </view>
  10. <view class="content">
  11. <view>申请获取以下权限</view>
  12. <text style="margin-top: 20rpx;">获得你的公开信息(昵称,头像、地区等)</text>
  13. </view>
  14. <button v-show="weixinPhone" style="background: #FF7F00;background-color: #FF7F00;color: #FFFFFF;"
  15. class="bottom" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
  16. 授权手机号
  17. </button>
  18. <!-- <button v-show="!weixinPhone" style="background: #FF3530; color: #FFF;" class="bottom"
  19. open-type="getUserInfo" withCredentials="true" lang="zh_CN" @getuserinfo="wxGetUserInfo">
  20. 立即登录
  21. </button> -->
  22. <button v-show="!weixinPhone" style="background: #FF7F00;color: #FFFFFF;" class='bottom'
  23. bindtap="getUserProfile" @tap="wxGetUserInfo">
  24. 授权登录
  25. </button>
  26. <!-- 底部信息 -->
  27. <view class="footer">
  28. <text @tap="isShowAgree" class="cuIcon" :class="showAgree?'cuIcon-radiobox':'cuIcon-round'">同意
  29. </text>
  30. <!-- 协议地址 -->
  31. <navigator url="/pages/riderMy/set/mimi" open-type="navigate">《隐私政策》</navigator>和
  32. <navigator url="/pages/riderMy/set/xieyi" open-type="navigate">《用户服务协议》</navigator>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- #endif -->
  37. <!-- #ifndef MP-WEIXIN -->
  38. <view class="register">
  39. <!-- <view class="back-btn yticon icon-zuojiantou-up" @click="navBack"></view> -->
  40. <view style="padding-top: 172upx;margin-left: 36upx;">
  41. <view style="color: #333333;font-size: 44upx;">手机快捷登录</view>
  42. <view style="color: #999999;font-size: 24upx;margin-top: 20upx;">未注册的手机号将自动创建账号</view>
  43. </view>
  44. <view style="margin-left: 26upx;margin-top: 104upx;">
  45. <wInput v-model="phoneData" type="number" maxlength="11" placeholder="请输入手机号"></wInput>
  46. <!-- <wInput v-model="passData" type="number" maxlength="6" placeholder="请输入密码"></wInput> -->
  47. <wInput v-model="verCode" type="number" maxlength="6" placeholder="请输入验证码" isShowCode ref="runCode"
  48. @setCode="sendMsg()"></wInput>
  49. <wInput v-show="show" v-model="invitation" isShowGet ref="setNumberCode" @setNumberCode="isShowGet()"
  50. placeholder="请填写邀请码"></wInput>
  51. </view>
  52. <view class="footer" style=" margin-right: 72px;">
  53. <image v-if="showAgree" @tap="isShowAgree"
  54. src="https://api.shengqianxiong.com.cn/img/20201112/669aa8946cfb4ebdb459d57193c0ebca.png"
  55. style="width: 36upx;height: 36upx;"></image>
  56. <image v-else @tap="isShowAgree"
  57. src="https://api.shengqianxiong.com.cn/img/20201112/1e9102fc891f4d86a13c7b2ba6921cba.png"
  58. style="width: 36upx;height: 36upx;"></image>
  59. <text style="margin-left: 10upx;margin-right: 0;">同意</text>
  60. <navigator url="/pages/riderMy/set/mimi" open-type="navigate">《隐私政策》</navigator>和
  61. <navigator url="/pages/riderMy/set/xieyi" open-type="navigate">《用户服务协议》</navigator>
  62. </view>
  63. <wButton text="登 录" :rotate="isRotate" @click.native="startReg()"></wButton>
  64. </view>
  65. <!-- #endif -->
  66. </view>
  67. </template>
  68. <script>
  69. import wInput from '@/components/watch-login/watch-input.vue' //input
  70. import wButton from '@/components/watch-login/watch-button.vue' //button
  71. export default {
  72. components: {
  73. wInput,
  74. wButton,
  75. },
  76. data() {
  77. return {
  78. phoneData: '',
  79. verCode: '',
  80. show: '',
  81. invitation: '',
  82. isRotate: false, //是否加载旋转
  83. platform: "app",
  84. userType: 2,
  85. passData: '', //密码
  86. numbers: '',
  87. password: '',
  88. type: 'number',
  89. pass: 'number',
  90. clearable: false,
  91. mobile: '',
  92. code: '',
  93. sessionkey: '',
  94. flag: '1',
  95. showAgree: false, //协议是否选择
  96. weixinPhone: false,
  97. sending: false,
  98. sendDataList: {},
  99. phone: '',
  100. sendTime: '获取验证码',
  101. count: 60
  102. }
  103. },
  104. methods: {
  105. navBack(){
  106. uni.navigateBack()
  107. },
  108. isShowAgree() {
  109. this.showAgree = !this.showAgree
  110. },
  111. startReg() {
  112. var that = this
  113. uni.getSystemInfo({
  114. success: function(res) {
  115. console.log(res.model);
  116. if (res.model == 'iPhone') {
  117. that.sysphone = 2
  118. } else if (res.model != 'iPhone') {
  119. that.sysphone = 1
  120. }
  121. }
  122. });
  123. //注册
  124. if (that.isRotate) {
  125. //判断是否加载中,避免重复点击请求
  126. return false;
  127. }
  128. if (that.showAgree == false) {
  129. uni.showToast({
  130. icon: 'none',
  131. position: 'bottom',
  132. title: '请先同意《协议》'
  133. });
  134. return false;
  135. }
  136. if (that.phoneData.length != 11) {
  137. uni.showToast({
  138. icon: 'none',
  139. position: 'bottom',
  140. title: '手机号不正确'
  141. });
  142. return false;
  143. }
  144. // if (that.passData.length < 5) {
  145. // uni.showToast({
  146. // icon: 'none',
  147. // position: 'bottom',
  148. // title: '密码不能低于六位'
  149. // });
  150. // return false;
  151. // }
  152. if (that.verCode == 6) {
  153. uni.showToast({
  154. icon: 'none',
  155. position: 'bottom',
  156. title: '验证码不正确'
  157. });
  158. return false;
  159. }
  160. that.isRotate = true;
  161. console.log('验证码', that.verCode, )
  162. // {
  163. // password: that.passData,
  164. // phone: that.phoneData,
  165. // msg: that.verCode,
  166. // platform: that.platform,
  167. // userType: that.userType,
  168. // sysphone: that.sysphone
  169. // // openid: this.$queue.getData("openid")
  170. // }
  171. var openid = this.$queue.getData("openid") ? this.$queue.getData("openid") : '';
  172. that.$Request.postJson("/app/Login/registerCode?password=" + that.passData + '&phone=' + that.phoneData +
  173. '&msg=' + that.verCode + '&platform=' + that.platform +
  174. '&userType=' + that.userType + '&sysphone=' + that.sysphone + '&openId=' + openid).then(res => {
  175. console.log(res)
  176. if (res.code == 0) {
  177. console.log(res.token)
  178. this.$queue.setData("token", res.token);
  179. this.$queue.setData("userId", res.user.userId);
  180. this.$queue.setData("mobile", res.user.phone);
  181. // this.getUserInfo(res.user.userId, res.token);
  182. uni.navigateTo({
  183. url: '/pages/index/index'
  184. })
  185. return false;
  186. } else {
  187. that.isRotate = false;
  188. uni.hideLoading();
  189. uni.showModal({
  190. showCancel: false,
  191. title: '登录失败',
  192. content: res.msg,
  193. });
  194. }
  195. });
  196. },
  197. sendMsg() {
  198. const {
  199. phoneData
  200. } = this;
  201. if (!phoneData) {
  202. this.$queue.showToast("请输入手机号");
  203. } else if (phoneData.length !== 11) {
  204. this.$queue.showToast("请输入正确的手机号");
  205. } else {
  206. this.$queue.showLoading("正在发送验证码...");
  207. this.$Request.getT("/app/Login/sendMsg/" + phoneData + '/register').then(res => {
  208. console.log(res)
  209. if (res.code == 0) {
  210. if (res.data === 'register') {
  211. this.show = true;
  212. }
  213. this.sending = true;
  214. this.$queue.showToast('验证码发送成功请注意查收');
  215. this.$refs.runCode.$emit('runCode');
  216. uni.hideLoading();
  217. } else {
  218. uni.hideLoading();
  219. uni.showModal({
  220. showCancel: false,
  221. title: '短信发送失败',
  222. content: res.msg ? res.msg : '请一分钟后再获取验证码',
  223. });
  224. }
  225. });
  226. }
  227. },
  228. bindriderlogin() {
  229. uni.navigateTo({
  230. url: '/pages/login/running_rider/running_rider'
  231. })
  232. },
  233. forgetPwd() {
  234. uni.navigateTo({
  235. url: '/pages/login/forgetPwd'
  236. })
  237. },
  238. //第一授权获取用户信息===》按钮触发
  239. wxGetUserInfo(e) {
  240. if (!this.showAgree) {
  241. uni.showToast({
  242. title: '请选择用户和隐私协议',
  243. icon: 'none'
  244. })
  245. return
  246. }
  247. let that = this;
  248. wx.getUserProfile({
  249. desc: '业务需要',
  250. success: infoRes => {
  251. console.log("infoRes.encryptedData__________:",infoRes.userInfo)
  252. let userName = infoRes.userInfo.nickName; //昵称
  253. let avatarUrl = infoRes.userInfo.avatarUrl; //头像
  254. let sex = infoRes.userInfo.gender; //头像
  255. try {
  256. that.login(userName, avatarUrl, sex);
  257. } catch (e) {}
  258. }
  259. })
  260. },
  261. //小程序微信登录后获取手机号
  262. getPhoneNumber: function(e) {
  263. console.log(e);
  264. if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
  265. console.log('用户拒绝提供手机号');
  266. } else {
  267. console.log('用户同意提供手机号');
  268. this.setPhoneByInsert(e.detail.encryptedData, e.detail.iv);
  269. }
  270. },
  271. //小程序微信登录后获取手机号
  272. setPhoneByInsert(decryptData, iv) {
  273. this.$queue.showLoading('登录中...');
  274. let data = {
  275. decryptData: decryptData,
  276. key: this.sessionkey,
  277. iv: iv
  278. };
  279. this.$Request.postJson('/app/Login/selectPhone', data).then(res => {
  280. if (res.code === 0) {
  281. uni.hideLoading();
  282. this.phone = res.data.phoneNumber;
  283. this.getWeixinInfo(this.sendDataList);
  284. } else {
  285. uni.hideLoading();
  286. this.$queue.showToast(res.msg);
  287. }
  288. });
  289. },
  290. //获取个人信息
  291. getWeixinInfo(sendData) {
  292. let that = this;
  293. // let url = '/user/mp/update';
  294. uni.showLoading({
  295. title: '登录中...'
  296. });
  297. var postData = {
  298. riderOpenId: sendData.openid, //小程序openid
  299. platform: '小程序', //unionId
  300. userName: sendData.userName, //微信名称
  301. avatar: sendData.imageUrl, //头像
  302. userId: '', //性别
  303. phone: that.phone,
  304. inviterCode: sendData.invitation,
  305. sex: sendData.gender
  306. };
  307. that.$Request.postJson('/app/Login/insertWxRiderUser', postData).then(res => {
  308. console.log(res);
  309. if (res.code === 0) {
  310. uni.hideLoading();
  311. that.$queue.setData('token', res.token);
  312. that.$queue.setData('userId', res.user.userId);
  313. that.$queue.setData("avatar", res.user.avatar ? res.user.avatar : '/static/img/logo.png');
  314. that.$queue.setData("userName", res.user.userName);
  315. that.$queue.setData("invitationCode", res.user.invitationCode);
  316. that.$queue.setData("inviterCode", res.user.inviterCode);
  317. that.$queue.setData("sex", res.user.sex);
  318. that.$queue.setData("phone", res.user.phone);
  319. that.$queue.setData("platform", res.user.platform);
  320. that.$queue.setData("zhiFuBao", res.user.zhiFuBao);
  321. that.$queue.setData("zhiFuBaoName", res.user.zhiFuBaoName);
  322. that.$queue.setData("checkCertification", res.user.checkCertification);
  323. uni.navigateBack();
  324. // that.initUserInfo(res.user.userId, res.token);
  325. } else {
  326. uni.hideLoading();
  327. uni.showModal({
  328. showCancel: false,
  329. title: '登录失败',
  330. content: res.msg
  331. });
  332. }
  333. });
  334. },
  335. login(userName, avatarUrl, sex) {
  336. console.log(userName, avatarUrl, sex, '*********')
  337. let that = this;
  338. uni.showLoading({
  339. title: '登录中...'
  340. });
  341. // 1.wx获取登录用户code
  342. uni.login({
  343. provider: 'weixin',
  344. success: function(loginRes) {
  345. var getParams = {
  346. code: loginRes.code,
  347. userType: 2
  348. };
  349. that.$Request.getT('/app/Login/wxRiderLogin', getParams).then(res => {
  350. console.log(res, '登录');
  351. if (res.code == 0) {
  352. that.$queue.setData('openid', res.data.open_id);
  353. that.$queue.setData('unionid', res.data.unionid);
  354. that.sessionkey = res.data.session_key;
  355. that.flag = res.data.flag;
  356. console.log(res.data.unionid, res.data.session_key);
  357. uni.hideLoading();
  358. //非第一次授权获取用户信息
  359. //获取用户信息后向调用信息更新方法
  360. that.$queue.setData("sessionkey", res.data.session_key);
  361. var userByinvitationId = that.$queue.getData('userByinvitationId');
  362. if (userByinvitationId) {
  363. that.userByinvitationId = userByinvitationId;
  364. } else {
  365. that.userByinvitationId = that.$queue.getInvitation();
  366. }
  367. var sendData = {
  368. openid: that.$queue.getData('openid'),
  369. unionid: that.$queue.getData('unionid'),
  370. userName: userName,
  371. imageUrl: avatarUrl,
  372. gender: sex, //性别
  373. invitation: that.userByinvitationId //别人登录进来携带你的邀请码
  374. };
  375. that.sendDataList = sendData;
  376. if (res.data.isPhone == 2) {
  377. that.weixinPhone = true
  378. } else {
  379. that.getWeixinInfo(sendData);
  380. }
  381. }
  382. });
  383. }
  384. });
  385. },
  386. }
  387. }
  388. </script>
  389. <style lang='scss'>
  390. .headers {
  391. text-align: center;
  392. }
  393. .headers>image {
  394. width: 400upx;
  395. height: 400upx;
  396. }
  397. .footer {
  398. /* // padding-left: 140upx; */
  399. justify-content: center;
  400. margin-top: 32upx;
  401. font-size: 24upx;
  402. color: #666666;
  403. display: flex;
  404. text-align: center;
  405. align-items: center;
  406. }
  407. page {
  408. background: #fff;
  409. }
  410. .send-msg {
  411. border-radius: 30px;
  412. color: black;
  413. background: white;
  414. height: 30px;
  415. font-size: 14px;
  416. line-height: 30px;
  417. }
  418. .container {
  419. top: 0;
  420. padding-top: 32upx;
  421. position: relative;
  422. width: 100%;
  423. height: 100%;
  424. overflow: hidden;
  425. background: #fff;
  426. }
  427. .mp_wxBox {}
  428. .headers {
  429. margin: 35% auto 50rpx;
  430. text-align: center;
  431. border-radius: 60rpx;
  432. width: 650rpx;
  433. height: 300rpx;
  434. line-height: 450rpx;
  435. }
  436. .headers image {
  437. width: 300rpx;
  438. height: 300rpx;
  439. }
  440. .content {
  441. text-align: center;
  442. }
  443. .headers text {
  444. display: block;
  445. color: #9d9d9d;
  446. /* // margin-top: 40rpx; */
  447. }
  448. .bottom {
  449. line-height: 80upx;
  450. border-radius: 80upx;
  451. margin: 50rpx;
  452. height: 80upx;
  453. font-size: 35rpx;
  454. }
  455. .welcome {
  456. position: relative;
  457. left: 30px;
  458. top: -55px;
  459. font-size: 28px;
  460. color: #555;
  461. text-shadow: 1px 0px 1px rgba(0, 0, 0, 0.3);
  462. }
  463. .input-content {
  464. padding: 0 20px;
  465. }
  466. .left-top-sign {
  467. font-size: 80px;
  468. /* color: $page-color-base; */
  469. position: relative;
  470. }
  471. .right-top-sign {
  472. position: absolute;
  473. top: 40px;
  474. right: -15px;
  475. z-index: 95;
  476. }
  477. .right-top-sign:before,
  478. .right-top-sign:after {
  479. display: block;
  480. content: '';
  481. width: 20px;
  482. height: 40px;
  483. background: #FF7F00;
  484. }
  485. .right-top-sign:before {
  486. transform: rotate(50deg);
  487. border-radius: 0 50px 0 0;
  488. }
  489. .right-top-sign:after {
  490. position: absolute;
  491. right: -198px;
  492. top: 0;
  493. transform: rotate(-50deg);
  494. border-radius: 50px 0 0 0;
  495. /* background: pink; */
  496. }
  497. /* ````` */
  498. .login {
  499. width: 100%;
  500. }
  501. .login_type {
  502. width: 90%;
  503. margin: 0 auto;
  504. margin-top: 50rpx;
  505. margin-bottom: 135rpx;
  506. }
  507. .type_name {
  508. font-size: 38rpx;
  509. font-weight: bold;
  510. letter-spacing: 2rpx;
  511. }
  512. .type_tit {
  513. color: #999999;
  514. font-size: 21rpx;
  515. margin-top: 10rpx;
  516. }
  517. /* 登录 */
  518. .login_input {
  519. width: 80%;
  520. margin: 0 auto;
  521. }
  522. .numbers {
  523. height: 120rpx;
  524. }
  525. .u-input__input {
  526. border-bottom: 1rpx solid #E6E6E6 !important;
  527. }
  528. .submit {
  529. width: 100%;
  530. height: 90rpx;
  531. background: #FF7F00;
  532. color: white;
  533. text-align: center;
  534. line-height: 90rpx;
  535. border-radius: 20rpx;
  536. margin-top: 75rpx;
  537. }
  538. .submit_bottom {
  539. display: flex;
  540. height: 70rpx;
  541. }
  542. .bottom_left {
  543. flex: 1;
  544. color: #999999;
  545. font-size: 26rpx;
  546. display: flex;
  547. justify-content: left;
  548. align-items: center;
  549. }
  550. .bottom_right {
  551. flex: 1;
  552. color: #FF7F00;
  553. display: flex;
  554. justify-content: flex-end;
  555. align-items: center;
  556. }
  557. .wrapper {
  558. position: relative;
  559. z-index: 90;
  560. background: #fff;
  561. padding-bottom: 20px;
  562. }
  563. </style>