login.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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. mask: true, // 是否显示透明蒙层,防止触摸穿透
  297. });
  298. var postData = {
  299. riderOpenId: sendData.openid, //小程序openid
  300. platform: '小程序', //unionId
  301. userName: sendData.userName, //微信名称
  302. avatar: sendData.imageUrl, //头像
  303. userId: '', //性别
  304. phone: that.phone,
  305. inviterCode: sendData.invitation,
  306. sex: sendData.gender
  307. };
  308. that.$Request.postJson('/app/Login/insertWxRiderUser', postData).then(res => {
  309. console.log(res);
  310. if (res.code === 0) {
  311. uni.hideLoading();
  312. that.$queue.setData('token', res.token);
  313. that.$queue.setData('userId', res.user.userId);
  314. that.$queue.setData("avatar", res.user.avatar ? res.user.avatar : '/static/img/logo.png');
  315. that.$queue.setData("userName", res.user.userName);
  316. that.$queue.setData("invitationCode", res.user.invitationCode);
  317. that.$queue.setData("inviterCode", res.user.inviterCode);
  318. that.$queue.setData("sex", res.user.sex);
  319. that.$queue.setData("phone", res.user.phone);
  320. that.$queue.setData("platform", res.user.platform);
  321. that.$queue.setData("zhiFuBao", res.user.zhiFuBao);
  322. that.$queue.setData("zhiFuBaoName", res.user.zhiFuBaoName);
  323. that.$queue.setData("checkCertification", res.user.checkCertification);
  324. uni.navigateBack();
  325. // that.initUserInfo(res.user.userId, res.token);
  326. } else {
  327. uni.hideLoading();
  328. uni.showModal({
  329. showCancel: false,
  330. title: '登录失败',
  331. content: res.msg
  332. });
  333. }
  334. });
  335. },
  336. login(userName, avatarUrl, sex) {
  337. console.log(userName, avatarUrl, sex, '*********')
  338. let that = this;
  339. uni.showLoading({
  340. title: '登录中...',
  341. mask: true, // 是否显示透明蒙层,防止触摸穿透
  342. });
  343. // 1.wx获取登录用户code
  344. uni.login({
  345. provider: 'weixin',
  346. success: function(loginRes) {
  347. var getParams = {
  348. code: loginRes.code,
  349. userType: 2
  350. };
  351. that.$Request.getT('/app/Login/wxRiderLogin', getParams).then(res => {
  352. console.log(res, '登录');
  353. if (res.code == 0) {
  354. that.$queue.setData('openid', res.data.open_id);
  355. that.$queue.setData('unionid', res.data.unionid);
  356. that.sessionkey = res.data.session_key;
  357. that.flag = res.data.flag;
  358. console.log(res.data.unionid, res.data.session_key);
  359. uni.hideLoading();
  360. //非第一次授权获取用户信息
  361. //获取用户信息后向调用信息更新方法
  362. that.$queue.setData("sessionkey", res.data.session_key);
  363. var userByinvitationId = that.$queue.getData('userByinvitationId');
  364. if (userByinvitationId) {
  365. that.userByinvitationId = userByinvitationId;
  366. } else {
  367. that.userByinvitationId = that.$queue.getInvitation();
  368. }
  369. var sendData = {
  370. openid: that.$queue.getData('openid'),
  371. unionid: that.$queue.getData('unionid'),
  372. userName: userName,
  373. imageUrl: avatarUrl,
  374. gender: sex, //性别
  375. invitation: that.userByinvitationId //别人登录进来携带你的邀请码
  376. };
  377. that.sendDataList = sendData;
  378. if (res.data.isPhone == 2) {
  379. that.weixinPhone = true
  380. } else {
  381. that.getWeixinInfo(sendData);
  382. }
  383. }
  384. });
  385. }
  386. });
  387. },
  388. }
  389. }
  390. </script>
  391. <style lang='scss'>
  392. .headers {
  393. text-align: center;
  394. }
  395. .headers>image {
  396. width: 400upx;
  397. height: 400upx;
  398. }
  399. .footer {
  400. /* // padding-left: 140upx; */
  401. justify-content: center;
  402. margin-top: 32upx;
  403. font-size: 24upx;
  404. color: #666666;
  405. display: flex;
  406. text-align: center;
  407. align-items: center;
  408. }
  409. page {
  410. background: #fff;
  411. }
  412. .send-msg {
  413. border-radius: 30px;
  414. color: black;
  415. background: white;
  416. height: 30px;
  417. font-size: 14px;
  418. line-height: 30px;
  419. }
  420. .container {
  421. top: 0;
  422. padding-top: 32upx;
  423. position: relative;
  424. width: 100%;
  425. height: 100%;
  426. overflow: hidden;
  427. background: #fff;
  428. }
  429. .mp_wxBox {}
  430. .headers {
  431. margin: 35% auto 50rpx;
  432. text-align: center;
  433. border-radius: 60rpx;
  434. width: 650rpx;
  435. height: 300rpx;
  436. line-height: 450rpx;
  437. }
  438. .headers image {
  439. width: 300rpx;
  440. height: 300rpx;
  441. }
  442. .content {
  443. text-align: center;
  444. }
  445. .headers text {
  446. display: block;
  447. color: #9d9d9d;
  448. /* // margin-top: 40rpx; */
  449. }
  450. .bottom {
  451. line-height: 80upx;
  452. border-radius: 80upx;
  453. margin: 50rpx;
  454. height: 80upx;
  455. font-size: 35rpx;
  456. }
  457. .welcome {
  458. position: relative;
  459. left: 30px;
  460. top: -55px;
  461. font-size: 28px;
  462. color: #555;
  463. text-shadow: 1px 0px 1px rgba(0, 0, 0, 0.3);
  464. }
  465. .input-content {
  466. padding: 0 20px;
  467. }
  468. .left-top-sign {
  469. font-size: 80px;
  470. /* color: $page-color-base; */
  471. position: relative;
  472. }
  473. .right-top-sign {
  474. position: absolute;
  475. top: 40px;
  476. right: -15px;
  477. z-index: 95;
  478. }
  479. .right-top-sign:before,
  480. .right-top-sign:after {
  481. display: block;
  482. content: '';
  483. width: 20px;
  484. height: 40px;
  485. background: #FF7F00;
  486. }
  487. .right-top-sign:before {
  488. transform: rotate(50deg);
  489. border-radius: 0 50px 0 0;
  490. }
  491. .right-top-sign:after {
  492. position: absolute;
  493. right: -198px;
  494. top: 0;
  495. transform: rotate(-50deg);
  496. border-radius: 50px 0 0 0;
  497. /* background: pink; */
  498. }
  499. /* ````` */
  500. .login {
  501. width: 100%;
  502. }
  503. .login_type {
  504. width: 90%;
  505. margin: 0 auto;
  506. margin-top: 50rpx;
  507. margin-bottom: 135rpx;
  508. }
  509. .type_name {
  510. font-size: 38rpx;
  511. font-weight: bold;
  512. letter-spacing: 2rpx;
  513. }
  514. .type_tit {
  515. color: #999999;
  516. font-size: 21rpx;
  517. margin-top: 10rpx;
  518. }
  519. /* 登录 */
  520. .login_input {
  521. width: 80%;
  522. margin: 0 auto;
  523. }
  524. .numbers {
  525. height: 120rpx;
  526. }
  527. .u-input__input {
  528. border-bottom: 1rpx solid #E6E6E6 !important;
  529. }
  530. .submit {
  531. width: 100%;
  532. height: 90rpx;
  533. background: #FF7F00;
  534. color: white;
  535. text-align: center;
  536. line-height: 90rpx;
  537. border-radius: 20rpx;
  538. margin-top: 75rpx;
  539. }
  540. .submit_bottom {
  541. display: flex;
  542. height: 70rpx;
  543. }
  544. .bottom_left {
  545. flex: 1;
  546. color: #999999;
  547. font-size: 26rpx;
  548. display: flex;
  549. justify-content: left;
  550. align-items: center;
  551. }
  552. .bottom_right {
  553. flex: 1;
  554. color: #FF7F00;
  555. display: flex;
  556. justify-content: flex-end;
  557. align-items: center;
  558. }
  559. .wrapper {
  560. position: relative;
  561. z-index: 90;
  562. background: #fff;
  563. padding-bottom: 20px;
  564. }
  565. </style>