AccountLogin.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <template>
  2. <view class="account-login-container">
  3. <view class="content-wrapper">
  4. <!-- 欢迎语 -->
  5. <view class="welcome-section">
  6. <text class="welcome-title">欢迎回来</text>
  7. <text class="welcome-desc">请输入您的账号密码登录系统</text>
  8. </view>
  9. <!-- 表单卡片 -->
  10. <view class="form-card">
  11. <view class="input-item">
  12. <view class="input-icon-box">
  13. <image class="input-icon" src="https://img.icons8.com/ios-glyphs/40/999999/user--v1.png"
  14. mode="aspectFit"></image>
  15. </view>
  16. <input class="form-input" v-model="account" placeholder="手机号" type="number" maxlength="11" />
  17. </view>
  18. <view class="input-divider"></view>
  19. <view class="input-item">
  20. <view class="input-icon-box">
  21. <image class="input-icon" src="https://img.icons8.com/ios-glyphs/40/999999/lock--v1.png"
  22. mode="aspectFit"></image>
  23. </view>
  24. <input class="form-input" v-model="password" placeholder="密码" :password="!showPwd" maxlength="20" />
  25. <view class="pwd-toggle" @click="showPwd = !showPwd">
  26. <text class="pwd-toggle-text">{{ showPwd ? '隐藏' : '显示' }}</text>
  27. </view>
  28. </view>
  29. </view>
  30. <!-- 登录按钮 -->
  31. <view class="login-btn-wrapper">
  32. <view class="login-btn-shadow"></view>
  33. <button class="login-btn" :class="{ 'is-disabled': !canSubmit }" :loading="submitting"
  34. @click="handleLogin">
  35. <text v-if="!submitting">登 录</text>
  36. </button>
  37. </view>
  38. <!-- 协议 -->
  39. <view class="agreement-box" @click="toggleAgreed">
  40. <view class="agreement-check" :class="{ checked: isAgreed }">
  41. <text v-if="isAgreed" class="check-mark">✓</text>
  42. </view>
  43. <text class="agreement-text">
  44. 已阅读并同意<text class="link" @click.stop="showProtocol('user')">《用户协议》</text>和<text class="link"
  45. @click.stop="showProtocol('privacy')">《隐私政策》</text>
  46. </text>
  47. </view>
  48. </view>
  49. <!-- 页脚 -->
  50. <view class="footer-section">
  51. <text>ERP Order System</text>
  52. </view>
  53. <!-- ========== 弹窗 ========== -->
  54. <view class="global-mask" v-if="activeModal" @click="closeAllModals"></view>
  55. <!-- 协议拦截弹窗 -->
  56. <view class="dialog-overlay" v-if="activeModal === 'confirm'">
  57. <view class="dialog-card">
  58. <view class="dialog-icon-wrap">
  59. <text class="dialog-icon">📋</text>
  60. </view>
  61. <text class="dialog-title">服务协议提示</text>
  62. <text class="dialog-body">请您阅读并同意我们的协议内容,以便为您提供更安全的服务体验。</text>
  63. <view class="dialog-btns">
  64. <view class="dialog-btn cancel" @click="activeModal = ''">拒绝</view>
  65. <view class="dialog-btn confirm" @click="agreeAndClose">同意并继续</view>
  66. </view>
  67. </view>
  68. </view>
  69. <!-- 协议富文本弹窗 -->
  70. <view class="dialog-overlay" v-if="activeModal === 'protocol'">
  71. <view class="dialog-card dialog-protocol">
  72. <view class="dialog-header">
  73. <text class="dialog-header-title">{{ currentProtocol.title }}</text>
  74. <view class="dialog-close" @click="activeModal = ''">
  75. <text class="dialog-close-text">✕</text>
  76. </view>
  77. </view>
  78. <scroll-view scroll-y class="dialog-scroll">
  79. <rich-text :nodes="currentProtocol.content"></rich-text>
  80. </scroll-view>
  81. <view class="dialog-bottom">
  82. <button class="dialog-confirm-btn" @click="activeModal = ''">我已了解</button>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. </template>
  88. <script>
  89. import { getAgreement } from '@/api/system/agreement.js';
  90. import { login } from '@/api/auth.js';
  91. export default {
  92. name: 'AccountLogin',
  93. emits: ['login-success'],
  94. data() {
  95. return {
  96. account: '',
  97. password: '',
  98. showPwd: false,
  99. submitting: false,
  100. isAgreed: false,
  101. activeModal: '',
  102. currentProtocol: { title: '', content: '' },
  103. protocols: {
  104. user: { title: '', content: '' },
  105. privacy: { title: '', content: '' }
  106. }
  107. }
  108. },
  109. computed: {
  110. canSubmit() {
  111. return this.account.trim().length === 11 && this.password.trim().length >= 6;
  112. }
  113. },
  114. methods: {
  115. toggleAgreed() {
  116. this.isAgreed = !this.isAgreed;
  117. },
  118. async handleLogin() {
  119. if (!this.canSubmit) return;
  120. if (!this.isAgreed) {
  121. this.activeModal = 'confirm';
  122. return;
  123. }
  124. this.submitting = true;
  125. try {
  126. const res = await login({
  127. username: this.account.trim(),
  128. password: this.password,
  129. grantType: 'password'
  130. });
  131. if (res.data && res.data.access_token) {
  132. uni.setStorageSync('token', res.data.access_token);
  133. uni.setStorageSync('isLogin', true);
  134. uni.showToast({ title: '登录成功', icon: 'success' });
  135. setTimeout(() => {
  136. this.$emit('login-success');
  137. }, 800);
  138. } else {
  139. uni.showToast({ title: '登录失败,请检查账号密码', icon: 'none' });
  140. }
  141. } catch (e) {
  142. console.error('登录错误:', e);
  143. uni.showToast({ title: e?.msg || e || '登录失败', icon: 'none' });
  144. } finally {
  145. this.submitting = false;
  146. }
  147. },
  148. agreeAndClose() {
  149. this.isAgreed = true;
  150. this.activeModal = '';
  151. },
  152. showProtocol(type) {
  153. this.currentProtocol = this.protocols[type];
  154. this.activeModal = 'protocol';
  155. },
  156. closeAllModals() {
  157. this.activeModal = '';
  158. }
  159. },
  160. async mounted() {
  161. try {
  162. const [userRes, privacyRes] = await Promise.all([
  163. getAgreement(1),
  164. getAgreement(2)
  165. ]);
  166. this.protocols.user = { title: userRes.data.title, content: userRes.data.content };
  167. this.protocols.privacy = { title: privacyRes.data.title, content: privacyRes.data.content };
  168. } catch (e) {
  169. console.error('[协议] 加载失败', e);
  170. }
  171. }
  172. }
  173. </script>
  174. <style scoped>
  175. .account-login-container {
  176. width: 100%;
  177. min-height: 100vh;
  178. display: flex;
  179. flex-direction: column;
  180. }
  181. .content-wrapper {
  182. flex: 1;
  183. padding: 60rpx 56rpx 0;
  184. display: flex;
  185. flex-direction: column;
  186. }
  187. /* ========== 欢迎语 ========== */
  188. .welcome-section {
  189. margin-bottom: 56rpx;
  190. }
  191. .welcome-title {
  192. font-size: 52rpx;
  193. font-weight: 700;
  194. color: #1a1a1a;
  195. display: block;
  196. line-height: 1.3;
  197. }
  198. .welcome-desc {
  199. font-size: 28rpx;
  200. color: #999;
  201. display: block;
  202. margin-top: 12rpx;
  203. letter-spacing: 1rpx;
  204. }
  205. /* ========== 表单卡片 ========== */
  206. .form-card {
  207. background: #fff;
  208. border-radius: 24rpx;
  209. box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.04);
  210. padding: 16rpx 32rpx;
  211. }
  212. .input-item {
  213. display: flex;
  214. align-items: center;
  215. height: 104rpx;
  216. }
  217. .input-icon-box {
  218. width: 52rpx;
  219. height: 52rpx;
  220. border-radius: 16rpx;
  221. background: #f5f6fa;
  222. display: flex;
  223. align-items: center;
  224. justify-content: center;
  225. margin-right: 20rpx;
  226. flex-shrink: 0;
  227. }
  228. .input-icon {
  229. width: 28rpx;
  230. height: 28rpx;
  231. }
  232. .form-input {
  233. flex: 1;
  234. font-size: 30rpx;
  235. color: #1a1a1a;
  236. height: 100%;
  237. }
  238. .input-divider {
  239. height: 1rpx;
  240. background: #f0f0f0;
  241. margin: 0 8rpx;
  242. }
  243. .pwd-toggle {
  244. flex-shrink: 0;
  245. padding: 8rpx 0 8rpx 20rpx;
  246. }
  247. .pwd-toggle-text {
  248. font-size: 24rpx;
  249. color: #b0b0b0;
  250. }
  251. /* ========== 登录按钮 ========== */
  252. .login-btn-wrapper {
  253. position: relative;
  254. margin-top: 48rpx;
  255. }
  256. .login-btn-shadow {
  257. position: absolute;
  258. bottom: -6rpx;
  259. left: 6%;
  260. width: 88%;
  261. height: 100rpx;
  262. border-radius: 50rpx;
  263. background: rgba(193, 0, 28, 0.18);
  264. filter: blur(16rpx);
  265. }
  266. .login-btn {
  267. position: relative;
  268. width: 100%;
  269. height: 100rpx;
  270. background: linear-gradient(135deg, #C1001C, #e0243f);
  271. border-radius: 50rpx;
  272. color: #fff;
  273. font-size: 34rpx;
  274. font-weight: 600;
  275. letter-spacing: 16rpx;
  276. border: none;
  277. display: flex;
  278. align-items: center;
  279. justify-content: center;
  280. transition: all 0.3s ease;
  281. box-shadow: 0 8rpx 24rpx rgba(193, 0, 28, 0.3);
  282. }
  283. .login-btn::after {
  284. border: none;
  285. }
  286. .login-btn.is-disabled {
  287. opacity: 0.45;
  288. box-shadow: none;
  289. }
  290. /* ========== 协议 ========== */
  291. .agreement-box {
  292. display: flex;
  293. align-items: center;
  294. justify-content: center;
  295. margin-top: 40rpx;
  296. }
  297. .agreement-check {
  298. width: 34rpx;
  299. height: 34rpx;
  300. border-radius: 50%;
  301. border: 2rpx solid #d0d0d0;
  302. display: flex;
  303. align-items: center;
  304. justify-content: center;
  305. margin-right: 12rpx;
  306. flex-shrink: 0;
  307. transition: all 0.2s ease;
  308. }
  309. .agreement-check.checked {
  310. background: #C1001C;
  311. border-color: #C1001C;
  312. }
  313. .check-mark {
  314. color: #fff;
  315. font-size: 20rpx;
  316. font-weight: bold;
  317. }
  318. .agreement-text {
  319. font-size: 24rpx;
  320. color: #b0b0b0;
  321. line-height: 1.5;
  322. }
  323. .link {
  324. color: #576b95;
  325. }
  326. /* ========== 页脚 ========== */
  327. .footer-section {
  328. text-align: center;
  329. padding: 48rpx 0;
  330. }
  331. .footer-section text {
  332. font-size: 22rpx;
  333. color: #d0d0d0;
  334. letter-spacing: 2rpx;
  335. }
  336. /* ========== 弹窗通用 ========== */
  337. .global-mask {
  338. position: fixed;
  339. top: 0;
  340. left: 0;
  341. right: 0;
  342. bottom: 0;
  343. background: rgba(0, 0, 0, 0.45);
  344. z-index: 998;
  345. }
  346. .dialog-overlay {
  347. position: fixed;
  348. top: 0;
  349. left: 0;
  350. right: 0;
  351. bottom: 0;
  352. display: flex;
  353. align-items: center;
  354. justify-content: center;
  355. z-index: 1000;
  356. padding: 60rpx;
  357. }
  358. .dialog-card {
  359. width: 100%;
  360. background: #fff;
  361. border-radius: 28rpx;
  362. padding: 52rpx 40rpx 36rpx;
  363. display: flex;
  364. flex-direction: column;
  365. align-items: center;
  366. }
  367. .dialog-protocol {
  368. padding: 0;
  369. align-items: stretch;
  370. max-height: 70vh;
  371. }
  372. .dialog-icon-wrap {
  373. width: 80rpx;
  374. height: 80rpx;
  375. border-radius: 50%;
  376. background: #fff5f5;
  377. display: flex;
  378. align-items: center;
  379. justify-content: center;
  380. margin-bottom: 28rpx;
  381. }
  382. .dialog-icon {
  383. font-size: 40rpx;
  384. }
  385. .dialog-title {
  386. font-size: 34rpx;
  387. font-weight: 600;
  388. color: #1a1a1a;
  389. margin-bottom: 16rpx;
  390. text-align: center;
  391. }
  392. .dialog-body {
  393. font-size: 28rpx;
  394. color: #888;
  395. line-height: 1.7;
  396. text-align: center;
  397. margin-bottom: 40rpx;
  398. }
  399. .dialog-btns {
  400. width: 100%;
  401. display: flex;
  402. gap: 20rpx;
  403. }
  404. .dialog-btn {
  405. flex: 1;
  406. height: 88rpx;
  407. border-radius: 44rpx;
  408. font-size: 30rpx;
  409. font-weight: 500;
  410. display: flex;
  411. align-items: center;
  412. justify-content: center;
  413. }
  414. .dialog-btn.cancel {
  415. background: #f5f5f5;
  416. color: #999;
  417. }
  418. .dialog-btn.confirm {
  419. background: #1a1a1a;
  420. color: #fff;
  421. }
  422. /* ========== 协议内容弹窗 ========== */
  423. .dialog-header {
  424. display: flex;
  425. align-items: center;
  426. justify-content: space-between;
  427. padding: 36rpx 40rpx 24rpx;
  428. border-bottom: 1rpx solid #f5f5f5;
  429. }
  430. .dialog-header-title {
  431. font-size: 34rpx;
  432. font-weight: 600;
  433. color: #1a1a1a;
  434. }
  435. .dialog-close {
  436. width: 48rpx;
  437. height: 48rpx;
  438. border-radius: 50%;
  439. background: #f5f5f5;
  440. display: flex;
  441. align-items: center;
  442. justify-content: center;
  443. }
  444. .dialog-close-text {
  445. font-size: 26rpx;
  446. color: #999;
  447. }
  448. .dialog-scroll {
  449. max-height: 50vh;
  450. padding: 28rpx 40rpx;
  451. color: #555;
  452. font-size: 28rpx;
  453. line-height: 1.8;
  454. }
  455. .dialog-bottom {
  456. padding: 24rpx 40rpx 36rpx;
  457. }
  458. .dialog-confirm-btn {
  459. width: 100%;
  460. height: 88rpx;
  461. background: #1a1a1a;
  462. color: #fff;
  463. border-radius: 44rpx;
  464. font-size: 30rpx;
  465. font-weight: 500;
  466. border: none;
  467. display: flex;
  468. align-items: center;
  469. justify-content: center;
  470. }
  471. .dialog-confirm-btn::after {
  472. border: none;
  473. }
  474. </style>