Browse Source

增加了文件删除功能和前端日期格式化功能

main
pixel 5 years ago
parent
commit
137143d91e
  1. 2
      QMPlusServer/controller/api/fileUploadAndDownload.go
  2. 5
      QMPlusServer/docs/docs.go
  3. 3
      QMPlusServer/docs/swagger.json
  4. 2
      QMPlusServer/docs/swagger.yaml
  5. 15
      QMPlusVuePage/src/api/fileUploadAndDownload.js
  6. 49
      QMPlusVuePage/src/view/example/upload/upload.vue

2
QMPlusServer/controller/api/fileUploadAndDownload.go

@ -62,7 +62,7 @@ func DeleteFile(c *gin.Context) {
if err != nil { if err != nil {
servers.ReportFormat(c, false, fmt.Sprintf("删除失败,%v", err), gin.H{}) servers.ReportFormat(c, false, fmt.Sprintf("删除失败,%v", err), gin.H{})
} else { } else {
err = file.DeleteFile()
err = f.DeleteFile()
if err != nil { if err != nil {
servers.ReportFormat(c, false, fmt.Sprintf("删除失败,%v", err), gin.H{}) servers.ReportFormat(c, false, fmt.Sprintf("删除失败,%v", err), gin.H{})
} else { } else {

5
QMPlusServer/docs/docs.go

@ -1,6 +1,6 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at // This file was generated by swaggo/swag at
// 2019-11-20 16:37:42.2606856 +0800 CST m=+0.064825001
// 2019-11-20 16:59:15.3568689 +0800 CST m=+0.056920101
package docs package docs
@ -1290,6 +1290,9 @@ var doc = `{
"dbModel.FileUploadAndDownload": { "dbModel.FileUploadAndDownload": {
"type": "object", "type": "object",
"properties": { "properties": {
"key": {
"type": "string"
},
"name": { "name": {
"type": "string" "type": "string"
}, },

3
QMPlusServer/docs/swagger.json

@ -1273,6 +1273,9 @@
"dbModel.FileUploadAndDownload": { "dbModel.FileUploadAndDownload": {
"type": "object", "type": "object",
"properties": { "properties": {
"key": {
"type": "string"
},
"name": { "name": {
"type": "string" "type": "string"
}, },

2
QMPlusServer/docs/swagger.yaml

@ -114,6 +114,8 @@ definitions:
type: object type: object
dbModel.FileUploadAndDownload: dbModel.FileUploadAndDownload:
properties: properties:
key:
type: string
name: name:
type: string type: string
tag: tag:

15
QMPlusVuePage/src/api/fileUploadAndDownload.js

@ -14,3 +14,18 @@ export const getFileList = (data) => {
data data
}) })
} }
// @Tags FileUploadAndDownload
// @Summary 删除文件
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body dbModel.FileUploadAndDownload true "传入文件里面id即可"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"返回成功"}"
// @Router /fileUploadAndDownload/deleteFile [post]
export const deleteFile = (data) => {
return service({
url: "/fileUploadAndDownload/deleteFile",
method: "post",
data
})
}

49
QMPlusVuePage/src/view/example/upload/upload.vue

@ -1,11 +1,11 @@
<template> <template>
<div> <div>
<el-upload <el-upload
:headers="{'x-token':token}"
:show-file-list="false"
:before-upload="checkFile" :before-upload="checkFile"
:headers="{'x-token':token}"
:on-error="uploadError" :on-error="uploadError"
:on-success="uploadSuccess" :on-success="uploadSuccess"
:show-file-list="false"
action="/api/fileUploadAndDownload/upload" action="/api/fileUploadAndDownload/upload"
> >
<el-button size="small" type="primary">点击上传</el-button> <el-button size="small" type="primary">点击上传</el-button>
@ -17,7 +17,13 @@
<img :alt="scope.row.alt" :src="scope.row.url" height="80" width="80" /> <img :alt="scope.row.alt" :src="scope.row.url" height="80" width="80" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="日期" prop="UpdatedAt" width="180"></el-table-column>
<el-table-column label="日期" prop="UpdatedAt" width="180">
<template slot-scope="scope">
<div>
{{scope.row.UpdatedAt|formatDate}}
</div>
</template>
</el-table-column>
<el-table-column label="文件名" prop="name" width="180"></el-table-column> <el-table-column label="文件名" prop="name" width="180"></el-table-column>
<el-table-column label="链接" prop="url"></el-table-column> <el-table-column label="链接" prop="url"></el-table-column>
<el-table-column label="标签" prop="tag" width="100"> <el-table-column label="标签" prop="tag" width="100">
@ -31,6 +37,7 @@
<el-table-column label="操作" width="100"> <el-table-column label="操作" width="100">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button @click="downloadFile(scope.row)" size="small" type="text">下载</el-button> <el-button @click="downloadFile(scope.row)" size="small" type="text">下载</el-button>
<el-button @click="deleteFile(scope.row)" size="small" type="text">删除</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -50,8 +57,9 @@
<script> <script>
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import infoList from '@/components/mixins/infoList' import infoList from '@/components/mixins/infoList'
import { getFileList } from '@/api/fileUploadAndDownload'
import { getFileList, deleteFile } from '@/api/fileUploadAndDownload'
import { downloadImage } from '@/utils/downloadImg' import { downloadImage } from '@/utils/downloadImg'
import { formatTimeToStr } from '@/utils/data'
export default { export default {
name: 'Upload', name: 'Upload',
mixins: [infoList], mixins: [infoList],
@ -78,7 +86,40 @@ export default {
computed: { computed: {
...mapGetters('user', ['userInfo', 'token']) ...mapGetters('user', ['userInfo', 'token'])
}, },
filters: {
formatDate: function(time) {
if (time != null && time != '') {
var date = new Date(time)
return formatTimeToStr(date, 'yyyy-MM-dd hh:mm:ss')
} else {
return ''
}
}
},
methods: { methods: {
async deleteFile(row) {
this.$confirm('此操作将永久删除所有角色下该菜单, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(async () => {
const res = await deleteFile(row)
if (res.success) {
this.$message({
type: 'success',
message: '删除成功!'
})
this.getTableData()
}
})
.catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
})
})
},
checkFile(file) { checkFile(file) {
const isJPG = file.type === 'image/jpeg' const isJPG = file.type === 'image/jpeg'
const isPng = file.type === 'image/png' const isPng = file.type === 'image/png'

Loading…
Cancel
Save