login.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. <template>
  2. <view class="container">
  3. <!-- <image @click="navBack" src="../../static/images/index/close.png" style="width: 32upx;height: 32upx;margin-left: 46upx;"></image> -->
  4. <!-- 小程序状态下登录 -->
  5. <!-- #ifdef MP-WEIXIN -->
  6. <view class="mp_wxBox">
  7. <view>
  8. <view class="headers">
  9. <image src="https://mxys.chuanghai-tech.com/wmfile/20250814/fff4dc5d02ea4af881db9685f2e1e61d.png" style="border-radius: 50%;"></image>
  10. </view>
  11. <view class="content">
  12. <view>申请获取以下权限</view>
  13. <text>获得你的公开信息(昵称,头像、地区等)</text>
  14. </view>
  15. <button v-show="weixinPhone" style="background: #FFAF5E;color: #333333;" class="bottom"
  16. open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
  17. 授权手机号
  18. </button>
  19. <button v-show="!weixinPhone" style="background: #FFAF5E;color: #333333;" class='bottom'
  20. bindtap="getUserProfile" @tap="wxGetUserInfo">
  21. 授权登录
  22. </button>
  23. </view>
  24. </view>
  25. <view style="text-align: center;">
  26. <view class="footers">
  27. <image v-if="showAgree" @tap="isShowAgree" src="https://mxys.chuanghai-tech.com/wmfile/20250814/a09a09f05f754d52a9a3d1a07fc063fb.png"
  28. style="width: 36upx;height: 36upx;"></image>
  29. <image v-else @tap="isShowAgree" src="https://mxys.chuanghai-tech.com/wmfile/20250814/0a89fc9a633e435aa4201c1e30045b67.png"
  30. style="width: 36upx;height: 36upx;"></image>
  31. <text style="margin-left: 10upx;margin-right: 0;">同意</text>
  32. <navigator url="/my/setting/mimi" open-type="navigate">《隐私政策》</navigator>和
  33. <navigator url="/my/setting/xieyi" open-type="navigate">《用户服务协议》</navigator>
  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: 40upx;margin-top: 104upx;margin-right: 40upx;">
  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">
  53. <image v-if="showAgree" @tap="isShowAgree" src="https://mxys.chuanghai-tech.com/wmfile/20250814/a09a09f05f754d52a9a3d1a07fc063fb.png"
  54. style="width: 36upx;height: 36upx;"></image>
  55. <image v-else @tap="isShowAgree" src="https://mxys.chuanghai-tech.com/wmfile/20250814/0a89fc9a633e435aa4201c1e30045b67.png"
  56. style="width: 36upx;height: 36upx;"></image>
  57. <text style="margin-left: 10upx;margin-right: 0;">同意</text>
  58. <navigator url="/my/setting/mimi" open-type="navigate">《隐私政策》</navigator>和
  59. <navigator url="/my/setting/xieyi" open-type="navigate">《用户服务协议》</navigator>
  60. </view>
  61. <wButton text="登 录" :rotate="isRotate" @click.native="startReg()"></wButton>
  62. </view>
  63. <!-- #endif -->
  64. </view>
  65. </template>
  66. <script>
  67. import wInput from '@/components/watch-login/watch-input.vue' //input
  68. import wButton from '@/components/watch-login/watch-button.vue' //button
  69. export default {
  70. components: {
  71. wInput,
  72. wButton,
  73. },
  74. data() {
  75. return {
  76. mobile: '',
  77. code: '',
  78. weixinLogin: false,
  79. sending: false,
  80. sendTime: '获取验证码',
  81. count: 60,
  82. weixinPhone: false,
  83. sendDataList: {},
  84. sessionkey: '',
  85. phoneNum: false,
  86. sysphone: 1,
  87. phoneData: '',
  88. verCode: '',
  89. invitation: '',
  90. show: '',
  91. showAgree: false, //协议是否选择
  92. isRotate: false, //是否加载旋转
  93. platform: "h5",
  94. };
  95. },
  96. onLoad(e) {
  97. if (e.inviterCode) {
  98. this.$queue.setData('inviterCode', e.inviterCode);
  99. }
  100. //微信登录开启
  101. this.$Request.getT('/app/common/type/53').then(res => {
  102. if (res.code == 0) {
  103. if (res.data && res.data.value && res.data.value == '是') {
  104. // this.weixinLogin = true;
  105. }
  106. }
  107. });
  108. this.$Request.getT('/app/common/type/188').then(res => {
  109. if (res.code == 0) {
  110. if (res.data && res.data.value && res.data.value == '是') {
  111. this.phoneNum = true;
  112. }
  113. }
  114. });
  115. },
  116. methods: {
  117. isShowAgree() {
  118. this.showAgree = !this.showAgree
  119. },
  120. startReg() {
  121. var that = this
  122. uni.getSystemInfo({
  123. success: function(res) {
  124. console.log(res.model);
  125. if (res.model == 'iPhone') {
  126. that.sysphone = 2
  127. } else if (res.model != 'iPhone') {
  128. that.sysphone = 1
  129. }
  130. }
  131. });
  132. //注册
  133. if (that.isRotate) {
  134. //判断是否加载中,避免重复点击请求
  135. return false;
  136. }
  137. if (!that.phoneData) {
  138. uni.showToast({
  139. icon: 'none',
  140. position: 'bottom',
  141. title: '请输入手机号'
  142. });
  143. return false;
  144. }
  145. if (that.phoneData.length != 11) {
  146. uni.showToast({
  147. icon: 'none',
  148. position: 'bottom',
  149. title: '手机号不正确'
  150. });
  151. return false;
  152. }
  153. if (that.verCode.length != 6) {
  154. uni.showToast({
  155. icon: 'none',
  156. position: 'bottom',
  157. title: '验证码不正确'
  158. });
  159. return false;
  160. }
  161. if (that.showAgree == false) {
  162. uni.showToast({
  163. icon: 'none',
  164. position: 'bottom',
  165. title: '请阅读并同意《隐私政策》和《用户服务协议》'
  166. });
  167. return false;
  168. }
  169. that.isRotate = true;
  170. var openid = this.$queue.getData("openid") ? this.$queue.getData("openid") : '';
  171. let data = {
  172. phone: that.phoneData,
  173. msg: that.verCode,
  174. platform: that.platform,
  175. sysPhone: that.sysphone,
  176. openId: openid,
  177. userType: 1
  178. }
  179. that.$Request.post("/app/Login/registerCode", data).then(res => {
  180. console.log(res)
  181. if (res.code == 0) {
  182. console.log(res.token)
  183. this.$queue.setData("token", res.token);
  184. this.$queue.setData("userId", res.user.userId);
  185. this.$queue.setData("phone", res.user.phone);
  186. uni.setStorageSync('userName', res.user.userName)
  187. uni.setStorageSync('avatar', res.user.avatar)
  188. uni.setStorageSync('phone', res.user.phone)
  189. uni.setStorageSync('sex', res.user.sex)
  190. uni.setStorageSync('userId', res.user.userId)
  191. uni.setStorageSync('wxCode', res.user.wxCode)
  192. uni.setStorageSync('wxQrCode', res.user.wxQrCode)
  193. uni.setStorageSync('zhiFuBao', res.user.zhiFuBao)
  194. uni.setStorageSync('zhiFuBaoName', res.user.zhiFuBaoName)
  195. uni.switchTab({
  196. url: '/pages/index/index'
  197. })
  198. return false;
  199. } else {
  200. that.isRotate = false;
  201. uni.hideLoading();
  202. uni.showModal({
  203. showCancel: false,
  204. title: '登录失败',
  205. content: res.msg,
  206. });
  207. }
  208. });
  209. },
  210. sendMsg() {
  211. const {
  212. phoneData
  213. } = this;
  214. if (!phoneData) {
  215. this.$queue.showToast("请输入手机号");
  216. } else if (phoneData.length !== 11) {
  217. this.$queue.showToast("请输入正确的手机号");
  218. } else {
  219. this.$queue.showLoading("正在发送验证码...");
  220. this.$Request.getT("/app/Login/sendMsg/" + phoneData + "/login").then(res => {
  221. console.log(res)
  222. if (res.code == 0) {
  223. if (res.data === 'register') {
  224. this.show = true;
  225. }
  226. this.sending = true;
  227. this.$queue.showToast('验证码发送成功请注意查收');
  228. this.$refs.runCode.$emit('runCode');
  229. uni.hideLoading();
  230. } else {
  231. uni.hideLoading();
  232. uni.showModal({
  233. showCancel: false,
  234. title: '短信发送失败',
  235. content: res.msg ? res.msg : '请一分钟后再获取验证码',
  236. });
  237. }
  238. });
  239. }
  240. },
  241. wxGetUserInfo(e) {
  242. if (this.showAgree == false) {
  243. uni.showToast({
  244. icon: 'none',
  245. position: 'bottom',
  246. title: '请阅读并同意《隐私政策》和《用户服务协议》'
  247. });
  248. return false;
  249. }
  250. wx.getUserProfile({
  251. desc: '业务需要',
  252. success: infoRes => {
  253. console.log("infoRes.encryptedData__________:" + JSON.stringify(infoRes.userInfo))
  254. let nickName = infoRes.userInfo.nickName; //昵称
  255. let avatarUrl = infoRes.userInfo.avatarUrl; //头像
  256. let sex = infoRes.userInfo.gender; //性别
  257. try {
  258. this.$queue.showLoading('正在登录中...');
  259. this.login(nickName, avatarUrl, sex);
  260. } catch (e) {}
  261. }
  262. })
  263. },
  264. //登录
  265. login(nickName, avatarUrl, sex) {
  266. let that = this;
  267. // 1.wx获取登录用户code
  268. uni.login({
  269. provider: 'weixin',
  270. success: function(loginRes) {
  271. console.log(loginRes, '************')
  272. let data = {
  273. code: loginRes.code,
  274. }
  275. that.$Request.get('/app/Login/wxLogin', data).then(res => {
  276. if (res.code == 0) {
  277. uni.hideLoading()
  278. uni.setStorageSync('openId', res.data.open_id)
  279. uni.setStorageSync('unionId', res.data.unionId)
  280. that.sessionkey = res.data.session_key;
  281. let inviterCode = '';
  282. if (uni.getStorageSync('inviterCode')) {
  283. inviterCode = uni.getStorageSync('inviterCode')
  284. }
  285. let sendData = {
  286. openId: uni.getStorageSync('openId'),
  287. unionId: uni.getStorageSync('unionId'),
  288. userName: nickName,
  289. avatar: avatarUrl,
  290. sex: sex, //性别
  291. inviterCode: inviterCode //别人登录进来携带你的邀请码
  292. };
  293. that.sendDataList = sendData;
  294. // 第一次登录获取手机号
  295. console.log(that.phoneNum)
  296. if (res.data.isPhone == '2' && that.phoneNum) {
  297. that.weixinPhone = true;
  298. uni.showToast({
  299. icon: 'none',
  300. position: 'bottom',
  301. title: '请再次点击授权手机号'
  302. });
  303. } else {
  304. that.getWeixinInfo(sendData);
  305. }
  306. } else {
  307. uni.showToast({
  308. icon: 'none',
  309. title: res.msg,
  310. duration: 2000
  311. });
  312. console.log(res, '失败')
  313. }
  314. })
  315. }
  316. });
  317. },
  318. //小程序微信登录后获取手机号
  319. getPhoneNumber: function(e) {
  320. if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
  321. console.log('用户拒绝提供手机号');
  322. } else {
  323. console.log('用户同意提供手机号');
  324. console.log(e)
  325. this.setPhoneByInsert(e.detail.encryptedData, e.detail.iv);
  326. }
  327. },
  328. //小程序微信登录后获取手机号
  329. setPhoneByInsert(decryptData, iv) {
  330. let data = {
  331. decryptData: decryptData,
  332. key: this.sessionkey,
  333. iv: iv
  334. };
  335. this.$Request.postJson('/app/Login/selectPhone', data).then(res => {
  336. if (res.code == 0) {
  337. this.phone = res.data.phoneNumber;
  338. this.getWeixinInfo(this.sendDataList);
  339. } else {
  340. uni.showToast({
  341. title: res.msg,
  342. icon: 'none',
  343. duration: 2000
  344. });
  345. }
  346. })
  347. },
  348. //获取个人信息
  349. getWeixinInfo(sendData) {
  350. let that = this;
  351. uni.showLoading({
  352. title: '登录中...',
  353. mask: true, // 是否显示透明蒙层,防止触摸穿透
  354. });
  355. let postData = {
  356. openId: sendData.openId, //小程序openId
  357. unionId: sendData.unionId, //unionId
  358. userName: sendData.userName, //微信名称
  359. avatar: sendData.avatar, //头像
  360. sex: sendData.sex, //性别
  361. phone: that.phone,
  362. inviterCode: sendData.inviterCode
  363. };
  364. that.$Request.postJson('/app/Login/insertWxUser', postData).then(res => {
  365. uni.hideLoading();
  366. if (res.code == 0) {
  367. uni.setStorageSync('token', res.token)
  368. uni.setStorageSync('adminUserId', res.user.adminUserId)
  369. uni.setStorageSync('userName', res.user.userName)
  370. uni.setStorageSync('avatar', res.user.avatar)
  371. uni.setStorageSync('phone', res.user.phone)
  372. uni.setStorageSync('invitationCode', res.user.invitationCode)
  373. uni.setStorageSync('sex', res.user.sex)
  374. uni.setStorageSync('userId', res.user.userId)
  375. uni.setStorageSync('openId', res.user.openId)
  376. uni.setStorageSync('zhiFuBao', res.user.zhiFuBao)
  377. uni.setStorageSync('zhiFuBaoName', res.user.zhiFuBaoName)
  378. // var pages = getCurrentPages();
  379. // var currPage = pages[pages.length - 1] //当前页面
  380. // var prePage = pages[pages.length - 2] //上一个页面
  381. //调用上一页拉取数据的方法
  382. // console.log(prePage.route)
  383. // if (prePage.route == "pages/my/index") {
  384. // prePage.$vm.getUserInfo()
  385. // }
  386. uni.navigateBack();
  387. } else {
  388. uni.showModal({
  389. showCancel: false,
  390. title: '登录失败',
  391. content: res.msg,
  392. });
  393. }
  394. })
  395. },
  396. weixinLo() {
  397. let that = this;
  398. uni.login({
  399. provider: 'weixin',
  400. success: function(loginRes) {
  401. that.$queue.showLoading('正在登录中...');
  402. console.error(loginRes.authResult);
  403. that.$queue.setData('weixinToken', loginRes.authResult.access_token);
  404. that.$queue.setData('unionid', loginRes.authResult.unionid);
  405. that.$queue.setData('weixinOpenid', loginRes.authResult.openid);
  406. that.$Request.postJson('/app/login/loginApp', {
  407. token: loginRes.authResult.access_token,
  408. unionid: loginRes.authResult.unionid,
  409. openid: loginRes.authResult.openid
  410. }).then(res => {
  411. console.log(JSON.stringify(res))
  412. if (res.code === 0) {
  413. if (uni.getSystemInfoSync().platform == "android") {
  414. let clientid = plus.push.getClientInfo().clientid;
  415. that.$Request.postT('/app/login/updateClientId?clientId=' +
  416. clientid + '&userId=' + res.userId).then(res => {
  417. });
  418. }
  419. that.$queue.setData("token", res.uuid);
  420. that.$queue.setData("userId", res.userId);
  421. that.getUserInfo(res.userId, res.token);
  422. } else {
  423. uni.hideLoading();
  424. uni.navigateTo({
  425. url: '/pages/public/wxmobile'
  426. });
  427. }
  428. });
  429. }
  430. });
  431. },
  432. forget() {
  433. uni.navigateTo({
  434. url: '/pages/public/pwd'
  435. });
  436. },
  437. register() {
  438. uni.navigateTo({
  439. url: '/pages/public/loginphone'
  440. });
  441. },
  442. inputChange(e) {
  443. const key = e.currentTarget.dataset.key;
  444. this[key] = e.detail.value;
  445. },
  446. navBack() {
  447. uni.navigateBack();
  448. },
  449. getUserInfo(userId, token) {
  450. this.$Request.postJson('/app/selectUserById?userId=' + userId).then(res => {
  451. if (res.code === 0) {
  452. this.$queue.setData('token', res.data.uuid);
  453. this.$queue.setData('image_url', res.data.imageUrl ? res.data.imageUrl :
  454. '/static/img/common/logo.jpg');
  455. this.$queue.setData('inviterCode', res.data.inviterCode);
  456. this.$queue.setData('invitationCode', res.data.invitationCode);
  457. this.$queue.setData('grade', res.data.grade);
  458. this.$queue.setData('mobile', res.data.mobile);
  459. this.$queue.setData('isInvitation', res.data.isInvitation);
  460. this.$queue.setData('nickName', res.data.nickName ? res.data.nickName : res.data.phone);
  461. this.$queue.setData('gender', parseInt(res.data.gender));
  462. uni.switchTab({
  463. url: '/pages/index/index'
  464. });
  465. } else {
  466. uni.showModal({
  467. showCancel: false,
  468. title: '登录失败',
  469. content: res.msg
  470. });
  471. this.$queue.logout();
  472. }
  473. uni.hideLoading();
  474. });
  475. }
  476. }
  477. };
  478. </script>
  479. <style lang="scss">
  480. page {
  481. height: 100%;
  482. background: #FFF;
  483. }
  484. .footers {
  485. padding-left: 140upx;
  486. margin-top: 32upx;
  487. font-size: 24upx;
  488. color: #666666;
  489. text-align: center;
  490. display: flex;
  491. }
  492. .confirm-btn-weixin {
  493. width: 200px;
  494. height: 42px;
  495. line-height: 42px;
  496. border-radius: 30px;
  497. margin-top: 40upx;
  498. background: -moz-linear-gradient(left, #f15b6c, #e10a07 100%);
  499. background: -webkit-gradient(linear, left top, left right, color-stop(0, #f15b6c), color-stop(100%, #e10a07));
  500. background: -webkit-linear-gradient(left, #f15b6c 0, #e10a07 100%);
  501. background: -o-linear-gradient(left, #f15b6c 0, #e10a07 100%);
  502. background: -ms-linear-gradient(left, #f15b6c 0, #e10a07 100%);
  503. background: linear-gradient(to left, #f15b6c 0, #e10a07 100%);
  504. color: #fff;
  505. font-size: 32upx;
  506. &:after {
  507. border-radius: 60px;
  508. }
  509. }
  510. .confirm-btn {
  511. width: 200px;
  512. height: 42px;
  513. line-height: 42px;
  514. border-radius: 30px;
  515. margin-top: 300upx;
  516. background: -moz-linear-gradient(left, #f15b6c, #e10a07 100%);
  517. background: -webkit-gradient(linear, left top, left right, color-stop(0, #f15b6c), color-stop(100%, #e10a07));
  518. background: -webkit-linear-gradient(left, #f15b6c 0, #e10a07 100%);
  519. background: -o-linear-gradient(left, #f15b6c 0, #e10a07 100%);
  520. background: -ms-linear-gradient(left, #f15b6c 0, #e10a07 100%);
  521. background: linear-gradient(to left, #f15b6c 0, #e10a07 100%);
  522. color: #fff;
  523. font-size: 32upx;
  524. &:after {
  525. border-radius: 60px;
  526. }
  527. }
  528. .headers {
  529. text-align: center;
  530. }
  531. .headers>image {
  532. width: 400upx;
  533. height: 400upx;
  534. }
  535. .footer {
  536. padding-left: 60upx;
  537. margin-top: 48upx;
  538. font-size: 24upx;
  539. color: #666666;
  540. text-align: center;
  541. display: flex;
  542. }
  543. page {
  544. background: #fff;
  545. }
  546. .send-msg {
  547. border-radius: 30px;
  548. color: black;
  549. background: white;
  550. height: 30px;
  551. font-size: 14px;
  552. line-height: 30px;
  553. }
  554. .container {
  555. top: 0;
  556. padding-top: 32upx;
  557. position: relative;
  558. width: 100%;
  559. height: 100%;
  560. overflow: hidden;
  561. // background: #111224;
  562. // color: #FFF;
  563. .mp_wxBox {
  564. .headers {
  565. margin: 35% auto 50rpx;
  566. text-align: center;
  567. border-radius: 60rpx;
  568. width: 650rpx;
  569. height: 300rpx;
  570. line-height: 450rpx;
  571. image {
  572. width: 300rpx;
  573. height: 300rpx;
  574. }
  575. }
  576. .content {
  577. text-align: center;
  578. }
  579. text {
  580. display: block;
  581. color: #9d9d9d;
  582. margin-top: 40rpx;
  583. }
  584. .bottom {
  585. line-height: 80upx;
  586. border-radius: 80upx;
  587. margin: 70rpx 50rpx;
  588. height: 80upx;
  589. font-size: 35rpx;
  590. }
  591. }
  592. }
  593. .wrapper {
  594. position: relative;
  595. z-index: 90;
  596. background: #fff;
  597. padding-bottom: 20px;
  598. }
  599. .input-content {
  600. padding: 0 20px;
  601. }
  602. .confirm-btn {
  603. width: 300px;
  604. height: 42px;
  605. line-height: 42px;
  606. border-radius: 30px;
  607. margin-top: 40px;
  608. background: linear-gradient(to left, #3f5ecb 0, #5074FF 100%);
  609. color: #fff;
  610. // font-size: $font-lg;
  611. &:after {
  612. border-radius: 60px;
  613. }
  614. }
  615. </style>