index.vue 14 KB

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