index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <template>
  2. <view class="file-select-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">{{ t('fileSelect.title') }}</text>
  10. <view class="placeholder"></view>
  11. </view>
  12. </view>
  13. <!-- 搜索框 -->
  14. <view class="search-bar">
  15. <input
  16. class="search-input"
  17. v-model="searchName"
  18. :placeholder="t('fileSelect.search.placeholder')"
  19. @confirm="handleSearch"
  20. />
  21. <view class="search-btn" @click="handleSearch">
  22. <text class="search-text">{{ t('fileSelect.search.button') }}</text>
  23. </view>
  24. </view>
  25. <!-- 文件列表 -->
  26. <scroll-view
  27. scroll-y
  28. class="file-list"
  29. @scrolltolower="handleLoadMore"
  30. >
  31. <view
  32. v-for="item in fileList"
  33. :key="item.id"
  34. class="file-item"
  35. @click="handleSelectFile(item)"
  36. >
  37. <view class="file-icon-wrapper">
  38. <image src="/static/icon/document.svg" mode="aspectFit" class="file-icon" />
  39. </view>
  40. <view class="file-info">
  41. <text class="file-name">{{ item.name }}</text>
  42. <text class="file-detail">{{ t('fileSelect.fileInfo.project') }}: {{ item.project }}</text>
  43. <text class="file-detail">{{ t('fileSelect.fileInfo.folder') }}: {{ item.folder }}</text>
  44. <text class="file-detail">{{ t('fileSelect.fileInfo.createBy') }}: {{ item.createBy }}</text>
  45. <text class="file-detail">{{ t('fileSelect.fileInfo.deadline') }}: {{ formatDate(item.deadline) }}</text>
  46. </view>
  47. </view>
  48. <view v-if="fileList.length === 0 && !loading" class="empty-tip">
  49. <text class="empty-text">{{ t('fileSelect.empty.noFiles') }}</text>
  50. <text class="empty-hint">{{ t('fileSelect.empty.hint') }}</text>
  51. </view>
  52. <view v-if="loading" class="loading-tip">
  53. <text class="loading-text">{{ t('fileSelect.message.loading') }}</text>
  54. </view>
  55. </scroll-view>
  56. <!-- 底部提交按钮 -->
  57. <view class="submit-footer">
  58. <view
  59. class="submit-btn secondary"
  60. @click="handleDirectUpload"
  61. >
  62. <text class="submit-text">{{ t('fileSelect.action.directUpload') }}</text>
  63. </view>
  64. </view>
  65. <!-- 生效日期选择弹窗 -->
  66. <view v-if="showDateModal" class="modal-overlay" @click="handleCloseModal">
  67. <view class="modal-content" @click.stop>
  68. <view class="modal-header">
  69. <text class="modal-title">{{ t('fileSelect.dateModal.title') }}</text>
  70. </view>
  71. <view class="modal-body">
  72. <view class="date-picker-wrapper">
  73. <picker
  74. mode="date"
  75. :value="selectedDate"
  76. @change="handleDateChange"
  77. >
  78. <view class="date-display">
  79. <text class="date-label">{{ t('fileSelect.dateModal.label') }}</text>
  80. <text class="date-value" :class="{ placeholder: !selectedDate }">
  81. {{ selectedDate || t('fileSelect.dateModal.placeholder') }}
  82. </text>
  83. <text class="date-arrow">›</text>
  84. </view>
  85. </picker>
  86. </view>
  87. </view>
  88. <view class="modal-footer">
  89. <view class="modal-btn cancel" @click="handleCloseModal">
  90. <text class="modal-btn-text">{{ t('fileSelect.action.cancel') }}</text>
  91. </view>
  92. <view class="modal-btn confirm" @click="handleConfirmDate">
  93. <text class="modal-btn-text">{{ t('fileSelect.action.confirm') }}</text>
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. </view>
  99. </template>
  100. <script setup>
  101. import { ref, onMounted } from 'vue'
  102. import { useI18n } from 'vue-i18n'
  103. import { getToSubmitList, uploadOnSubmit } from '@/apis/scan'
  104. const { t } = useI18n()
  105. // 状态栏高度
  106. const statusBarHeight = ref(0)
  107. // 文件列表
  108. const fileList = ref([])
  109. const searchName = ref('')
  110. const pageNum = ref(1)
  111. const pageSize = ref(10)
  112. const total = ref(0)
  113. const loading = ref(false)
  114. // 日期选择弹窗
  115. const showDateModal = ref(false)
  116. const selectedDate = ref('')
  117. const selectedFile = ref(null)
  118. onMounted(() => {
  119. // 获取系统信息
  120. const windowInfo = uni.getWindowInfo()
  121. statusBarHeight.value = windowInfo.statusBarHeight || 0
  122. // 加载文件列表
  123. loadFileList()
  124. })
  125. // 返回上一页
  126. const handleBack = () => {
  127. uni.navigateBack()
  128. }
  129. // 加载文件列表
  130. const loadFileList = async () => {
  131. if (loading.value) return
  132. try {
  133. loading.value = true
  134. const response = await getToSubmitList({
  135. name: searchName.value,
  136. pageNum: pageNum.value,
  137. pageSize: pageSize.value
  138. })
  139. if (response.code === 200) {
  140. if (pageNum.value === 1) {
  141. fileList.value = response.rows || []
  142. } else {
  143. fileList.value = [...fileList.value, ...(response.rows || [])]
  144. }
  145. total.value = response.total || 0
  146. }
  147. } catch (error) {
  148. console.error('加载文件列表失败:', error)
  149. uni.showToast({
  150. title: t('fileSelect.message.loadFailed'),
  151. icon: 'none'
  152. })
  153. } finally {
  154. loading.value = false
  155. }
  156. }
  157. // 搜索
  158. const handleSearch = () => {
  159. pageNum.value = 1
  160. fileList.value = []
  161. loadFileList()
  162. }
  163. // 加载更多
  164. const handleLoadMore = () => {
  165. if (loading.value) return
  166. if (fileList.value.length >= total.value) return
  167. pageNum.value++
  168. loadFileList()
  169. }
  170. // 选择文件 - 先弹出日期选择框
  171. const handleSelectFile = (file) => {
  172. selectedFile.value = file
  173. selectedDate.value = ''
  174. showDateModal.value = true
  175. }
  176. // 关闭弹窗
  177. const handleCloseModal = () => {
  178. showDateModal.value = false
  179. selectedFile.value = null
  180. selectedDate.value = ''
  181. }
  182. // 日期选择变化
  183. const handleDateChange = (e) => {
  184. selectedDate.value = e.detail.value
  185. }
  186. // 确认日期并提交
  187. const handleConfirmDate = async () => {
  188. if (!selectedDate.value) {
  189. uni.showToast({
  190. title: t('fileSelect.message.selectDateFirst'),
  191. icon: 'none'
  192. })
  193. return
  194. }
  195. if (!selectedFile.value) {
  196. uni.showToast({
  197. title: t('fileSelect.message.noFileSelected'),
  198. icon: 'none'
  199. })
  200. return
  201. }
  202. try {
  203. // 从全局数据中获取扫描的fileBase64List
  204. const fileBase64List = getApp().globalData.scannedFileBase64List
  205. if (!fileBase64List || fileBase64List.length === 0) {
  206. uni.showToast({
  207. title: t('fileSelect.message.noScanFile'),
  208. icon: 'none'
  209. })
  210. return
  211. }
  212. // 关闭弹窗
  213. showDateModal.value = false
  214. uni.showLoading({
  215. title: t('fileSelect.message.submitting'),
  216. mask: true
  217. })
  218. // 调用上传接口
  219. const response = await uploadOnSubmit({
  220. documentId: selectedFile.value.id,
  221. fileBase64List: fileBase64List,
  222. effectiveDate: selectedDate.value
  223. })
  224. uni.hideLoading()
  225. if (response.code === 200) {
  226. // 清除全局数据
  227. getApp().globalData.scannedFileBase64List = null
  228. uni.showToast({
  229. title: t('fileSelect.message.submitSuccess'),
  230. icon: 'success',
  231. duration: 2000
  232. })
  233. // 返回首页
  234. setTimeout(() => {
  235. uni.reLaunch({
  236. url: '/pages/home/index'
  237. })
  238. }, 2000)
  239. } else {
  240. throw new Error(response.msg || '提交失败')
  241. }
  242. } catch (error) {
  243. uni.hideLoading()
  244. console.error('提交失败:', error)
  245. uni.showToast({
  246. title: t('fileSelect.message.submitFailed'),
  247. icon: 'none'
  248. })
  249. }
  250. }
  251. // 底部提交按钮(与点击文件相同的逻辑,但需要先选择文件)
  252. const handleSubmitAll = () => {
  253. if (fileList.value.length === 0) {
  254. uni.showToast({
  255. title: t('fileSelect.message.noAvailableFile'),
  256. icon: 'none'
  257. })
  258. return
  259. }
  260. uni.showToast({
  261. title: t('fileSelect.message.pleaseSelectFile'),
  262. icon: 'none'
  263. })
  264. }
  265. // 直接上传 - 跳转到项目选择页面
  266. const handleDirectUpload = () => {
  267. // 从全局数据中获取扫描的fileBase64List
  268. const fileBase64List = getApp().globalData.scannedFileBase64List
  269. if (!fileBase64List || fileBase64List.length === 0) {
  270. uni.showToast({
  271. title: t('fileSelect.message.noScanFile'),
  272. icon: 'none'
  273. })
  274. return
  275. }
  276. // 跳转到项目选择页面
  277. uni.navigateTo({
  278. url: '/pages/scan/projectSelect/index'
  279. })
  280. }
  281. // 格式化日期(只显示到天)
  282. const formatDate = (dateStr) => {
  283. if (!dateStr) return ''
  284. // 如果日期格式是 "2026-01-04 10:58:37",只取前10位
  285. return dateStr.split(' ')[0]
  286. }
  287. </script>
  288. <style lang="scss" scoped>
  289. .file-select-page {
  290. width: 100%;
  291. height: 100vh;
  292. display: flex;
  293. flex-direction: column;
  294. background-color: #f5f5f5;
  295. // 顶部导航栏
  296. .header-bg {
  297. background: linear-gradient(180deg, #1ec9c9 0%, #1eb8b8 100%);
  298. position: relative;
  299. z-index: 100;
  300. .header-content {
  301. height: 88rpx;
  302. display: flex;
  303. align-items: center;
  304. justify-content: space-between;
  305. padding: 0 24rpx;
  306. .back-btn {
  307. width: 60rpx;
  308. height: 60rpx;
  309. display: flex;
  310. align-items: center;
  311. justify-content: flex-start;
  312. .back-icon {
  313. font-size: 56rpx;
  314. color: #ffffff;
  315. font-weight: 300;
  316. }
  317. }
  318. .header-title {
  319. flex: 1;
  320. text-align: center;
  321. font-size: 32rpx;
  322. font-weight: 600;
  323. color: #ffffff;
  324. }
  325. .placeholder {
  326. width: 60rpx;
  327. }
  328. }
  329. }
  330. // 搜索框
  331. .search-bar {
  332. padding: 24rpx;
  333. background: #ffffff;
  334. display: flex;
  335. gap: 16rpx;
  336. .search-input {
  337. flex: 1;
  338. height: 64rpx;
  339. padding: 0 24rpx;
  340. background: #f5f5f5;
  341. border-radius: 32rpx;
  342. font-size: 28rpx;
  343. }
  344. .search-btn {
  345. width: 120rpx;
  346. height: 64rpx;
  347. background: #1ec9c9;
  348. border-radius: 32rpx;
  349. display: flex;
  350. align-items: center;
  351. justify-content: center;
  352. &:active {
  353. background: #1ab8b8;
  354. }
  355. .search-text {
  356. font-size: 28rpx;
  357. color: #ffffff;
  358. font-weight: 500;
  359. }
  360. }
  361. }
  362. // 文件列表
  363. .file-list {
  364. flex: 1;
  365. background: #ffffff;
  366. .file-item {
  367. padding: 24rpx;
  368. display: flex;
  369. align-items: center;
  370. border-bottom: 1rpx solid #f5f5f5;
  371. &:active {
  372. background: #f8f8f8;
  373. }
  374. .file-icon-wrapper {
  375. width: 80rpx;
  376. height: 80rpx;
  377. background: #f5f5f5;
  378. border-radius: 12rpx;
  379. display: flex;
  380. align-items: center;
  381. justify-content: center;
  382. margin-right: 24rpx;
  383. .file-icon {
  384. width: 48rpx;
  385. height: 48rpx;
  386. }
  387. }
  388. .file-info {
  389. flex: 1;
  390. display: flex;
  391. flex-direction: column;
  392. gap: 6rpx;
  393. .file-name {
  394. font-size: 32rpx;
  395. font-weight: 600;
  396. color: #333333;
  397. margin-bottom: 4rpx;
  398. }
  399. .file-detail {
  400. font-size: 26rpx;
  401. color: #666666;
  402. line-height: 1.5;
  403. }
  404. }
  405. }
  406. .empty-tip {
  407. padding: 200rpx 0;
  408. text-align: center;
  409. display: flex;
  410. flex-direction: column;
  411. gap: 16rpx;
  412. .empty-text {
  413. font-size: 28rpx;
  414. color: #999999;
  415. }
  416. .empty-hint {
  417. font-size: 26rpx;
  418. color: #1ec9c9;
  419. }
  420. }
  421. .loading-tip {
  422. padding: 32rpx 0;
  423. text-align: center;
  424. .loading-text {
  425. font-size: 28rpx;
  426. color: #999999;
  427. }
  428. }
  429. }
  430. // 底部提交按钮
  431. .submit-footer {
  432. background: #ffffff;
  433. padding: 24rpx 32rpx;
  434. padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
  435. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.05);
  436. display: flex;
  437. gap: 16rpx;
  438. .submit-btn {
  439. flex: 1;
  440. height: 88rpx;
  441. background: linear-gradient(135deg, #1ec9c9 0%, #1eb8b8 100%);
  442. border-radius: 44rpx;
  443. display: flex;
  444. align-items: center;
  445. justify-content: center;
  446. box-shadow: 0 4rpx 16rpx rgba(30, 201, 201, 0.3);
  447. &:active {
  448. transform: scale(0.98);
  449. opacity: 0.9;
  450. }
  451. &.secondary {
  452. background: #ffffff;
  453. border: 2rpx solid #1ec9c9;
  454. box-shadow: none;
  455. .submit-text {
  456. color: #1ec9c9;
  457. }
  458. }
  459. .submit-text {
  460. font-size: 32rpx;
  461. font-weight: 600;
  462. color: #ffffff;
  463. }
  464. &.full-width {
  465. flex: 1;
  466. }
  467. }
  468. }
  469. // 日期选择弹窗
  470. .modal-overlay {
  471. position: fixed;
  472. top: 0;
  473. left: 0;
  474. right: 0;
  475. bottom: 0;
  476. background: rgba(0, 0, 0, 0.5);
  477. display: flex;
  478. align-items: center;
  479. justify-content: center;
  480. z-index: 1000;
  481. .modal-content {
  482. width: 600rpx;
  483. background: #ffffff;
  484. border-radius: 24rpx;
  485. overflow: hidden;
  486. .modal-header {
  487. padding: 32rpx;
  488. border-bottom: 1rpx solid #f5f5f5;
  489. .modal-title {
  490. font-size: 32rpx;
  491. font-weight: 600;
  492. color: #333333;
  493. text-align: center;
  494. display: block;
  495. }
  496. }
  497. .modal-body {
  498. padding: 32rpx;
  499. .date-picker-wrapper {
  500. .date-display {
  501. background: #f5f5f5;
  502. border-radius: 12rpx;
  503. padding: 24rpx;
  504. display: flex;
  505. align-items: center;
  506. .date-label {
  507. font-size: 28rpx;
  508. color: #666666;
  509. margin-right: 16rpx;
  510. }
  511. .date-value {
  512. flex: 1;
  513. font-size: 28rpx;
  514. color: #333333;
  515. &.placeholder {
  516. color: #999999;
  517. }
  518. }
  519. .date-arrow {
  520. font-size: 40rpx;
  521. color: #999999;
  522. font-weight: 300;
  523. }
  524. }
  525. }
  526. }
  527. .modal-footer {
  528. display: flex;
  529. border-top: 1rpx solid #f5f5f5;
  530. .modal-btn {
  531. flex: 1;
  532. height: 88rpx;
  533. display: flex;
  534. align-items: center;
  535. justify-content: center;
  536. &:active {
  537. background: #f5f5f5;
  538. }
  539. &.cancel {
  540. border-right: 1rpx solid #f5f5f5;
  541. .modal-btn-text {
  542. color: #666666;
  543. }
  544. }
  545. &.confirm {
  546. .modal-btn-text {
  547. color: #1ec9c9;
  548. font-weight: 600;
  549. }
  550. }
  551. .modal-btn-text {
  552. font-size: 32rpx;
  553. }
  554. }
  555. }
  556. }
  557. }
  558. }
  559. </style>