浏览代码

:recycle: 重构代码。重构文件上传代码及其文件管理字段调整

冷冷 6 年之前
父节点
当前提交
8d23163a81
共有 6 个文件被更改,包括 86 次插入86 次删除
  1. 1 1
      src/config/env.js
  2. 32 26
      src/const/crud/admin/sys-file.js
  3. 2 1
      src/const/iconList.js
  4. 26 7
      src/util/util.js
  5. 24 50
      src/views/admin/file/index.vue
  6. 1 1
      src/views/admin/user/info.vue

+ 1 - 1
src/config/env.js

@@ -3,7 +3,7 @@
 const env = process.env
 const baseUrl = ''
 // 图表库为avue和pig2套地址
-const iconfontVersion = ['567566_qo5lxgtishg', '667895_hzxmega6h6i']
+const iconfontVersion = ['567566_qo5lxgtishg', '667895_cg8sxwocfzr']
 const iconfontUrl = '//at.alicdn.com/t/font_$key.css'
 const codeUrl = `${window.location.origin}/code`
 const actUrl = `${window.location.origin}/act/modeler.html?modelId=`

+ 32 - 26
src/const/crud/admin/sys-file.js

@@ -22,47 +22,53 @@ export const tableOption = {
   stripe: true,
   menuAlign: 'center',
   align: 'center',
-  viewBtn:true,
+  viewBtn:false,
+  editBtn:false,
+  addBtn: false,
   column: [
-	  /*{
-      label: '编号',
-      prop: 'id'
-    },*/
 	  {
-      label: '文件名',
-      prop: 'name'
+      label: '编号',
+      prop: 'id',
+      hide: true
     },
-	  /*{
-      label: '保存路径',
-      prop: 'path'
+    {
+      label: '空间',
+      prop: 'bucketName',
+      overHidden:true
     },
 	  {
-      label: '绝对路径',
-      prop: 'absolutePath'
+      label: '文件名',
+      prop: 'name',
+      overHidden:true,
+      search: true
     },
 	  {
-      label: '上传服务器前缀地址',
-      prop: 'prefix'
-    },*/
-	  {
       label: '原文件名',
-      prop: 'original'
-    },
-	  {
-      label: '后缀名',
-      prop: 'suffix'
+      prop: 'original',
+      overHidden:true
     },
 	  {
       label: '文件类型',
       prop: 'type'
     },
-	  /*{
+	  {
       label: '文件大小',
       prop: 'fileSize'
-    },*/
-	  {
-      label: '显示大小',
-      prop: 'displaySize'
     },
+    {
+      label: '上传人',
+      prop: 'createUser'
+    },
+    {
+      width: 180,
+      label: '创建时间',
+      prop: 'createTime',
+      type: 'datetime',
+      format: 'yyyy-MM-dd HH:mm',
+      valueFormat: 'yyyy-MM-dd HH:mm:ss',
+      editDisabled: true,
+      addDisplay: false,
+      span: 24
+    }
   ]
 }

+ 2 - 1
src/const/iconList.js

@@ -36,7 +36,8 @@ export default [
       'icon-dingdan',
       'icon-tuikuan',
       'icon-webicon14',
-      'icon-shouyintai'
+      'icon-shouyintai',
+      'icon-wenjianguanli'
     ]
   }
 ]

+ 26 - 7
src/util/util.js

@@ -1,4 +1,4 @@
-import { validatenull } from './validate'
+import {validatenull} from './validate'
 import request from '@/router/axios'
 import * as CryptoJS from 'crypto-js'
 
@@ -150,16 +150,16 @@ export const listenfullscreen = (callback) => {
     callback()
   }
 
