login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <template>
  2. <view class="login-container">
  3. <!-- 背景装饰 -->
  4. <view class="background-decoration"> </view>
  5. <!-- 返回按钮 -->
  6. <view class="back-btn" @click="showInterruptLoginModal = true" v-if="step === 2">
  7. <image src="@/static/images/login/back.png" mode="widthFix" style="width: 50rpx;height: 50rpx;"></image>
  8. </view>
  9. <!-- 主内容区 -->
  10. <view class="login-content">
  11. <!-- 标题 -->
  12. <view class="title">登录律师账号</view>
  13. <view class="subtitle">请使用手机号接收验证码进行登录</view>
  14. <!-- 第一步:输入手机号 -->
  15. <view class="form-section" v-if="step === 1">
  16. <view class="input-label">手机号码</view>
  17. <view class="input-wrapper">
  18. <input v-model="phone" type="number" class="phone-input" placeholder="请输入手机号码" maxlength="11" />
  19. </view>
  20. <view class="resend-code-btn" @click="handleGetCode"> 获取验证码</view>
  21. </view>
  22. <!-- 第二步:输入验证码 -->
  23. <view class="form-section" v-if="step === 2">
  24. <view class="input-label">验证码</view>
  25. <view class="input-wrapper">
  26. <input v-model="code" type="number" class="code-input" placeholder="请输入验证码" maxlength="6"
  27. @input="handleInputCode" />
  28. </view>
  29. <button class="resend-code-btn" @click="handleResendCode">
  30. {{ countdown > 0 ? `重新获取 (${countdown}s)` : '重新获取' }}
  31. </button>
  32. <!-- <button
  33. class="login-btn"
  34. :disabled="!canLogin"
  35. @click="handleLogin"
  36. >
  37. 登录
  38. </button> -->
  39. </view>
  40. <!-- 用户协议 -->
  41. <view class="agreement-section">
  42. <view class="checkbox-wrapper" @click="toggleAgreement">
  43. <view class="checkbox" :class="{ 'checked': agreed }">
  44. <text class="check-icon" v-if="agreed">✓</text>
  45. </view>
  46. <text class="agreement-text">
  47. 我已阅读并同意
  48. <text class="link-text" @click.stop="handleUserAgrement">《用户协议》</text>
  49. <text class="link-text" @click.stop="handlePrivacy">《隐私政策》</text>
  50. </text>
  51. </view>
  52. </view>
  53. </view>
  54. <!-- 用户协议弹窗 -->
  55. <view class="modal-overlay" v-if="showAgreementModal" @click="showAgreementModal = false">
  56. <view class="modal-content" @click.stop>
  57. <view class="modal-title">用户协议及隐私政策</view>
  58. <view class="modal-text">
  59. 为了更好的保障您的合法权益,请您阅读并同意以下协议
  60. <text class="link-text" @click="handleUserAgrement">《用户协议》</text>
  61. <text class="link-text" @click="handlePrivacy">《隐私政策》</text>
  62. </view>
  63. <view class="modal-buttons">
  64. <button class="modal-btn reject-btn" @click="handleReject">拒绝</button>
  65. <button class="modal-btn agree-btn" @click="handleAgree">同意</button>
  66. </view>
  67. </view>
  68. </view>
  69. <!-- 中断登录弹窗 -->
  70. <view class="modal-overlay" v-if="showInterruptLoginModal">
  71. <view class="modal-content" @click.stop>
  72. <view class="modal-title" style="margin-bottom: 60rpx;">
  73. 返回将中断登录,确定返回?
  74. </view>
  75. <view class="modal-buttons">
  76. <button class="modal-btn reject-btn" @click="showInterruptLoginModal = false">取消</button>
  77. <button class="modal-btn agree-btn" @click="interruptLogin">确定</button>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </template>
  83. <script>
  84. import { sendSmsCode } from '@/api/login'
  85. import { getToken } from '@/utils/auth'
  86. export default {
  87. data() {
  88. return {
  89. step: 1, // 1: 输入手机号, 2: 输入验证码
  90. phone: '',
  91. code: '',
  92. countdown: 0,
  93. agreed: false,
  94. showAgreementModal: false,
  95. globalConfig: getApp().globalData.config,
  96. timer: null,
  97. showInterruptLoginModal: false
  98. }
  99. },
  100. computed: {
  101. canGetCode() {
  102. return /^1[3-9]\d{9}$/.test(this.phone) && this.agreed
  103. },
  104. canLogin() {
  105. return this.code.length >= 4 && this.agreed
  106. }
  107. },
  108. onLoad() {
  109. //#ifdef H5
  110. if (getToken()) {
  111. this.$tab.reLaunch('/pages/index')
  112. }
  113. //#endif
  114. // 首次进入显示协议弹窗
  115. this.showAgreementModal = true
  116. },
  117. onUnload() {
  118. if (this.timer) {
  119. clearInterval(this.timer)
  120. }
  121. },
  122. methods: {
  123. interruptLogin() {
  124. this.showInterruptLoginModal = false
  125. this.step = 1
  126. this.code = ''
  127. },
  128. toggleAgreement() {
  129. this.agreed = !this.agreed
  130. },
  131. handleGetCode() {
  132. if (!this.canGetCode) {
  133. if (!/^1[3-9]\d{9}$/.test(this.phone)) {
  134. this.$modal.msgError('请输入正确的手机号码')
  135. } else if (!this.agreed) {
  136. this.$modal.msgError('请先同意用户协议和隐私政策')
  137. }
  138. return
  139. }
  140. this.$modal.loading('发送中...')
  141. sendSmsCode(this.phone).then(() => {
  142. this.$modal.closeLoading()
  143. this.$modal.msgSuccess('验证码已发送')
  144. this.step = 2
  145. this.startCountdown()
  146. }).catch(() => {
  147. this.$modal.closeLoading()
  148. })
  149. },
  150. handleResendCode() {
  151. if (this.countdown > 0) return
  152. this.handleGetCode()
  153. },
  154. startCountdown() {
  155. this.countdown = 60
  156. if (this.timer) {
  157. clearInterval(this.timer)
  158. }
  159. this.timer = setInterval(() => {
  160. this.countdown--
  161. if (this.countdown <= 0) {
  162. clearInterval(this.timer)
  163. this.timer = null
  164. }
  165. }, 1000)
  166. },
  167. handleInputCode() {
  168. if (this.code.length >= 6) {
  169. this.handleLogin()
  170. }
  171. },
  172. async handleLogin() {
  173. if (!this.canLogin) {
  174. if (this.code.length < 4) {
  175. this.$modal.msgError('请输入验证码')
  176. } else if (!this.agreed) {
  177. this.$modal.msgError('请先同意用户协议和隐私政策')
  178. }
  179. return
  180. }
  181. this.$modal.loading('登录中,请耐心等待...')
  182. this.$modal.closeLoading()
  183. this.loginSuccess()
  184. try {
  185. await this.$store.dispatch('LoginBySms', {
  186. phone: this.phone,
  187. code: this.code
  188. })
  189. this.$modal.closeLoading()
  190. this.loginSuccess()
  191. } catch (error) {
  192. this.$modal.closeLoading()
  193. }
  194. },
  195. loginSuccess() {
  196. // this.$store.dispatch('GetInfo').then(res => {
  197. this.$tab.reLaunch('/pages/setUserInfo')
  198. // })
  199. },
  200. handleUserAgrement() {
  201. let site = this.globalConfig.appInfo.agreements[1]
  202. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  203. },
  204. handlePrivacy() {
  205. let site = this.globalConfig.appInfo.agreements[0]
  206. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  207. },
  208. handleReject() {
  209. this.showAgreementModal = false
  210. this.agreed = false
  211. },
  212. handleAgree() {
  213. this.showAgreementModal = false
  214. this.agreed = true
  215. }
  216. }
  217. }
  218. </script>
  219. <style lang="scss" scoped>
  220. page {
  221. background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf0 100%);
  222. min-height: 100vh;
  223. }
  224. .login-container {
  225. position: relative;
  226. width: 100%;
  227. min-height: 100vh;
  228. padding: 0 60rpx;
  229. padding-top: 120rpx;
  230. overflow: hidden;
  231. background-image: url('@/static/images/login/bg1.png');
  232. background-size: cover;
  233. background-repeat: no-repeat;
  234. background-position: center center;
  235. }
  236. .background-decoration {
  237. position: absolute;
  238. top: 0;
  239. right: 0;
  240. width: 100%;
  241. height: 80%;
  242. background-image: url('@/static/images/login/bg2.png');
  243. background-size: cover;
  244. }
  245. .back-btn {
  246. position: absolute;
  247. top: 100rpx;
  248. left: 40rpx;
  249. width: 60rpx;
  250. height: 60rpx;
  251. display: flex;
  252. align-items: center;
  253. justify-content: center;
  254. z-index: 10;
  255. .back-icon {
  256. font-size: 40rpx;
  257. color: #333;
  258. font-weight: bold;
  259. }
  260. }
  261. .login-content {
  262. position: relative;
  263. z-index: 1;
  264. top: 260rpx;
  265. }
  266. .title {
  267. font-size: 56rpx;
  268. font-weight: bold;
  269. color: #333;
  270. margin-bottom: 20rpx;
  271. text-align: left;
  272. }
  273. .subtitle {
  274. font-size: 28rpx;
  275. color: #666;
  276. margin-bottom: 80rpx;
  277. text-align: left;
  278. }
  279. .form-section {
  280. margin-bottom: 60rpx;
  281. }
  282. .input-label {
  283. font-size: 28rpx;
  284. color: #333;
  285. margin-bottom: 20rpx;
  286. text-align: left;
  287. }
  288. .input-wrapper {
  289. background-color: #f8f9fa;
  290. border-radius: 16rpx;
  291. padding: 24rpx 30rpx;
  292. margin-bottom: 40rpx;
  293. }
  294. .phone-input,
  295. .code-input {
  296. width: 100%;
  297. font-size: 32rpx;
  298. color: #333;
  299. background: transparent;
  300. border: none;
  301. }
  302. .get-code-btn,
  303. .resend-code-btn {
  304. width: 100%;
  305. height: 88rpx;
  306. background: linear-gradient(135deg, #4a90e2 0%, #5ba0f2 100%);
  307. color: #fff;
  308. font-size: 32rpx;
  309. border-radius: 16rpx;
  310. border: none;
  311. display: flex;
  312. align-items: center;
  313. justify-content: center;
  314. margin-bottom: 40rpx;
  315. &[disabled] {
  316. background: #d0d0d0;
  317. color: #999;
  318. }
  319. }
  320. .login-btn {
  321. width: 100%;
  322. height: 88rpx;
  323. background: linear-gradient(135deg, #4a90e2 0%, #5ba0f2 100%);
  324. color: #fff;
  325. font-size: 32rpx;
  326. border-radius: 16rpx;
  327. border: none;
  328. margin-top: 40rpx;
  329. &[disabled] {
  330. background: #d0d0d0;
  331. color: #999;
  332. }
  333. }
  334. .agreement-section {
  335. position: fixed;
  336. bottom: 60rpx;
  337. left: 0;
  338. right: 0;
  339. padding: 0 60rpx;
  340. z-index: 2;
  341. }
  342. .checkbox-wrapper {
  343. display: flex;
  344. align-items: center;
  345. justify-content: center;
  346. }
  347. .checkbox {
  348. width: 36rpx;
  349. height: 36rpx;
  350. border: 2rpx solid #ddd;
  351. border-radius: 50%;
  352. margin-right: 16rpx;
  353. display: flex;
  354. align-items: center;
  355. justify-content: center;
  356. flex-shrink: 0;
  357. &.checked {
  358. background: #4a90e2;
  359. border-color: #4a90e2;
  360. .check-icon {
  361. color: #fff;
  362. font-size: 24rpx;
  363. font-weight: bold;
  364. }
  365. }
  366. }
  367. .agreement-text {
  368. font-size: 24rpx;
  369. color: #666;
  370. line-height: 1.6;
  371. }
  372. .link-text {
  373. color: #4a90e2;
  374. }
  375. .modal-overlay {
  376. position: fixed;
  377. top: 0;
  378. left: 0;
  379. right: 0;
  380. bottom: 0;
  381. background: rgba(0, 0, 0, 0.5);
  382. display: flex;
  383. align-items: center;
  384. justify-content: center;
  385. z-index: 1000;
  386. }
  387. .modal-content {
  388. width: 600rpx;
  389. background: #fff;
  390. border-radius: 24rpx;
  391. padding: 60rpx 40rpx 0 40rpx;
  392. margin: 0 40rpx;
  393. }
  394. .modal-title {
  395. font-size: 36rpx;
  396. font-weight: bold;
  397. color: #333;
  398. margin-bottom: 30rpx;
  399. text-align: center;
  400. }
  401. .modal-text {
  402. font-size: 28rpx;
  403. color: #666;
  404. line-height: 1.8;
  405. margin-bottom: 50rpx;
  406. text-align: left;
  407. }
  408. .modal-buttons {
  409. display: flex;
  410. border-top: 1rpx solid #eee;
  411. // padding-top: 30rpx;
  412. }
  413. .modal-btn {
  414. flex: 1;
  415. height: 100rpx;
  416. font-size: 32rpx;
  417. border: none;
  418. background: transparent;
  419. border-radius: 12rpx;
  420. padding: 10rpx;
  421. &.reject-btn {
  422. color: #999;
  423. margin-right: 20rpx;
  424. border-right: 1rpx solid #eee;
  425. }
  426. &.agree-btn {
  427. color: #4a90e2;
  428. font-weight: bold;
  429. }
  430. }
  431. uni-button:after {
  432. border: none !important;
  433. }
  434. </style>