当前位置:   article > 正文

vue 拖拽文件、文件夹上传 vue-simple-uploader插件_新建文件夹 拖拽 删除 新增插件

新建文件夹 拖拽 删除 新增插件
  1. <!-- 拖拽文件上传 -->
  2. <template lang="html">
  3. <div class="upload-container">
  4. <uploader :options="options" :fileStatusText="fileStatusText" @dragenter="dragEnter" @file-progress="onFileProgress" @file-added="onFileAdded" @files-added="onFilesAdded" @complete="onComplete">
  5. <!-- <uploader-unsupport></uploader-unsupport> -->
  6. <uploader-drop>
  7. <!-- <uploader-list></uploader-list> -->
  8. <!-- <div v-show="showMask" style="position: fixed;width:100%;background-color:rgba(220,220,220,.6);z-index:2042;" :style="{height: height + 72 +'px'}">
  9. <div style="position:absolute;left:40%;top:50%;text-align:center;margin:-46px 0 0 -48px;">
  10. <img :src="require('@/assets/images/common/openfile.png')" style="margin-bottom:10px;"/>
  11. <p style="font-size:16PX;color:#666666;">即将打开文件</p>
  12. </div>
  13. </div> -->
  14. <div class="upload-toolbox">
  15. <div style="display:inline;">
  16. <button v-if="!isSee" class="btn-upload ivu-btn" @mouseover="uploadMouseOver" @mouseleave="uploadMouseLeave" @click="uploadClick">
  17. 上传
  18. </button>
  19. <div class="panel-upload" v-show="panelShow" @mouseover="uploadMouseOver" @mouseleave="uploadMouseLeave">
  20. <uploader-btn ref="btnUpload">上传文件</uploader-btn>
  21. <uploader-btn :directory="true">上传文件夹</uploader-btn>
  22. </div>
  23. <!-- <button class="btn-newFolder ivu-btn">新建文件夹</button> -->
  24. <div class="toolbox-contain">
  25. <button class="btn-download ivu-btn" @click="multiDownload">下载</button>
  26. <button v-if="!isSee" class="btn-delete ivu-btn" @click="multiDelete">删除</button>
  27. <!-- <button class="btn-rename ivu-btn">重命名</button> -->
  28. <!-- <button class="btn-copy ivu-btn">复制到</button>
  29. <button class="btn-move ivu-btn">移动到</button> -->
  30. </div>
  31. </div>
  32. <div style="float:right;display:inline-flex;">
  33. <Input search clearable enter-button v-model="fileInput" placeholder="当前目录搜索文件/文件夹" @on-search="inputSearch" style="width:220px;vertical-align:bottom;margin-right:10px;" class="input-search"/>
  34. <span class="btn-change" @click="changeMode">
  35. <icon-svg :name="mode == 'list' ? 'list' : 'grid'" style="font-size:19px;cursor:pointer;"></icon-svg>
  36. </span>
  37. </div>
  38. <div style="clear:both;"></div>
  39. </div>
  40. <div class="upload-contain">
  41. <div class="contain-head">
  42. <div class="contain-head-link">
  43. <span v-if="linkIds.length == 1">全部文件</span>
  44. <div v-else >
  45. <div v-for="(item, index) in linkIds" :key="item.id" v-if="index !== linkIds.length - 1" style="display:inline-block;">
  46. <a @click="linkTo(item.id)" class="linkIds">{{item.name}}</a>
  47. <span style="margin:0 5px;">></span>
  48. </div>
  49. <span>{{linkIds[linkIds.length - 1].name}}</span>
  50. </div>
  51. </div>
  52. <div class="contain-head-num">已选中{{selectItems.length}}个文件/文件夹,共{{listData.length}}个</div>
  53. <div style="clear:both;"></div>
  54. </div>
  55. <div class="contain-body">
  56. <div v-if="mode == 'list'">
  57. <div class="panel-list" style="position:relative;" :style="{height: height +'px'}">
  58. <Table ref="tables" v-if="listData.length" :columns="columns" :data="listData" :height="height" :no-data-text="''" @on-selection-change="selectChange"></Table>
  59. <div v-else style="position:absolute;left:50%;top:50%;text-align:center;margin:-43px 0 0 -36px;">
  60. <img style="margin-bottom:10px;" :src="require('@/assets/images/common/nodata.png')">
  61. <p style="letter-spacing:1px;">亲,没有你想要的数据</p>
  62. </div>
  63. </div>
  64. </div>
  65. <div v-if="mode == 'grid'">
  66. <div v-if="listData.length">
  67. <div style="border-bottom:1px solid #dcdee2;">
  68. <Checkbox v-model="selectAll" class="grid-check" @on-change="gridSelectAll">全选</Checkbox>
  69. </div>
  70. <div class="panel-grid" style="overflow-y:auto;" :style="{height: height - 30 +'px'}">
  71. <div v-for="item in listData" :key="item.id" class="grid-content" :class="{ actived: item._checked}"
  72. @click="/\.pdf|\.png|\.jpg|\.jpeg|\.bmp/.test(item.filePath.toLowerCase()) ? filePreview(item.filePath.replace('c:/tomcat/static', '')) : reloadGridById(item.id, item.fileType, item.fileType === '1' ? item.fileName : item.docName, item.filePath)"
  73. @mouseover="mouseoverGrid($event)" @mouseout="mouseoutGrid($event)" >
  74. <img class="panel-img1" draggable="false" v-if="/\.png|\.jpg|\.jpeg|\.bmp/.test(item.filePath.toLowerCase())" :src="item.filePath.replace('c:/tomcat/static', fileShowUrl)">
  75. <img class="panel-img" draggable="false" v-else :src="item.fileType === '1' ? (/\.pdf/.test(item.filePath.toLowerCase()) ? require('@/assets/images/common/pdf.png') : (/\.doc|\.docx/.test(item.filePath.toLowerCase()) ? require('@/assets/images/common/doc.png') : (/\.xls|\.xlsx/.test(item.filePath.toLowerCase()) ? require('@/assets/images/common/xls.png') : (/\.zip|\.rar|\.7z/.test(item.filePath.toLowerCase()) ? require('@/assets/images/common/zip.png') : (/\.ppt/.test(item.filePath.toLowerCase()) ? require('@/assets/images/common/ppt.png') : (/\.txt/.test(item.filePath.toLowerCase()) ? require('@/assets/images/common/txt.png') : (/\.avi|\.mov|\.qt|\.asf|\.rm|\.navi|\.divx|\.mpeg|\.mpg|\.dat|\.mp4/.test(item.filePath.toLowerCase()) ? require('@/assets/images/common/video.png') : require('@/assets/images/common/file.png')))))))) : require('@/assets/images/common/folder.png')">
  76. <div class="panel-title" :title="item.fileType === '1' ? item.fileName : item.docName">{{item.fileType === '1' ? item.fileName : item.docName}}</div>
  77. <img class="select-img" @click.stop="panelSelect(item)" :src="require('@/assets/images/common/cloudSelect.png')">
  78. </div>
  79. <div style="clear:both;"></div>
  80. </div>
  81. </div>
  82. <div v-else style="position:relative;" :style="{height: height +'px'}">
  83. <div style="position:absolute;left:50%;top:50%;text-align:center;margin:-43px 0 0 -36px;">
  84. <img style="margin-bottom:10px;" :src="require('@/assets/images/common/nodata.png')">
  85. <p style="letter-spacing:1px;">亲,没有你想要的数据</p>
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. <Modal ref="mmodal" v-model="isshow" :transfer="false" :title="'上传列表'" :scrollable="true" :mask="false" :footer-hide="true" width="600" :class-name="'modalContain'">
  92. <!-- <div slot="title">
  93. </div> -->
  94. <div slot="close">
  95. <Icon :type="isMin ? 'md-square-outline' : 'md-remove'" @click.stop="minOrMax" style="font-size:15px;color:#FFF;"/>
  96. <Icon type="md-close" style="font-size:16px;color:#FFF;"/>
  97. </div>
  98. <uploader-list></uploader-list>
  99. </Modal>
  100. </uploader-drop>
  101. </uploader>
  102. <Modal v-model="deleteModel" title="确认删除操作" @on-ok="handleDelete">
  103. <p>确定删除选中的文件/文件夹</p>
  104. </Modal>
  105. <Dialog ref="dialog" :isPdf="true" :url="diaPath" :defaultHeight="diaHeight"></Dialog>
  106. </div>
  107. </template>
  108. <script>
  109. import { yunFileDownload, yunMultiFileDownload, yunFileDelete } from '@/api//api-base'
  110. import Dialog from '@/view/modules/common/dialog'
  111. export default {
  112. data() {
  113. return {
  114. listData: [], // 数据
  115. mode: 'list', // 展示模式
  116. fileInput: '', // 查询栏值
  117. selectAll: false, // 是否全选
  118. selectItems: [], // 已选择的条目
  119. panelShow: false, // 上传按钮区域是否显示
  120. linkIds: [{id: '1', name: '全部文件'}], // 导航id
  121. percent: 0, // 下载进度条
  122. isshow: false, // 上传进度页面是否显示
  123. isMin: false, // 上传进度页面是否最小化
  124. deleteModel: false, // 删除提示框隐藏
  125. fileShowUrl: window.SITE_CONFIG.fileShowURL,
  126. diaPath: null, // 预览文件路径
  127. diaHeight: 500, // 预览文件高度
  128. isTip: true, // 控制是否提示用户无权限
  129. fileStatusText: { // 上传列表状态提示
  130. success: '成功',
  131. error: '失败',
  132. uploading: '上传中',
  133. paused: '暂停',
  134. waiting: '排队中'
  135. },
  136. columns: [
  137. {
  138. type: 'selection',
  139. width: 60,
  140. align: 'center'
  141. },
  142. {
  143. title: '文件名',
  144. key: 'fileName',
  145. sortable: true,
  146. sortMethod: (a, b, type) => type === 'asc' ? (a === null ? -1 : (b === null ? 1 : (a > b ? 1 : -1))) : (a === null ? -1 : (b === null ? 1 : (a < b ? 1 : -1))),
  147. ellipsis: true,
  148. render: (h, params) => {
  149. let id = params.row.id
  150. let fileType = params.row.fileType
  151. let filePath = params.row.filePath
  152. if(fileType === '1') { // 普通文件
  153. let value = params.row.fileName
  154. if (typeof (value) === 'undefined' || value === null || value === '') {
  155. value = '--'
  156. }
  157. return h('a', {
  158. attrs: {
  159. class: 'link ' + (/\.avi|\.mov|\.qt|\.asf|\.rm|\.navi|\.divx|\.mpeg|\.mpg|\.dat|\.mp4/.test(filePath.toLowerCase()) ? 'video-link' : (/\.ppt/.test(filePath.toLowerCase()) ? 'ppt-link' : (/\.txt/.test(filePath.toLowerCase()) ? 'txt-link' : (/\.png|\.jpg|\.jpeg|\.bmp/.test(filePath.toLowerCase()) ? 'picture-link' : (/\.pdf/.test(filePath.toLowerCase()) ? 'pdf-link' : (/\.doc|\.docx/.test(filePath.toLowerCase()) ? 'doc-link' : (/\.xls|\.xlsx/.test(filePath.toLowerCase()) ? 'xls-link' : (/\.zip|\.rar|\.7z/.test(filePath.toLowerCase()) ? 'zip-link' : 'file-link'))))))))
  160. },
  161. domProps: {
  162. title: value,
  163. innerHTML: value
  164. },
  165. on: {
  166. click: () => {
  167. if(/\.pdf|\.png|\.jpg|\.jpeg|\.bmp/.test(filePath.toLowerCase())) {
  168. this.filePreview(filePath.replace('c:/tomcat/static', ''))
  169. }else {
  170. this.downloadFile(filePath, value, 'file')
  171. }
  172. }
  173. }
  174. })
  175. }else if(fileType === '2') { // 文件夹
  176. let value = params.row.docName
  177. if (typeof (value) === 'undefined' || value === null || value === '') {
  178. value = '--'
  179. }
  180. return h('a', {
  181. attrs: {
  182. class: 'link folder-link'
  183. },
  184. domProps: {
  185. title: value,
  186. innerHTML: value
  187. },
  188. on: {
  189. click: () => {
  190. this.reloadById(id, value)
  191. }
  192. }
  193. })
  194. }
  195. }
  196. },
  197. {
  198. title: '大小',
  199. sortable: true,
  200. key: 'fileSize',
  201. sortMethod: (a, b, type) => type === 'asc' ? (parseInt(a) > parseInt(b) ? 1 : -1) : (parseInt(a) < parseInt(b) ? 1 : -1),
  202. render: (h, params) => {
  203. let fileSize = params.row.fileSize
  204. let value = '--'
  205. if (typeof (fileSize) === 'undefined' || fileSize === null || fileSize === '') {
  206. }else {
  207. fileSize = parseInt(fileSize)
  208. if(fileSize < 1024) {
  209. value = fileSize + 'B'
  210. }else if(fileSize >= 1024 && fileSize < 1024 * 1024) {
  211. fileSize = parseFloat(fileSize / 1024).toFixed(1)
  212. value = fileSize + 'KB'
  213. }else if(fileSize >= 1024 * 1024 && fileSize < 1024 * 1024 * 1024) {
  214. fileSize = parseFloat(fileSize / (1024 * 1024)).toFixed(1)
  215. value = fileSize + 'MB'
  216. }else if(fileSize >= 1024 * 1024 * 1024 && fileSize < 1024 * 1024 * 1024 * 1024) {
  217. fileSize = parseFloat(fileSize / (1024 * 1024 * 1024)).toFixed(1)
  218. value = fileSize + 'GB'
  219. }
  220. }
  221. return h('span', value + '')
  222. }
  223. },
  224. {
  225. title: '修改日期',
  226. sortable: true,
  227. key: 'createTime'
  228. }
  229. ],
  230. options: {
  231. target: 'url',
  232. headers: {
  233. token: this.$cookie.get('token')
  234. },
  235. allowDuplicateUploads: true,
  236. query: {
  237. flag: this.flag
  238. },
  239. parseTimeRemaining: function(timeRemaining, parsedTimeRemaining) {
  240. return parsedTimeRemaining
  241. .replace(/\syears?/, '年')
  242. .replace(/\days?/, '天')
  243. .replace(/\shours?/, '小时')
  244. .replace(/\sminutes?/, '分钟')
  245. .replace(/\sseconds?/, '秒')
  246. },
  247. chunkSize: 1024 * 1024 * 1024 * 1024,
  248. testChunks: false
  249. }
  250. }
  251. },
  252. components: {
  253. Dialog
  254. },
  255. props: {
  256. height: {
  257. type: Number,
  258. default: 500
  259. },
  260. flag: {
  261. type: String,
  262. default: ''
  263. },
  264. isSee: { // 是否有操作权限
  265. type: Boolean,
  266. default: false
  267. },
  268. dataList: {
  269. type: Array,
  270. default: function() {
  271. return []
  272. }
  273. }
  274. },
  275. created() {
  276. },
  277. computed: {
  278. documentClientHeight: {
  279. get() {
  280. return this.$store.state.common.documentClientHeight
  281. },
  282. set(val) {
  283. this.$store.commit('common/updateDocumentClientHeight', val)
  284. }
  285. }
  286. },
  287. methods: {
  288. // 初始化预览框高度
  289. initDialogHeight() {
  290. this.diaHeight = this.documentClientHeight
  291. },
  292. // 改变页面布局
  293. changeMode() {
  294. if(this.mode === 'list') {
  295. this.mode = 'grid'
  296. }else if(this.mode === 'grid') {
  297. this.mode = 'list'
  298. }
  299. },
  300. // 列表某一项改变时触发
  301. selectChange(selection) {
  302. this.selectItems = selection
  303. },
  304. dragEnter(e) {
  305. if(this.isTip) {
  306. if(this.isSee) {
  307. this.$Message.error('您没有上传权限')
  308. }
  309. this.isTip = false
  310. setTimeout(() => {
  311. this.isTip = true
  312. }, 3000)
  313. }
  314. },
  315. // 文件上传验证
  316. onFileAdded(file) {
  317. if(file.ignored) {
  318. }else if(this.isSee) {
  319. file.ignored = true
  320. }else {
  321. this.isshow = true
  322. }
  323. },
  324. // 文件夹/多文件上传验证
  325. onFilesAdded(files, fileList) {
  326. if(this.isSee) {
  327. files.ignored = true
  328. }else {
  329. this.isshow = true
  330. }
  331. },
  332. onFileProgress() {
  333. // 上传时自动弹出
  334. this.isMin = false
  335. this.isshow = true
  336. },
  337. // 文件上传成功
  338. onComplete() {
  339. // this.$Message.success('上传完毕')
  340. this.fileInput = ''
  341. const _this = this
  342. _this.$emit('reloadList', {
  343. id: '1',
  344. fileName: this.fileInput
  345. })
  346. this.linkIds = [{id: '1', name: '全部文件'}]
  347. setTimeout(() => {
  348. _this.isMin = true
  349. }, 1000)
  350. },
  351. inputSearch(value) {
  352. this.$emit('reloadList', {
  353. id: this.linkIds[this.linkIds.length - 1].id,
  354. fileName: value
  355. })
  356. },
  357. // 下载按钮
  358. multiDownload() {
  359. if(this.selectItems.length === 0) {
  360. this.$Message.warning('请选择至少一个文件或文件夹')
  361. }else {
  362. let url = ''
  363. let fileName = ''
  364. if(this.selectItems.length === 1) {
  365. let item = this.selectItems[0]
  366. url = item.filePath
  367. fileName = item.fileType === '2' ? (item.docName + '.zip') : item.fileName
  368. this.downloadFile(url, fileName, item.fileType === '2' ? 'folder' : 'file')
  369. }else {
  370. this.selectItems.forEach((item, index) => {
  371. url += item.filePath + ','
  372. })
  373. this.downloadMultiFile(url, '批量下载.zip')
  374. }
  375. }
  376. },
  377. multiDelete() {
  378. if(this.selectItems.length === 0) {
  379. this.$Message.warning('请选择至少一个文件或文件夹')
  380. }else {
  381. this.deleteModel = true
  382. }
  383. },
  384. handleDelete() {
  385. if(this.selectItems.length === 0) {
  386. this.$Message.warning('请选择至少一个文件或文件夹')
  387. }else {
  388. let ids = ''
  389. this.selectItems.forEach(item => {
  390. ids += item.id + ','
  391. })
  392. let params = {
  393. ids: ids,
  394. flag: this.flag
  395. }
  396. yunFileDelete(params).then(res => {
  397. if (res.status) {
  398. // 删除成功状态
  399. this.selectItems = []
  400. this.$Message.success('成功删除信息')
  401. // 刷新数据
  402. this.$emit('reloadList', {
  403. id: this.linkIds[this.linkIds.length - 1].id,
  404. fileName: this.fileInput
  405. })
  406. }
  407. })
  408. }
  409. },
  410. filePreview(url) {
  411. this.diaPath = url // 附件路径
  412. this.$refs.dialog.open()
  413. },
  414. // 导航跳转
  415. linkTo(id) {
  416. this.fileInput = ''
  417. this.$emit('reloadList', { // 刷新数据
  418. id: id,
  419. fileName: this.fileInput
  420. })
  421. this.selectItems = [] // 清空已选择文件
  422. for(let i = 0; i < this.linkIds.length; i++) {
  423. if(this.linkIds[i].id === id) {
  424. this.linkIds.splice(i + 1, this.linkIds.length - 1 - i)
  425. break
  426. }
  427. }
  428. },
  429. // 文件层级跳转 及拼接导航
  430. reloadById(id, name) {
  431. this.linkIds.push({'id': id, 'name': name})
  432. this.selectItems = [] // 清空已选择文件
  433. this.fileInput = ''
  434. this.$emit('reloadList', { // 刷新数据
  435. id: id,
  436. fileName: this.fileInput
  437. })
  438. },
  439. reloadGridById(id, type, name, path) {
  440. if(type === '1') { // 文件下载
  441. this.downloadFile(path, name, 'file')
  442. }else if(type === '2') { // 文件夹下载
  443. this.reloadById(id, name)
  444. }
  445. },
  446. // 平铺面板的移入移出事件
  447. mouseoverGrid(e) {
  448. // e.target.$el.addClass('abc')
  449. e.currentTarget.className += ' isMove'
  450. },
  451. mouseoutGrid(e) {
  452. // e.target.$el.addClass('abc')
  453. e.currentTarget.className = e.currentTarget.className.replace(/ isMove/g, '')
  454. },
  455. // 平铺面板的选中/取消事件
  456. panelSelect(item) {
  457. item._checked = !item._checked
  458. if(item._checked) {
  459. this.selectItems.push(item)
  460. }else {
  461. for(let i = 0; i < this.selectItems.length; i++) {
  462. if(this.selectItems[i].id === item.id) {
  463. this.selectItems.splice(i, 1)
  464. break
  465. }
  466. }
  467. }
  468. },
  469. // 平铺面板全选按钮事件
  470. gridSelectAll(bool) {
  471. if(bool) {
  472. this.selectItems = JSON.parse(JSON.stringify(this.listData))
  473. }else {
  474. this.selectItems = []
  475. }
  476. },
  477. minOrMax() {
  478. this.isMin = !this.isMin
  479. },
  480. // 上传列表最大最小化公共方法
  481. minChange() {
  482. if(this.isMin) {
  483. this.$refs.mmodal.$el.children[0].children[0].style.top = this.height + 168 + 'px'
  484. // this.$refs.mmodal.$children[2].$el.style.height = '0px'
  485. // this.$refs.mmodal.$children[2].$el.parentElement.style.padding = '0px'
  486. }else {
  487. this.$refs.mmodal.$el.children[0].children[0].style.top = (this.height + 168) * 0.6 + 'px'
  488. // this.$refs.mmodal.$children[2].$el.style.height = (this.height + 190) * 0.4 - 76 + 'px'
  489. // this.$refs.mmodal.$children[2].$el.parentElement.style.padding = '0.21333rem'
  490. }
  491. this.$refs.mmodal.$children[2].$el.style.height = (this.height + 168) * 0.4 - 27 + 'px'
  492. },
  493. // 模拟上传文件按钮
  494. uploadClick() {
  495. this.$refs.btnUpload.$el.click()
  496. },
  497. uploadMouseOver() {
  498. this.panelShow = true
  499. },
  500. uploadMouseLeave() {
  501. this.panelShow = false
  502. },
  503. // 仅用于单个文件下载
  504. downloadFile(url, fileName, flag) {
  505. const _this = this
  506. _this.percent = 0
  507. _this.$Spin.show({
  508. render: (h) => {
  509. return h('div', [
  510. h('Progress', {
  511. style: {
  512. width: '300px'
  513. },
  514. props: {
  515. percent: _this.percent
  516. }
  517. }, fileName.slice(0, 10) + '...' + fileName.slice(-10) + '下载中...' + _this.percent + '%')
  518. ])
  519. }
  520. })
  521. if (/\.pdf|\.PDF/.test(url)) {
  522. const interval = setInterval(() => {
  523. if (_this.percent === 10) {
  524. _this.downloadMethod(url, fileName, flag)
  525. }
  526. if (_this.percent >= 80) {
  527. clearInterval(interval)
  528. return
  529. }
  530. _this.percent += 10
  531. }, 500)
  532. } else {
  533. const interval = setInterval(() => {
  534. if (_this.percent === 50) {
  535. _this.downloadMethod(url, fileName, flag)
  536. }
  537. if (_this.percent >= 50) {
  538. clearInterval(interval)
  539. return
  540. }
  541. _this.percent += 10
  542. }, 100)
  543. }
  544. },
  545. downloadMethod(url, fileName, flag) {
  546. const _this = this
  547. url = url.replace(/\\/g, '/')
  548. // 下载pdf
  549. let params = {
  550. path: url,
  551. flag: flag
  552. }
  553. yunFileDownload(params).then(res => {
  554. _this.closeProgress()
  555. let blob = new Blob([res.data])
  556. let objectUrl = URL.createObjectURL(blob)
  557. let link = document.createElement('a')
  558. link.href = objectUrl
  559. link.setAttribute('download', fileName) // 下载文件的名字
  560. document.body.appendChild(link)
  561. link.style.display = 'none'
  562. link.click()
  563. document.body.removeChild(link)
  564. })
  565. },
  566. closeProgress() {
  567. const _this = this
  568. const interval = setInterval(() => {
  569. if (_this.percent >= 100) {
  570. clearInterval(interval)
  571. _this.$Message.success('文件下载成功')
  572. _this.$Spin.hide()
  573. return
  574. }
  575. _this.percent += 10
  576. }, 100)
  577. },
  578. // 仅用于多个文件下载
  579. downloadMultiFile(url, fileName) {
  580. const _this = this
  581. _this.percent = 0
  582. _this.$Spin.show({
  583. render: (h) => {
  584. return h('div', [
  585. h('Progress', {
  586. style: {
  587. width: '300px'
  588. },
  589. props: {
  590. percent: _this.percent
  591. }
  592. }, fileName.slice(0, 10) + '...' + fileName.slice(-10) + '下载中...' + _this.percent + '%')
  593. ])
  594. }
  595. })
  596. const interval = setInterval(() => {
  597. if (_this.percent === 10) {
  598. _this.downloadMultiMethod(url, fileName)
  599. }
  600. if (_this.percent >= 80) {
  601. clearInterval(interval)
  602. return
  603. }
  604. _this.percent += 10
  605. }, 500)
  606. },
  607. downloadMultiMethod(url, fileName) {
  608. const _this = this
  609. url = url.replace(/\\/g, '/')
  610. // 下载pdf
  611. let params = {
  612. paths: url
  613. }
  614. yunMultiFileDownload(params).then(res => {
  615. _this.closeProgress()
  616. let blob = new Blob([res.data])
  617. let objectUrl = URL.createObjectURL(blob)
  618. let link = document.createElement('a')
  619. link.href = objectUrl
  620. link.setAttribute('download', fileName) // 下载文件的名字
  621. document.body.appendChild(link)
  622. link.style.display = 'none'
  623. link.click()
  624. document.body.removeChild(link)
  625. })
  626. }
  627. // 23232
  628. // initDragEvent() {
  629. // window.ondragleave = (e) => {
  630. // e.preventDefault()
  631. // }
  632. // window.ondrop = (e) => {
  633. // this.uploadFunc(e)
  634. // }
  635. // window.ondragenter = (e) => {
  636. // e.preventDefault() // 阻止拖入时的浏览器默认行为
  637. // }
  638. // window.ondragover = (e) => {
  639. // e.preventDefault() // 阻止拖来拖去的浏览器默认行为
  640. // }
  641. // },
  642. // uploadFunc(event) {
  643. // event.preventDefault()
  644. // let files = []
  645. // if (event.type === 'drop') {
  646. // let fileList = event.dataTransfer.files
  647. // let len = fileList.length
  648. // for (let i = 0; i < len; i++) {
  649. // files[i] = fileList[i]
  650. // }
  651. // if (files.length) {
  652. // let items = event.dataTransfer.items
  653. // if (items && items.length && items[0].webkitGetAsEntry != null) {
  654. // console.log(1)
  655. // this.addFilesItems(items)
  656. // }
  657. // }
  658. // }
  659. // },
  660. // addFilesItems(items) {
  661. // var ret = []
  662. // for (var i = 0; i < items.length; i++) {
  663. // var item = items[i]
  664. // var entry
  665. // if (item.webkitGetAsEntry && (entry = item.webkitGetAsEntry())) {
  666. // console.log(entry)
  667. // if (entry.isFile) {
  668. // // 把文件对象放到结果数组中 这里的addFile方法要单独写 我没有写上 这个不是重点
  669. // ret.push(this.addFile(item.getAsFiles()))
  670. // } else if (entry.isDirectory) {
  671. // ret.push(this.addFilesFormDirectory(entry, entry.name))
  672. // }
  673. // }
  674. // }
  675. // console.log(ret)
  676. // },
  677. // addFile(xx) {},
  678. // // 读取文件夹下的文件
  679. // addFilesFormDirectory(directory, path) {
  680. // const dirReader = directory.createReader()
  681. // const readEntries = () => {
  682. // return dirReader.readEntries((entries) => {
  683. // entries.forEach((entry) => {
  684. // console.log(entry)
  685. // if (entry.isFile) {
  686. // // 如果是文件
  687. // entry.file((file) => {
  688. // file.fullPath = path + '/' + file.name
  689. // console.log(path + '/' + file.name)
  690. // // 那么暴露出去的就是'文件夹/q.jpg'这种形式
  691. // return this.addFile(file)
  692. // })
  693. // // return this.addFile(file)
  694. // } else if (entry.isDirectory) {
  695. // // 递归处理
  696. // this.addFilesFormDirectory(entry, path + '/' + entry.name)
  697. // }
  698. // })
  699. // })
  700. // }
  701. // return readEntries()
  702. // },
  703. },
  704. watch: {
  705. 'dataList': function() {
  706. this.listData = this.dataList
  707. },
  708. 'selectItems': function(array) {
  709. if(this.listData.length > 0) {
  710. this.listData.forEach(item => {
  711. item._checked = false
  712. for(let i = 0; i < array.length; i++) {
  713. if(item.id === array[i].id) {
  714. item._checked = true
  715. }
  716. }
  717. })
  718. if(this.listData.length === array.length) {
  719. this.selectAll = true
  720. }else {
  721. this.selectAll = false
  722. }
  723. }
  724. },
  725. 'height': function(h) {
  726. this.minChange()
  727. },
  728. 'isMin': function() {
  729. this.minChange()
  730. },
  731. 'documentClientHeight': function() {
  732. this.initDialogHeight()
  733. }
  734. },
  735. mounted() {
  736. this.listData = this.dataList
  737. this.minChange()
  738. this.initDialogHeight()
  739. // this.initDragEvent()
  740. }
  741. }
  742. </script>
  743. <style lang="less" scoped>
  744. .upload-container {
  745. .uploader-drop {
  746. padding: 0;
  747. border: none;
  748. background-color: inherit;
  749. }
  750. .upload-toolbox {
  751. padding: 10px 20px 10px 10px;
  752. position: relative;
  753. .btn-upload {
  754. color: #FFF;
  755. background-color: #00A0E9;
  756. width: 78PX;
  757. }
  758. .panel-upload {
  759. position: absolute;
  760. top: 53px;
  761. left: 10px;
  762. z-index: 1000;
  763. background-color: #FFF;
  764. border: 1px solid #00A0E9;
  765. width: 78PX;
  766. text-align: center;
  767. .uploader-btn {
  768. display: block;
  769. color: #00A0E9;
  770. border: none;
  771. padding: 6px 8px;
  772. &:hover {
  773. background-color: #e0e8f3;
  774. }
  775. }
  776. }
  777. .btn-newFolder {
  778. color: #00A0E9;
  779. }
  780. .toolbox-contain {
  781. display: inline-block;
  782. button {
  783. color: #00A0E9;
  784. }
  785. }
  786. .btn-change {
  787. // float: right;
  788. padding-top: 2px;
  789. }
  790. .input-search {
  791. /deep/.ivu-input-icon {
  792. right: 40PX;
  793. }
  794. /deep/.ivu-input {
  795. padding-right: 23PX;
  796. }
  797. }
  798. }
  799. .upload-contain {
  800. .contain-head {
  801. padding: 3px 20px 5px 10px;
  802. .contain-head-link {
  803. float: left;
  804. }
  805. .contain-head-num {
  806. float: right;
  807. }
  808. }
  809. .contain-body {
  810. .panel-list {
  811. /deep/.ivu-table-wrapper {
  812. border: 0px solid #dcdee2;
  813. .ivu-table th {
  814. background-color: #FFF;
  815. }
  816. .ivu-table td {
  817. height: 55px;
  818. position: relative;
  819. }
  820. .ivu-table:after {
  821. width: 0;
  822. }
  823. }
  824. }
  825. .grid-check {
  826. margin: 7px 0 7px 25PX;
  827. /deep/.ivu-checkbox {
  828. margin-right: 5px;
  829. }
  830. }
  831. .panel-grid {
  832. .grid-content {
  833. height: 129PX;
  834. width: 123PX;
  835. float: left;
  836. display: block;
  837. margin: 1px;
  838. padding-top: 20px;
  839. cursor: pointer;
  840. border-radius: 8px;
  841. position: relative;
  842. z-index: 200;
  843. border: 1px solid #FFF;
  844. .panel-img {
  845. display: block;
  846. width: 70px;
  847. height: 70px;
  848. margin: 15PX auto 16PX;
  849. }
  850. .panel-img1 {
  851. display: block;
  852. width: 90px;
  853. height: 100px;
  854. margin: 0px auto 10px;
  855. }
  856. .panel-title {
  857. display: block;
  858. // width: 100%;
  859. margin: 0 10px;
  860. text-align: center;
  861. font-size: 12px;
  862. white-space: nowrap;
  863. overflow: hidden;
  864. text-overflow: ellipsis;
  865. }
  866. &:hover {
  867. background-color: #f6f6f6;
  868. .panel-title {
  869. color: #00A0E9;
  870. }
  871. }
  872. .select-img {
  873. position: absolute;
  874. left: 8PX;
  875. top: 8PX;
  876. width: 22PX;
  877. height: 22PX;
  878. z-index: 300;
  879. display: none;
  880. }
  881. }
  882. .isMove {
  883. .select-img {
  884. opacity: .4;
  885. display: block;
  886. &:hover {
  887. opacity: .5;
  888. }
  889. }
  890. }
  891. .actived {
  892. border: 1px solid #00A0E9;
  893. background-color: #f6f6f6;
  894. .select-img {
  895. opacity: 1;
  896. display: block;
  897. &:hover {
  898. opacity: 1;
  899. }
  900. }
  901. }
  902. }
  903. }
  904. }
  905. }
  906. /deep/.ivu-table-sort {
  907. width: 15PX;
  908. height: 12PX;
  909. i {
  910. font-size: 14PX;
  911. }
  912. }
  913. /deep/.ivu-checkbox-inner {
  914. width: 11px;
  915. }
  916. /deep/.link {
  917. color: #666666;
  918. cursor: pointer;
  919. padding-left: 30PX;
  920. &:hover {
  921. color: #00A0E9 !important;
  922. }
  923. }
  924. /deep/.file-link {
  925. &::before {
  926. content: '';
  927. background-image: url('~assets/images/common/file.png');
  928. background-size: 24PX 24PX;
  929. width: 24PX;
  930. height: 24PX;
  931. position: absolute;
  932. margin-left: -32PX;
  933. margin-top: -6PX;
  934. }
  935. }
  936. /deep/.picture-link {
  937. &::before {
  938. content: '';
  939. background-image: url('~assets/images/common/picture.png');
  940. background-size: 24PX 24PX;
  941. width: 24PX;
  942. height: 24PX;
  943. position: absolute;
  944. margin-left: -32PX;
  945. margin-top: -6PX;
  946. }
  947. }
  948. /deep/.doc-link {
  949. &::before {
  950. content: '';
  951. background-image: url('~assets/images/common/doc.png');
  952. background-size: 24PX 24PX;
  953. width: 24PX;
  954. height: 24PX;
  955. position: absolute;
  956. margin-left: -32PX;
  957. margin-top: -6PX;
  958. }
  959. }
  960. /deep/.xls-link {
  961. &::before {
  962. content: '';
  963. background-image: url('~assets/images/common/xls.png');
  964. background-size: 24PX 24PX;
  965. width: 24PX;
  966. height: 24PX;
  967. position: absolute;
  968. margin-left: -32PX;
  969. margin-top: -6PX;
  970. }
  971. }
  972. /deep/.pdf-link {
  973. &::before {
  974. content: '';
  975. background-image: url('~assets/images/common/pdf.png');
  976. background-size: 24PX 24PX;
  977. width: 24PX;
  978. height: 24PX;
  979. position: absolute;
  980. margin-left: -32PX;
  981. margin-top: -6PX;
  982. }
  983. }
  984. /deep/.zip-link {
  985. &::before {
  986. content: '';
  987. background-image: url('~assets/images/common/zip.png');
  988. background-size: 24PX 24PX;
  989. width: 24PX;
  990. height: 24PX;
  991. position: absolute;
  992. margin-left: -32PX;
  993. margin-top: -6PX;
  994. }
  995. }
  996. /deep/.ppt-link {
  997. &::before {
  998. content: '';
  999. background-image: url('~assets/images/common/ppt.png');
  1000. background-size: 24PX 24PX;
  1001. width: 24PX;
  1002. height: 24PX;
  1003. position: absolute;
  1004. margin-left: -32PX;
  1005. margin-top: -6PX;
  1006. }
  1007. }
  1008. /deep/.txt-link {
  1009. &::before {
  1010. content: '';
  1011. background-image: url('~assets/images/common/txt.png');
  1012. background-size: 24PX 24PX;
  1013. width: 24PX;
  1014. height: 24PX;
  1015. position: absolute;
  1016. margin-left: -32PX;
  1017. margin-top: -6PX;
  1018. }
  1019. }
  1020. /deep/.video-link {
  1021. &::before {
  1022. content: '';
  1023. background-image: url('~assets/images/common/video.png');
  1024. background-size: 24PX 24PX;
  1025. width: 24PX;
  1026. height: 24PX;
  1027. position: absolute;
  1028. margin-left: -32PX;
  1029. margin-top: -6PX;
  1030. }
  1031. }
  1032. /deep/.folder-link {
  1033. &::before {
  1034. content: '';
  1035. background-image: url('~assets/images/common/folder.png');
  1036. background-size: 26PX 26PX;
  1037. width: 26PX;
  1038. height: 26PX;
  1039. position: absolute;
  1040. margin-left: -34PX;
  1041. margin-top: -6PX;
  1042. }
  1043. }
  1044. .linkIds {
  1045. color: #00A0E9 !important;
  1046. cursor: pointer;
  1047. }
  1048. /deep/.ivu-progress-outer{
  1049. margin-bottom: 5px;
  1050. }
  1051. /deep/.modalContain{
  1052. overflow: hidden;
  1053. .ivu-modal {
  1054. transition: all 1s ease;
  1055. -webkit-transition: all 1s ease;
  1056. margin: 0 40px 0 0;
  1057. float: right;
  1058. .ivu-modal-content{
  1059. box-shadow: 0 0px 10px rgba(0,0,0,.15);
  1060. border-radius: 6px 6px 0 0;
  1061. .ivu-modal-header {
  1062. background-color: #00A0E9;
  1063. border-radius: 6px 6px 0 0;
  1064. .ivu-modal-header-inner {
  1065. color: #FFF;
  1066. }
  1067. }
  1068. .ivu-modal-body {
  1069. .uploader-list {
  1070. overflow-y: auto;
  1071. }
  1072. }
  1073. }
  1074. }
  1075. }
  1076. </style>

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/66602
推荐阅读
相关标签