-  document.addEventListener('fullscreenchange', function() {
+  document.addEventListener('fullscreenchange', function () {
     listen()
   })
-  document.addEventListener('mozfullscreenchange', function() {
+  document.addEventListener('mozfullscreenchange', function () {
     listen()
   })
-  document.addEventListener('webkitfullscreenchange', function() {
+  document.addEventListener('webkitfullscreenchange', function () {
     listen()
   })
-  document.addEventListener('msfullscreenchange', function() {
+  document.addEventListener('msfullscreenchange', function () {
     listen()
   })
 }
@@ -314,15 +314,34 @@ export const openWindow = (url, title, w, h) => {
  */
 export function handleImg(fileName, id) {
   return validatenull(fileName) ? null : request({
-    url: '/admin/file/' + fileName,
+    url: '/admin/sys-file/' + fileName,
     method: 'get',
     responseType: 'blob'
   }).then((response) => { // 处理返回的文件流
     const blob = response.data
     const img = document.getElementById(id)
     img.src = URL.createObjectURL(blob)
-    window.setTimeout(function() {
+    window.setTimeout(function () {
       window.URL.revokeObjectURL(blob)
     }, 0)
   })
 }
+
+export function handleDown(filename, bucket) {
+  return request({
+    url: '/admin/sys-file/' + bucket + '-' + filename,
+    method: 'get',
+    responseType: 'blob'
+  }).then((response) => { // 处理返回的文件流
+    const blob = response.data
+    const link = document.createElement('a')
+    link.href = URL.createObjectURL(blob)
+    link.download = filename
+    document.body.appendChild(link)
+    link.click()
+    window.setTimeout(function () {
+      URL.revokeObjectURL(blob)
+      document.body.removeChild(link)
+    }, 0)
+  })
+}

+ 24 - 50
src/views/admin/file/index.vue

@@ -26,18 +26,29 @@
                  @on-load="getList"
                  @search-change="searchChange"
                  @refresh-change="refreshChange"
-                 @row-update="handleUpdate"
-                 @row-save="handleSave"
                  @row-del="rowDel">
+        <template
+          slot="menu"
+          slot-scope="scope">
+          <el-button
+            type="text"
+            size="mini"
+            icon="el-icon-download"
+            @click="download(scope.row,scope.index)">下载
+          </el-button>
+        </template>
+
       </avue-crud>
     </basic-container>
   </div>
 </template>
 
 <script>
-  import { addObj, delObj, fetchList, putObj } from '@/api/admin/sys-file'
-  import { tableOption } from '@/const/crud/admin/sys-file'
-  import { mapGetters } from 'vuex'
+  import {delObj, fetchList} from '@/api/admin/sys-file'
+  import {tableOption} from '@/const/crud/admin/sys-file'
+  import {mapGetters} from 'vuex'
+  import {handleDown} from '@/util/util'
+
 
   export default {
     name: 'sys-file',
@@ -55,14 +66,14 @@
     },
     created() {
     },
-    mounted: function() {
+    mounted: function () {
     },
     computed: {
       ...mapGetters(['permissions']),
       permissionList() {
         return {
           addBtn: this.vaildData(this.permissions.sys_file_add, false),
-          delBtn: this.vaildData(this.permissions.sys_file_del, false),
+          delBtn: this.vaildData(this.permissions.sys_file_del, true),
           editBtn: this.vaildData(this.permissions.sys_file_edit, false)
         }
       }
@@ -71,6 +82,7 @@
       getList(page, params) {
         this.tableLoading = true
         fetchList(Object.assign({
+          descs: 'create_time',
           current: page.currentPage,
           size: page.pageSize
         }, params)).then(response => {
@@ -81,13 +93,13 @@
           this.tableLoading = false
         })
       },
-      rowDel: function(row, index) {
+      rowDel: function (row, index) {
         var _this = this
         this.$confirm('是否确认删除ID为' + row.id, '提示', {
           confirmButtonText: '确定',
           cancelButtonText: '取消',
           type: 'warning'
-        }).then(function() {
+        }).then(function () {
           return delObj(row.id)
         }).then(data => {
           _this.tableData.splice(index, 1)
@@ -99,47 +111,6 @@
           this.getList(this.page)
         })
       },
-      /**
-       * @title 数据更新
-       * @param row 为当前的数据
-       * @param index 为当前更新数据的行数
-       * @param done 为表单关闭函数
-       *
-       **/
-      handleUpdate: function(row, index, done, loading) {
-        putObj(row).then(data => {
-          this.tableData.splice(index, 1, Object.assign({}, row))
-          this.$message({
-            showClose: true,
-            message: '修改成功',
-            type: 'success'
-          })
-          done()
-          this.getList(this.page)
-        }).catch(() => {
-          loading()
-        })
-      },
-      /**
-       * @title 数据添加
-       * @param row 为当前的数据
-       * @param done 为表单关闭函数
-       *
-       **/
-      handleSave: function(row, done, loading) {
-        addObj(row).then(data => {
-          this.tableData.push(Object.assign({}, row))
-          this.$message({
-            showClose: true,
-            message: '添加成功',
-            type: 'success'
-          })
-          done()
-          this.getList(this.page)
-        }).catch(() => {
-          loading()
-        })
-      },
       /**
        * 搜索回调
        */
@@ -151,6 +122,9 @@
        */
       refreshChange() {
         this.getList(this.page)
+      },
+      download: function (row, index) {
+        handleDown(row.name,row.bucketName)
       }
     }
   }

+ 1 - 1
src/views/admin/user/info.vue

@@ -51,7 +51,7 @@
                   :show-file-list="false"
                   :on-success="handleAvatarSuccess"
                   class="avatar-uploader"
-                  action="/admin/file/upload">
+                  action="/admin/sys-file/upload">
                   <img v-if="ruleForm2.avatar" id="avatar" :src="avatarUrl" class="avatar">
                   <i v-else class="el-icon-plus avatar-uploader-icon"/>
                 </el-upload>