index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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. if (res.code === 200 && res.data) {
  193. this.agreementTitle = res.data.title;
  194. this.agreementContent = res.data.content;
  195. this.showAgreementModal = true;
  196. } else {
  197. uni.showToast({ title: res.msg || '获取协议失败', icon: 'none' });
  198. }
  199. } catch (err) {
  200. console.error('获取协议详情失败:', err);
  201. } finally {
  202. uni.hideLoading();
  203. }
  204. },
  205. /* async getVerifyCode() {
  206. if (this.currentTab === 1) return;
  207. if (this.countDown > 0) return;
  208. if (!this.mobile || this.mobile.length !== 11) {
  209. uni.showToast({ title: '请输入正确的手机号', icon: 'none' });
  210. return;
  211. }
  212. try {
  213. const res = await sendSmsCode(this.mobile);
  214. // 发送成功,启动倒计时
  215. this.countDown = 60;
  216. this.timer = setInterval(() => {
  217. this.countDown--;
  218. if (this.countDown <= 0) {
  219. clearInterval(this.timer);
  220. }
  221. }, 1000);
  222. // TODO 【生产环境必须删除】开发模式下后端会返回验证码,自动填入方便测试
  223. const devCode = res.data;
  224. if (devCode) {
  225. this.code = devCode;
  226. uni.showToast({ title: '验证码: ' + devCode, icon: 'none', duration: 3000 });
  227. } else {
  228. uni.showToast({ title: '验证码已发送', icon: 'none' });
  229. }
  230. } catch (err) {
  231. console.error('发送验证码失败:', err);
  232. }
  233. }, */
  234. async handleLogin() {
  235. if (!this.isAgreed) {
  236. uni.showToast({ title: '请先同意用户协议', icon: 'none' });
  237. return;
  238. }
  239. if (!this.mobile) {
  240. uni.showToast({ title: '请输入手机号', icon: 'none' });
  241. return;
  242. }
  243. /* if (this.currentTab === 0) {
  244. // 免密登录
  245. if (!this.code) {
  246. uni.showToast({ title: '请输入验证码', icon: 'none' });
  247. return;
  248. }
  249. } else {
  250. // 密码登录
  251. if (!this.password) {
  252. uni.showToast({ title: '请输入密码', icon: 'none' });
  253. return;
  254. }
  255. } */
  256. if (!this.password) {
  257. uni.showToast({ title: '请输入密码', icon: 'none' });
  258. return;
  259. }
  260. if (this.loginLoading) return;
  261. this.loginLoading = true;
  262. uni.showLoading({
  263. title: '登录中...',
  264. mask: true
  265. });
  266. try {
  267. let res;
  268. /* if (this.currentTab === 0) {
  269. // 短信验证码登录
  270. res = await loginBySms(this.mobile, this.code);
  271. } else {
  272. // 密码登录
  273. res = await loginByPassword(this.mobile, this.password);
  274. } */
  275. res = await loginByPassword(this.mobile, this.password);
  276. // 保存 Token
  277. const token = res.data?.access_token || res.access_token;
  278. if (token) {
  279. setToken(token);
  280. }
  281. startGpsTimer();
  282. uni.showToast({ title: '登录成功', icon: 'success' });
  283. setTimeout(() => {
  284. uni.reLaunch({
  285. url: '/pages/home/index'
  286. });
  287. }, 1000);
  288. } catch (err) {
  289. // 错误已在 request.js 中统一处理
  290. console.error('登录失败:', err);
  291. } finally {
  292. this.loginLoading = false;
  293. uni.hideLoading();
  294. }
  295. },
  296. goToRecruit() {
  297. uni.navigateTo({
  298. url: '/pages/recruit/landing/index'
  299. });
  300. },
  301. goToForgotPwd() {
  302. uni.navigateTo({
  303. url: '/pages/login/reset-pwd-verify/index'
  304. });
  305. }
  306. }
  307. }
  308. </script>
  309. <style>
  310. /* 页面容器 */
  311. .container {
  312. height: 100vh;
  313. /* 强制全屏高度 */
  314. overflow: hidden;
  315. /* 禁止溢出滚动 */
  316. background-color: #fff;
  317. position: relative;
  318. display: flex;
  319. flex-direction: column;
  320. }
  321. /* 顶部 Banner */
  322. .banner-area {
  323. width: 100%;
  324. position: relative;
  325. /* 移除高度限制,依靠 content-card 的 margin-top 控制遮挡 */
  326. }
  327. .banner-img {
  328. width: 100%;
  329. display: block;
  330. /* 消除图片底部空隙 */
  331. }
  332. /* 内容卡片 - 核心布局技巧 */
  333. .content-card {
  334. flex: 1;
  335. background-color: #fff;
  336. margin-top: -80rpx;
  337. /* 向上覆盖 banner,形成遮挡 */
  338. /* 实现向上凸起的圆弧效果: 使用 border-radius 实现顶部椭圆 */
  339. border-radius: 100% 100% 0 0 / 60rpx 60rpx 0 0;
  340. position: relative;
  341. z-index: 10;
  342. padding: 0 50rpx;
  343. display: flex;
  344. flex-direction: column;
  345. align-items: center;
  346. }
  347. /* 悬浮 Logo */
  348. .logo-wrapper {
  349. margin-top: -70rpx;
  350. /* Logo 向上悬浮 */
  351. margin-bottom: 50rpx;
  352. /* 添加白色光晕/阴影增强悬浮感 */
  353. border-radius: 50%;
  354. box-shadow: 0 10rpx 40rpx rgba(0, 0, 0, 0.1);
  355. background-color: #fff;
  356. padding: 8rpx;
  357. /* 白色边框 */
  358. }
  359. .logo-img {
  360. width: 120rpx;
  361. height: 120rpx;
  362. border-radius: 50%;
  363. display: block;
  364. }
  365. /* Tabs */
  366. .tabs {
  367. display: flex;
  368. align-items: center;
  369. margin-bottom: 60rpx;
  370. }
  371. .tab-item {
  372. display: flex;
  373. flex-direction: column;
  374. align-items: center;
  375. padding: 0 30rpx;
  376. }
  377. .tab-text {
  378. font-size: 32rpx;
  379. color: #999;
  380. font-weight: 500;
  381. margin-bottom: 10rpx;
  382. }
  383. .tab-item.active .tab-text {
  384. color: #FF5722;
  385. /* 主色调橙色 */
  386. font-weight: bold;
  387. font-size: 36rpx;
  388. }
  389. .tab-indicator {
  390. width: 40rpx;
  391. height: 6rpx;
  392. background-color: #FF5722;
  393. border-radius: 3rpx;
  394. }
  395. .divider {
  396. width: 1px;
  397. height: 30rpx;
  398. background-color: #eee;
  399. margin: 0 10rpx;
  400. }
  401. /* 表单 */
  402. .form-area {
  403. width: 100%;
  404. }
  405. .input-group {
  406. display: flex;
  407. align-items: center;
  408. border-bottom: 1px solid #f0f0f0;
  409. padding: 30rpx 0;
  410. margin-bottom: 20rpx;
  411. }
  412. .area-code {
  413. display: flex;
  414. align-items: center;
  415. margin-right: 20rpx;
  416. font-size: 32rpx;
  417. color: #333;
  418. height: 100%;
  419. /* 确保高度撑满 */
  420. }
  421. .arrow {
  422. font-size: 20rpx;
  423. color: #999;
  424. margin-left: 8rpx;
  425. /* margin-top: 4rpx; 移除微调,依靠 flex 居中 */
  426. }
  427. .input {
  428. flex: 1;
  429. font-size: 30rpx;
  430. }
  431. .get-code-btn {
  432. background-color: #FFF0E9;
  433. /* 浅橙色背景 */
  434. padding: 15rpx 30rpx;
  435. /* 增大内边距 */
  436. border-radius: 40rpx;
  437. /* 稍微增大圆角 */
  438. display: flex;
  439. align-items: center;
  440. justify-content: center;
  441. }
  442. .code-text {
  443. color: #FF5722;
  444. font-size: 28rpx;
  445. /* 增大字体 */
  446. line-height: 1;
  447. /* 修正文字垂直居中 */
  448. }
  449. .eye-icon {
  450. padding: 10rpx;
  451. display: flex;
  452. align-items: center;
  453. justify-content: center;
  454. }
  455. .svg-icon {
  456. width: 40rpx;
  457. height: 40rpx;
  458. }
  459. .forgot-pwd {
  460. width: 100%;
  461. text-align: right;
  462. padding-top: 20rpx;
  463. font-size: 26rpx;
  464. color: #666;
  465. }
  466. /* 按钮 */
  467. .login-btn {
  468. /* 鲜亮的橙色渐变 */
  469. background: linear-gradient(90deg, #FF9E60 0%, #FF5722 100%);
  470. color: #fff;
  471. border-radius: 50rpx;
  472. margin-top: 60rpx;
  473. margin-bottom: 40rpx;
  474. font-size: 34rpx;
  475. font-weight: bold;
  476. box-shadow: 0 10rpx 30rpx rgba(255, 87, 34, 0.35);
  477. /* 增强投影 */
  478. }
  479. .login-btn::after {
  480. border: none;
  481. }
  482. /* 协议 */
  483. .agreement {
  484. display: flex;
  485. align-items: center;
  486. /* 改为居中对齐,如果文字换行可能需要改为 flex-start 并调整 margin-top */
  487. justify-content: center;
  488. }
  489. .checkbox {
  490. width: 32rpx;
  491. height: 32rpx;
  492. border: 2rpx solid #ccc;
  493. border-radius: 50%;
  494. margin-right: 12rpx;
  495. /* margin-top: 4rpx; 移除顶部 margin,由 align-items: center 控制 */
  496. display: flex;
  497. align-items: center;
  498. justify-content: center;
  499. }
  500. .checkbox.checked {
  501. border-color: #FF5722;
  502. background-color: #FF5722;
  503. }
  504. .check-mark {
  505. color: #fff;
  506. font-size: 22rpx;
  507. line-height: 1;
  508. /* 确保勾选符号居中 */
  509. }
  510. .agree-text {
  511. font-size: 24rpx;
  512. color: #999;
  513. line-height: 1.5;
  514. }
  515. .link {
  516. color: #666;
  517. }
  518. /* 底部招募 */
  519. .footer-recruit {
  520. margin-top: auto;
  521. padding-bottom: 80rpx;
  522. /* 增加底部距离 */
  523. width: 100%;
  524. display: flex;
  525. justify-content: center;
  526. }
  527. .recruit-badge {
  528. display: flex;
  529. align-items: center;
  530. padding: 20rpx 50rpx;
  531. background-color: #fff;
  532. /* 白色背景 */
  533. border: 1px solid #FF5722;
  534. /* 橙色边框 */
  535. border-radius: 60rpx;
  536. /* 胶囊圆角 */
  537. color: #FF5722;
  538. /* 橙色文字 */
  539. font-size: 28rpx;
  540. font-weight: bold;
  541. box-shadow: 0 5rpx 15rpx rgba(255, 87, 34, 0.2);
  542. /* 橙色阴影 */
  543. }
  544. .flag-icon {
  545. margin-right: 15rpx;
  546. font-size: 28rpx;
  547. color: #FF5722;
  548. }
  549. /* 弹窗样式 */
  550. .modal-mask {
  551. position: fixed;
  552. top: 0;
  553. left: 0;
  554. right: 0;
  555. bottom: 0;
  556. background-color: rgba(0, 0, 0, 0.5);
  557. z-index: 999;
  558. display: flex;
  559. align-items: center;
  560. justify-content: center;
  561. }
  562. .modal-content {
  563. width: 600rpx;
  564. background-color: #fff;
  565. border-radius: 20rpx;
  566. overflow: hidden;
  567. display: flex;
  568. flex-direction: column;
  569. max-height: 70vh;
  570. }
  571. .modal-header {
  572. padding: 30rpx;
  573. text-align: center;
  574. border-bottom: 1px solid #eee;
  575. }
  576. .modal-title {
  577. font-size: 32rpx;
  578. font-weight: bold;
  579. }
  580. .modal-body {
  581. padding: 30rpx;
  582. flex: 1;
  583. overflow-y: auto;
  584. }
  585. .modal-text {
  586. font-size: 28rpx;
  587. color: #666;
  588. line-height: 1.6;
  589. }
  590. .modal-footer {
  591. padding: 20rpx 30rpx 30rpx;
  592. }
  593. .confirm-btn {
  594. background-color: #FF5722;
  595. color: #fff;
  596. font-size: 30rpx;
  597. border-radius: 40rpx;
  598. }
  599. </style>