|
@@ -38,7 +38,7 @@ const quilleditorKey = ref(1)
|
|
|
//分页条数据模型
|
|
|
const pageNum = ref(1)//当前页
|
|
|
const total = ref(20)//总条数
|
|
|
-const pageSize = ref(10)//每页条数
|
|
|
+const pageSize = ref(3)//每页条数
|
|
|
|
|
|
//当每页条数发生了变化,调用此函数
|
|
|
const onSizeChange = (size) => {
|
|
@@ -51,7 +51,7 @@ const onCurrentChange = (num) => {
|
|
|
articleList();
|
|
|
}
|
|
|
//回显文章标签
|
|
|
-import {articleCategoryListService, articleListService,articleAddService, articleDeleteService} from '@/api/article.js'
|
|
|
+import {articleCategoryListService, articleListService,articleAddService, articleDeleteService,uploadFileService} from '@/api/article.js'
|
|
|
const articleCategoryList=async()=>{
|
|
|
let result = await articleCategoryListService();
|
|
|
categorys.value=result.data;
|
|
@@ -181,9 +181,9 @@ const addArticle=async(clickState)=>{
|
|
|
for (const key in formVla) {
|
|
|
if(key == 'coverImg') {
|
|
|
let file = fileList.value[0].raw
|
|
|
- if(!isFile(file)) {
|
|
|
- file = base64ToFile(file, 'image.png')
|
|
|
- }
|
|
|
+ // if(!isFile(file)) {
|
|
|
+ // file = base64ToFile(file, 'image.png')
|
|
|
+ // }
|
|
|
formData.append('coverImage', file)
|
|
|
} else {
|
|
|
formData.append(key, formVla[key])
|
|
@@ -203,6 +203,19 @@ const isFile = (obj) => {
|
|
|
return obj instanceof File;
|
|
|
}
|
|
|
|
|
|
+// 图片上传
|
|
|
+const fileUploadArticle = async (row) => {
|
|
|
+ const file = row.file
|
|
|
+ const formData = new FormData()
|
|
|
+ formData.append('multipartFile', file)
|
|
|
+ const res = await uploadFileService(formData)
|
|
|
+ console.log(res, '<===== 上传后的文件')
|
|
|
+ fileList.value = [{
|
|
|
+ name: '图片',
|
|
|
+ url: res.data,
|
|
|
+ raw: res.data
|
|
|
+ }]
|
|
|
+}
|
|
|
const base64ToFile = (base64String, fileName) => {
|
|
|
const arr = base64String.split(',');
|
|
|
const mime = arr[0].match(/:(.*?);/)[1];
|
|
@@ -232,7 +245,7 @@ const addArticleAdministration = () => {
|
|
|
}
|
|
|
// 修改文章
|
|
|
const editArticle = (row) => {
|
|
|
- const { categoryIds, content, title, profile, id, coverImg, productId } = row
|
|
|
+ const { categoryIds, content, title, profile, id, coverImg, coverImgUrl, productId } = row
|
|
|
articleModel.value = {
|
|
|
categoryId: categoryIds ? JSON.parse(categoryIds) : [],
|
|
|
content,
|
|
@@ -242,11 +255,13 @@ const editArticle = (row) => {
|
|
|
coverImg: '',
|
|
|
productId: productId
|
|
|
}
|
|
|
- if(coverImg) {
|
|
|
+ if(coverImgUrl) {
|
|
|
fileList.value = [{
|
|
|
name: '图片',
|
|
|
- url: `data:image/jpeg;base64, ${coverImg}`,
|
|
|
- raw: `data:image/jpeg;base64, ${coverImg}`,
|
|
|
+ // url: `data:image/jpeg;base64, ${coverImg}`,
|
|
|
+ // raw: `data:image/jpeg;base64, ${coverImg}`,
|
|
|
+ url: `${coverImgUrl}`,
|
|
|
+ raw: `${coverImgUrl}`,
|
|
|
}]
|
|
|
} else {
|
|
|
fileList.value = []
|
|
@@ -361,9 +376,10 @@ const deleteArticle = async (row) => {
|
|
|
<el-upload
|
|
|
v-model:file-list="fileList"
|
|
|
list-type="picture-card"
|
|
|
- :auto-upload="false"
|
|
|
+ :auto-upload="true"
|
|
|
:limit="1"
|
|
|
:on-exceed="fileExceedsLimit"
|
|
|
+ :http-request="fileUploadArticle"
|
|
|
>
|
|
|
<el-icon><Plus /></el-icon>
|
|
|
</el-upload>
|