feat: 文章管理增加附件上传/删除/下载功能
This commit is contained in:
@@ -170,8 +170,12 @@ const init = reactive({
|
|||||||
})
|
})
|
||||||
loading.close()
|
loading.close()
|
||||||
console.log("🚀 ~ file:res.data ", res.data)
|
console.log("🚀 ~ file:res.data ", res.data)
|
||||||
fileLists.value.push(res.data)
|
res.data.originalFileName=res.data.originalFilename
|
||||||
if(meta.filetype !== "image"){
|
console.log("🚀 ~ file:'meta.filetype ",meta.filetype )
|
||||||
|
|
||||||
|
if (res && res.data && res.data.fileType &&
|
||||||
|
!["png", "jpg", "jpeg","gif", "svg","ico"].includes(res.data.fileType.toLowerCase())){
|
||||||
|
fileLists.value.push(res.data)
|
||||||
emit('getFiles',fileLists.value)
|
emit('getFiles',fileLists.value)
|
||||||
}
|
}
|
||||||
const fileUrl = res.data.url;
|
const fileUrl = res.data.url;
|
||||||
|
|||||||
@@ -1,49 +1,65 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-loading="loading" class="add-block">
|
<div v-loading="loading" class="add-block">
|
||||||
<baseTitle title="文章信息录入"></baseTitle>
|
<baseTitle title="文章信息录入"></baseTitle>
|
||||||
<el-form :model="formData" ref="fundForm" :rules="rules" style="margin-left: 5px;margin-bottom: -18px">
|
<el-form :model="formData" ref="fundForm" :rules="rules" style="margin-left: 5px;margin-bottom: -18px">
|
||||||
<el-row gutter="30">
|
<el-row gutter="30">
|
||||||
<el-col :span="6" style="margin-left: 10px">
|
<el-col :span="6" style="margin-left: 10px">
|
||||||
<el-form-item label="文章标题" prop="articleTitle">
|
<el-form-item label="文章标题" prop="articleTitle">
|
||||||
<el-input v-model="formData.articleTitle" placeholder="请输入文章标题" clearable></el-input>
|
<el-input v-model="formData.articleTitle" placeholder="请输入文章标题" clearable></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="6">
|
<el-col :span="6">
|
||||||
<el-form-item label="文章类型" prop="articleType">
|
<el-form-item label="文章类型" prop="articleType">
|
||||||
<el-select v-model="formData.articleType" placeholder="请选择文章类型" clearable filterable>
|
<el-select v-model="formData.articleType" placeholder="请选择文章类型" clearable filterable>
|
||||||
<el-option
|
<el-option
|
||||||
v-for="item in cacheStore.getDict('article_type')"
|
v-for="item in cacheStore.getDict('article_type')"
|
||||||
:key="item.value"
|
:key="item.value"
|
||||||
:label="item.label"
|
:label="item.label"
|
||||||
:value="item.value"
|
:value="item.value"
|
||||||
/>
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="6" >
|
<el-col :span="6">
|
||||||
<el-form-item label="备注" prop="remarks">
|
<el-form-item label="备注" prop="remarks">
|
||||||
<el-input v-model="formData.remarks" placeholder="请输入备注" clearable></el-input>
|
<el-input v-model="formData.remarks" placeholder="请输入备注" clearable></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="24" style="margin-left: 10px">
|
<el-col :span="24" style="margin-left: 10px">
|
||||||
<el-form-item label="文章内容" prop="articleContent">
|
<el-form-item label="文章内容" prop="articleContent">
|
||||||
<Tinymce v-model:value="formData.articleContent" @getFiles="getFiles" imageUrl="/workflow/process/file/upload" :height="500" v-if="showTinymce" :toolbar="['undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image axupimgs']" />
|
<!-- link-->
|
||||||
|
<Tinymce v-model:value="formData.articleContent"
|
||||||
|
imageUrl="/workflow/process/file/upload" :height="500" v-if="showTinymce"
|
||||||
|
:toolbar="['undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | image axupimgs']"/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
|
<el-col :span="24" style="margin-bottom: -10px">
|
||||||
|
<el-form-item label="附件上传" prop="" style="margin-left: 20px;">
|
||||||
|
<file-upload @getFile="getFiles"/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="24" style="margin-left:90px;">
|
||||||
|
|
||||||
<el-col :span="24" style="margin-left:90px;">
|
<el-form-item label="公告附件列表" prop=""
|
||||||
<el-form-item label="公告附件列表" prop="" style="display: flex;flex-direction: column;justify-content: flex-start;">
|
style="display: flex;flex-direction: column;justify-content: flex-start;">
|
||||||
<template #label>
|
<template #label>
|
||||||
<div style="width: 100%;display: flex;align-items: center;justify-content: flex-start">
|
<div style="width: 100%;display: flex;align-items: center;justify-content: flex-start">
|
||||||
<el-icon size="16"><Paperclip /></el-icon>公告附件列表
|
<el-icon size="16">
|
||||||
</div>
|
<Paperclip/>
|
||||||
|
</el-icon>
|
||||||
|
公告附件列表
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<el-col :span="24" style="margin-left: -15px">
|
<el-col :span="24" style="margin-left: -15px">
|
||||||
<div style="display: flex;flex-direction: column">
|
<div style="display: flex;flex-direction: column">
|
||||||
<div v-for="(item,index) in articleFile" style="display: flex;align-items: center">
|
<div v-for="(item,index) in formData.fileList" style="display: flex;align-items: center">
|
||||||
{{index+1}}{{item.originalFilename}}<el-icon size="18" style="margin-left: 30px" color="#84cdfd"><CircleClose /></el-icon>
|
附件{{ index + 1 }}: <a :href="item.url" style="color: #409eff;" class="a-style" target="_blank">{{ item.originalFileName }}</a>
|
||||||
|
<el-icon size="18" style="margin:0 20px;cursor: pointer" color="#409eff" @click="handleDelete(item,index)">
|
||||||
|
<CircleClose/>
|
||||||
|
</el-icon>
|
||||||
|
<el-button type="primary" link @click="handleDownload(item)" style="font-size: 16px;margin-left: 10px">下载</el-button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
@@ -58,10 +74,14 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="jsx">
|
<script setup lang="jsx">
|
||||||
import {ElNotification} from "element-plus";
|
import {ElMessageBox, ElNotification} from "element-plus";
|
||||||
import {addArticle, editArticle, getArticleDetail} from "@/api/article";
|
import {addArticle, editArticle, getArticleDetail} from "@/api/article";
|
||||||
import {useTagsView} from '@/stores/tagsview.js'
|
import {useTagsView} from '@/stores/tagsview.js'
|
||||||
import { useCacheStore } from "@/stores/cache.js";
|
import {useCacheStore} from "@/stores/cache.js";
|
||||||
|
import {deleteFile, downloadFile} from "../../api/project-demand";
|
||||||
|
import FileUpload from "../../components/FileUpload.vue";
|
||||||
|
import Tinymce from "../../components/Tinymce.vue";
|
||||||
|
|
||||||
const cacheStore = useCacheStore();
|
const cacheStore = useCacheStore();
|
||||||
const tagsViewStore = useTagsView()
|
const tagsViewStore = useTagsView()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -69,37 +89,70 @@ const route = useRoute()
|
|||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const showTinymce = ref(true)
|
const showTinymce = ref(true)
|
||||||
const fundForm = ref()
|
const fundForm = ref()
|
||||||
const formData = ref({})
|
const formData = ref({
|
||||||
const articleFile = ref({})
|
fileList:[]
|
||||||
|
})
|
||||||
const routerName = ref(router.currentRoute.value.name)
|
const routerName = ref(router.currentRoute.value.name)
|
||||||
const rules = reactive({
|
const rules = reactive({
|
||||||
articleTitle: [{required: true, message: '请输入文章标题', trigger: ['blur', 'change']}],
|
articleTitle: [{required: true, message: '请输入文章标题', trigger: ['blur', 'change']}],
|
||||||
articleType: [{required: true, message: '请输入文章类型', trigger: ['blur', 'change']}],
|
articleType: [{required: true, message: '请输入文章类型', trigger: ['blur', 'change']}],
|
||||||
articleContent: [{required: true, message: '请输入文章内容', trigger: ['blur', 'change']}],
|
articleContent: [{required: true, message: '请输入文章内容', trigger: ['blur', 'change']}],
|
||||||
})
|
})
|
||||||
|
const handleDelete = (row,index) => {
|
||||||
|
ElMessageBox.confirm(`确认删除名称为${row.originalFileName}的文件吗?`, '系统提示', {
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning'
|
||||||
|
}).then(() => {
|
||||||
|
deleteFile(row.fileId).then(res => {
|
||||||
|
ElNotification({
|
||||||
|
title: '提示',
|
||||||
|
message: res.msg,
|
||||||
|
type: res.code === 1000 ? 'success' : 'error'
|
||||||
|
})
|
||||||
|
if (res.code === 1000) {
|
||||||
|
formData.value.fileList.splice(index, 1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
const handleBack = () => {
|
const handleBack = () => {
|
||||||
history.back()
|
history.back()
|
||||||
}
|
}
|
||||||
const getFiles=(filelist)=>{
|
const getFiles = (val) => {
|
||||||
console.log("🚀 ~ file:filelist ", filelist)
|
console.log("🚀 ~ file:val ", val)
|
||||||
articleFile.value=filelist
|
val.originalFileName=val.originalFilename
|
||||||
|
let file = compositeParam(val)
|
||||||
|
formData.value.fileList.push(file)
|
||||||
|
}
|
||||||
|
const handleDownload = (row) => {
|
||||||
|
downloadFile(row.fileId).then(res => {
|
||||||
|
const blob = new Blob([res])
|
||||||
|
let a = document.createElement('a')
|
||||||
|
a.href = URL.createObjectURL(blob)
|
||||||
|
a.download = row.originalFileName
|
||||||
|
a.click()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const submitParam = (item) => {
|
const submitParam = (item) => {
|
||||||
|
console.log("🚀 ~ file:item.fileList ", item.fileList)
|
||||||
|
item.fileList= item.fileList.map((it)=>{
|
||||||
|
return {
|
||||||
|
...it,
|
||||||
|
articleId:item.articleId
|
||||||
|
}
|
||||||
|
})
|
||||||
return {
|
return {
|
||||||
articleContent: item.articleContent,
|
articleContent: item.articleContent,
|
||||||
articleTitle: item.articleTitle,
|
articleTitle: item.articleTitle,
|
||||||
articleType: item.articleType,
|
articleType: item.articleType,
|
||||||
remarks: item.remarks,
|
remarks: item.remarks,
|
||||||
articleId: item.articleId,
|
articleId: item.articleId,
|
||||||
fileList:compositeParam(articleFile.value,item.articleId)
|
fileList: item.fileList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const compositeParam = (list,id) => {
|
const compositeParam = (item) => {
|
||||||
const array= list?.map(item => {
|
|
||||||
return {
|
return {
|
||||||
articleId:id?id:null,
|
|
||||||
fileId: item.id,
|
fileId: item.id,
|
||||||
size: item.size,
|
size: item.size,
|
||||||
originalFileName: item.originalFilename,
|
originalFileName: item.originalFilename,
|
||||||
@@ -108,9 +161,6 @@ const compositeParam = (list,id) => {
|
|||||||
newFile: true,
|
newFile: true,
|
||||||
tag: 'article'
|
tag: 'article'
|
||||||
}
|
}
|
||||||
})
|
|
||||||
console.log('array',array)
|
|
||||||
return array
|
|
||||||
}
|
}
|
||||||
const handleSubmit = async (instance) => {
|
const handleSubmit = async (instance) => {
|
||||||
if (!instance) return
|
if (!instance) return
|
||||||
@@ -143,7 +193,7 @@ const handleResubmit = () => {
|
|||||||
articleId: route.query.id,
|
articleId: route.query.id,
|
||||||
...submitParam(formData.value)
|
...submitParam(formData.value)
|
||||||
}
|
}
|
||||||
console.log('params',params)
|
console.log('params', params)
|
||||||
editArticle(params).then(res => {
|
editArticle(params).then(res => {
|
||||||
ElNotification({
|
ElNotification({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
@@ -164,11 +214,11 @@ const getDetailInfo = async () => {
|
|||||||
if (res.code === 1000) {
|
if (res.code === 1000) {
|
||||||
formData.value = res.data
|
formData.value = res.data
|
||||||
loading.value = false
|
loading.value = false
|
||||||
showTinymce.value=false
|
showTinymce.value = false
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
showTinymce.value=true
|
showTinymce.value = true
|
||||||
})
|
})
|
||||||
}else{
|
} else {
|
||||||
ElNotification({
|
ElNotification({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
message: res.msg,
|
message: res.msg,
|
||||||
@@ -185,6 +235,9 @@ onMounted(async () => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
.a-style:hover{
|
||||||
|
text-decoration: underline !important;
|
||||||
|
}
|
||||||
.company-select {
|
.company-select {
|
||||||
:deep(.el-form-item__content .el-select__wrapper ) {
|
:deep(.el-form-item__content .el-select__wrapper ) {
|
||||||
width: 750px;
|
width: 750px;
|
||||||
@@ -206,6 +259,7 @@ onMounted(async () => {
|
|||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.el-table--fit ) {
|
:deep(.el-table--fit ) {
|
||||||
height: 300px !important;
|
height: 300px !important;
|
||||||
}
|
}
|
||||||
@@ -216,9 +270,11 @@ onMounted(async () => {
|
|||||||
|
|
||||||
:deep(.el-input-number) {
|
:deep(.el-input-number) {
|
||||||
width: 88.5%;
|
width: 88.5%;
|
||||||
.el-input__wrapper{
|
|
||||||
padding: 1px 11px!important;
|
.el-input__wrapper {
|
||||||
|
padding: 1px 11px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.el-input__inner {
|
.el-input__inner {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<el-row gutter="20">
|
<el-row gutter="20">
|
||||||
<el-col :span="24">
|
<el-col :span="24">
|
||||||
<el-form-item>
|
<div style="display: flex;flex-direction: column">
|
||||||
<!-- <div class="article-a" v-html="formData.articleContent" @click="clickHandle"></div>-->
|
<div v-for="(item,index) in formData.fileList" style="display: flex;align-items: center">
|
||||||
</el-form-item>
|
附件{{ index + 1 }}: <a :href="item.url" style="color: #409eff;" class="a-style" target="_blank">{{ item.originalFileName }}</a>
|
||||||
|
<el-button type="primary" link @click="handleDownload(item)" style="font-size: 16px;margin-left: 10px">下载</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-form>
|
</el-form>
|
||||||
@@ -64,6 +67,15 @@ const clickHandle = (e) => {
|
|||||||
// })
|
// })
|
||||||
// })
|
// })
|
||||||
// }
|
// }
|
||||||
|
const handleDownload = (row) => {
|
||||||
|
downloadFile(row.fileId).then(res => {
|
||||||
|
const blob = new Blob([res])
|
||||||
|
let a = document.createElement('a')
|
||||||
|
a.href = URL.createObjectURL(blob)
|
||||||
|
a.download = row.originalFileName
|
||||||
|
a.click()
|
||||||
|
})
|
||||||
|
}
|
||||||
const download = (row) => {
|
const download = (row) => {
|
||||||
const x = new window.XMLHttpRequest();
|
const x = new window.XMLHttpRequest();
|
||||||
x.open('GET', row.url, true);
|
x.open('GET', row.url, true);
|
||||||
@@ -101,6 +113,7 @@ onMounted(async () => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
|
||||||
.article-a {
|
.article-a {
|
||||||
a {
|
a {
|
||||||
color: #409eff !important;
|
color: #409eff !important;
|
||||||
@@ -112,7 +125,9 @@ onMounted(async () => {
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
.a-style:hover{
|
||||||
|
text-decoration: underline !important;
|
||||||
|
}
|
||||||
.article-detail {
|
.article-detail {
|
||||||
padding: 0 30px;
|
padding: 0 30px;
|
||||||
padding-top: 15px;
|
padding-top: 15px;
|
||||||
|
|||||||
Reference in New Issue
Block a user