FileList.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. <template>
  2. <el-row>
  3. <el-row>
  4. <el-form :inline="true" :model="searchForm" class="demo-form-inline" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  5. <el-form-item>
  6. <el-button size="mini" type="danger" @click="goToUpload">上传</el-button>
  7. <el-button size="mini" type="danger" @click="downloadFile">下载</el-button>
  8. <el-button size="mini" type="danger" @click="deleteMultiple">删除</el-button>
  9. <el-button size="mini" type="danger" @click="createNewFolder">新建文件夹</el-button>
  10. <el-button size="mini" type="danger" @click="move(1)">移动</el-button>
  11. <el-button size="mini" type="danger" @click="move(2)">复制</el-button>
  12. <el-button size="mini" type="danger" @click="share">分享</el-button>
  13. </el-form-item>
  14. <el-form-item>
  15. <el-select v-model="searchForm.fileType" placeholder="文件类型" @change="onSelect">
  16. <el-option label="全部" value="0" />
  17. <el-option label="图片" value="1001" />
  18. <el-option label="视频" value="1002" />
  19. <el-option label="音频" value="1003" />
  20. <el-option label="文本" value="1004" />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-input v-model="searchForm.filename" placeholder="" />
  25. </el-form-item>
  26. <el-form-item>
  27. <el-button size="mini" type="warning" @click="search">查询</el-button>
  28. </el-form-item>
  29. </el-form>
  30. </el-row>
  31. <el-row>
  32. <el-col :md="2">
  33. <span>当前路径:</span>
  34. </el-col>
  35. <el-col :md="22">
  36. <el-breadcrumb separator-class="el-icon-arrow-right" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  37. <el-breadcrumb-item v-for="(item, index) of parentDirs" :key="index">
  38. <a href="javascript:void(0)" style="text-decoration-line: none" @click="goTo(item.path)">{{ item.filename }}</a>
  39. </el-breadcrumb-item>
  40. </el-breadcrumb>
  41. </el-col>
  42. </el-row>
  43. <el-row>
  44. <el-table
  45. ref="multipleTable"
  46. :data="dataList"
  47. border
  48. style="width: 100%"
  49. @selection-change="handleSelectionChange"
  50. >
  51. <el-table-column
  52. type="selection"
  53. />
  54. <el-table-column
  55. prop="filename"
  56. label="文件名"
  57. >
  58. <template slot-scope="scope">
  59. <a href="javascript:void(0)" style="text-decoration-line: none" @click="handleFile(scope.row)">
  60. <el-image :src="scope.row.icon" min-width="16" height="16" />
  61. <el-tooltip
  62. :content="scope.row.filename"
  63. raw-content
  64. placement="top-start"
  65. >
  66. <span v-if="scope.row.filename.length <= 60">
  67. {{ scope.row.filename }}
  68. </span>
  69. <span v-else>
  70. {{ scope.row.filename.substr(0, 55) + "..." }}
  71. </span>
  72. </el-tooltip>
  73. </a>
  74. </template>
  75. </el-table-column>
  76. <el-table-column
  77. prop="owner"
  78. label="修改时间"
  79. />
  80. <el-table-column
  81. prop="size"
  82. label="大小"
  83. />
  84. <el-table-column
  85. prop="fileType"
  86. label="文件类型"
  87. >
  88. <template slot-scope="scope">
  89. <el-tag v-if="scope.row.fileType === 1000" :type="'warning'" disable-transitions>
  90. 目录
  91. </el-tag>
  92. <el-tag v-else-if="scope.row.fileType === 1001" :type="'warning'" disable-transitions>
  93. 图片
  94. </el-tag>
  95. <el-tag v-else-if="scope.row.fileType === 1002" :type="'success'" disable-transitions>
  96. 视频
  97. </el-tag>
  98. <el-tag v-else-if="scope.row.fileType === 1003" :type="'danger'" disable-transitions>
  99. 音频
  100. </el-tag>
  101. <el-tag v-else-if="scope.row.fileType === 1004" :type="'danger'" disable-transitions>
  102. 文本
  103. </el-tag>
  104. <el-tag v-else-if="scope.row.fileType === 1005" :type="'danger'" disable-transitions>
  105. 其他
  106. </el-tag>
  107. <el-tag v-else-if="scope.row.fileType === 1006" :type="'danger'" disable-transitions>
  108. PDF
  109. </el-tag>
  110. <el-tag v-else :type="'danger'" disable-transitions>
  111. 二进制
  112. </el-tag>
  113. </template>
  114. </el-table-column>
  115. <el-table-column
  116. label="操作"
  117. >
  118. <template slot-scope="scope">
  119. <el-button
  120. size="mini"
  121. @click="getDetail(scope.row.fileId)"
  122. >详情</el-button>
  123. <el-button
  124. size="mini"
  125. @click="share(scope.row)"
  126. >分享</el-button>
  127. <el-button
  128. size="mini"
  129. @click="remove(scope.row)"
  130. >删除</el-button>
  131. </template>
  132. </el-table-column>
  133. </el-table>
  134. </el-row>
  135. <el-row>
  136. <el-pagination
  137. background
  138. :small="screenWidth <= 768"
  139. layout="prev, pager, next"
  140. :page-size="pageSize"
  141. :current-page="currentPage"
  142. :total="totalSize"
  143. @current-change="handleCurrentChange"
  144. @prev-click="handleCurrentChange"
  145. @next-click="handleCurrentChange"
  146. />
  147. </el-row>
  148. <!--创建新目录弹窗-->
  149. <el-dialog
  150. title="创建新目录"
  151. append-to-body
  152. :visible.sync="createFolderDialog"
  153. width="30%"
  154. center
  155. >
  156. <el-form ref="form" :model="createFolderForm">
  157. <el-form-item label="目录名">
  158. <el-input
  159. v-model="createFolderForm.folderName"
  160. placeholder="新目录名"
  161. style="width: 70%; padding-right: 2px"
  162. clearable
  163. />
  164. </el-form-item>
  165. <el-form-item>
  166. <el-button
  167. type="primary"
  168. @click="onCreateFolder"
  169. >创建</el-button>
  170. </el-form-item>
  171. </el-form>
  172. </el-dialog>
  173. <!--文件预览弹窗-->
  174. <el-dialog
  175. append-to-body
  176. width="70%"
  177. center
  178. :visible.sync="previewFileDialog"
  179. :before-close="handleDialogClose"
  180. destroy-on-close
  181. >
  182. <div v-if="fileDetail !== null">
  183. <el-card class="box-card">
  184. <div slot="header" class="clearfix">
  185. <span style="left: 0;margin-bottom: 0px;color: black;">{{ fileDetail.filename }}</span>
  186. </div>
  187. <div class="text item">
  188. <div v-if="fileDetail.fileType === 1001">
  189. <el-image
  190. :src="fileDetail.originalUrl"
  191. lazy
  192. />
  193. </div>
  194. <div v-else-if="fileDetail.fileType === 1002">
  195. <video-preview :video-prop="videoProp" />
  196. </div>
  197. <div v-else-if="fileDetail.fileType === 1003">
  198. <audio-player
  199. ref="audioPlayer"
  200. :is-loop="false"
  201. :show-prev-button="false"
  202. :show-next-button="false"
  203. :show-playback-rate="false"
  204. :audio-list="fileDetail.audioList.map(elm => elm.url)"
  205. theme-color="#87CEFA"
  206. />
  207. </div>
  208. <div v-else-if="fileDetail.fileType === 1004" style="white-space: pre-wrap;">
  209. {{textContent}}
  210. </div>
  211. <div v-else-if="fileDetail.fileType === 1005">
  212. <span>文本文件</span>
  213. </div>
  214. <div v-else-if="fileDetail.fileType === 1006" style="height: 80vh; overflow: auto">
  215. <iframe :src="fileUrl" width="100%" height="100%"></iframe>
  216. </div>
  217. <div v-else>
  218. <span>无预览</span>
  219. </div>
  220. </div>
  221. </el-card>
  222. </div>
  223. </el-dialog>
  224. <!--移动/复制弹窗-->
  225. <el-dialog
  226. title="移动文件"
  227. append-to-body
  228. :visible.sync="moveDialog"
  229. width="50%"
  230. center
  231. >
  232. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  233. <el-card class="box-card" :body-style="{ paddingTop: '0px' }">
  234. <div slot="header" class="clearfix">
  235. <span>选择目录</span>
  236. <el-button style="float: right; padding: 3px 0" type="text" @click="onMove">确定</el-button>
  237. </div>
  238. <div class="item">
  239. <el-tree
  240. :accordion="true"
  241. :data="treeNode"
  242. :props="defaultProps"
  243. highlight-current
  244. @node-click="handleNodeClick"
  245. >
  246. <span slot-scope="{ node, data }">
  247. <span :class="data.icon">{{ node.label }}</span>
  248. </span>
  249. </el-tree>
  250. </div>
  251. </el-card>
  252. </el-row>
  253. </el-dialog>
  254. </el-row>
  255. </template>
  256. <script>
  257. import VideoPreview from 'components/VideoPreview'
  258. import {
  259. getFileList,
  260. deleteDiskFile,
  261. addDiskFolder,
  262. getFileDetail,
  263. getFileUrl,
  264. getFolderTree,
  265. moveDiskFile
  266. } from '@/api/disk'
  267. export default {
  268. name: 'FileList',
  269. components: { VideoPreview },
  270. data() {
  271. return {
  272. // 屏幕宽度, 为了控制分页条的大小
  273. screenWidth: document.body.clientWidth,
  274. currentPage: 1,
  275. pageSize: 10,
  276. totalSize: 0,
  277. dataList: [],
  278. searchForm: {
  279. page: 1,
  280. path: '/',
  281. fileType: '0',
  282. filename: null
  283. },
  284. currentDir: '/',
  285. multipleSelection: [],
  286. parentDirs: [],
  287. createFolderDialog: false,
  288. createFolderForm: {
  289. parent: null,
  290. folderName: null
  291. },
  292. previewFileDialog: false,
  293. fileDetail: null,
  294. moveDialog: false,
  295. treeNode: [],
  296. defaultProps: {
  297. children: 'children',
  298. label: 'label',
  299. value: 'value'
  300. },
  301. moveForm: {
  302. type: 1,
  303. pid: null,
  304. fileIds: []
  305. },
  306. videoProp: null,
  307. fileUrl: null,
  308. textContent: null,
  309. }
  310. },
  311. created() {
  312. const path = this.$route.query.path
  313. if (path !== undefined && path !== null) {
  314. this.searchForm.path = path
  315. }
  316. document.title = '文件列表'
  317. this.getData(this.searchForm)
  318. },
  319. methods: {
  320. handleCurrentChange(pageNumber) {
  321. this.currentPage = pageNumber
  322. this.searchForm.page = this.currentPage
  323. this.getData(this.searchForm)
  324. // 回到顶部
  325. scrollTo(0, 0)
  326. },
  327. getData() {
  328. this.dataList = []
  329. getFileList(this.searchForm).then(resp => {
  330. if (resp.code === 0) {
  331. this.dataList = resp.data.fileList.list
  332. this.totalSize = resp.data.fileList.totalSize
  333. this.parentDirs = resp.data.pathList
  334. this.currentDir = this.parentDirs[this.parentDirs.length - 1].path
  335. } else {
  336. this.$notify({
  337. title: '提示',
  338. message: resp.msg,
  339. type: 'warning',
  340. duration: 3000
  341. })
  342. }
  343. }).catch(error => {
  344. this.$notify({
  345. title: '提示',
  346. message: error.message,
  347. type: 'error',
  348. duration: 3000
  349. })
  350. })
  351. },
  352. getDetail(fileId) {
  353. getFileDetail(fileId).then(resp => {
  354. if (resp.code === 0) {
  355. this.$message(resp.data)
  356. }
  357. })
  358. },
  359. share(row) {
  360. this.$message('share 未实现')
  361. },
  362. remove(row) {
  363. this.$message('remove 未实现')
  364. },
  365. onSelect() {
  366. this.currentPage = 1
  367. this.searchForm.page = this.currentPage
  368. this.getData(this.searchForm)
  369. },
  370. search() {
  371. this.currentPage = 1
  372. this.searchForm.page = this.currentPage
  373. this.getData(this.searchForm)
  374. },
  375. handleSelectionChange(val) {
  376. this.multipleSelection = val
  377. },
  378. goToUpload() {
  379. const path = '/disk/upload'
  380. if (this.$route.path === path) {
  381. this.$router.go(0)
  382. return
  383. }
  384. this.$router.push(path)
  385. },
  386. downloadFile() {
  387. console.log('下载文件')
  388. },
  389. deleteMultiple() {
  390. if (this.multipleSelection.length === 0) {
  391. this.$notify({
  392. message: '至少应选中一行',
  393. type: 'warning',
  394. duration: 3000
  395. })
  396. return
  397. }
  398. var fileIds = []
  399. for (const item of this.multipleSelection) {
  400. fileIds.push(item.fileId)
  401. }
  402. this.$confirm('确定要删除文件?', '提示', {
  403. confirmButtonText: '确定',
  404. cancelButtonText: '取消',
  405. type: 'warning'
  406. }).then(() => {
  407. deleteDiskFile(fileIds).then(resp => {
  408. if (resp.code === 0) {
  409. this.$refs.multipleTable.clearSelection()
  410. this.$notify({
  411. message: resp.msg,
  412. type: 'warning',
  413. duration: 3000
  414. })
  415. } else {
  416. this.$notify({
  417. title: '提示',
  418. message: resp.msg,
  419. type: 'warning',
  420. duration: 3000
  421. })
  422. }
  423. }).catch(error => {
  424. this.$notify({
  425. title: '提示',
  426. message: error.message,
  427. type: 'error',
  428. duration: 3000
  429. })
  430. })
  431. }).catch(() => {
  432. this.$message({
  433. type: 'info',
  434. message: '已取消'
  435. })
  436. })
  437. },
  438. handleFile(item) {
  439. const fileType = item.fileType
  440. if (fileType === 1000) {
  441. const filename = item.filename
  442. const namePath = this.parentDirs[this.parentDirs.length - 1]
  443. let currentPath
  444. if (namePath.filename === '/') {
  445. currentPath = namePath.path + filename
  446. } else {
  447. currentPath = namePath.path + '/' + filename
  448. }
  449. this.searchForm.path = currentPath
  450. this.getData(this.searchForm)
  451. } else {
  452. const fileId = item.fileId
  453. this.previewFile(fileType, fileId)
  454. }
  455. },
  456. goTo(path) {
  457. this.searchForm.page = 1
  458. this.searchForm.path = path
  459. this.getData(this.searchForm)
  460. },
  461. previewFile(fileType, fileId) {
  462. getFileUrl(fileType, fileId).then(resp => {
  463. if (resp.code === 0) {
  464. this.fileDetail = resp.data
  465. if (fileType === 1001) {
  466. } else if (fileType === 1002) {
  467. this.videoProp = {
  468. videoId: this.fileDetail.fileId,
  469. url: this.fileDetail.originalUrl,
  470. type: 'mp4'
  471. }
  472. } else if (fileType === 1003) {
  473. this.fileDetail.audioList = [
  474. { name: this.fileDetail.filename, url: this.fileDetail.originalUrl }
  475. ]
  476. } else if (fileType === 1004) {
  477. this.textContent = null
  478. const textUrl = this.fileDetail.originalUrl
  479. var that = this
  480. fetch(textUrl).then(function (data) {
  481. const contentType = data.headers.get("content-type")
  482. console.log(contentType)
  483. data.text().then(result => {
  484. that.textContent = result
  485. console.log(that.textContent)
  486. })
  487. }).catch(e => {
  488. this.$message(e)
  489. })
  490. } else if (fileType === 1005) {
  491. } else if (fileType === 1006) {
  492. const pdfUrl = this.fileDetail.originalUrl
  493. this.fileUrl = '/pdfjs/web/viewer.html?file=' + encodeURIComponent(pdfUrl)
  494. } else {
  495. }
  496. this.previewFileDialog = true
  497. }
  498. }).catch(error => {
  499. this.$notify({
  500. title: '请求错误',
  501. message: error.message,
  502. type: 'error',
  503. duration: 3000
  504. })
  505. })
  506. },
  507. handleDialogClose(done) {
  508. console.log('dialog close')
  509. done()
  510. },
  511. createNewFolder() {
  512. this.createFolderDialog = true
  513. },
  514. onCreateFolder() {
  515. this.createFolderForm.parent = this.currentDir
  516. addDiskFolder(this.createFolderForm).then(resp => {
  517. if (resp.code === 0) {
  518. this.$router.go(0)
  519. } else {
  520. this.$notify({
  521. message: resp.msg,
  522. type: 'warning',
  523. duration: 3000
  524. })
  525. }
  526. })
  527. },
  528. move(type) {
  529. if (this.multipleSelection.length === 0) {
  530. this.$notify({
  531. message: '至少应选中一行',
  532. type: 'warning',
  533. duration: 3000
  534. })
  535. return
  536. }
  537. this.moveForm.type = type
  538. for (const item of this.multipleSelection) {
  539. this.moveForm.fileIds.push(item.fileId)
  540. }
  541. getFolderTree().then(resp => {
  542. if (resp.code === 0) {
  543. this.treeNode = resp.data
  544. this.moveDialog = true
  545. } else {
  546. this.$notify({
  547. title: '提示',
  548. message: resp.msg,
  549. type: 'error',
  550. duration: 3000
  551. })
  552. }
  553. }).catch(error => {
  554. this.$notify({
  555. title: '提示',
  556. message: error.message,
  557. type: 'warning',
  558. duration: 3000
  559. })
  560. })
  561. },
  562. handleNodeClick(data) {
  563. this.moveForm.pid = data.fileId
  564. },
  565. onMove() {
  566. moveDiskFile(this.moveForm).then(resp => {
  567. if (resp.code === 0) {
  568. this.moveDialog = false
  569. this.$refs.multipleTable.clearSelection()
  570. }
  571. })
  572. }
  573. }
  574. }
  575. </script>
  576. <style>
  577. /*处于手机屏幕时*/
  578. @media screen and (max-width: 768px) {
  579. .tit {
  580. font-weight: 600;
  581. font-size: 12px;
  582. height: 32px;
  583. }
  584. .time {
  585. font-size: 10px;
  586. color: #999;
  587. }
  588. .num {
  589. font-size: 9px;
  590. padding-top: 3px;
  591. }
  592. .bottom {
  593. margin-top: 2px;
  594. line-height: 7px;
  595. }
  596. .coverImg {
  597. height: 120px !important;
  598. }
  599. }
  600. .coverImg {
  601. width: 100%;
  602. height: 175px;
  603. display: block;
  604. }
  605. .clearfix:before,
  606. .clearfix:after {
  607. display: table;
  608. content: "";
  609. }
  610. .clearfix:after {
  611. clear: both;
  612. }
  613. </style>