login.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. <template>
  2. <view :class="[AppTheme]" class="all_box">
  3. <view class="loginstatus" v-if="logintype">
  4. <view class="sign_in_title">验证码登录</view>
  5. <!-- 登录信息 -->
  6. <view class="login_infon">
  7. <view class="inputline">
  8. <u-input placeholder="请输入手机号" v-model="loginphone" border="bottom" fontSize="22"></u-input>
  9. </view>
  10. <view class="inputline">
  11. <u-input placeholder="请输入验证码" :password="false" v-model="verificationcode" border="bottom"
  12. fontSize="22">
  13. <template slot="suffix">
  14. <u-button class="bg-primary" @tap="getCode" :disabled="!ifsend" :text="codemess"
  15. :type="ifsend?'success':'warning'" shape="circle"></u-button>
  16. </template>
  17. </u-input>
  18. </view>
  19. </view>
  20. <view class="consent_agreement">
  21. <view class="" @click="judgecheck()">
  22. <u-icon v-if="ifcheck" size="20" name="checkmark-circle-fill" :color="primary"></u-icon>
  23. <u-icon v-if="!ifcheck" size="20" name="checkmark-circle-fill" color="#606266"></u-icon>
  24. </view>
  25. <view class="agreement_details">
  26. 未注册手机号登录将自动生成账号,且代表您已阅读并同意
  27. <text class="agreement_details_text" @click="ifshowpop('用户服务协议')">《用户服务协议》</text>
  28. <text class="agreement_details_text" @click="ifshowpop('隐私政策')">《隐私政策》</text>
  29. </view>
  30. </view>
  31. <!-- 登录按钮 -->
  32. <view class="login_button bg-linear-gradient" @click="gologin()">
  33. 登录
  34. </view>
  35. <!-- 切换登录方式 -->
  36. <view class="switch_de">
  37. <view class="switch_de_text" @click="logintype=false">密码登录</view>
  38. <view class="switch_de_text" @click="gotoresin()">新用户注册</view>
  39. </view>
  40. <view class="other_methods" v-if="qqopen||wxopen">
  41. <!-- #ifdef APP-PLUS -->
  42. <u-divider fontSize="30" half-width="250" bg-color="#f7f7f7" text="其他登陆方式"></u-divider>
  43. <!-- #endif -->
  44. <!-- #ifdef H5 -->
  45. <u-divider fontSize="30" half-width="250" bg-color="#f7f7f7" text="其他登陆方式"></u-divider>
  46. <!-- #endif -->
  47. <view class="login_list">
  48. <!-- #ifdef APP-PLUS -->
  49. <!-- <image v-if="qqopen" @click="qqlogin()" :src="settingFile.root_img+'/static/app/imgs/farm/qq.png'"
  50. mode="scaleToFill" class="login_list_item" /> -->
  51. <image v-if="wxopen" @click="wxlogin()"
  52. :src="settingFile.root_img+'/static/app/imgs/farm/weixin.png'" mode="scaleToFill"
  53. class="login_list_item" />
  54. <!-- #endif -->
  55. <!-- #ifdef H5 -->
  56. <image v-if="wxopen" @click="wxlogin()"
  57. :src="settingFile.root_img+'/static/app/imgs/farm/weixin.png'" mode="scaleToFill"
  58. class="login_list_item" />
  59. <!-- #endif -->
  60. </view>
  61. </view>
  62. </view>
  63. <view class="loginstatus" v-if="!logintype">
  64. <view class="sign_in_title">密码登录</view>
  65. <!-- 登录信息 -->
  66. <view class="login_infon">
  67. <view class="inputline">
  68. <u-input placeholder="用户名或手机号" v-model="loginphone" border="bottom" fontSize="22"></u-input>
  69. </view>
  70. <view class="inputline">
  71. <u-input placeholder="密码" :password="true" v-model="loginpassword" border="bottom" fontSize="22">
  72. </u-input>
  73. </view>
  74. </view>
  75. <view class="consent_agreement">
  76. <view @click="judgecheck_in()">
  77. <u-icon v-if="fiarmej" size="20" name="checkmark-circle-fill" :color="primary"></u-icon>
  78. <u-icon v-if="!fiarmej" size="20" name="checkmark-circle-fill" color="#606266"></u-icon>
  79. </view>
  80. <view class="agreement_details">
  81. 我已阅读并同意
  82. <text class="agreement_details_text" @click="ifshowpop('用户服务协议')">《用户服务协议》</text>
  83. <text class="agreement_details_text" @click="ifshowpop('隐私政策')">《隐私政策》</text>
  84. </view>
  85. </view>
  86. <!-- 登录按钮 -->
  87. <view class="login_button bg-linear-gradient" @click="gologinbypas()">
  88. 登录
  89. </view>
  90. <!-- 切换登录方式 -->
  91. <view class="switch_de">
  92. <view class="switch_de_text" @click="logintype=true">验证码登录</view>
  93. <view class="switch_de_text" @click="gotoresin()">新用户注册</view>
  94. <navigator hover-class="none" url="/pagesC/pages/login/forgetpassword" class="switch_de_text">找回密码
  95. </navigator>
  96. </view>
  97. <view class="other_methods" v-if="qqopen||wxopen">
  98. <!-- #ifdef APP-PLUS -->
  99. <u-divider fontSize="30" half-width="250" bg-color="#f7f7f7" text="其他登陆方式"></u-divider>
  100. <!-- #endif -->
  101. <!-- #ifdef H5 -->
  102. <u-divider fontSize="30" half-width="250" bg-color="#f7f7f7" text="其他登陆方式"></u-divider>
  103. <!-- #endif -->
  104. <view class="login_list">
  105. <!-- #ifdef APP-PLUS -->
  106. <!-- <image v-if="qqopen" @click="qqlogin()" src="../../../static/imgs/farm/qq.png" mode="scaleToFill"
  107. class="login_list_item" /> -->
  108. <image v-if="wxopen" @click="wxlogin()"
  109. :src="settingFile.root_img+'/static/app/imgs/farm/weixin.png'" mode="scaleToFill"
  110. class="login_list_item" />
  111. <!-- #endif -->
  112. <!-- #ifdef H5 -->
  113. <image v-if="wxopen" @click="wxlogin()"
  114. :src="settingFile.root_img+'/static/app/imgs/farm/weixin.png'" mode="scaleToFill"
  115. class="login_list_item" />
  116. <!-- #endif -->
  117. </view>
  118. </view>
  119. </view>
  120. </view>
  121. </template>
  122. <script>
  123. import loginapi from "@/api/login/login.js"
  124. import until from "@/js/until.js"
  125. export default {
  126. data() {
  127. return {
  128. primary: this.$theme.primary,
  129. settingFile: this.$siteinfo,
  130. appid: '', //获取到的公众号appid
  131. code: '',
  132. //头部导航
  133. navbarhead: true,
  134. // 登录手机号
  135. loginphone: null,
  136. // 验证码
  137. verificationcode: null,
  138. //密码
  139. loginpassword: null,
  140. //验证码是否可以发送
  141. ifsend: true,
  142. // 验证码状态
  143. codemess: '获取验证码',
  144. // 是否同意注册协议
  145. ifcheck: false,
  146. // 是否同意隐私协议
  147. fiarmej: false,
  148. //true为验证码登录,false为密码登录
  149. logintype: true,
  150. contearticle: '',
  151. setting: null,
  152. wxopen: false,
  153. qqopen: false,
  154. }
  155. },
  156. onShow() {
  157. until.onNetworkStatusChange();
  158. this.$init_config();
  159. },
  160. onLoad() {
  161. let that = this
  162. let isWeixin = that.isWeiXin();
  163. that.$init_config(2, function(res) {
  164. if (res) {
  165. // #ifdef APP-PLUS
  166. if (res.app.open_wx_auth == 1) {
  167. that.wxopen = true;
  168. }
  169. // #endif
  170. // #ifdef H5
  171. if (res.app.gzh_wx_auth == 1 && isWeixin) {
  172. that.wxopen = true;
  173. }
  174. // #endif
  175. // #ifdef MP-WEIXIN
  176. if (res.app.open_wx_auth == 1) {
  177. that.wxopen = true;
  178. }
  179. // #endif
  180. }
  181. })
  182. },
  183. methods: {
  184. // 获取验证码
  185. getCode() {
  186. let that = this
  187. if (!that.ifcheck) {
  188. uni.showToast({
  189. icon: 'none',
  190. title: '请先同意协议'
  191. })
  192. return
  193. }
  194. if (that.loginphone !== null && that.loginphone !== undefined && that.loginphone.length === 11) {
  195. var myreg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
  196. if (myreg.test(that.loginphone)) {
  197. uni.showLoading({
  198. title: '正在获取验证码'
  199. })
  200. setTimeout(() => {
  201. uni.hideLoading()
  202. //获取验证码
  203. let params = {
  204. mobile: that.loginphone
  205. }
  206. loginapi.sendvecode(params).then(res => {
  207. if (parseInt(res.status) === 1) {
  208. uni.showToast({
  209. icon: 'none',
  210. title: res.msg
  211. })
  212. that.ifsend = false
  213. } else {
  214. uni.showToast({
  215. icon: 'none',
  216. title: res.msg
  217. })
  218. }
  219. })
  220. }, 1000)
  221. let num = 60
  222. that.timeer = setInterval(function() {
  223. if (num > 0) {
  224. that.codemess = num + 's后重新获取'
  225. num = num - 1
  226. } else {
  227. clearInterval(that.timeer)
  228. that.ifsend = true
  229. that.codemess = '重新获取验证码'
  230. }
  231. }, 1000)
  232. } else {
  233. uni.showToast({
  234. icon: 'none',
  235. title: '请输入有效的手机号'
  236. })
  237. }
  238. } else {
  239. uni.showToast({
  240. icon: 'none',
  241. title: '请输入有效的手机号'
  242. })
  243. }
  244. },
  245. // 根据密码登录
  246. gologinbypas() {
  247. let that = this
  248. if (!that.fiarmej) {
  249. uni.showToast({
  250. icon: 'none',
  251. title: '请先同意协议'
  252. })
  253. return
  254. }
  255. if (that.loginphone !== null && that.loginphone !== undefined) {
  256. if (that.loginpassword !== null && that.loginpassword !== undefined && that.loginpassword.length > 0) {
  257. //验证完毕,执行验证码登录
  258. let parms = {
  259. mobile: that.loginphone,
  260. password: that.loginpassword
  261. }
  262. loginapi.login(parms).then(res => {
  263. if (parseInt(res.status) === 200) {
  264. // 登陆成功
  265. uni.setStorage({
  266. key: 'userInfo',
  267. data: res.data.userinfo,
  268. success: function() {
  269. uni.setStorage({
  270. key: "token",
  271. data: res.data.token,
  272. success() {
  273. uni.setStorage({
  274. key: 'iflogin',
  275. data: true,
  276. success() {
  277. uni.showToast({
  278. icon: 'none',
  279. title: '登陆成功'
  280. })
  281. }
  282. })
  283. setTimeout(() => {
  284. until.beforeSwitch(0)
  285. uni.switchTab({
  286. url: '/pages/user/user'
  287. })
  288. }, 1000)
  289. }
  290. })
  291. },
  292. fail() {
  293. uni.showToast({
  294. icon: 'none',
  295. title: '请重新登录'
  296. })
  297. }
  298. })
  299. } else {
  300. uni.showToast({
  301. icon: 'none',
  302. title: res.msg
  303. })
  304. }
  305. })
  306. } else {
  307. uni.showToast({
  308. icon: 'none',
  309. title: '请输入正确的密码'
  310. })
  311. }
  312. } else {
  313. uni.showToast({
  314. icon: 'none',
  315. title: '请输入正确的账号'
  316. })
  317. }
  318. },
  319. //验证码登录
  320. gologin() {
  321. let that = this
  322. if (!that.ifcheck) {
  323. uni.showToast({
  324. icon: 'none',
  325. title: '请先同意协议'
  326. })
  327. return
  328. }
  329. if (that.loginphone !== null && that.loginphone !== undefined && that.loginphone.length === 11) {
  330. var myreg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
  331. if (myreg.test(that.loginphone)) {
  332. if (that.verificationcode !== null && that.verificationcode !== undefined && that.verificationcode
  333. .length > 0) {
  334. //验证完毕,执行验证码登录
  335. let parms = {
  336. mobile: that.loginphone,
  337. code: that.verificationcode
  338. }
  339. loginapi.reg(parms).then(res => {
  340. if (parseInt(res.status) === 200) {
  341. // 登陆成功
  342. uni.setStorage({
  343. key: 'userInfo',
  344. data: res.data.userinfo,
  345. success: function() {
  346. uni.setStorage({
  347. key: "token",
  348. data: res.data.token,
  349. success: function() {
  350. uni.showToast({
  351. icon: 'none',
  352. title: "登陆成功"
  353. })
  354. setTimeout(() => {
  355. uni.switchTab({
  356. url: '/pages/user/user'
  357. })
  358. }, 500)
  359. },
  360. fail: function() {
  361. uni.showToast({
  362. title: "请重新登陆",
  363. icon: "none"
  364. })
  365. }
  366. })
  367. },
  368. fail() {
  369. uni.showToast({
  370. icon: 'none',
  371. title: '请重新登录'
  372. })
  373. }
  374. })
  375. } else {
  376. uni.showToast({
  377. icon: 'none',
  378. title: '登陆失败'
  379. })
  380. }
  381. })
  382. } else {
  383. uni.showToast({
  384. icon: 'none',
  385. title: '请输入正确的验证码'
  386. })
  387. }
  388. } else {
  389. uni.showToast({
  390. icon: 'none',
  391. title: '请输入正确的手机号'
  392. })
  393. }
  394. } else {
  395. uni.showToast({
  396. icon: 'none',
  397. title: '请输入正确的手机号'
  398. })
  399. }
  400. },
  401. //切换协议状态
  402. judgecheck() {
  403. this.ifcheck = !this.ifcheck
  404. },
  405. judgecheck_in() {
  406. this.fiarmej = !this.fiarmej
  407. },
  408. //注册新用户
  409. gotoresin() {
  410. uni.navigateTo({
  411. url: '/pagesC/pages/register/register'
  412. })
  413. },
  414. //协议
  415. ifshowpop(title) {
  416. this.$until.toarticle(title, 0, 2)
  417. },
  418. wxlogin() {
  419. let that = this
  420. if (!that.ifcheck) {
  421. uni.showToast({
  422. icon: 'none',
  423. title: '请先同意协议'
  424. })
  425. return
  426. }
  427. // #ifdef APP-PLUS
  428. uni.showLoading({
  429. title: '登陆中'
  430. })
  431. uni.login({
  432. provider: 'weixin',
  433. success: res => {
  434. uni.getUserInfo({
  435. provider: 'weixin',
  436. success: function(infoRes) {
  437. let formdata = {
  438. nickname: infoRes.userInfo.nickName,
  439. sex: infoRes.userInfo.gender,
  440. headimgurl: infoRes.userInfo.avatarUrl,
  441. openid: infoRes.userInfo.openId,
  442. pid: uni.getStorageSync('sys_pid'),
  443. unionid: infoRes.userInfo.unionId
  444. }
  445. loginapi.wxLogin(formdata).then(res => {
  446. uni.hideLoading()
  447. if (res.status == 200) {
  448. // 登陆成功
  449. uni.hideLoading()
  450. uni.showToast({
  451. icon: 'none',
  452. title: '登陆成功'
  453. })
  454. that.$store.commit('login', res.data.userinfo);
  455. setTimeout(() => {
  456. uni.switchTab({
  457. url: '/pages/user/user'
  458. });
  459. }, 500)
  460. return true
  461. } else {
  462. uni.hideLoading()
  463. uni.showToast({
  464. title: res.msg,
  465. icon: 'none'
  466. })
  467. return false
  468. }
  469. })
  470. },
  471. fail: function() {
  472. uni.hideLoading()
  473. },
  474. complete: function() {
  475. uni.hideLoading()
  476. }
  477. })
  478. },
  479. fail: function(err) {
  480. uni.hideLoading()
  481. uni.showToast({
  482. title: err.errMsg,
  483. icon: 'none'
  484. })
  485. }
  486. })
  487. // #endif
  488. // #ifdef H5
  489. that.h5_wx_auth();
  490. // #endif
  491. },
  492. qqlogin() {
  493. let that = this
  494. uni.showLoading({
  495. title: '登陆中'
  496. })
  497. uni.login({
  498. provider: 'qq',
  499. success: resp => {
  500. var access_token = resp.authResult.access_token
  501. uni.getUserInfo({
  502. provider: 'qq',
  503. success: function(infoRes) {
  504. console.log(infoRes, "infoRes")
  505. let formdata = {
  506. nickname: infoRes.userInfo.nickname,
  507. sex: infoRes.userInfo.gender == '男' ? 0 : 1,
  508. headimgurl: infoRes.userInfo.headimgurl,
  509. openid2: infoRes.userInfo.openId,
  510. access_token: access_token
  511. }
  512. uni.showLoading({
  513. title: '登陆中'
  514. })
  515. loginapi.qqlogin(formdata).then(res => {
  516. console.log(res, "res")
  517. if (res.status === 200) {
  518. // 登陆成功
  519. uni.hideLoading()
  520. uni.setStorage({
  521. key: 'userInfo',
  522. data: res.data.userinfo,
  523. success: function() {
  524. uni.setStorage({
  525. key: "token",
  526. data: res.data
  527. .token,
  528. success: function() {
  529. uni.showToast({
  530. icon: 'none',
  531. title: '登陆成功'
  532. })
  533. setTimeout
  534. (() => {
  535. until
  536. .beforeSwitch(
  537. 0
  538. )
  539. uni.switchTab({
  540. url: '/pages/index/index'
  541. })
  542. },
  543. 1000
  544. )
  545. },
  546. fail() {
  547. uni.showToast({
  548. icon: 'none',
  549. title: '请重新登录'
  550. })
  551. }
  552. })
  553. },
  554. fail() {
  555. uni.showToast({
  556. icon: 'none',
  557. title: '请重新登录'
  558. })
  559. }
  560. })
  561. return true
  562. } else {
  563. uni.hideLoading()
  564. uni.showToast({
  565. title: res.msg,
  566. icon: 'none'
  567. })
  568. }
  569. })
  570. }
  571. })
  572. },
  573. fail: function(err) {
  574. uni.showToast({
  575. title: err.errMsg,
  576. icon: 'none'
  577. })
  578. }
  579. })
  580. // }
  581. },
  582. h5_wx_auth() {
  583. let that = this;
  584. let appid = that.$config.app.wxgzhappid;
  585. if (appid == '') {
  586. uni.showToast({
  587. title: '公众号参数配置错误',
  588. icon: 'none'
  589. });
  590. return;
  591. }
  592. let pid = uni.getStorageSync('sys_pid');
  593. let purl = that.$siteinfo.h5_siteroot + "/h5?uuid=" + that.$uuid + "&pid=" + pid +
  594. "#/pages/user/user";
  595. let redirect_uri = encodeURIComponent(purl);
  596. that.$until.h5_wx_auth(appid, redirect_uri);
  597. }
  598. }
  599. }
  600. </script>
  601. <style lang="scss" scoped>
  602. .all_box {
  603. .loginstatus {
  604. .sign_in_title {
  605. padding: 240rpx 10% 0 10%;
  606. width: 80%;
  607. color: #000000;
  608. font-size: 45rpx;
  609. font-weight: 600;
  610. }
  611. .login_infon {
  612. padding: 60rpx 10%;
  613. width: 80%;
  614. .inputline {
  615. margin: 20rpx 0;
  616. }
  617. }
  618. .consent_agreement {
  619. display: flex;
  620. justify-content: center;
  621. align-items: center;
  622. width: 80%;
  623. margin: 0 10%;
  624. .agreement_details {
  625. margin-left: 15rpx;
  626. color: #999;
  627. font-size: 24rpx;
  628. .agreement_details_text {
  629. line-height: 40rpx;
  630. color: #3C9CFF;
  631. }
  632. }
  633. }
  634. .login_button {
  635. margin: 70rpx 10% 25rpx 10%;
  636. padding: 24rpx 0;
  637. width: 80%;
  638. text-align: center;
  639. color: #FFFFFF;
  640. font-size: 32rpx;
  641. background-color: #FE7C0D;
  642. border-radius: 50rpx;
  643. }
  644. .switch_de {
  645. display: flex;
  646. justify-content: space-between;
  647. align-items: center;
  648. width: 80%;
  649. margin: 0 10%;
  650. .switch_de_text {
  651. font-size: 28rpx;
  652. color: #4271A1;
  653. }
  654. }
  655. .other_methods {
  656. bottom: 100rpx;
  657. left: 10%;
  658. margin-top: 50rpx;
  659. .login_list {
  660. width: 270rpx;
  661. margin: 25rpx calc(50% - 135rpx) 0 calc(50% - 135rpx);
  662. justify-content: space-evenly;
  663. align-items: center;
  664. display: flex;
  665. .login_list_item {
  666. width: 70rpx;
  667. height: 70rpx;
  668. }
  669. }
  670. }
  671. }
  672. .agreement_content {
  673. margin: 0 15rpx;
  674. height: 100vh;
  675. .agreement_content_title {
  676. padding: 20rpx 0 25rpx 0;
  677. font-size: 36rpx;
  678. color: #000000;
  679. font-weight: 700;
  680. width: 100%;
  681. text-align: center;
  682. position: relative;
  683. .closepop_boton {
  684. position: absolute;
  685. right: 15rpx;
  686. top: 50%;
  687. transform: translate(0, -50%);
  688. }
  689. }
  690. .ementconte_content {
  691. width: 100%;
  692. }
  693. }
  694. }
  695. </style>