index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <template>
  2. <view class="task-documents-page">
  3. <!-- 顶部导航栏 -->
  4. <view class="header-bg" :style="{ paddingTop: statusBarHeight + 'px' }">
  5. <view class="header-content">
  6. <view class="back-btn" @click="handleBack">
  7. <text class="back-icon">‹</text>
  8. </view>
  9. <text class="header-title">{{ pageTitle }}</text>
  10. <view class="placeholder"></view>
  11. </view>
  12. </view>
  13. <!-- 页面内容 -->
  14. <scroll-view
  15. scroll-y
  16. class="page-scroll"
  17. :style="{ paddingTop: (statusBarHeight * 2 + 88) + 'rpx' }"
  18. @scrolltolower="handleLoadMore"
  19. >
  20. <view class="page-content">
  21. <!-- 搜索和筛选区域 -->
  22. <view class="search-filter-row">
  23. <!-- 搜索框 -->
  24. <view class="search-box">
  25. <image class="search-icon" src="/static/pages/home/search.png" mode="aspectFit" />
  26. <input
  27. class="search-input"
  28. :placeholder="t('taskDocuments.searchPlaceholder')"
  29. placeholder-class="search-placeholder"
  30. v-model="searchKeyword"
  31. @confirm="handleSearch"
  32. />
  33. <view class="search-btn" @click="handleSearch">
  34. <text class="btn-text">{{ t('taskDocuments.search') }}</text>
  35. </view>
  36. </view>
  37. <!-- 状态选择器 -->
  38. <view class="status-selector">
  39. <picker
  40. mode="selector"
  41. :range="statusOptions"
  42. range-key="label"
  43. :value="statusOptions.findIndex(opt => opt.value === taskStatus)"
  44. @change="handleStatusChange"
  45. >
  46. <view class="selector-value">
  47. <text class="value-text">{{ selectedStatusLabel }}</text>
  48. <text class="arrow-icon">▼</text>
  49. </view>
  50. </picker>
  51. </view>
  52. </view>
  53. <!-- 文档列表 -->
  54. <view class="document-list">
  55. <view
  56. v-for="(doc, index) in documentList"
  57. :key="doc.id"
  58. class="document-item"
  59. @click="handleDocumentClick(doc)"
  60. >
  61. <image class="doc-thumbnail" :src="getFileIcon(doc.url)" mode="aspectFit" />
  62. <view class="doc-info">
  63. <text class="doc-name">{{ doc.name }}</text>
  64. <view class="doc-meta">
  65. <text class="meta-text">{{ t('taskDocuments.createTime') }}:{{ doc.createTime }}</text>
  66. <text class="meta-text" v-if="doc.submitter">{{ t('taskDocuments.submitter') }}:{{ doc.submitter }}</text>
  67. </view>
  68. </view>
  69. </view>
  70. <!-- 加载状态 -->
  71. <view v-if="loading" class="loading-more">
  72. <text class="loading-text">{{ t('taskDocuments.loading') }}</text>
  73. </view>
  74. <!-- 没有更多数据 -->
  75. <view v-if="!hasMore && documentList.length > 0" class="no-more">
  76. <text class="no-more-text">{{ t('taskDocuments.noMore') }}</text>
  77. </view>
  78. <!-- 空状态 -->
  79. <view v-if="!loading && documentList.length === 0" class="empty-state">
  80. <text class="empty-text">{{ t('taskDocuments.empty') }}</text>
  81. </view>
  82. </view>
  83. </view>
  84. </scroll-view>
  85. </view>
  86. </template>
  87. <script setup>
  88. import { ref, onMounted, computed } from 'vue'
  89. import { useI18n } from 'vue-i18n'
  90. import { getTaskDocuments } from '@/apis/auth'
  91. const { t } = useI18n()
  92. // 状态栏高度
  93. const statusBarHeight = ref(0)
  94. // 任务状态
  95. const taskStatus = ref(null)
  96. // 状态选项列表
  97. const statusOptions = computed(() => [
  98. { label: t('taskDocuments.status.all'), value: null },
  99. { label: t('taskDocuments.status.unUpload'), value: 0 },
  100. { label: t('taskDocuments.status.unAudit'), value: 1 },
  101. { label: t('taskDocuments.status.auditReject'), value: 2 },
  102. { label: t('taskDocuments.status.unFiling'), value: 3 },
  103. { label: t('taskDocuments.status.filing'), value: 4 },
  104. { label: t('taskDocuments.status.unQualityControl'), value: 5 },
  105. { label: t('taskDocuments.status.qualityControlPass'), value: 6 },
  106. { label: t('taskDocuments.status.qualityControlReject'), value: 7 }
  107. ])
  108. // 当前选中的状态标签
  109. const selectedStatusLabel = computed(() => {
  110. const option = statusOptions.value.find(opt => opt.value === taskStatus.value)
  111. return option ? option.label : t('taskDocuments.status.all')
  112. })
  113. // 搜索关键词
  114. const searchKeyword = ref('')
  115. // 文档列表
  116. const documentList = ref([])
  117. // 分页参数
  118. const pageNum = ref(1)
  119. const pageSize = ref(10)
  120. const total = ref(0)
  121. const loading = ref(false)
  122. const hasMore = ref(true)
  123. // 页面标题
  124. const pageTitle = computed(() => {
  125. if (taskStatus.value === 0) return t('taskDocuments.toSubmit')
  126. if (taskStatus.value === 1) return t('taskDocuments.toAudit')
  127. return t('taskDocuments.myTasks')
  128. })
  129. // 根据文件URL获取文件类型图标
  130. const getFileIcon = (url) => {
  131. if (!url) return '/static/icon/document.svg'
  132. // 提取文件扩展名
  133. const extension = url.split('.').pop().toLowerCase()
  134. // 根据扩展名返回对应图标
  135. const iconMap = {
  136. // Word文档
  137. 'doc': '/static/icon/word.svg',
  138. 'docx': '/static/icon/word.svg',
  139. // Excel表格
  140. 'xls': '/static/icon/excel.svg',
  141. 'xlsx': '/static/icon/excel.svg',
  142. // PowerPoint演示
  143. 'ppt': '/static/icon/ppt.svg',
  144. 'pptx': '/static/icon/ppt.svg',
  145. // PDF文档
  146. 'pdf': '/static/icon/pdf.svg'
  147. }
  148. return iconMap[extension] || '/static/icon/document.svg'
  149. }
  150. onMounted(() => {
  151. // 获取系统信息
  152. const windowInfo = uni.getWindowInfo()
  153. statusBarHeight.value = windowInfo.statusBarHeight || 0
  154. // 获取页面参数
  155. const pages = getCurrentPages()
  156. const currentPage = pages[pages.length - 1]
  157. const status = currentPage.options.status
  158. if (status !== undefined && status !== '') {
  159. taskStatus.value = parseInt(status)
  160. }
  161. // 加载文档列表
  162. fetchDocuments()
  163. })
  164. // 获取文档列表
  165. const fetchDocuments = async (isLoadMore = false) => {
  166. if (loading.value) return
  167. try {
  168. loading.value = true
  169. // 构建请求参数
  170. const params = {
  171. pageNum: pageNum.value,
  172. pageSize: pageSize.value
  173. }
  174. // 只有当搜索关键词不为空时才添加 name 参数
  175. if (searchKeyword.value && searchKeyword.value.trim()) {
  176. params.name = searchKeyword.value.trim()
  177. }
  178. // 只有当状态不为空时才添加 status 参数
  179. if (taskStatus.value !== null && taskStatus.value !== undefined) {
  180. params.status = taskStatus.value
  181. }
  182. const response = await getTaskDocuments(params)
  183. if (response && response.code === 200) {
  184. const { rows, total: totalCount } = response
  185. total.value = totalCount
  186. if (isLoadMore) {
  187. // 加载更多,追加数据
  188. documentList.value = [...documentList.value, ...rows]
  189. } else {
  190. // 首次加载或搜索,替换数据
  191. documentList.value = rows
  192. }
  193. // 判断是否还有更多数据
  194. hasMore.value = documentList.value.length < total.value
  195. }
  196. } catch (error) {
  197. console.error('获取文档列表失败:', error)
  198. if (!isLoadMore) {
  199. documentList.value = []
  200. }
  201. uni.showToast({
  202. title: t('taskDocuments.loadFailed'),
  203. icon: 'none'
  204. })
  205. } finally {
  206. loading.value = false
  207. }
  208. }
  209. // 加载更多
  210. const handleLoadMore = () => {
  211. if (!hasMore.value || loading.value) return
  212. pageNum.value++
  213. fetchDocuments(true)
  214. }
  215. // 搜索
  216. const handleSearch = () => {
  217. // 重置分页
  218. pageNum.value = 1
  219. hasMore.value = true
  220. // 重新加载数据
  221. fetchDocuments()
  222. }
  223. // 状态选择
  224. const handleStatusChange = (e) => {
  225. const index = e.detail.value
  226. taskStatus.value = statusOptions.value[index].value
  227. // 重置分页
  228. pageNum.value = 1
  229. hasMore.value = true
  230. // 重新加载数据
  231. fetchDocuments()
  232. }
  233. // 点击文档
  234. const handleDocumentClick = (doc) => {
  235. if (!doc.url) {
  236. uni.showToast({
  237. title: t('taskDocuments.invalidUrl'),
  238. icon: 'none'
  239. })
  240. return
  241. }
  242. // 构建跳转URL,传递文档信息
  243. const params = []
  244. if (doc.name) {
  245. params.push(`name=${encodeURIComponent(doc.name)}`)
  246. }
  247. if (doc.url) {
  248. params.push(`url=${encodeURIComponent(doc.url)}`)
  249. }
  250. const queryString = params.join('&')
  251. uni.navigateTo({
  252. url: `/pages/home/documentViewer/index?${queryString}`
  253. })
  254. }
  255. // 返回
  256. const handleBack = () => {
  257. uni.navigateBack({
  258. fail: () => {
  259. uni.reLaunch({
  260. url: '/pages/my/index'
  261. })
  262. }
  263. })
  264. }
  265. </script>
  266. <style lang="scss" scoped>
  267. .task-documents-page {
  268. width: 100%;
  269. height: 100vh;
  270. background-color: #f5f5f5;
  271. position: relative;
  272. overflow: hidden;
  273. // 顶部导航栏
  274. .header-bg {
  275. position: fixed;
  276. top: 0;
  277. left: 0;
  278. right: 0;
  279. background: linear-gradient(180deg, #1ec9c9 0%, #1eb8b8 100%);
  280. z-index: 100;
  281. .header-content {
  282. height: 88rpx;
  283. display: flex;
  284. align-items: center;
  285. justify-content: space-between;
  286. padding: 0 24rpx;
  287. .back-btn {
  288. width: 60rpx;
  289. height: 60rpx;
  290. display: flex;
  291. align-items: center;
  292. justify-content: flex-start;
  293. .back-icon {
  294. font-size: 56rpx;
  295. color: #ffffff;
  296. font-weight: 300;
  297. }
  298. }
  299. .header-title {
  300. flex: 1;
  301. text-align: center;
  302. font-size: 32rpx;
  303. font-weight: 600;
  304. color: #ffffff;
  305. }
  306. .placeholder {
  307. width: 60rpx;
  308. }
  309. }
  310. }
  311. // 可滚动区域
  312. .page-scroll {
  313. width: 100%;
  314. height: 100%;
  315. .page-content {
  316. padding: 24rpx;
  317. padding-bottom: 40rpx;
  318. // 搜索和筛选行
  319. .search-filter-row {
  320. display: flex;
  321. gap: 16rpx;
  322. margin-bottom: 24rpx;
  323. }
  324. // 搜索框
  325. .search-box {
  326. flex: 1;
  327. background: #ffffff;
  328. border-radius: 16rpx;
  329. padding: 16rpx 20rpx;
  330. display: flex;
  331. align-items: center;
  332. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  333. .search-icon {
  334. width: 32rpx;
  335. height: 32rpx;
  336. margin-right: 12rpx;
  337. flex-shrink: 0;
  338. }
  339. .search-input {
  340. flex: 1;
  341. font-size: 26rpx;
  342. color: #333333;
  343. min-width: 0;
  344. }
  345. .search-placeholder {
  346. color: #999999;
  347. }
  348. .search-btn {
  349. margin-left: 12rpx;
  350. padding: 8rpx 20rpx;
  351. background: linear-gradient(135deg, #1ec9c9 0%, #17b3b3 100%);
  352. border-radius: 8rpx;
  353. flex-shrink: 0;
  354. &:active {
  355. opacity: 0.8;
  356. }
  357. .btn-text {
  358. font-size: 24rpx;
  359. color: #ffffff;
  360. font-weight: 500;
  361. }
  362. }
  363. }
  364. // 状态选择器
  365. .status-selector {
  366. background: #ffffff;
  367. border-radius: 16rpx;
  368. padding: 16rpx 20rpx;
  369. display: flex;
  370. align-items: center;
  371. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  372. flex-shrink: 0;
  373. picker {
  374. display: flex;
  375. }
  376. .selector-value {
  377. display: flex;
  378. align-items: center;
  379. gap: 8rpx;
  380. .value-text {
  381. font-size: 26rpx;
  382. color: #1ec9c9;
  383. font-weight: 500;
  384. white-space: nowrap;
  385. }
  386. .arrow-icon {
  387. font-size: 20rpx;
  388. color: #1ec9c9;
  389. }
  390. }
  391. }
  392. // 文档列表
  393. .document-list {
  394. .document-item {
  395. background: #ffffff;
  396. border-radius: 16rpx;
  397. padding: 24rpx;
  398. display: flex;
  399. align-items: center;
  400. margin-bottom: 16rpx;
  401. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  402. &:active {
  403. background-color: #f8f8f8;
  404. }
  405. .doc-thumbnail {
  406. width: 100rpx;
  407. height: 120rpx;
  408. border-radius: 8rpx;
  409. margin-right: 24rpx;
  410. background-color: #f0f0f0;
  411. padding: 10rpx;
  412. box-sizing: border-box;
  413. }
  414. .doc-info {
  415. flex: 1;
  416. display: flex;
  417. flex-direction: column;
  418. gap: 12rpx;
  419. .doc-name {
  420. font-size: 28rpx;
  421. font-weight: 500;
  422. color: #333333;
  423. overflow: hidden;
  424. text-overflow: ellipsis;
  425. white-space: nowrap;
  426. }
  427. .doc-meta {
  428. display: flex;
  429. flex-direction: column;
  430. gap: 8rpx;
  431. .meta-text {
  432. font-size: 24rpx;
  433. color: #999999;
  434. }
  435. }
  436. }
  437. }
  438. // 加载更多
  439. .loading-more {
  440. padding: 32rpx;
  441. text-align: center;
  442. .loading-text {
  443. font-size: 24rpx;
  444. color: #999999;
  445. }
  446. }
  447. // 没有更多
  448. .no-more {
  449. padding: 32rpx;
  450. text-align: center;
  451. .no-more-text {
  452. font-size: 24rpx;
  453. color: #999999;
  454. }
  455. }
  456. // 空状态
  457. .empty-state {
  458. padding: 120rpx 32rpx;
  459. text-align: center;
  460. .empty-text {
  461. font-size: 28rpx;
  462. color: #999999;
  463. }
  464. }
  465. }
  466. }
  467. }
  468. }
  469. </style>