index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. <template>
  2. <view class="upload-edit-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. <scroll-view scroll-y class="page-content">
  15. <!-- 文件夹信息卡片 -->
  16. <view class="info-card">
  17. <view class="info-row">
  18. <text class="info-label">文件夹路径:</text>
  19. <text class="info-value">{{ folderPath }}</text>
  20. </view>
  21. </view>
  22. <!-- 文件列表 -->
  23. <view class="file-list-section">
  24. <view class="section-title">文件列表 ({{ fileList.length }})</view>
  25. <view class="file-list">
  26. <view
  27. v-for="(file, index) in fileList"
  28. :key="index"
  29. class="file-item"
  30. >
  31. <view class="file-main" @click="handlePreview(file, index)">
  32. <view class="file-icon-wrapper">
  33. <image src="/static/icon/pdf.svg" mode="aspectFit" class="file-icon" />
  34. </view>
  35. <view class="file-info">
  36. <text class="file-name">{{ file.name }}</text>
  37. <text class="file-tip">点击预览</text>
  38. </view>
  39. </view>
  40. <!-- 操作按钮 -->
  41. <view class="file-actions">
  42. <view
  43. v-if="index > 0"
  44. class="action-icon"
  45. @click="handleMoveUp(index)"
  46. >
  47. <text class="icon-text">↑</text>
  48. </view>
  49. <view
  50. v-if="index < fileList.length - 1"
  51. class="action-icon"
  52. @click="handleMoveDown(index)"
  53. >
  54. <text class="icon-text">↓</text>
  55. </view>
  56. <view class="action-icon delete" @click="handleDelete(index)">
  57. <text class="icon-text">×</text>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </scroll-view>
  64. <!-- 底部操作按钮 -->
  65. <view class="footer-actions">
  66. <view class="action-btn secondary" @click="handleCancel">
  67. <text class="action-text">取消</text>
  68. </view>
  69. <view class="action-btn primary" @click="handleUpload">
  70. <text class="action-text">上传</text>
  71. </view>
  72. </view>
  73. <!-- 上传弹出框 -->
  74. <view v-if="showUploadDialog" class="dialog-overlay" @click="closeDialog">
  75. <view class="dialog-content" @click.stop>
  76. <view class="dialog-header">
  77. <text class="dialog-title">上传文件</text>
  78. <view class="dialog-close" @click="closeDialog">
  79. <text class="close-icon">×</text>
  80. </view>
  81. </view>
  82. <view class="dialog-body">
  83. <view class="form-item">
  84. <text class="form-label">文件名</text>
  85. <input
  86. class="form-input"
  87. v-model="uploadForm.fileName"
  88. placeholder="请输入文件名"
  89. maxlength="100"
  90. />
  91. </view>
  92. <view class="form-item">
  93. <text class="form-label">备注</text>
  94. <textarea
  95. class="form-textarea"
  96. v-model="uploadForm.note"
  97. placeholder="请输入备注(可选)"
  98. maxlength="500"
  99. :auto-height="true"
  100. />
  101. </view>
  102. </view>
  103. <view class="dialog-footer">
  104. <view class="dialog-btn cancel" @click="closeDialog">
  105. <text class="btn-text">取消</text>
  106. </view>
  107. <view class="dialog-btn confirm" @click="confirmUpload">
  108. <text class="btn-text">确认</text>
  109. </view>
  110. </view>
  111. </view>
  112. </view>
  113. </view>
  114. </template>
  115. <script>
  116. import { uploadNew } from '@/apis/scan.js'
  117. export default {
  118. data() {
  119. return {
  120. statusBarHeight: 0,
  121. folderId: 0,
  122. projectId: 0,
  123. folderPath: '',
  124. fileList: [], // 文件列表,每个元素包含 { base64, name, path }
  125. showUploadDialog: false,
  126. uploadForm: {
  127. fileName: '',
  128. note: ''
  129. }
  130. }
  131. },
  132. onLoad(options) {
  133. console.log('========== 编辑上传文件页面 ==========')
  134. console.log('页面参数:', options)
  135. this.folderId = parseInt(options.folderId) || 0
  136. this.projectId = parseInt(options.projectId) || 0
  137. this.folderPath = decodeURIComponent(options.folderPath || '')
  138. console.log('文件夹ID:', this.folderId)
  139. console.log('项目ID:', this.projectId)
  140. console.log('文件夹路径:', this.folderPath)
  141. },
  142. onReady() {
  143. // 获取系统信息
  144. const windowInfo = uni.getWindowInfo()
  145. this.statusBarHeight = windowInfo.statusBarHeight || 0
  146. // 从全局数据获取文件列表
  147. const fileBase64List = getApp().globalData.scannedFileBase64List
  148. const pdfData = getApp().globalData.pdfData
  149. console.log('fileBase64List:', fileBase64List)
  150. console.log('pdfData:', pdfData)
  151. if (fileBase64List && fileBase64List.length > 0) {
  152. // 如果有 pdfData(包含文件名和路径),使用它
  153. if (pdfData && pdfData.length > 0) {
  154. this.fileList = pdfData.map((item, index) => ({
  155. base64: item.base64 || fileBase64List[index],
  156. name: item.name || `文件_${index + 1}`,
  157. path: item.path
  158. }))
  159. } else {
  160. // 否则只有 base64 数据
  161. this.fileList = fileBase64List.map((base64, index) => ({
  162. base64: base64,
  163. name: `文件_${index + 1}`,
  164. path: null
  165. }))
  166. }
  167. console.log('文件列表:', this.fileList)
  168. } else {
  169. console.error('未找到文件列表')
  170. uni.showToast({
  171. title: '未找到文件',
  172. icon: 'none'
  173. })
  174. }
  175. },
  176. methods: {
  177. // 返回上一页
  178. handleBack() {
  179. uni.navigateBack()
  180. },
  181. // 取消
  182. handleCancel() {
  183. uni.showModal({
  184. title: '提示',
  185. content: '确定要取消上传吗?',
  186. confirmText: '确定',
  187. cancelText: '继续编辑',
  188. success: (res) => {
  189. if (res.confirm) {
  190. // 清除全局数据
  191. getApp().globalData.scannedFileBase64List = null
  192. getApp().globalData.selectedFolder = null
  193. // 返回首页
  194. uni.reLaunch({
  195. url: '/pages/home/index'
  196. })
  197. }
  198. }
  199. })
  200. },
  201. // 上传
  202. handleUpload() {
  203. if (this.fileList.length === 0) {
  204. uni.showToast({
  205. title: '没有可上传的文件',
  206. icon: 'none'
  207. })
  208. return
  209. }
  210. // 显示上传弹出框
  211. this.showUploadDialog = true
  212. },
  213. // 关闭弹出框
  214. closeDialog() {
  215. this.showUploadDialog = false
  216. this.uploadForm = {
  217. fileName: '',
  218. note: ''
  219. }
  220. },
  221. // 确认上传
  222. async confirmUpload() {
  223. // 验证文件名
  224. if (!this.uploadForm.fileName.trim()) {
  225. uni.showToast({
  226. title: '请输入文件名',
  227. icon: 'none'
  228. })
  229. return
  230. }
  231. console.log('========== 开始上传 ==========')
  232. console.log('文件夹ID:', this.folderId)
  233. console.log('项目ID:', this.projectId)
  234. console.log('文件名:', this.uploadForm.fileName)
  235. console.log('备注:', this.uploadForm.note)
  236. console.log('文件数量:', this.fileList.length)
  237. // 准备上传数据(在关闭弹出框之前)
  238. const uploadData = {
  239. folderId: this.folderId,
  240. fileName: this.uploadForm.fileName.trim(),
  241. projectId: this.projectId,
  242. note: this.uploadForm.note.trim(),
  243. files: this.fileList.map(item => item.base64)
  244. }
  245. // 关闭弹出框
  246. this.closeDialog()
  247. // 显示加载提示
  248. uni.showLoading({
  249. title: '上传中...',
  250. mask: true
  251. })
  252. try {
  253. // 调用上传接口
  254. await uploadNew(uploadData)
  255. uni.hideLoading()
  256. uni.showToast({
  257. title: '上传成功',
  258. icon: 'success',
  259. duration: 2000
  260. })
  261. // 清除全局数据
  262. getApp().globalData.scannedFileBase64List = null
  263. getApp().globalData.selectedFolder = null
  264. getApp().globalData.pdfData = null
  265. // 返回首页
  266. setTimeout(() => {
  267. uni.reLaunch({
  268. url: '/pages/home/index'
  269. })
  270. }, 2000)
  271. } catch (error) {
  272. console.error('上传失败:', error)
  273. uni.hideLoading()
  274. uni.showToast({
  275. title: error.msg || '上传失败',
  276. icon: 'none',
  277. duration: 2000
  278. })
  279. }
  280. },
  281. // 预览文件
  282. // 预览文件
  283. handlePreview(file, index) {
  284. console.log('预览文件:', file.name)
  285. console.log('文件索引:', index)
  286. if (!file.base64) {
  287. uni.showToast({
  288. title: '文件数据异常',
  289. icon: 'none'
  290. })
  291. return
  292. }
  293. // 将 base64 转换为 Data URL
  294. const dataUrl = `data:application/pdf;base64,${file.base64}`
  295. // 跳转到文档查看器页面
  296. uni.navigateTo({
  297. url: `/pages/home/documentViewer/index?name=${encodeURIComponent(file.name)}&url=${encodeURIComponent(dataUrl)}`
  298. })
  299. },
  300. // 上移文件
  301. handleMoveUp(index) {
  302. if (index === 0) return
  303. const temp = this.fileList[index]
  304. this.fileList[index] = this.fileList[index - 1]
  305. this.fileList[index - 1] = temp
  306. // 触发响应式更新
  307. this.fileList = [...this.fileList]
  308. uni.showToast({
  309. title: '已上移',
  310. icon: 'success',
  311. duration: 1000
  312. })
  313. },
  314. // 下移文件
  315. handleMoveDown(index) {
  316. if (index === this.fileList.length - 1) return
  317. const temp = this.fileList[index]
  318. this.fileList[index] = this.fileList[index + 1]
  319. this.fileList[index + 1] = temp
  320. // 触发响应式更新
  321. this.fileList = [...this.fileList]
  322. uni.showToast({
  323. title: '已下移',
  324. icon: 'success',
  325. duration: 1000
  326. })
  327. },
  328. // 删除文件
  329. handleDelete(index) {
  330. // 不允许删除最后一个文件
  331. if (this.fileList.length <= 1) {
  332. uni.showToast({
  333. title: '至少保留一个文件',
  334. icon: 'none',
  335. duration: 2000
  336. })
  337. return
  338. }
  339. uni.showModal({
  340. title: '确认删除',
  341. content: `确定要删除"${this.fileList[index].name}"吗?`,
  342. confirmText: '删除',
  343. cancelText: '取消',
  344. success: (res) => {
  345. if (res.confirm) {
  346. this.fileList.splice(index, 1)
  347. uni.showToast({
  348. title: '已删除',
  349. icon: 'success',
  350. duration: 1000
  351. })
  352. }
  353. }
  354. })
  355. },
  356. // 格式化文件大小
  357. formatFileSize(bytes) {
  358. if (!bytes) return '0 B'
  359. const k = 1024
  360. const sizes = ['B', 'KB', 'MB', 'GB']
  361. const i = Math.floor(Math.log(bytes) / Math.log(k))
  362. return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i]
  363. }
  364. }
  365. }
  366. </script>
  367. <style lang="scss" scoped>
  368. .upload-edit-page {
  369. width: 100%;
  370. height: 100vh;
  371. display: flex;
  372. flex-direction: column;
  373. background-color: #f5f5f5;
  374. // 顶部导航栏
  375. .header-bg {
  376. background: linear-gradient(180deg, #1ec9c9 0%, #1eb8b8 100%);
  377. position: relative;
  378. z-index: 100;
  379. .header-content {
  380. height: 88rpx;
  381. display: flex;
  382. align-items: center;
  383. justify-content: space-between;
  384. padding: 0 24rpx;
  385. .back-btn {
  386. width: 60rpx;
  387. height: 60rpx;
  388. display: flex;
  389. align-items: center;
  390. justify-content: flex-start;
  391. .back-icon {
  392. font-size: 56rpx;
  393. color: #ffffff;
  394. font-weight: 300;
  395. }
  396. }
  397. .header-title {
  398. flex: 1;
  399. text-align: center;
  400. font-size: 32rpx;
  401. font-weight: 600;
  402. color: #ffffff;
  403. }
  404. .placeholder {
  405. width: 60rpx;
  406. }
  407. }
  408. }
  409. // 页面内容
  410. .page-content {
  411. flex: 1;
  412. padding: 24rpx;
  413. // 信息卡片
  414. .info-card {
  415. background: #ffffff;
  416. border-radius: 16rpx;
  417. padding: 32rpx 24rpx;
  418. margin-bottom: 24rpx;
  419. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  420. .info-row {
  421. display: flex;
  422. align-items: flex-start;
  423. margin-bottom: 20rpx;
  424. &:last-child {
  425. margin-bottom: 0;
  426. }
  427. .info-label {
  428. font-size: 28rpx;
  429. color: #666666;
  430. min-width: 180rpx;
  431. }
  432. .info-value {
  433. flex: 1;
  434. font-size: 28rpx;
  435. color: #333333;
  436. font-weight: 500;
  437. word-break: break-all;
  438. }
  439. }
  440. }
  441. // 文件列表区域
  442. .file-list-section {
  443. .section-title {
  444. font-size: 30rpx;
  445. font-weight: 600;
  446. color: #333333;
  447. margin-bottom: 16rpx;
  448. }
  449. .file-list {
  450. background: #ffffff;
  451. border-radius: 16rpx;
  452. overflow: hidden;
  453. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  454. .file-item {
  455. display: flex;
  456. align-items: center;
  457. justify-content: space-between;
  458. padding: 24rpx;
  459. border-bottom: 1rpx solid #f5f5f5;
  460. &:last-child {
  461. border-bottom: none;
  462. }
  463. .file-main {
  464. flex: 1;
  465. display: flex;
  466. align-items: center;
  467. &:active {
  468. opacity: 0.7;
  469. }
  470. .file-icon-wrapper {
  471. width: 64rpx;
  472. height: 64rpx;
  473. background: #f5f5f5;
  474. border-radius: 12rpx;
  475. display: flex;
  476. align-items: center;
  477. justify-content: center;
  478. margin-right: 16rpx;
  479. .file-icon {
  480. width: 40rpx;
  481. height: 40rpx;
  482. }
  483. }
  484. .file-info {
  485. flex: 1;
  486. display: flex;
  487. flex-direction: column;
  488. gap: 8rpx;
  489. .file-name {
  490. font-size: 28rpx;
  491. color: #333333;
  492. font-weight: 500;
  493. }
  494. .file-tip {
  495. font-size: 24rpx;
  496. color: #999999;
  497. }
  498. }
  499. }
  500. .file-actions {
  501. display: flex;
  502. align-items: center;
  503. gap: 12rpx;
  504. margin-left: 16rpx;
  505. .action-icon {
  506. width: 56rpx;
  507. height: 56rpx;
  508. border-radius: 50%;
  509. background: #f5f5f5;
  510. display: flex;
  511. align-items: center;
  512. justify-content: center;
  513. &:active {
  514. background: #e0e0e0;
  515. }
  516. &.delete {
  517. background: #ffe5e5;
  518. &:active {
  519. background: #ffcccc;
  520. }
  521. .icon-text {
  522. color: #ff4444;
  523. font-size: 40rpx;
  524. }
  525. }
  526. .icon-text {
  527. font-size: 32rpx;
  528. color: #666666;
  529. font-weight: 600;
  530. line-height: 1;
  531. }
  532. }
  533. }
  534. }
  535. }
  536. }
  537. }
  538. // 底部操作按钮
  539. .footer-actions {
  540. background: #ffffff;
  541. padding: 24rpx 32rpx;
  542. padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
  543. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.05);
  544. display: flex;
  545. gap: 16rpx;
  546. .action-btn {
  547. flex: 1;
  548. height: 88rpx;
  549. border-radius: 44rpx;
  550. display: flex;
  551. align-items: center;
  552. justify-content: center;
  553. &:active {
  554. transform: scale(0.98);
  555. opacity: 0.9;
  556. }
  557. &.secondary {
  558. background: #ffffff;
  559. border: 2rpx solid #1ec9c9;
  560. .action-text {
  561. color: #1ec9c9;
  562. }
  563. }
  564. &.primary {
  565. background: linear-gradient(135deg, #1ec9c9 0%, #1eb8b8 100%);
  566. box-shadow: 0 4rpx 16rpx rgba(30, 201, 201, 0.3);
  567. .action-text {
  568. color: #ffffff;
  569. }
  570. }
  571. .action-text {
  572. font-size: 32rpx;
  573. font-weight: 600;
  574. }
  575. }
  576. }
  577. // 弹出框遮罩
  578. .dialog-overlay {
  579. position: fixed;
  580. top: 0;
  581. left: 0;
  582. right: 0;
  583. bottom: 0;
  584. background: rgba(0, 0, 0, 0.5);
  585. display: flex;
  586. align-items: center;
  587. justify-content: center;
  588. z-index: 1000;
  589. .dialog-content {
  590. width: 600rpx;
  591. background: #ffffff;
  592. border-radius: 24rpx;
  593. overflow: hidden;
  594. .dialog-header {
  595. padding: 32rpx 32rpx 24rpx;
  596. display: flex;
  597. align-items: center;
  598. justify-content: space-between;
  599. border-bottom: 1rpx solid #f5f5f5;
  600. .dialog-title {
  601. font-size: 32rpx;
  602. font-weight: 600;
  603. color: #333333;
  604. }
  605. .dialog-close {
  606. width: 48rpx;
  607. height: 48rpx;
  608. display: flex;
  609. align-items: center;
  610. justify-content: center;
  611. &:active {
  612. opacity: 0.7;
  613. }
  614. .close-icon {
  615. font-size: 48rpx;
  616. color: #999999;
  617. line-height: 1;
  618. }
  619. }
  620. }
  621. .dialog-body {
  622. padding: 32rpx;
  623. .form-item {
  624. margin-bottom: 32rpx;
  625. &:last-child {
  626. margin-bottom: 0;
  627. }
  628. .form-label {
  629. display: block;
  630. font-size: 28rpx;
  631. color: #333333;
  632. margin-bottom: 16rpx;
  633. font-weight: 500;
  634. }
  635. .form-input {
  636. width: 100%;
  637. height: 80rpx;
  638. padding: 0 24rpx;
  639. background: #f5f5f5;
  640. border-radius: 12rpx;
  641. font-size: 28rpx;
  642. color: #333333;
  643. box-sizing: border-box;
  644. }
  645. .form-textarea {
  646. width: 100%;
  647. min-height: 120rpx;
  648. padding: 16rpx 24rpx;
  649. background: #f5f5f5;
  650. border-radius: 12rpx;
  651. font-size: 28rpx;
  652. color: #333333;
  653. box-sizing: border-box;
  654. }
  655. }
  656. }
  657. .dialog-footer {
  658. padding: 24rpx 32rpx 32rpx;
  659. display: flex;
  660. gap: 16rpx;
  661. .dialog-btn {
  662. flex: 1;
  663. height: 80rpx;
  664. border-radius: 40rpx;
  665. display: flex;
  666. align-items: center;
  667. justify-content: center;
  668. &:active {
  669. transform: scale(0.98);
  670. opacity: 0.9;
  671. }
  672. &.cancel {
  673. background: #f5f5f5;
  674. .btn-text {
  675. color: #666666;
  676. }
  677. }
  678. &.confirm {
  679. background: linear-gradient(135deg, #1ec9c9 0%, #1eb8b8 100%);
  680. .btn-text {
  681. color: #ffffff;
  682. }
  683. }
  684. .btn-text {
  685. font-size: 30rpx;
  686. font-weight: 600;
  687. }
  688. }
  689. }
  690. }
  691. }
  692. }
  693. </style>