index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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="getFileIcon(doc.url)" mode="aspectFit" />
  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. // 根据文件URL获取文件类型图标
  117. const getFileIcon = (url) => {
  118. if (!url) return '/static/icon/document.svg'
  119. // 提取文件扩展名
  120. const extension = url.split('.').pop().toLowerCase()
  121. // 根据扩展名返回对应图标
  122. const iconMap = {
  123. // Word文档
  124. 'doc': '/static/icon/word.svg',
  125. 'docx': '/static/icon/word.svg',
  126. // Excel表格
  127. 'xls': '/static/icon/excel.svg',
  128. 'xlsx': '/static/icon/excel.svg',
  129. // PowerPoint演示
  130. 'ppt': '/static/icon/ppt.svg',
  131. 'pptx': '/static/icon/ppt.svg',
  132. // PDF文档
  133. 'pdf': '/static/icon/pdf.svg'
  134. }
  135. return iconMap[extension] || '/static/icon/document.svg'
  136. }
  137. onMounted(() => {
  138. // 获取系统信息
  139. const windowInfo = uni.getWindowInfo()
  140. statusBarHeight.value = windowInfo.statusBarHeight || 0
  141. // 获取轮播图数据
  142. fetchCarouselList()
  143. // 获取最近文档列表
  144. fetchRecentDocuments()
  145. })
  146. // 获取轮播图列表
  147. const fetchCarouselList = async () => {
  148. try {
  149. const response = await getCarouselList()
  150. if (response && response.code === 200 && response.data) {
  151. // 按 sort 字段排序
  152. const sortedData = response.data.sort((a, b) => a.sort - b.sort)
  153. // 转换为轮播图所需的格式
  154. bannerList.value = sortedData.map(item => ({
  155. id: item.id,
  156. image: item.ossidUrl,
  157. note: item.note
  158. }))
  159. }
  160. } catch (error) {
  161. console.error('获取轮播图失败:', error)
  162. // 失败时使用默认图片
  163. bannerList.value = [
  164. {
  165. id: 1,
  166. image: '/static/pages/home/banner1.png',
  167. note: '默认轮播图1'
  168. },
  169. {
  170. id: 2,
  171. image: '/static/pages/home/banner2.png',
  172. note: '默认轮播图2'
  173. }
  174. ]
  175. }
  176. }
  177. // 获取最近文档列表
  178. const fetchRecentDocuments = async (isLoadMore = false) => {
  179. if (loading.value) return
  180. try {
  181. loading.value = true
  182. // 构建请求参数,只在有搜索关键词时才添加 name 参数
  183. const params = {
  184. pageNum: pageNum.value,
  185. pageSize: pageSize.value
  186. }
  187. // 只有当搜索关键词不为空时才添加 name 参数
  188. if (searchKeyword.value && searchKeyword.value.trim()) {
  189. params.name = searchKeyword.value.trim()
  190. }
  191. const response = await getRecentDocuments(params)
  192. if (response && response.code === 200) {
  193. const { rows, total: totalCount } = response
  194. total.value = totalCount
  195. if (isLoadMore) {
  196. // 加载更多,追加数据
  197. recentDocuments.value = [...recentDocuments.value, ...rows]
  198. } else {
  199. // 首次加载或搜索,替换数据
  200. recentDocuments.value = rows
  201. }
  202. // 判断是否还有更多数据
  203. hasMore.value = recentDocuments.value.length < total.value
  204. }
  205. } catch (error) {
  206. console.error('获取最近文档失败:', error)
  207. if (!isLoadMore) {
  208. recentDocuments.value = []
  209. }
  210. } finally {
  211. loading.value = false
  212. }
  213. }
  214. // 加载更多
  215. const handleLoadMore = () => {
  216. if (!hasMore.value || loading.value) return
  217. pageNum.value++
  218. fetchRecentDocuments(true)
  219. }
  220. // 搜索
  221. const handleSearch = () => {
  222. if (!searchKeyword.value.trim()) {
  223. uni.showToast({
  224. title: t('home.searchKeywordEmpty'),
  225. icon: 'none'
  226. })
  227. return
  228. }
  229. // 重置分页
  230. pageNum.value = 1
  231. hasMore.value = true
  232. // 重新加载数据
  233. fetchRecentDocuments()
  234. }
  235. // 跳转到扫描页面
  236. const handleGoToScan = () => {
  237. uni.reLaunch({
  238. url: '/pages/scan/index'
  239. })
  240. }
  241. // 查看更多文档
  242. const handleViewMore = () => {
  243. uni.showToast({
  244. title: '查看更多文档',
  245. icon: 'none'
  246. })
  247. // TODO: 跳转到文档列表页
  248. }
  249. // 点击文档
  250. const handleDocumentClick = (doc) => {
  251. if (!doc.url && !doc.ossId) {
  252. uni.showToast({
  253. title: '文档地址无效',
  254. icon: 'none'
  255. })
  256. return
  257. }
  258. // 手动构建URL参数
  259. const params = []
  260. if (doc.name) {
  261. params.push(`name=${encodeURIComponent(doc.name)}`)
  262. }
  263. if (doc.url) {
  264. params.push(`url=${encodeURIComponent(doc.url)}`)
  265. }
  266. if (doc.ossId) {
  267. params.push(`ossId=${doc.ossId}`)
  268. }
  269. const queryString = params.join('&')
  270. uni.navigateTo({
  271. url: `/pages/home/documentViewer/index?${queryString}`
  272. })
  273. }
  274. </script>
  275. <style lang="scss" scoped>
  276. .home-page {
  277. width: 100%;
  278. height: 100vh;
  279. background-color: #f5f5f5;
  280. position: relative;
  281. overflow: hidden;
  282. // 顶部渐变背景 - 固定
  283. .header-bg {
  284. position: fixed;
  285. top: 0;
  286. left: 0;
  287. right: 0;
  288. background: linear-gradient(180deg, #1ec9c9 0%, #1eb8b8 100%);
  289. z-index: 100;
  290. .header-content {
  291. padding: 0 24rpx 16rpx;
  292. .header-title {
  293. font-size: 32rpx;
  294. font-weight: 600;
  295. color: #ffffff;
  296. display: block;
  297. padding: 12rpx 0;
  298. line-height: 1.4;
  299. }
  300. }
  301. }
  302. // 可滚动区域
  303. .page-scroll {
  304. width: 100%;
  305. height: 100%;
  306. // 页面内容
  307. .page-content {
  308. padding: 0 24rpx 24rpx;
  309. padding-bottom: calc(124rpx + env(safe-area-inset-bottom));
  310. // 搜索框
  311. .search-box {
  312. background: #ffffff;
  313. border-radius: 16rpx;
  314. padding: 20rpx 24rpx;
  315. display: flex;
  316. align-items: center;
  317. margin-bottom: 24rpx;
  318. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  319. .search-icon {
  320. width: 32rpx;
  321. height: 32rpx;
  322. margin-right: 16rpx;
  323. }
  324. .search-input {
  325. flex: 1;
  326. font-size: 28rpx;
  327. color: #333333;
  328. }
  329. .search-placeholder {
  330. color: #999999;
  331. }
  332. }
  333. // 轮播图
  334. .banner-section {
  335. margin-bottom: 24rpx;
  336. .banner-swiper {
  337. width: 100%;
  338. height: 280rpx;
  339. border-radius: 16rpx;
  340. overflow: hidden;
  341. .banner-image {
  342. width: 100%;
  343. height: 100%;
  344. }
  345. }
  346. }
  347. // 智能扫描卡片
  348. .scan-card {
  349. background: #ffffff;
  350. border-radius: 16rpx;
  351. padding: 32rpx 24rpx;
  352. display: flex;
  353. align-items: center;
  354. margin-bottom: 24rpx;
  355. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  356. &:active {
  357. background-color: #f8f8f8;
  358. }
  359. .scan-icon-wrapper {
  360. width: 88rpx;
  361. height: 88rpx;
  362. background: linear-gradient(135deg, #1ec9c9 0%, #17b3b3 100%);
  363. border-radius: 16rpx;
  364. display: flex;
  365. align-items: center;
  366. justify-content: center;
  367. margin-right: 24rpx;
  368. .scan-icon {
  369. width: 56rpx;
  370. height: 56rpx;
  371. }
  372. }
  373. .scan-info {
  374. flex: 1;
  375. display: flex;
  376. flex-direction: column;
  377. gap: 8rpx;
  378. .scan-title {
  379. font-size: 32rpx;
  380. font-weight: 600;
  381. color: #333333;
  382. }
  383. .scan-desc {
  384. font-size: 24rpx;
  385. color: #999999;
  386. line-height: 1.4;
  387. }
  388. }
  389. }
  390. // 最近文档
  391. .recent-section {
  392. .section-header {
  393. display: flex;
  394. align-items: center;
  395. justify-content: space-between;
  396. margin-bottom: 24rpx;
  397. .section-title {
  398. font-size: 32rpx;
  399. font-weight: 600;
  400. color: #333333;
  401. }
  402. .more-btn {
  403. display: flex;
  404. align-items: center;
  405. gap: 4rpx;
  406. .more-text {
  407. font-size: 26rpx;
  408. color: #999999;
  409. }
  410. .more-arrow {
  411. font-size: 36rpx;
  412. color: #999999;
  413. font-weight: 300;
  414. }
  415. }
  416. }
  417. .document-list {
  418. .document-item {
  419. background: #ffffff;
  420. border-radius: 16rpx;
  421. padding: 24rpx;
  422. display: flex;
  423. align-items: center;
  424. margin-bottom: 16rpx;
  425. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  426. &:active {
  427. background-color: #f8f8f8;
  428. }
  429. .doc-thumbnail {
  430. width: 100rpx;
  431. height: 120rpx;
  432. border-radius: 8rpx;
  433. margin-right: 24rpx;
  434. background-color: #f0f0f0;
  435. padding: 10rpx;
  436. box-sizing: border-box;
  437. }
  438. .doc-info {
  439. flex: 1;
  440. display: flex;
  441. flex-direction: column;
  442. gap: 12rpx;
  443. .doc-name {
  444. font-size: 28rpx;
  445. font-weight: 500;
  446. color: #333333;
  447. overflow: hidden;
  448. text-overflow: ellipsis;
  449. white-space: nowrap;
  450. }
  451. .doc-meta {
  452. font-size: 24rpx;
  453. color: #999999;
  454. }
  455. }
  456. }
  457. }
  458. }
  459. // 加载更多
  460. .loading-more {
  461. padding: 32rpx;
  462. text-align: center;
  463. .loading-text {
  464. font-size: 24rpx;
  465. color: #999999;
  466. }
  467. }
  468. // 没有更多
  469. .no-more {
  470. padding: 32rpx;
  471. text-align: center;
  472. .no-more-text {
  473. font-size: 24rpx;
  474. color: #999999;
  475. }
  476. }
  477. // 空状态
  478. .empty-state {
  479. padding: 120rpx 32rpx;
  480. text-align: center;
  481. .empty-text {
  482. font-size: 28rpx;
  483. color: #999999;
  484. }
  485. }
  486. }
  487. }
  488. }
  489. </style>