|
@@ -17,6 +17,21 @@
|
|
|
<div class="main">
|
|
|
<naf-form ref="ruleForm" @save="formSave" :meta="formfiled" :rules="formrules" :data="formdata" :close="true" @close="close">
|
|
|
<template v-slot:field="{ form, item }">
|
|
|
+ <!-- 图片上传 -->
|
|
|
+ <el-upload
|
|
|
+ v-if="item.name == 'thumbnail'"
|
|
|
+ class="avatar-uploader avatar"
|
|
|
+ action="/api/files/upload"
|
|
|
+ :show-file-list="false"
|
|
|
+ :on-success="handleAvatarSuccess"
|
|
|
+ :before-upload="beforeAvatarUpload"
|
|
|
+ :data="{ type: 'resource' }"
|
|
|
+ :headers="myHeaders"
|
|
|
+ :on-error="imgerror"
|
|
|
+ >
|
|
|
+ <img v-if="imageUrl" :src="imageUrl" class="avatar">
|
|
|
+ <i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
|
|
+ </el-upload>
|
|
|
<!-- 选择日期 -->
|
|
|
<el-date-picker
|
|
|
value-format="yyyy-MM-dd"
|
|
@@ -75,6 +90,7 @@ export default {
|
|
|
lookUser: false,
|
|
|
fileList: [],
|
|
|
myHeaders: { Authorization: `Bearer ${token}` },
|
|
|
+ imageUrl: '',
|
|
|
title: '',
|
|
|
visibleSync: false,
|
|
|
filed: [
|
|
@@ -84,6 +100,7 @@ export default {
|
|
|
],
|
|
|
formdata: {},
|
|
|
formfiled: [
|
|
|
+ { name: 'thumbnail', title: '封面', slots: 'field' },
|
|
|
{ name: 'name', title: '标题' },
|
|
|
{ name: 'describe', title: '描述' },
|
|
|
{ name: 'status', title: '状态', formatter: 'journalStatus' },
|
|
@@ -115,6 +132,9 @@ export default {
|
|
|
],
|
|
|
content: [
|
|
|
{ required: true, message: '请输输入内容', trigger: 'blur' }
|
|
|
+ ],
|
|
|
+ thumbnail: [
|
|
|
+ { required: true, message: '请上封面', trigger: 'blur' }
|
|
|
]
|
|
|
},
|
|
|
operation: [
|
|
@@ -150,10 +170,12 @@ export default {
|
|
|
this.title = '添加期刊'
|
|
|
this.visibleSync = true
|
|
|
this.isNew = false
|
|
|
+ this.imageUrl = ''
|
|
|
},
|
|
|
// 修改
|
|
|
async filtereEdit (e) {
|
|
|
this.formdata = e
|
|
|
+ if (e.thumbnail) this.imageUrl = e.thumbnail
|
|
|
this.fileList.push({ name: e.filename, url: e.url })
|
|
|
this.title = '修改期刊'
|
|
|
this.visibleSync = true
|
|
@@ -203,6 +225,7 @@ export default {
|
|
|
this.$refs.grid.resetpage(-1)
|
|
|
this.visibleSync = false
|
|
|
this.fileList = []
|
|
|
+ this.imageUrl = ''
|
|
|
}
|
|
|
},
|
|
|
// 富文本改变
|
|
@@ -235,6 +258,31 @@ export default {
|
|
|
// 文件超出个数限制时的钩子
|
|
|
handleExceed (files, fileList) {
|
|
|
this.$message.warning(`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
|
|
|
+ },
|
|
|
+ // 图片上传
|
|
|
+ // 文件上传成功时的钩子
|
|
|
+ handleAvatarSuccess (res, file) {
|
|
|
+ this.is_data = { ...this.$refs.ruleForm.form }
|
|
|
+ this.is_data.thumbnail = res.data.path
|
|
|
+ this.$refs.ruleForm.formChage('thumbnail', res.data.path)
|
|
|
+ this.imageUrl = URL.createObjectURL(file.raw)
|
|
|
+ },
|
|
|
+ imgerror () {
|
|
|
+ this.$message.error('上传失败')
|
|
|
+ },
|
|
|
+ // 上传文件之前的钩子
|
|
|
+ beforeAvatarUpload (file) {
|
|
|
+ const isJPG = file.type === 'image/jpeg'
|
|
|
+ const isPNG = file.type === 'image/png'
|
|
|
+ const isLt2M = file.size / 1024 / 1024 < 2
|
|
|
+
|
|
|
+ if (!isJPG && !isPNG) {
|
|
|
+ this.$message.error('上传图片只能是 JPG 或 PNG 格式!')
|
|
|
+ }
|
|
|
+ if (!isLt2M) {
|
|
|
+ this.$message.error('上传图片大小不能超过 2MB!')
|
|
|
+ }
|
|
|
+ return (isJPG || isPNG) && isLt2M
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -306,4 +354,9 @@ export default {
|
|
|
line-height: 150px;
|
|
|
text-align: center;
|
|
|
}
|
|
|
+.avatar {
|
|
|
+ width: 150px;
|
|
|
+ height: 150px;
|
|
|
+ display: block;
|
|
|
+}
|
|
|
</style>
|