Lijy 6 mesiacov pred
rodič
commit
ad12874377

+ 5 - 0
fhKeeper/formulahousekeeper/articleBackend/src/api/article.js

@@ -40,4 +40,9 @@ export const articleAddService=(articleData)=>{
 // 删除文章
 export const articleDeleteService=(params)=>{
     return request.get('/article/deleteById', {params:params})
+}
+
+// 上传文件
+export const uploadFileService=(params)=>{
+    return request.post('/common/uploadFile', params)
 }

+ 26 - 10
fhKeeper/formulahousekeeper/articleBackend/src/views/article/ArticleManage.vue

@@ -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>

+ 2 - 2
fhKeeper/formulahousekeeper/articleBackend/vite.config.js

@@ -29,8 +29,8 @@ export default defineConfig({
     proxy:{
       '/api':{
         // target:'http://localhost:8080',  // 后台服务所在的源,用这个源替换前端服务源
-        target:'http://47.101.180.183:8091',  // 后台服务所在的源,用这个源替换前端服务源
-        // target:'http://192.168.2.17:8091',  // 后台服务所在的源,用这个源替换前端服务源
+        // target:'http://47.101.180.183:8091',  // 后台服务所在的源,用这个源替换前端服务源
+        target:'http://192.168.2.17:8091',  // 后台服务所在的源,用这个源替换前端服务源
         changeOrigin:true,     // 开启修改源
         rewrite:(path)=>path.replace(/^\/api/,'')   // url路径中的 /api 将会被替换成 '' 
       }