index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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">请选择对应缺失文件</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="搜索文件名"
  19. @confirm="handleSearch"
  20. />
  21. <view class="search-btn" @click="handleSearch">
  22. <text class="search-text">搜索</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">项目: {{ item.project }}</text>
  43. <text class="file-detail">文件夹: {{ item.folder }}</text>
  44. <text class="file-detail">创建人: {{ item.createBy }}</text>
  45. <text class="file-detail">截止日期: {{ formatDate(item.deadline) }}</text>
  46. </view>
  47. </view>
  48. <view v-if="fileList.length === 0 && !loading" class="empty-tip">
  49. <text class="empty-text">暂无待递交文件</text>
  50. </view>
  51. <view v-if="loading" class="loading-tip">
  52. <text class="loading-text">加载中...</text>
  53. </view>
  54. </scroll-view>
  55. <!-- 底部提交按钮 -->
  56. <view class="submit-footer" v-if="fileList.length > 0">
  57. <view class="submit-btn secondary" @click="handleDirectUpload">
  58. <text class="submit-text">直接上传</text>
  59. </view>
  60. <view class="submit-btn" @click="handleSubmitAll">
  61. <text class="submit-text">提交</text>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script setup>
  67. import { ref, onMounted } from 'vue'
  68. import { getToSubmitList, uploadOnSubmit } from '@/apis/scan'
  69. // 状态栏高度
  70. const statusBarHeight = ref(0)
  71. // 文件列表
  72. const fileList = ref([])
  73. const searchName = ref('')
  74. const pageNum = ref(1)
  75. const pageSize = ref(10)
  76. const total = ref(0)
  77. const loading = ref(false)
  78. onMounted(() => {
  79. // 获取系统信息
  80. const windowInfo = uni.getWindowInfo()
  81. statusBarHeight.value = windowInfo.statusBarHeight || 0
  82. // 加载文件列表
  83. loadFileList()
  84. })
  85. // 返回上一页
  86. const handleBack = () => {
  87. uni.navigateBack()
  88. }
  89. // 加载文件列表
  90. const loadFileList = async () => {
  91. if (loading.value) return
  92. try {
  93. loading.value = true
  94. const response = await getToSubmitList({
  95. name: searchName.value,
  96. pageNum: pageNum.value,
  97. pageSize: pageSize.value
  98. })
  99. if (response.code === 200) {
  100. if (pageNum.value === 1) {
  101. fileList.value = response.rows || []
  102. } else {
  103. fileList.value = [...fileList.value, ...(response.rows || [])]
  104. }
  105. total.value = response.total || 0
  106. }
  107. } catch (error) {
  108. console.error('加载文件列表失败:', error)
  109. uni.showToast({
  110. title: '加载失败',
  111. icon: 'none'
  112. })
  113. } finally {
  114. loading.value = false
  115. }
  116. }
  117. // 搜索
  118. const handleSearch = () => {
  119. pageNum.value = 1
  120. fileList.value = []
  121. loadFileList()
  122. }
  123. // 加载更多
  124. const handleLoadMore = () => {
  125. if (loading.value) return
  126. if (fileList.value.length >= total.value) return
  127. pageNum.value++
  128. loadFileList()
  129. }
  130. // 选择文件
  131. const handleSelectFile = async (file) => {
  132. try {
  133. // 从全局数据中获取扫描的fileBase64List
  134. const fileBase64List = getApp().globalData.scannedFileBase64List
  135. if (!fileBase64List || fileBase64List.length === 0) {
  136. uni.showToast({
  137. title: '未找到扫描文件',
  138. icon: 'none'
  139. })
  140. return
  141. }
  142. uni.showLoading({
  143. title: '提交中...',
  144. mask: true
  145. })
  146. // 调用上传接口
  147. const response = await uploadOnSubmit({
  148. documentId: file.id,
  149. fileBase64List: fileBase64List
  150. })
  151. uni.hideLoading()
  152. if (response.code === 200) {
  153. // 清除全局数据
  154. getApp().globalData.scannedFileBase64List = null
  155. uni.showToast({
  156. title: '提交成功',
  157. icon: 'success',
  158. duration: 2000
  159. })
  160. // 返回首页
  161. setTimeout(() => {
  162. uni.reLaunch({
  163. url: '/pages/home/index'
  164. })
  165. }, 2000)
  166. } else {
  167. throw new Error(response.msg || '提交失败')
  168. }
  169. } catch (error) {
  170. uni.hideLoading()
  171. console.error('提交失败:', error)
  172. uni.showToast({
  173. title: error.message || '提交失败',
  174. icon: 'none'
  175. })
  176. }
  177. }
  178. // 底部提交按钮(与点击文件相同的逻辑,但需要先选择文件)
  179. const handleSubmitAll = () => {
  180. if (fileList.value.length === 0) {
  181. uni.showToast({
  182. title: '暂无可选文件',
  183. icon: 'none'
  184. })
  185. return
  186. }
  187. uni.showToast({
  188. title: '请点击选择对应的文件',
  189. icon: 'none'
  190. })
  191. }
  192. // 直接上传 - 跳转到项目选择页面
  193. const handleDirectUpload = () => {
  194. // 从全局数据中获取扫描的fileBase64List
  195. const fileBase64List = getApp().globalData.scannedFileBase64List
  196. if (!fileBase64List || fileBase64List.length === 0) {
  197. uni.showToast({
  198. title: '未找到扫描文件',
  199. icon: 'none'
  200. })
  201. return
  202. }
  203. // 跳转到项目选择页面
  204. uni.navigateTo({
  205. url: '/pages/scan/projectSelect/index'
  206. })
  207. }
  208. // 格式化日期(只显示到天)
  209. const formatDate = (dateStr) => {
  210. if (!dateStr) return ''
  211. // 如果日期格式是 "2026-01-04 10:58:37",只取前10位
  212. return dateStr.split(' ')[0]
  213. }
  214. </script>
  215. <style lang="scss" scoped>
  216. .file-select-page {
  217. width: 100%;
  218. height: 100vh;
  219. display: flex;
  220. flex-direction: column;
  221. background-color: #f5f5f5;
  222. // 顶部导航栏
  223. .header-bg {
  224. background: linear-gradient(180deg, #1ec9c9 0%, #1eb8b8 100%);
  225. position: relative;
  226. z-index: 100;
  227. .header-content {
  228. height: 88rpx;
  229. display: flex;
  230. align-items: center;
  231. justify-content: space-between;
  232. padding: 0 24rpx;
  233. .back-btn {
  234. width: 60rpx;
  235. height: 60rpx;
  236. display: flex;
  237. align-items: center;
  238. justify-content: flex-start;
  239. .back-icon {
  240. font-size: 56rpx;
  241. color: #ffffff;
  242. font-weight: 300;
  243. }
  244. }
  245. .header-title {
  246. flex: 1;
  247. text-align: center;
  248. font-size: 32rpx;
  249. font-weight: 600;
  250. color: #ffffff;
  251. }
  252. .placeholder {
  253. width: 60rpx;
  254. }
  255. }
  256. }
  257. // 搜索框
  258. .search-bar {
  259. padding: 24rpx;
  260. background: #ffffff;
  261. display: flex;
  262. gap: 16rpx;
  263. .search-input {
  264. flex: 1;
  265. height: 64rpx;
  266. padding: 0 24rpx;
  267. background: #f5f5f5;
  268. border-radius: 32rpx;
  269. font-size: 28rpx;
  270. }
  271. .search-btn {
  272. width: 120rpx;
  273. height: 64rpx;
  274. background: #1ec9c9;
  275. border-radius: 32rpx;
  276. display: flex;
  277. align-items: center;
  278. justify-content: center;
  279. &:active {
  280. background: #1ab8b8;
  281. }
  282. .search-text {
  283. font-size: 28rpx;
  284. color: #ffffff;
  285. font-weight: 500;
  286. }
  287. }
  288. }
  289. // 文件列表
  290. .file-list {
  291. flex: 1;
  292. background: #ffffff;
  293. .file-item {
  294. padding: 24rpx;
  295. display: flex;
  296. align-items: center;
  297. border-bottom: 1rpx solid #f5f5f5;
  298. &:active {
  299. background: #f8f8f8;
  300. }
  301. .file-icon-wrapper {
  302. width: 80rpx;
  303. height: 80rpx;
  304. background: #f5f5f5;
  305. border-radius: 12rpx;
  306. display: flex;
  307. align-items: center;
  308. justify-content: center;
  309. margin-right: 24rpx;
  310. .file-icon {
  311. width: 48rpx;
  312. height: 48rpx;
  313. }
  314. }
  315. .file-info {
  316. flex: 1;
  317. display: flex;
  318. flex-direction: column;
  319. gap: 6rpx;
  320. .file-name {
  321. font-size: 32rpx;
  322. font-weight: 600;
  323. color: #333333;
  324. margin-bottom: 4rpx;
  325. }
  326. .file-detail {
  327. font-size: 26rpx;
  328. color: #666666;
  329. line-height: 1.5;
  330. }
  331. }
  332. }
  333. .empty-tip {
  334. padding: 200rpx 0;
  335. text-align: center;
  336. .empty-text {
  337. font-size: 28rpx;
  338. color: #999999;
  339. }
  340. }
  341. .loading-tip {
  342. padding: 32rpx 0;
  343. text-align: center;
  344. .loading-text {
  345. font-size: 28rpx;
  346. color: #999999;
  347. }
  348. }
  349. }
  350. // 底部提交按钮
  351. .submit-footer {
  352. background: #ffffff;
  353. padding: 24rpx 32rpx;
  354. padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
  355. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.05);
  356. display: flex;
  357. gap: 16rpx;
  358. .submit-btn {
  359. flex: 1;
  360. height: 88rpx;
  361. background: linear-gradient(135deg, #1ec9c9 0%, #1eb8b8 100%);
  362. border-radius: 44rpx;
  363. display: flex;
  364. align-items: center;
  365. justify-content: center;
  366. box-shadow: 0 4rpx 16rpx rgba(30, 201, 201, 0.3);
  367. &:active {
  368. transform: scale(0.98);
  369. opacity: 0.9;
  370. }
  371. &.secondary {
  372. background: #ffffff;
  373. border: 2rpx solid #1ec9c9;
  374. box-shadow: none;
  375. .submit-text {
  376. color: #1ec9c9;
  377. }
  378. }
  379. .submit-text {
  380. font-size: 32rpx;
  381. font-weight: 600;
  382. color: #ffffff;
  383. }
  384. }
  385. }
  386. }
  387. </style>