index.vue 10 KB

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