index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <template>
  2. <view class="home-page">
  3. <!-- 顶部渐变背景区域 - 固定 -->
  4. <view class="header-bg" :style="{ paddingTop: statusBarHeight + 'px' }">
  5. <view class="header-content">
  6. <text class="header-title">{{ t('home.title') }}</text>
  7. </view>
  8. </view>
  9. <!-- 页面内容 - 可滚动 -->
  10. <scroll-view
  11. scroll-y
  12. class="page-scroll"
  13. :style="{ paddingTop: (statusBarHeight + 60) + 'px' }"
  14. @scrolltolower="handleLoadMore"
  15. >
  16. <view class="page-content">
  17. <!-- 搜索框 -->
  18. <view class="search-box">
  19. <image class="search-icon" src="/static/pages/home/search.png" mode="aspectFit" />
  20. <input
  21. class="search-input"
  22. :placeholder="t('home.searchPlaceholder')"
  23. placeholder-class="search-placeholder"
  24. v-model="searchKeyword"
  25. @confirm="handleSearch"
  26. />
  27. </view>
  28. <!-- 轮播图 -->
  29. <view class="banner-section">
  30. <swiper
  31. class="banner-swiper"
  32. :indicator-dots="true"
  33. :autoplay="true"
  34. :interval="3000"
  35. :duration="500"
  36. indicator-color="rgba(255, 255, 255, 0.5)"
  37. indicator-active-color="#1ec9c9"
  38. >
  39. <swiper-item v-for="(item, index) in bannerList" :key="index">
  40. <image class="banner-image" :src="item.image" mode="aspectFill" />
  41. </swiper-item>
  42. </swiper>
  43. </view>
  44. <!-- 智能扫描卡片 -->
  45. <view class="scan-card" @click="handleGoToScan">
  46. <view class="scan-icon-wrapper">
  47. <image class="scan-icon" src="/static/pages/home/scan-icon.png" mode="aspectFit" />
  48. </view>
  49. <view class="scan-info">
  50. <text class="scan-title">{{ t('home.intelligentScan') }}</text>
  51. <text class="scan-desc">{{ t('home.scanDesc') }}</text>
  52. </view>
  53. </view>
  54. <!-- 最近文档 -->
  55. <view class="recent-section">
  56. <view class="section-header">
  57. <text class="section-title">{{ t('home.recentDocuments') }}</text>
  58. <view class="more-btn" @click="handleViewMore">
  59. <text class="more-text">{{ t('home.viewMore') }}</text>
  60. <text class="more-arrow">›</text>
  61. </view>
  62. </view>
  63. <view class="document-list">
  64. <view
  65. v-for="(doc, index) in recentDocuments"
  66. :key="doc.id"
  67. class="document-item"
  68. @click="handleDocumentClick(doc)"
  69. >
  70. <image class="doc-thumbnail" :src="doc.thumbnail || '/static/pages/home/doc-thumb.png'" mode="aspectFill" />
  71. <view class="doc-info">
  72. <text class="doc-name">{{ doc.name }}</text>
  73. <text class="doc-meta">{{ doc.createTime }}</text>
  74. </view>
  75. </view>
  76. <!-- 加载状态 -->
  77. <view v-if="loading" class="loading-more">
  78. <text class="loading-text">{{ t('common.message.loading') }}</text>
  79. </view>
  80. <!-- 没有更多数据 -->
  81. <view v-if="!hasMore && recentDocuments.length > 0" class="no-more">
  82. <text class="no-more-text">没有更多了</text>
  83. </view>
  84. <!-- 空状态 -->
  85. <view v-if="!loading && recentDocuments.length === 0" class="empty-state">
  86. <text class="empty-text">{{ t('common.message.noData') }}</text>
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. </scroll-view>
  92. <!-- 底部导航栏 -->
  93. <TabBar current-tab="home" />
  94. </view>
  95. </template>
  96. <script setup>
  97. import { ref, onMounted } from 'vue'
  98. import { useI18n } from 'vue-i18n'
  99. import TabBar from '@/components/TabBar/index.vue'
  100. import { getCarouselList, getRecentDocuments } from '@/apis/setting'
  101. const { t } = useI18n()
  102. // 状态栏高度
  103. const statusBarHeight = ref(0)
  104. // 搜索关键词
  105. const searchKeyword = ref('')
  106. // 轮播图数据
  107. const bannerList = ref([])
  108. // 最近文档数据
  109. const recentDocuments = ref([])
  110. // 分页参数
  111. const pageNum = ref(1)
  112. const pageSize = ref(10)
  113. const total = ref(0)
  114. const loading = ref(false)
  115. const hasMore = ref(true)
  116. onMounted(() => {
  117. // 获取系统信息
  118. const windowInfo = uni.getWindowInfo()
  119. statusBarHeight.value = windowInfo.statusBarHeight || 0
  120. // 获取轮播图数据
  121. fetchCarouselList()
  122. // 获取最近文档列表
  123. fetchRecentDocuments()
  124. })
  125. // 获取轮播图列表
  126. const fetchCarouselList = async () => {
  127. try {
  128. const response = await getCarouselList()
  129. if (response && response.code === 200 && response.data) {
  130. // 按 sort 字段排序
  131. const sortedData = response.data.sort((a, b) => a.sort - b.sort)
  132. // 转换为轮播图所需的格式
  133. bannerList.value = sortedData.map(item => ({
  134. id: item.id,
  135. image: item.ossidUrl,
  136. note: item.note
  137. }))
  138. console.log('轮播图加载成功:', bannerList.value.length, '张')
  139. }
  140. } catch (error) {
  141. console.error('获取轮播图失败:', error)
  142. // 失败时使用默认图片
  143. bannerList.value = [
  144. {
  145. id: 1,
  146. image: '/static/pages/home/banner1.png',
  147. note: '默认轮播图1'
  148. },
  149. {
  150. id: 2,
  151. image: '/static/pages/home/banner2.png',
  152. note: '默认轮播图2'
  153. }
  154. ]
  155. }
  156. }
  157. // 获取最近文档列表
  158. const fetchRecentDocuments = async (isLoadMore = false) => {
  159. if (loading.value) return
  160. try {
  161. loading.value = true
  162. // 构建请求参数,只在有搜索关键词时才添加 name 参数
  163. const params = {
  164. pageNum: pageNum.value,
  165. pageSize: pageSize.value
  166. }
  167. // 只有当搜索关键词不为空时才添加 name 参数
  168. if (searchKeyword.value && searchKeyword.value.trim()) {
  169. params.name = searchKeyword.value.trim()
  170. }
  171. console.log('请求参数:', params)
  172. const response = await getRecentDocuments(params)
  173. if (response && response.code === 200) {
  174. const { rows, total: totalCount } = response
  175. total.value = totalCount
  176. if (isLoadMore) {
  177. // 加载更多,追加数据
  178. recentDocuments.value = [...recentDocuments.value, ...rows]
  179. } else {
  180. // 首次加载或搜索,替换数据
  181. recentDocuments.value = rows
  182. }
  183. // 判断是否还有更多数据
  184. hasMore.value = recentDocuments.value.length < total.value
  185. console.log('最近文档加载成功:', rows.length, '条')
  186. }
  187. } catch (error) {
  188. console.error('获取最近文档失败:', error)
  189. if (!isLoadMore) {
  190. recentDocuments.value = []
  191. }
  192. } finally {
  193. loading.value = false
  194. }
  195. }
  196. // 加载更多
  197. const handleLoadMore = () => {
  198. if (!hasMore.value || loading.value) return
  199. pageNum.value++
  200. fetchRecentDocuments(true)
  201. }
  202. // 搜索
  203. const handleSearch = () => {
  204. if (!searchKeyword.value.trim()) {
  205. uni.showToast({
  206. title: t('home.searchKeywordEmpty'),
  207. icon: 'none'
  208. })
  209. return
  210. }
  211. // 重置分页
  212. pageNum.value = 1
  213. hasMore.value = true
  214. // 重新加载数据
  215. fetchRecentDocuments()
  216. }
  217. // 跳转到扫描页面
  218. const handleGoToScan = () => {
  219. uni.reLaunch({
  220. url: '/pages/scan/index'
  221. })
  222. }
  223. // 查看更多文档
  224. const handleViewMore = () => {
  225. uni.showToast({
  226. title: '查看更多文档',
  227. icon: 'none'
  228. })
  229. // TODO: 跳转到文档列表页
  230. }
  231. // 点击文档
  232. const handleDocumentClick = (doc) => {
  233. uni.showToast({
  234. title: `打开文档: ${doc.name}`,
  235. icon: 'none'
  236. })
  237. // TODO: 跳转到文档详情页
  238. }
  239. </script>
  240. <style lang="scss" scoped>
  241. .home-page {
  242. width: 100%;
  243. height: 100vh;
  244. background-color: #f5f5f5;
  245. position: relative;
  246. overflow: hidden;
  247. // 顶部渐变背景 - 固定
  248. .header-bg {
  249. position: fixed;
  250. top: 0;
  251. left: 0;
  252. right: 0;
  253. background: linear-gradient(180deg, #1ec9c9 0%, #1eb8b8 100%);
  254. z-index: 100;
  255. .header-content {
  256. padding: 0 24rpx 16rpx;
  257. .header-title {
  258. font-size: 32rpx;
  259. font-weight: 600;
  260. color: #ffffff;
  261. display: block;
  262. padding: 12rpx 0;
  263. line-height: 1.4;
  264. }
  265. }
  266. }
  267. // 可滚动区域
  268. .page-scroll {
  269. width: 100%;
  270. height: 100%;
  271. // 页面内容
  272. .page-content {
  273. padding: 0 24rpx 24rpx;
  274. padding-bottom: calc(124rpx + env(safe-area-inset-bottom));
  275. // 搜索框
  276. .search-box {
  277. background: #ffffff;
  278. border-radius: 16rpx;
  279. padding: 20rpx 24rpx;
  280. display: flex;
  281. align-items: center;
  282. margin-bottom: 24rpx;
  283. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  284. .search-icon {
  285. width: 32rpx;
  286. height: 32rpx;
  287. margin-right: 16rpx;
  288. }
  289. .search-input {
  290. flex: 1;
  291. font-size: 28rpx;
  292. color: #333333;
  293. }
  294. .search-placeholder {
  295. color: #999999;
  296. }
  297. }
  298. // 轮播图
  299. .banner-section {
  300. margin-bottom: 24rpx;
  301. .banner-swiper {
  302. width: 100%;
  303. height: 280rpx;
  304. border-radius: 16rpx;
  305. overflow: hidden;
  306. .banner-image {
  307. width: 100%;
  308. height: 100%;
  309. }
  310. }
  311. }
  312. // 智能扫描卡片
  313. .scan-card {
  314. background: #ffffff;
  315. border-radius: 16rpx;
  316. padding: 32rpx 24rpx;
  317. display: flex;
  318. align-items: center;
  319. margin-bottom: 24rpx;
  320. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  321. &:active {
  322. background-color: #f8f8f8;
  323. }
  324. .scan-icon-wrapper {
  325. width: 88rpx;
  326. height: 88rpx;
  327. background: linear-gradient(135deg, #1ec9c9 0%, #17b3b3 100%);
  328. border-radius: 16rpx;
  329. display: flex;
  330. align-items: center;
  331. justify-content: center;
  332. margin-right: 24rpx;
  333. .scan-icon {
  334. width: 56rpx;
  335. height: 56rpx;
  336. }
  337. }
  338. .scan-info {
  339. flex: 1;
  340. display: flex;
  341. flex-direction: column;
  342. gap: 8rpx;
  343. .scan-title {
  344. font-size: 32rpx;
  345. font-weight: 600;
  346. color: #333333;
  347. }
  348. .scan-desc {
  349. font-size: 24rpx;
  350. color: #999999;
  351. line-height: 1.4;
  352. }
  353. }
  354. }
  355. // 最近文档
  356. .recent-section {
  357. .section-header {
  358. display: flex;
  359. align-items: center;
  360. justify-content: space-between;
  361. margin-bottom: 24rpx;
  362. .section-title {
  363. font-size: 32rpx;
  364. font-weight: 600;
  365. color: #333333;
  366. }
  367. .more-btn {
  368. display: flex;
  369. align-items: center;
  370. gap: 4rpx;
  371. .more-text {
  372. font-size: 26rpx;
  373. color: #999999;
  374. }
  375. .more-arrow {
  376. font-size: 36rpx;
  377. color: #999999;
  378. font-weight: 300;
  379. }
  380. }
  381. }
  382. .document-list {
  383. .document-item {
  384. background: #ffffff;
  385. border-radius: 16rpx;
  386. padding: 24rpx;
  387. display: flex;
  388. align-items: center;
  389. margin-bottom: 16rpx;
  390. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  391. &:active {
  392. background-color: #f8f8f8;
  393. }
  394. .doc-thumbnail {
  395. width: 100rpx;
  396. height: 120rpx;
  397. border-radius: 8rpx;
  398. margin-right: 24rpx;
  399. background-color: #f0f0f0;
  400. }
  401. .doc-info {
  402. flex: 1;
  403. display: flex;
  404. flex-direction: column;
  405. gap: 12rpx;
  406. .doc-name {
  407. font-size: 28rpx;
  408. font-weight: 500;
  409. color: #333333;
  410. overflow: hidden;
  411. text-overflow: ellipsis;
  412. white-space: nowrap;
  413. }
  414. .doc-meta {
  415. font-size: 24rpx;
  416. color: #999999;
  417. }
  418. }
  419. }
  420. }
  421. }
  422. // 加载更多
  423. .loading-more {
  424. padding: 32rpx;
  425. text-align: center;
  426. .loading-text {
  427. font-size: 24rpx;
  428. color: #999999;
  429. }
  430. }
  431. // 没有更多
  432. .no-more {
  433. padding: 32rpx;
  434. text-align: center;
  435. .no-more-text {
  436. font-size: 24rpx;
  437. color: #999999;
  438. }
  439. }
  440. // 空状态
  441. .empty-state {
  442. padding: 120rpx 32rpx;
  443. text-align: center;
  444. .empty-text {
  445. font-size: 28rpx;
  446. color: #999999;
  447. }
  448. }
  449. }
  450. }
  451. }
  452. </style>