login.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <view class="login-page">
  3. <view class="login-hero"></view>
  4. <view class="login-content">
  5. <view class="status-bar"></view>
  6. <view class="header">
  7. <text class="header-title">登录律师账号</text>
  8. <text class="header-subtitle">请使用手机号接收验证码进行登录</text>
  9. </view>
  10. <view class="form-card">
  11. <view class="field">
  12. <text class="field-label">手机号码</text>
  13. <input class="field-input" type="number" :value="phoneDisplay" placeholder="请输入手机号" maxlength="13"
  14. @input="handlePhoneInput" />
  15. </view>
  16. <button @click="handleLogin" class="primary-btn">获取验证码</button>
  17. <view class="agreement-row" @click="toggleAgreement">
  18. <view :class="['agreement-checkbox', { checked: agreementChecked }]">
  19. <view class="checkbox-inner"></view>
  20. </view>
  21. <text class="agreement-text">
  22. 我已阅读并同意
  23. <text class="link" @click.stop="handleUserAgrement">《用户协议》</text>
  24. <text class="link" @click.stop="handlePrivacy">《隐私政策》</text>
  25. </text>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import { getCodeImg } from '@/api/login'
  33. import { getToken } from '@/utils/auth'
  34. export default {
  35. data() {
  36. return {
  37. codeUrl: "",
  38. captchaEnabled: true,
  39. register: false,
  40. agreementChecked: true,
  41. phoneDisplay: "",
  42. globalConfig: getApp().globalData.config,
  43. loginForm: {
  44. username: "",
  45. password: "admin123",
  46. code: "",
  47. uuid: ""
  48. }
  49. }
  50. },
  51. created() {
  52. this.getCode()
  53. },
  54. onLoad() {
  55. //#ifdef H5
  56. if (getToken()) {
  57. this.$tab.reLaunch('/pages/index')
  58. }
  59. //#endif
  60. },
  61. methods: {
  62. handlePhoneInput(e) {
  63. const raw = (e.detail.value || '').replace(/\D/g, '').slice(0, 11)
  64. this.loginForm.username = raw
  65. if (raw.length > 7) {
  66. this.phoneDisplay = raw.replace(/(\d{3})(\d{4})(\d{0,4})/, '$1 $2 $3').trim()
  67. } else if (raw.length > 3) {
  68. this.phoneDisplay = raw.replace(/(\d{3})(\d{0,4})/, '$1 $2').trim()
  69. } else {
  70. this.phoneDisplay = raw
  71. }
  72. },
  73. toggleAgreement() {
  74. this.agreementChecked = !this.agreementChecked
  75. },
  76. handleUserRegister() {
  77. this.$tab.redirectTo(`/pages/register`)
  78. },
  79. handlePrivacy() {
  80. let site = this.globalConfig.appInfo.agreements[0]
  81. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  82. },
  83. handleUserAgrement() {
  84. let site = this.globalConfig.appInfo.agreements[1]
  85. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  86. },
  87. getCode() {
  88. getCodeImg().then(res => {
  89. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
  90. if (this.captchaEnabled) {
  91. this.codeUrl = 'data:image/gif;base64,' + res.img
  92. this.loginForm.uuid = res.uuid
  93. }
  94. })
  95. },
  96. async handleLogin() {
  97. if (!this.agreementChecked) {
  98. this.$modal.msgError('请先阅读并同意相关协议')
  99. return
  100. }
  101. if (!/^1\d{10}$/.test(this.loginForm.username)) {
  102. this.$modal.msgError('请输入正确的手机号')
  103. return
  104. }
  105. this.$modal.loading('登录中,请耐心等待...')
  106. this.pwdLogin()
  107. },
  108. async pwdLogin() {
  109. this.$store.dispatch('Login', this.loginForm).then(() => {
  110. this.$modal.closeLoading()
  111. this.loginSuccess()
  112. }).catch(() => {
  113. this.$modal.closeLoading()
  114. if (this.captchaEnabled) {
  115. this.getCode()
  116. }
  117. })
  118. },
  119. loginSuccess() {
  120. this.$store.dispatch('GetInfo').then(() => {
  121. this.$tab.reLaunch('/pages/index')
  122. })
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. page {
  129. background-color: #eaf3ff;
  130. }
  131. .login-page {
  132. position: relative;
  133. min-height: 100vh;
  134. width: 100%;
  135. overflow: hidden;
  136. background: url('../static/login/login-bg.png') no-repeat center center;
  137. }
  138. .login-bg {
  139. position: absolute;
  140. right: 0;
  141. top: 0;
  142. width: 100%;
  143. height: 100%;
  144. z-index: 0;
  145. }
  146. .login-hero {
  147. position: absolute;
  148. width: 360px;
  149. height: 580px;
  150. background: url('../static/login/login-illustration.png') no-repeat;
  151. background-size: 100% 100%;
  152. right: 0rpx;
  153. top: 40rpx;
  154. }
  155. .login-content {
  156. padding: 470rpx 40rpx 0;
  157. display: flex;
  158. flex-direction: column;
  159. box-sizing: border-box;
  160. }
  161. .status-bar {
  162. height: var(--status-bar-height, 0px);
  163. }
  164. .header {
  165. display: flex;
  166. flex-direction: column;
  167. }
  168. .header-title {
  169. font-size: 50rpx;
  170. font-weight: 600;
  171. color: #19274b;
  172. line-height: 1.2;
  173. }
  174. .header-subtitle {
  175. margin-top: 24rpx;
  176. font-size: 26rpx;
  177. color: rgba(25, 39, 75, 0.68);
  178. line-height: 1.6;
  179. }
  180. .form-card {
  181. z-index: 9;
  182. margin-top: 160rpx;
  183. width: 100%;
  184. box-sizing: border-box;
  185. }
  186. .field {
  187. width: 100%;
  188. display: flex;
  189. flex-direction: column;
  190. }
  191. .field-label {
  192. font-size: 26rpx;
  193. color: #151515;
  194. font-size: 28rpx;
  195. margin-bottom: 18rpx;
  196. }
  197. .field-input {
  198. text-align: center;
  199. width: 100%;
  200. height: 102rpx;
  201. border-radius: 28rpx;
  202. background: rgba(255, 255, 255, 0.7);
  203. border: 1px solid rgba(47, 94, 187, 0.08);
  204. box-shadow: inset 0 4rpx 12rpx rgba(41, 94, 187, 0.06);
  205. padding: 0 36rpx;
  206. box-sizing: border-box;
  207. font-size: 28rpx;
  208. color: #AAA;
  209. letter-spacing: 6rpx;
  210. }
  211. .field-input::placeholder {
  212. color: #AAA;
  213. letter-spacing: 6rpx;
  214. opacity: 0.7;
  215. }
  216. .primary-btn {
  217. margin-top: 44rpx;
  218. width: 100%;
  219. height: 100rpx;
  220. border-radius: 28rpx;
  221. background: linear-gradient(90deg, #3677E9 0%, #2856C7 100%);
  222. color: #ffffff;
  223. font-size: 28rpx;
  224. font-weight: 500;
  225. display: flex;
  226. align-items: center;
  227. justify-content: center;
  228. border: none;
  229. box-shadow: 0 20rpx 40rpx rgba(38, 104, 255, 0.35);
  230. }
  231. .agreement-row {
  232. position: fixed;
  233. bottom: 100rpx;
  234. left: 0;
  235. width: 100%;
  236. box-sizing: border-box;
  237. display: flex;
  238. align-items: center;
  239. justify-content: center;
  240. }
  241. .agreement-checkbox {
  242. width: 30rpx;
  243. height: 30rpx;
  244. margin-right: 8rpx;
  245. border-radius: 50%;
  246. border: 1px solid rgba(35, 96, 255, 0.5);
  247. background: rgba(250, 252, 255, 0.8);
  248. display: flex;
  249. align-items: center;
  250. justify-content: center;
  251. }
  252. .agreement-checkbox.checked {
  253. background: linear-gradient(140deg, #3c7dff 0%, #235aff 100%);
  254. border: none;
  255. }
  256. .checkbox-inner {
  257. width: 16rpx;
  258. height: 16rpx;
  259. border-radius: 50%;
  260. background: #ffffff;
  261. opacity: 0;
  262. }
  263. .agreement-checkbox.checked .checkbox-inner {
  264. opacity: 1;
  265. }
  266. .agreement-text {
  267. font-size: 24rpx;
  268. color: rgba(34, 52, 91, 0.75);
  269. line-height: 1.5;
  270. }
  271. .agreement-text .link {
  272. color: #2360ff;
  273. margin: 0 6rpx;
  274. }
  275. </style>