index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. <template>
  2. <view class="container">
  3. <!-- 顶部 Banner 区域 -->
  4. <view class="banner-area">
  5. <image class="banner-img" :src="loginBackgroundUrl" mode="widthFix"></image>
  6. </view>
  7. <!-- 白色内容卡片 -->
  8. <view class="content-card">
  9. <!-- 悬浮 Logo -->
  10. <view class="logo-wrapper">
  11. <image class="logo-img" :src="loginIconUrl" mode="widthFix"></image>
  12. </view>
  13. <!-- 登录 Tab 切换 -->
  14. <!-- <view class="tabs">
  15. <view
  16. class="tab-item"
  17. :class="{ active: currentTab === 0 }"
  18. @click="currentTab = 0"
  19. >
  20. <text class="tab-text">免密登录</text>
  21. <view class="tab-indicator" v-if="currentTab === 0"></view>
  22. </view>
  23. <view class="divider"></view>
  24. <view
  25. class="tab-item"
  26. :class="{ active: currentTab === 1 }"
  27. @click="currentTab = 1"
  28. >
  29. <text class="tab-text">密码登录</text>
  30. <view class="tab-indicator" v-if="currentTab === 1"></view>
  31. </view>
  32. </view> -->
  33. <view class="tabs">
  34. <view class="tab-item active">
  35. <text class="tab-text">密码登录</text>
  36. <view class="tab-indicator"></view>
  37. </view>
  38. </view>
  39. <!-- 表单区域 -->
  40. <view class="form-area">
  41. <!-- 手机号 (通用) -->
  42. <view class="input-group">
  43. <view class="area-code">
  44. <text>+86</text>
  45. <text class="arrow">﹀</text>
  46. </view>
  47. <input class="input" type="number" placeholder="手机号" placeholder-style="color: #ccc" v-model="mobile"
  48. maxlength="11" />
  49. </view>
  50. <!-- 免密登录: 验证码 -->
  51. <!-- <view class="input-group" v-if="currentTab === 0">
  52. <input
  53. class="input"
  54. type="number"
  55. placeholder="验证码"
  56. placeholder-style="color: #ccc"
  57. v-model="code"
  58. maxlength="6"
  59. />
  60. <view class="get-code-btn" @click="getVerifyCode">
  61. <text class="code-text">{{ countDown > 0 ? `${countDown}s后重试` : '获取验证码' }}</text>
  62. </view>
  63. </view> -->
  64. <!-- 密码登录: 密码框 -->
  65. <view class="input-group">
  66. <input class="input" :password="!showPassword" type="text" placeholder="请输入密码" placeholder-style="color: #ccc"
  67. v-model="password" />
  68. <view class="eye-icon" @click="showPassword = !showPassword">
  69. <template v-if="showPassword">
  70. <!-- 睁眼线框图标 -->
  71. <svg class="svg-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
  72. <path
  73. d="M12 4.5C7 4.5 2.73 7.61 1 12C2.73 16.39 7 19.5 12 19.5C17 19.5 21.27 16.39 23 12C21.27 7.61 17 4.5 12 4.5ZM12 17C9.24 17 7 14.76 7 12C7 9.24 9.24 7 12 7C14.76 7 17 9.24 17 12C17 14.76 14.76 17 12 17ZM12 9C10.34 9 9 10.34 9 12C9 13.66 10.34 15 12 15C13.66 15 15 13.66 15 12C15 10.34 13.66 9 12 9Z"
  74. fill="#CCCCCC" />
  75. </svg>
  76. </template>
  77. <template v-else>
  78. <!-- 闭眼线框图标 (带睫毛) -->
  79. <svg class="svg-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
  80. <path d="M12 7C7 7 2.73 10.11 1 14.5" stroke="#CCCCCC" stroke-width="2" stroke-linecap="round" />
  81. <path d="M23 14.5C21.27 10.11 17 7 12 7" stroke="#CCCCCC" stroke-width="2" stroke-linecap="round" />
  82. <path d="M12 7V4" stroke="#CCCCCC" stroke-width="2" stroke-linecap="round" />
  83. <path d="M16 8L18 5" stroke="#CCCCCC" stroke-width="2" stroke-linecap="round" />
  84. <path d="M8 8L6 5" stroke="#CCCCCC" stroke-width="2" stroke-linecap="round" />
  85. <path d="M20 10L22 8" stroke="#CCCCCC" stroke-width="2" stroke-linecap="round" />
  86. <path d="M4 10L2 8" stroke="#CCCCCC" stroke-width="2" stroke-linecap="round" />
  87. </svg>
  88. </template>
  89. </view>
  90. </view>
  91. <!-- 忘记密码 -->
  92. <!-- <view class="forgot-pwd">
  93. <text @click="goToForgotPwd">忘记密码?</text>
  94. </view> -->
  95. <!-- 登录按钮 -->
  96. <button class="login-btn" @click="handleLogin">登 录</button>
  97. <!-- 协议 -->
  98. <view class="agreement">
  99. <view class="checkbox" :class="{ checked: isAgreed }" @click="isAgreed = !isAgreed">
  100. <text v-if="isAgreed" class="check-mark">✓</text>
  101. </view>
  102. <text class="agree-text">
  103. 我已经阅读并同意 <text class="link" @click.stop="showAgreement(1)">《用户服务协议》</text> 和 <text class="link"
  104. @click.stop="showAgreement(2)">《隐私政策》</text>
  105. </text>
  106. </view>
  107. </view>
  108. <!-- 底部招募入口 (固定底部) -->
  109. <view class="footer-recruit" @click="goToRecruit">
  110. <view class="recruit-badge">
  111. <!-- 旗帜线框图标 -->
  112. <svg class="svg-icon flag-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"
  113. style="width:30rpx; height:30rpx;">
  114. <path d="M4 14V4H18L17 9L18 14H4Z" stroke="#FF5722" stroke-width="2" stroke-linejoin="round" />
  115. <path d="M4 22V14" stroke="#FF5722" stroke-width="2" stroke-linecap="round" />
  116. </svg>
  117. <text> 宠宝履约者招募</text>
  118. </view>
  119. </view>
  120. <!-- 协议弹窗 公共组件 -->
  121. <agreement :visible="showAgreementModal" :title="agreementTitle" :content="agreementContent"
  122. @close="showAgreementModal = false">
  123. </agreement>
  124. </view>
  125. </view>
  126. </template>
  127. <script>
  128. import { loginByPassword, loginBySms } from '@/api/auth'
  129. import { sendSmsCode } from '@/api/resource/sms'
  130. import { getAgreement } from '@/api/system/agreement'
  131. import { getAppSetting } from '@/api/system/appSetting'
  132. import { setToken } from '@/utils/auth'
  133. import { startGpsTimer } from '@/utils/gps'
  134. import Agreement from '@/components/agreement/index.vue'
  135. export default {
  136. components: {
  137. Agreement
  138. },
  139. data() {
  140. return {
  141. currentTab: 1, // 0: 免密, 1: 密码
  142. mobile: '',
  143. code: '',
  144. password: '',
  145. showPassword: false,
  146. isAgreed: false,
  147. countDown: 0,
  148. timer: null,
  149. showAgreementModal: false,
  150. agreementTitle: '', // 协议标题
  151. agreementContent: '', // 协议内容
  152. loginLoading: false,
  153. loginIconUrl: '/static/logo.png', // 登录图标
  154. loginBackgroundUrl: '/static/header.png' // 登录背景
  155. }
  156. },
  157. async onLoad() {
  158. // 进入登录页时,清除招募认证暂存数据
  159. uni.removeStorageSync('recruit_form_data');
  160. uni.removeStorageSync('recruit_auth_data');
  161. uni.removeStorageSync('recruit_qual_data');
  162. // 获取应用配置
  163. await this.fetchAppSetting();
  164. },
  165. methods: {
  166. /**
  167. * 获取应用配置
  168. */
  169. async fetchAppSetting() {
  170. try {
  171. const res = await getAppSetting(1);
  172. if (res.code === 200 && res.data) {
  173. if (res.data.loginIconUrl) {
  174. this.loginIconUrl = res.data.loginIconUrl;
  175. }
  176. if (res.data.loginBackgroundUrl) {
  177. this.loginBackgroundUrl = res.data.loginBackgroundUrl;
  178. }
  179. }
  180. } catch (err) {
  181. console.error('获取应用配置失败:', err);
  182. }
  183. },
  184. /**
  185. * 显示协议弹窗
  186. * @param {Number} id 协议ID (1: 用户服务协议, 2: 隐私政策)
  187. */
  188. async showAgreement(id) {
  189. try {
  190. uni.showLoading({ title: '加载中...' });
  191. const res = await getAgreement(id);
  192. this.agreementTitle = res.data.title;
  193. this.agreementContent = res.data.content;
  194. this.showAgreementModal = true;
  195. } catch (err) {
  196. console.error('获取协议详情失败:', err);
  197. } finally {
  198. uni.hideLoading();
  199. }
  200. },
  201. /* async getVerifyCode() {
  202. if (this.currentTab === 1) return;
  203. if (this.countDown > 0) return;
  204. if (!this.mobile || this.mobile.length !== 11) {
  205. uni.showToast({ title: '请输入正确的手机号', icon: 'none' });
  206. return;
  207. }
  208. try {
  209. const res = await sendSmsCode(this.mobile);
  210. // 发送成功,启动倒计时
  211. this.countDown = 60;
  212. this.timer = setInterval(() => {
  213. this.countDown--;
  214. if (this.countDown <= 0) {
  215. clearInterval(this.timer);
  216. }
  217. }, 1000);
  218. // TODO 【生产环境必须删除】开发模式下后端会返回验证码,自动填入方便测试
  219. const devCode = res.data;
  220. if (devCode) {
  221. this.code = devCode;
  222. uni.showToast({ title: '验证码: ' + devCode, icon: 'none', duration: 3000 });
  223. } else {
  224. uni.showToast({ title: '验证码已发送', icon: 'none' });
  225. }
  226. } catch (err) {
  227. console.error('发送验证码失败:', err);
  228. }
  229. }, */
  230. async handleLogin() {
  231. if (!this.isAgreed) {
  232. uni.showToast({ title: '请先同意用户协议', icon: 'none' });
  233. return;
  234. }
  235. if (!this.mobile) {
  236. uni.showToast({ title: '请输入手机号', icon: 'none' });
  237. return;
  238. }
  239. /* if (this.currentTab === 0) {
  240. // 免密登录
  241. if (!this.code) {
  242. uni.showToast({ title: '请输入验证码', icon: 'none' });
  243. return;
  244. }
  245. } else {
  246. // 密码登录
  247. if (!this.password) {
  248. uni.showToast({ title: '请输入密码', icon: 'none' });
  249. return;
  250. }
  251. } */
  252. if (!this.password) {
  253. uni.showToast({ title: '请输入密码', icon: 'none' });
  254. return;
  255. }
  256. if (this.loginLoading) return;
  257. this.loginLoading = true;
  258. uni.showLoading({
  259. title: '登录中...',
  260. mask: true
  261. });
  262. try {
  263. let res;
  264. /* if (this.currentTab === 0) {
  265. // 短信验证码登录
  266. res = await loginBySms(this.mobile, this.code);
  267. } else {
  268. // 密码登录
  269. res = await loginByPassword(this.mobile, this.password);
  270. } */
  271. res = await loginByPassword(this.mobile, this.password);
  272. // 保存 Token
  273. const token = res.data?.access_token || res.access_token;
  274. if (token) {
  275. setToken(token);
  276. }
  277. startGpsTimer();
  278. uni.showToast({ title: '登录成功', icon: 'success' });
  279. setTimeout(() => {
  280. uni.reLaunch({
  281. url: '/pages/home/index'
  282. });
  283. }, 1000);
  284. } catch (err) {
  285. // 错误已在 request.js 中统一处理
  286. console.error('登录失败:', err);
  287. } finally {
  288. this.loginLoading = false;
  289. uni.hideLoading();
  290. }
  291. },
  292. goToRecruit() {
  293. uni.navigateTo({
  294. url: '/pages/recruit/landing/index'
  295. });
  296. },
  297. goToForgotPwd() {
  298. uni.navigateTo({
  299. url: '/pages/login/reset-pwd-verify/index'
  300. });
  301. }
  302. }
  303. }
  304. </script>
  305. <style>
  306. /* 页面容器 */
  307. .container {
  308. height: 100vh;
  309. /* 强制全屏高度 */
  310. overflow: hidden;
  311. /* 禁止溢出滚动 */
  312. background-color: #fff;
  313. position: relative;
  314. display: flex;
  315. flex-direction: column;
  316. }
  317. /* 顶部 Banner */
  318. .banner-area {
  319. width: 100%;
  320. position: relative;
  321. /* 移除高度限制,依靠 content-card 的 margin-top 控制遮挡 */
  322. }
  323. .banner-img {
  324. width: 100%;
  325. display: block;
  326. /* 消除图片底部空隙 */
  327. }
  328. /* 内容卡片 - 核心布局技巧 */
  329. .content-card {
  330. flex: 1;
  331. background-color: #fff;
  332. margin-top: -80rpx;
  333. /* 向上覆盖 banner,形成遮挡 */
  334. /* 实现向上凸起的圆弧效果: 使用 border-radius 实现顶部椭圆 */
  335. border-radius: 100% 100% 0 0 / 60rpx 60rpx 0 0;
  336. position: relative;
  337. z-index: 10;
  338. padding: 0 50rpx;
  339. display: flex;
  340. flex-direction: column;
  341. align-items: center;
  342. }
  343. /* 悬浮 Logo */
  344. .logo-wrapper {
  345. margin-top: -70rpx;
  346. /* Logo 向上悬浮 */
  347. margin-bottom: 50rpx;
  348. /* 添加白色光晕/阴影增强悬浮感 */
  349. border-radius: 50%;
  350. box-shadow: 0 10rpx 40rpx rgba(0, 0, 0, 0.1);
  351. background-color: #fff;
  352. padding: 8rpx;
  353. /* 白色边框 */
  354. }
  355. .logo-img {
  356. width: 120rpx;
  357. height: 120rpx;
  358. border-radius: 50%;
  359. display: block;
  360. }
  361. /* Tabs */
  362. .tabs {
  363. display: flex;
  364. align-items: center;
  365. margin-bottom: 60rpx;
  366. }
  367. .tab-item {
  368. display: flex;
  369. flex-direction: column;
  370. align-items: center;
  371. padding: 0 30rpx;
  372. }
  373. .tab-text {
  374. font-size: 32rpx;
  375. color: #999;
  376. font-weight: 500;
  377. margin-bottom: 10rpx;
  378. }
  379. .tab-item.active .tab-text {
  380. color: #FF5722;
  381. /* 主色调橙色 */
  382. font-weight: bold;
  383. font-size: 36rpx;
  384. }
  385. .tab-indicator {
  386. width: 40rpx;
  387. height: 6rpx;
  388. background-color: #FF5722;
  389. border-radius: 3rpx;
  390. }
  391. .divider {
  392. width: 1px;
  393. height: 30rpx;
  394. background-color: #eee;
  395. margin: 0 10rpx;
  396. }
  397. /* 表单 */
  398. .form-area {
  399. width: 100%;
  400. }
  401. .input-group {
  402. display: flex;
  403. align-items: center;
  404. border-bottom: 1px solid #f0f0f0;
  405. padding: 30rpx 0;
  406. margin-bottom: 20rpx;
  407. }
  408. .area-code {
  409. display: flex;
  410. align-items: center;
  411. margin-right: 20rpx;
  412. font-size: 32rpx;
  413. color: #333;
  414. height: 100%;
  415. /* 确保高度撑满 */
  416. }
  417. .arrow {
  418. font-size: 20rpx;
  419. color: #999;
  420. margin-left: 8rpx;
  421. /* margin-top: 4rpx; 移除微调,依靠 flex 居中 */
  422. }
  423. .input {
  424. flex: 1;
  425. font-size: 30rpx;
  426. }
  427. .get-code-btn {
  428. background-color: #FFF0E9;
  429. /* 浅橙色背景 */
  430. padding: 15rpx 30rpx;
  431. /* 增大内边距 */
  432. border-radius: 40rpx;
  433. /* 稍微增大圆角 */
  434. display: flex;
  435. align-items: center;
  436. justify-content: center;
  437. }
  438. .code-text {
  439. color: #FF5722;
  440. font-size: 28rpx;
  441. /* 增大字体 */
  442. line-height: 1;
  443. /* 修正文字垂直居中 */
  444. }
  445. .eye-icon {
  446. padding: 10rpx;
  447. display: flex;
  448. align-items: center;
  449. justify-content: center;
  450. }
  451. .svg-icon {
  452. width: 40rpx;
  453. height: 40rpx;
  454. }
  455. .forgot-pwd {
  456. width: 100%;
  457. text-align: right;
  458. padding-top: 20rpx;
  459. font-size: 26rpx;
  460. color: #666;
  461. }
  462. /* 按钮 */
  463. .login-btn {
  464. /* 鲜亮的橙色渐变 */
  465. background: linear-gradient(90deg, #FF9E60 0%, #FF5722 100%);
  466. color: #fff;
  467. border-radius: 50rpx;
  468. margin-top: 60rpx;
  469. margin-bottom: 40rpx;
  470. font-size: 34rpx;
  471. font-weight: bold;
  472. box-shadow: 0 10rpx 30rpx rgba(255, 87, 34, 0.35);
  473. /* 增强投影 */
  474. }
  475. .login-btn::after {
  476. border: none;
  477. }
  478. /* 协议 */
  479. .agreement {
  480. display: flex;
  481. align-items: center;
  482. /* 改为居中对齐,如果文字换行可能需要改为 flex-start 并调整 margin-top */
  483. justify-content: center;
  484. }
  485. .checkbox {
  486. width: 32rpx;
  487. height: 32rpx;
  488. border: 2rpx solid #ccc;
  489. border-radius: 50%;
  490. margin-right: 12rpx;
  491. /* margin-top: 4rpx; 移除顶部 margin,由 align-items: center 控制 */
  492. display: flex;
  493. align-items: center;
  494. justify-content: center;
  495. }
  496. .checkbox.checked {
  497. border-color: #FF5722;
  498. background-color: #FF5722;
  499. }
  500. .check-mark {
  501. color: #fff;
  502. font-size: 22rpx;
  503. line-height: 1;
  504. /* 确保勾选符号居中 */
  505. }
  506. .agree-text {
  507. font-size: 24rpx;
  508. color: #999;
  509. line-height: 1.5;
  510. }
  511. .link {
  512. color: #666;
  513. }
  514. /* 底部招募 */
  515. .footer-recruit {
  516. margin-top: auto;
  517. padding-bottom: 80rpx;
  518. /* 增加底部距离 */
  519. width: 100%;
  520. display: flex;
  521. justify-content: center;
  522. }
  523. .recruit-badge {
  524. display: flex;
  525. align-items: center;
  526. padding: 20rpx 50rpx;
  527. background-color: #fff;
  528. /* 白色背景 */
  529. border: 1px solid #FF5722;
  530. /* 橙色边框 */
  531. border-radius: 60rpx;
  532. /* 胶囊圆角 */
  533. color: #FF5722;
  534. /* 橙色文字 */
  535. font-size: 28rpx;
  536. font-weight: bold;
  537. box-shadow: 0 5rpx 15rpx rgba(255, 87, 34, 0.2);
  538. /* 橙色阴影 */
  539. }
  540. .flag-icon {
  541. margin-right: 15rpx;
  542. font-size: 28rpx;
  543. color: #FF5722;
  544. }
  545. /* 弹窗样式 */
  546. .modal-mask {
  547. position: fixed;
  548. top: 0;
  549. left: 0;
  550. right: 0;
  551. bottom: 0;
  552. background-color: rgba(0, 0, 0, 0.5);
  553. z-index: 999;
  554. display: flex;
  555. align-items: center;
  556. justify-content: center;
  557. }
  558. .modal-content {
  559. width: 600rpx;
  560. background-color: #fff;
  561. border-radius: 20rpx;
  562. overflow: hidden;
  563. display: flex;
  564. flex-direction: column;
  565. max-height: 70vh;
  566. }
  567. .modal-header {
  568. padding: 30rpx;
  569. text-align: center;
  570. border-bottom: 1px solid #eee;
  571. }
  572. .modal-title {
  573. font-size: 32rpx;
  574. font-weight: bold;
  575. }
  576. .modal-body {
  577. padding: 30rpx;
  578. flex: 1;
  579. overflow-y: auto;
  580. }
  581. .modal-text {
  582. font-size: 28rpx;
  583. color: #666;
  584. line-height: 1.6;
  585. }
  586. .modal-footer {
  587. padding: 20rpx 30rpx 30rpx;
  588. }
  589. .confirm-btn {
  590. background-color: #FF5722;
  591. color: #fff;
  592. font-size: 30rpx;
  593. border-radius: 40rpx;
  594. }
  595. </style>