index.vue 17 KB

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