index.vue 14 KB

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