login.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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. uni.showLoading({
  268. title: '登录中...',
  269. mask: true // 是否显示透明蒙层,防止触摸穿透
  270. })
  271. // 1.wx获取登录用户code
  272. uni.login({
  273. provider: 'weixin',
  274. success: function(loginRes) {
  275. console.log(loginRes, '************')
  276. let data = {
  277. code: loginRes.code,
  278. }
  279. that.$Request.get('/app/Login/wxLogin', data).then(res => {
  280. if (res.code == 0) {
  281. uni.hideLoading()
  282. uni.setStorageSync('openId', res.data.open_id)
  283. uni.setStorageSync('unionId', res.data.unionId)
  284. that.sessionkey = res.data.session_key;
  285. let inviterCode = '';
  286. if (uni.getStorageSync('inviterCode')) {
  287. inviterCode = uni.getStorageSync('inviterCode')
  288. }
  289. let sendData = {
  290. openId: uni.getStorageSync('openId'),
  291. unionId: uni.getStorageSync('unionId'),
  292. userName: nickName,
  293. avatar: avatarUrl,
  294. sex: sex, //性别
  295. inviterCode: inviterCode //别人登录进来携带你的邀请码
  296. };
  297. that.sendDataList = sendData;
  298. // 第一次登录获取手机号
  299. console.log(that.phoneNum)
  300. if (res.data.isPhone == '2' && that.phoneNum) {
  301. that.weixinPhone = true;
  302. uni.showToast({
  303. icon: 'none',
  304. position: 'bottom',
  305. title: '请再次点击授权手机号'
  306. });
  307. } else {
  308. that.getWeixinInfo(sendData);
  309. }
  310. } else {
  311. uni.showToast({
  312. icon: 'none',
  313. title: res.msg,
  314. duration: 2000
  315. });
  316. console.log(res, '失败')
  317. }
  318. })
  319. }
  320. });
  321. },
  322. //小程序微信登录后获取手机号
  323. getPhoneNumber: function(e) {
  324. if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
  325. console.log('用户拒绝提供手机号');
  326. } else {
  327. console.log('用户同意提供手机号');
  328. console.log(e)
  329. this.setPhoneByInsert(e.detail.encryptedData, e.detail.iv);
  330. }
  331. },
  332. //小程序微信登录后获取手机号
  333. setPhoneByInsert(decryptData, iv) {
  334. let data = {
  335. decryptData: decryptData,
  336. key: this.sessionkey,
  337. iv: iv
  338. };
  339. this.$Request.postJson('/app/Login/selectPhone', data).then(res => {
  340. if (res.code == 0) {
  341. this.phone = res.data.phoneNumber;
  342. this.getWeixinInfo(this.sendDataList);
  343. } else {
  344. uni.showToast({
  345. title: res.msg,
  346. icon: 'none',
  347. duration: 2000
  348. });
  349. }
  350. })
  351. },
  352. //获取个人信息
  353. getWeixinInfo(sendData) {
  354. let that = this;
  355. uni.showLoading({
  356. title: '登录中...',
  357. mask: true, // 是否显示透明蒙层,防止触摸穿透
  358. });
  359. let postData = {
  360. openId: sendData.openId, //小程序openId
  361. unionId: sendData.unionId, //unionId
  362. userName: sendData.userName, //微信名称
  363. avatar: sendData.avatar, //头像
  364. sex: sendData.sex, //性别
  365. phone: that.phone,
  366. inviterCode: sendData.inviterCode
  367. };
  368. that.$Request.postJson('/app/Login/insertWxUser', postData).then(res => {
  369. uni.hideLoading();
  370. if (res.code == 0) {
  371. uni.setStorageSync('token', res.token)
  372. uni.setStorageSync('adminUserId', res.user.adminUserId)
  373. uni.setStorageSync('userName', res.user.userName)
  374. uni.setStorageSync('avatar', res.user.avatar)
  375. uni.setStorageSync('phone', res.user.phone)
  376. uni.setStorageSync('invitationCode', res.user.invitationCode)
  377. uni.setStorageSync('sex', res.user.sex)
  378. uni.setStorageSync('userId', res.user.userId)
  379. uni.setStorageSync('openId', res.user.openId)
  380. uni.setStorageSync('zhiFuBao', res.user.zhiFuBao)
  381. uni.setStorageSync('zhiFuBaoName', res.user.zhiFuBaoName)
  382. // var pages = getCurrentPages();
  383. // var currPage = pages[pages.length - 1] //当前页面
  384. // var prePage = pages[pages.length - 2] //上一个页面
  385. //调用上一页拉取数据的方法
  386. // console.log(prePage.route)
  387. // if (prePage.route == "pages/my/index") {
  388. // prePage.$vm.getUserInfo()
  389. // }
  390. uni.navigateBack();
  391. } else {
  392. uni.showModal({
  393. showCancel: false,
  394. title: '登录失败',
  395. content: res.msg,
  396. });
  397. }
  398. })
  399. },
  400. weixinLo() {
  401. let that = this;
  402. uni.login({
  403. provider: 'weixin',
  404. success: function(loginRes) {
  405. that.$queue.showLoading('正在登录中...');
  406. console.error(loginRes.authResult);
  407. that.$queue.setData('weixinToken', loginRes.authResult.access_token);
  408. that.$queue.setData('unionid', loginRes.authResult.unionid);
  409. that.$queue.setData('weixinOpenid', loginRes.authResult.openid);
  410. that.$Request.postJson('/app/login/loginApp', {
  411. token: loginRes.authResult.access_token,
  412. unionid: loginRes.authResult.unionid,
  413. openid: loginRes.authResult.openid
  414. }).then(res => {
  415. console.log(JSON.stringify(res))
  416. if (res.code === 0) {
  417. if (uni.getSystemInfoSync().platform == "android") {
  418. let clientid = plus.push.getClientInfo().clientid;
  419. that.$Request.postT('/app/login/updateClientId?clientId=' +
  420. clientid + '&userId=' + res.userId).then(res => {
  421. });
  422. }
  423. that.$queue.setData("token", res.uuid);
  424. that.$queue.setData("userId", res.userId);
  425. that.getUserInfo(res.userId, res.token);
  426. } else {
  427. uni.hideLoading();
  428. uni.navigateTo({
  429. url: '/pages/public/wxmobile'
  430. });
  431. }
  432. });
  433. }
  434. });
  435. },
  436. forget() {
  437. uni.navigateTo({
  438. url: '/pages/public/pwd'
  439. });
  440. },
  441. register() {
  442. uni.navigateTo({
  443. url: '/pages/public/loginphone'
  444. });
  445. },
  446. inputChange(e) {
  447. const key = e.currentTarget.dataset.key;
  448. this[key] = e.detail.value;
  449. },
  450. navBack() {
  451. uni.navigateBack();
  452. },
  453. getUserInfo(userId, token) {
  454. this.$Request.postJson('/app/selectUserById?userId=' + userId).then(res => {
  455. if (res.code === 0) {
  456. this.$queue.setData('token', res.data.uuid);
  457. this.$queue.setData('image_url', res.data.imageUrl ? res.data.imageUrl :
  458. '/static/img/common/logo.jpg');
  459. this.$queue.setData('inviterCode', res.data.inviterCode);
  460. this.$queue.setData('invitationCode', res.data.invitationCode);
  461. this.$queue.setData('grade', res.data.grade);
  462. this.$queue.setData('mobile', res.data.mobile);
  463. this.$queue.setData('isInvitation', res.data.isInvitation);
  464. this.$queue.setData('nickName', res.data.nickName ? res.data.nickName : res.data.phone);
  465. this.$queue.setData('gender', parseInt(res.data.gender));
  466. uni.switchTab({
  467. url: '/pages/index/index'
  468. });
  469. } else {
  470. uni.showModal({
  471. showCancel: false,
  472. title: '登录失败',
  473. content: res.msg
  474. });
  475. this.$queue.logout();
  476. }
  477. uni.hideLoading();
  478. });
  479. }
  480. }
  481. };
  482. </script>
  483. <style lang="scss">
  484. page {
  485. height: 100%;
  486. background: #FFF;
  487. }
  488. .footers {
  489. padding-left: 140upx;
  490. margin-top: 32upx;
  491. font-size: 24upx;
  492. color: #666666;
  493. text-align: center;
  494. display: flex;
  495. }
  496. .confirm-btn-weixin {
  497. width: 200px;
  498. height: 42px;
  499. line-height: 42px;
  500. border-radius: 30px;
  501. margin-top: 40upx;
  502. background: -moz-linear-gradient(left, #f15b6c, #e10a07 100%);
  503. background: -webkit-gradient(linear, left top, left right, color-stop(0, #f15b6c), color-stop(100%, #e10a07));
  504. background: -webkit-linear-gradient(left, #f15b6c 0, #e10a07 100%);
  505. background: -o-linear-gradient(left, #f15b6c 0, #e10a07 100%);
  506. background: -ms-linear-gradient(left, #f15b6c 0, #e10a07 100%);
  507. background: linear-gradient(to left, #f15b6c 0, #e10a07 100%);
  508. color: #fff;
  509. font-size: 32upx;
  510. &:after {
  511. border-radius: 60px;
  512. }
  513. }
  514. .confirm-btn {
  515. width: 200px;
  516. height: 42px;
  517. line-height: 42px;
  518. border-radius: 30px;
  519. margin-top: 300upx;
  520. background: -moz-linear-gradient(left, #f15b6c, #e10a07 100%);
  521. background: -webkit-gradient(linear, left top, left right, color-stop(0, #f15b6c), color-stop(100%, #e10a07));
  522. background: -webkit-linear-gradient(left, #f15b6c 0, #e10a07 100%);
  523. background: -o-linear-gradient(left, #f15b6c 0, #e10a07 100%);
  524. background: -ms-linear-gradient(left, #f15b6c 0, #e10a07 100%);
  525. background: linear-gradient(to left, #f15b6c 0, #e10a07 100%);
  526. color: #fff;
  527. font-size: 32upx;
  528. &:after {
  529. border-radius: 60px;
  530. }
  531. }
  532. .headers {
  533. text-align: center;
  534. }
  535. .headers>image {
  536. width: 400upx;
  537. height: 400upx;
  538. }
  539. .footer {
  540. padding-left: 60upx;
  541. margin-top: 48upx;
  542. font-size: 24upx;
  543. color: #666666;
  544. text-align: center;
  545. display: flex;
  546. }
  547. page {
  548. background: #fff;
  549. }
  550. .send-msg {
  551. border-radius: 30px;
  552. color: black;
  553. background: white;
  554. height: 30px;
  555. font-size: 14px;
  556. line-height: 30px;
  557. }
  558. .container {
  559. top: 0;
  560. padding-top: 32upx;
  561. position: relative;
  562. width: 100%;
  563. height: 100%;
  564. overflow: hidden;
  565. // background: #111224;
  566. // color: #FFF;
  567. .mp_wxBox {
  568. .headers {
  569. margin: 35% auto 50rpx;
  570. text-align: center;
  571. border-radius: 60rpx;
  572. width: 650rpx;
  573. height: 300rpx;
  574. line-height: 450rpx;
  575. image {
  576. width: 300rpx;
  577. height: 300rpx;
  578. }
  579. }
  580. .content {
  581. text-align: center;
  582. }
  583. text {
  584. display: block;
  585. color: #9d9d9d;
  586. margin-top: 40rpx;
  587. }
  588. .bottom {
  589. line-height: 80upx;
  590. border-radius: 80upx;
  591. margin: 70rpx 50rpx;
  592. height: 80upx;
  593. font-size: 35rpx;
  594. }
  595. }
  596. }
  597. .wrapper {
  598. position: relative;
  599. z-index: 90;
  600. background: #fff;
  601. padding-bottom: 20px;
  602. }
  603. .input-content {
  604. padding: 0 20px;
  605. }
  606. .confirm-btn {
  607. width: 300px;
  608. height: 42px;
  609. line-height: 42px;
  610. border-radius: 30px;
  611. margin-top: 40px;
  612. background: linear-gradient(to left, #3f5ecb 0, #5074FF 100%);
  613. color: #fff;
  614. // font-size: $font-lg;
  615. &:after {
  616. border-radius: 60px;
  617. }
  618. }
  619. </style>