login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <script setup>
  2. import { computed, ref } from 'vue'
  3. import { onShow } from '@dcloudio/uni-app'
  4. import { useUserStore } from '@/stores/user'
  5. import { DEFAULT_PLACEHOLDER_IMAGE_URL } from '@/utils/staticAsset'
  6. const userStore = useUserStore()
  7. const form = ref({
  8. username: '',
  9. password: ''
  10. })
  11. const isLoading = ref(false)
  12. const agreeProtocol = ref(false)
  13. const loginDisabled = computed(() => isLoading.value)
  14. const protocolDialogVisible = ref(false)
  15. let protocolDialogResolver = null
  16. onShow(() => {
  17. userStore.checkLoginStatus()
  18. if (userStore.isLoggedIn) {
  19. userStore.navigateToHome()
  20. }
  21. })
  22. const loginPageStyle = computed(() => ({ '--theme-color': '#0a9f6d' }))
  23. const handleSubmit = async () => {
  24. if (!agreeProtocol.value) {
  25. const shouldContinue = await new Promise((resolve) => {
  26. protocolDialogResolver = resolve
  27. protocolDialogVisible.value = true
  28. })
  29. if (!shouldContinue) return
  30. agreeProtocol.value = true
  31. }
  32. if (!form.value.username) {
  33. uni.showToast({ title: '请输入用户名', icon: 'none' })
  34. return
  35. }
  36. if (!form.value.password) {
  37. uni.showToast({ title: '请输入密码', icon: 'none' })
  38. return
  39. }
  40. isLoading.value = true
  41. try {
  42. const success = await userStore.login({
  43. username: form.value.username,
  44. password: form.value.password
  45. })
  46. if (success) {
  47. userStore.navigateToHome()
  48. }
  49. } finally {
  50. isLoading.value = false
  51. }
  52. }
  53. const goUserAgreement = () => {
  54. uni.navigateTo({ url: '/pages/login/user-agreement' })
  55. }
  56. const goPrivacyPolicy = () => {
  57. uni.navigateTo({ url: '/pages/login/privacy-policy' })
  58. }
  59. const toggleProtocolAgreement = () => {
  60. agreeProtocol.value = !agreeProtocol.value
  61. }
  62. const resolveProtocolDialog = (confirmed) => {
  63. protocolDialogVisible.value = false
  64. if (protocolDialogResolver) {
  65. protocolDialogResolver(confirmed)
  66. protocolDialogResolver = null
  67. }
  68. }
  69. </script>
  70. <template>
  71. <view class="login-page" :style="loginPageStyle">
  72. <!-- 背景装饰 -->
  73. <view class="login-bg">
  74. <view class="bg-circle circle-1"></view>
  75. <view class="bg-circle circle-2"></view>
  76. <view class="bg-circle circle-3"></view>
  77. </view>
  78. <view class="login-content">
  79. <view class="logo-section">
  80. <image class="logo-image" :src="DEFAULT_PLACEHOLDER_IMAGE_URL" mode="widthFix" />
  81. <text class="app-slogan">一体化业务移动端</text>
  82. </view>
  83. <view class="login-form">
  84. <view class="form-item">
  85. <text class="form-label">用户名</text>
  86. <view class="form-input-box">
  87. <uni-icons class="form-input-ico" type="person" size="18" color="#c0c4cc" />
  88. <input
  89. v-model="form.username"
  90. class="form-input"
  91. type="text"
  92. placeholder="请输入用户名"
  93. placeholder-class="input-placeholder"
  94. />
  95. </view>
  96. </view>
  97. <view class="form-item">
  98. <text class="form-label">密码</text>
  99. <view class="form-input-box">
  100. <uni-icons class="form-input-ico" type="locked" size="18" color="#c0c4cc" />
  101. <input
  102. v-model="form.password"
  103. class="form-input"
  104. type="password"
  105. placeholder="请输入密码"
  106. placeholder-class="input-placeholder"
  107. />
  108. </view>
  109. </view>
  110. <view class="form-actions">
  111. <button class="btn-login" :disabled="loginDisabled" @click="handleSubmit">
  112. <text v-if="isLoading" class="btn-login-text">登录中...</text>
  113. <text v-else class="btn-login-text">账号密码登录</text>
  114. </button>
  115. </view>
  116. </view>
  117. <view class="login-footer">
  118. <view class="footer-line">
  119. <view class="agree-check" @tap="toggleProtocolAgreement">
  120. <view class="agree-check__icon" :class="{ 'agree-check__icon--checked': agreeProtocol }">
  121. <text class="agree-check__tick">✓</text>
  122. </view>
  123. </view>
  124. <text class="footer-text">登录即表示同意</text>
  125. <text class="link" @tap="goUserAgreement">《用户服务协议》</text>
  126. <text class="footer-text">和</text>
  127. <text class="link" @tap="goPrivacyPolicy">《隐私政策》</text>
  128. </view>
  129. </view>
  130. </view>
  131. <view v-if="protocolDialogVisible" class="protocol-dialog-mask" @tap="resolveProtocolDialog(false)">
  132. <view class="protocol-dialog" @tap.stop>
  133. <text class="protocol-dialog__title">协议确认</text>
  134. <text class="protocol-dialog__desc">登录前请先同意《用户服务协议》和《隐私政策》</text>
  135. <view class="protocol-dialog__actions">
  136. <view class="protocol-dialog__btn protocol-dialog__btn--cancel" @tap="resolveProtocolDialog(false)">否</view>
  137. <view class="protocol-dialog__btn protocol-dialog__btn--confirm" @tap="resolveProtocolDialog(true)">是,继续登录</view>
  138. </view>
  139. </view>
  140. </view>
  141. </view>
  142. </template>
  143. <style lang="scss" scoped>
  144. .login-page {
  145. min-height: 100vh;
  146. min-height: 100dvh;
  147. background: linear-gradient(180deg, #f8fff8 0%, #ffffff 100%);
  148. position: relative;
  149. overflow: hidden;
  150. display: flex;
  151. flex-direction: column;
  152. align-items: center;
  153. justify-content: center;
  154. box-sizing: border-box;
  155. padding: calc(32rpx + var(--sq-safe-top, env(safe-area-inset-top, 0px))) 32rpx
  156. calc(32rpx + env(safe-area-inset-bottom, 0px));
  157. /* 与 placeholder 同色,供图标 mask 与 :deep(.input-placeholder) 共用 */
  158. --login-input-placeholder: #c0c4cc;
  159. }
  160. .login-bg {
  161. position: absolute;
  162. top: 0;
  163. left: 0;
  164. right: 0;
  165. bottom: 0;
  166. pointer-events: none;
  167. }
  168. .login-bg .bg-circle {
  169. position: absolute;
  170. border-radius: 50%;
  171. background: var(--theme-color);
  172. opacity: 0.05;
  173. }
  174. .login-bg .circle-1 {
  175. width: 400rpx;
  176. height: 400rpx;
  177. top: -100rpx;
  178. right: -100rpx;
  179. }
  180. .login-bg .circle-2 {
  181. width: 300rpx;
  182. height: 300rpx;
  183. top: 300rpx;
  184. left: -150rpx;
  185. }
  186. .login-bg .circle-3 {
  187. width: 200rpx;
  188. height: 200rpx;
  189. bottom: 100rpx;
  190. right: -50rpx;
  191. }
  192. .login-content {
  193. position: relative;
  194. z-index: 1;
  195. width: 100%;
  196. max-width: 680rpx;
  197. margin: 0 auto;
  198. box-sizing: border-box;
  199. padding: 0 8rpx;
  200. flex-shrink: 0;
  201. }
  202. /* 对齐 bxapp 登录页 brand-logo:横向自适应宽图,非圆角方标 */
  203. .logo-section {
  204. display: flex;
  205. flex-direction: column;
  206. align-items: center;
  207. text-align: center;
  208. margin-bottom: 44rpx;
  209. }
  210. .logo-image {
  211. display: block;
  212. width: 360rpx;
  213. max-width: 48vw;
  214. height: auto;
  215. margin: 0 auto 24rpx;
  216. }
  217. .app-slogan {
  218. font-size: 44rpx;
  219. font-weight: 700;
  220. letter-spacing: 0.02em;
  221. color: #1e293b;
  222. margin-top: 4rpx;
  223. }
  224. .login-form {
  225. background: #fff;
  226. border-radius: 24rpx;
  227. padding: 50rpx 40rpx;
  228. box-shadow: 0 10rpx 40rpx rgba(0, 0, 0, 0.08);
  229. }
  230. .form-item {
  231. margin-bottom: 36rpx;
  232. }
  233. .form-item:last-of-type {
  234. margin-bottom: 50rpx;
  235. }
  236. .form-label {
  237. display: block;
  238. font-size: 28rpx;
  239. color: #303133;
  240. margin-bottom: 16rpx;
  241. font-weight: 500;
  242. }
  243. .form-input-box {
  244. display: flex;
  245. align-items: center;
  246. height: 88rpx;
  247. background: #f5f7fa;
  248. border-radius: 16rpx;
  249. padding: 0 24rpx;
  250. box-sizing: border-box;
  251. }
  252. .form-input-ico {
  253. margin-right: 10rpx;
  254. flex-shrink: 0;
  255. display: flex;
  256. align-items: center;
  257. justify-content: center;
  258. }
  259. .form-input {
  260. flex: 1;
  261. min-width: 0;
  262. height: 100%;
  263. padding: 0;
  264. border: none;
  265. background: transparent;
  266. font-size: 28rpx;
  267. color: #303133;
  268. line-height: 1.25;
  269. }
  270. .form-actions {
  271. width: 100%;
  272. }
  273. .btn-login {
  274. width: 100%;
  275. height: 88rpx;
  276. border-radius: 44rpx;
  277. font-size: 30rpx;
  278. color: #fff;
  279. background: linear-gradient(135deg, var(--theme-color) 0%, #07c160 100%);
  280. border: none;
  281. display: flex;
  282. align-items: center;
  283. justify-content: center;
  284. padding: 0;
  285. line-height: 1.2;
  286. }
  287. .btn-login::after {
  288. border: none;
  289. }
  290. .btn-login.button-hover,
  291. .btn-login:active {
  292. background: linear-gradient(135deg, var(--theme-color) 0%, #07c160 100%);
  293. color: #fff;
  294. opacity: 1;
  295. }
  296. .btn-login-text {
  297. line-height: 1.2;
  298. font-size: 30rpx;
  299. }
  300. .login-footer {
  301. margin-top: 60rpx;
  302. padding: 0 20rpx;
  303. }
  304. .footer-line {
  305. display: flex;
  306. flex-wrap: wrap;
  307. justify-content: center;
  308. align-items: center;
  309. column-gap: 4rpx;
  310. row-gap: 8rpx;
  311. }
  312. .agree-check {
  313. display: inline-flex;
  314. align-items: center;
  315. justify-content: center;
  316. padding: 8rpx;
  317. margin-right: 4rpx;
  318. flex-shrink: 0;
  319. }
  320. .agree-check__icon {
  321. width: 30rpx;
  322. height: 30rpx;
  323. border-radius: 50%;
  324. border: 2rpx solid #c0c4cc;
  325. box-sizing: border-box;
  326. display: flex;
  327. align-items: center;
  328. justify-content: center;
  329. background: #fff;
  330. }
  331. .agree-check__tick {
  332. font-size: 18rpx;
  333. font-weight: 700;
  334. line-height: 1;
  335. color: transparent;
  336. }
  337. .agree-check__icon--checked {
  338. border-color: var(--theme-color);
  339. background: var(--theme-color);
  340. }
  341. .agree-check__icon--checked .agree-check__tick {
  342. color: #fff;
  343. }
  344. .footer-text,
  345. .link {
  346. font-size: 22rpx;
  347. line-height: 1.6;
  348. }
  349. .footer-text {
  350. color: #909399;
  351. }
  352. .link {
  353. color: var(--theme-color);
  354. }
  355. .protocol-dialog-mask {
  356. position: fixed;
  357. inset: 0;
  358. background: rgba(0, 0, 0, 0.42);
  359. z-index: 99;
  360. display: flex;
  361. align-items: center;
  362. justify-content: center;
  363. padding: 40rpx;
  364. box-sizing: border-box;
  365. }
  366. .protocol-dialog {
  367. width: 100%;
  368. max-width: 620rpx;
  369. background: #fff;
  370. border-radius: 24rpx;
  371. padding: 36rpx 30rpx 28rpx;
  372. box-sizing: border-box;
  373. box-shadow: 0 14rpx 48rpx rgba(0, 0, 0, 0.16);
  374. }
  375. .protocol-dialog__title {
  376. display: block;
  377. text-align: center;
  378. font-size: 34rpx;
  379. font-weight: 700;
  380. color: #303133;
  381. }
  382. .protocol-dialog__desc {
  383. display: block;
  384. margin-top: 16rpx;
  385. text-align: center;
  386. font-size: 26rpx;
  387. line-height: 1.6;
  388. color: #606266;
  389. }
  390. .protocol-dialog__actions {
  391. margin-top: 30rpx;
  392. display: flex;
  393. gap: 16rpx;
  394. }
  395. .protocol-dialog__btn {
  396. flex: 1;
  397. min-height: 78rpx;
  398. border-radius: 999rpx;
  399. display: flex;
  400. align-items: center;
  401. justify-content: center;
  402. font-size: 28rpx;
  403. font-weight: 600;
  404. }
  405. .protocol-dialog__btn--cancel {
  406. background: #f4f7f6;
  407. color: #5b6b64;
  408. border: 1px solid #ddebe5;
  409. }
  410. .protocol-dialog__btn--confirm {
  411. background: linear-gradient(135deg, var(--theme-color) 0%, #07c160 100%);
  412. color: #fff;
  413. }
  414. </style>
  415. <!-- placeholder-class 在部分真机需非 scoped 才稳定生效;颜色与 --login-input-placeholder 一致 -->
  416. <style lang="scss">
  417. .input-placeholder {
  418. color: #c0c4cc;
  419. font-size: 28rpx;
  420. }
  421. </style>