浏览代码

轮播图编辑修改bug

LiRong 3 月之前
父节点
当前提交
8fe75ad24c
共有 2 个文件被更改,包括 31 次插入9 次删除
  1. 6 0
      src/api/system/banner.js
  2. 25 9
      src/views/system/banner/index.vue

+ 6 - 0
src/api/system/banner.js

@@ -1,5 +1,11 @@
 import request from '@/utils/request'
 export function add(data) {
+  return request({
+    url: '/web/core/slideshow',
+    method: 'put',
+    data: data
+  })
+}export function update(data) {
   return request({
     url: '/web/core/slideshow',
     method: 'post',

+ 25 - 9
src/views/system/banner/index.vue

@@ -21,7 +21,7 @@
 <script setup>
 import { onMounted, ref, render } from 'vue';
 import ListPage from '@/views/components/ListPage/index.vue';
-import { add, list,delbanner } from "@/api/system/banner";
+import { add, update,list,delbanner } from "@/api/system/banner";
 
 const { proxy } = getCurrentInstance();
 
@@ -56,7 +56,7 @@ const listPageData = reactive({
             label: '新增',
             func: () => {
                 console.log('新增')
-                openDialog();
+                openDialog(null,"add");
             },
             key: 'add',
             hasPermi: ['banner:add'],
@@ -74,7 +74,7 @@ const listPageData = reactive({
             key: 'edit',
             func: (row) => {
                 console.log(row)
-                openDialog(row);
+                openDialog(row,"update");
 
             }
         },
@@ -92,17 +92,21 @@ const listPageData = reactive({
 })
 
 const open = ref(false);
+const curDialogType = ref('');
 const files = ref('');
+const curEditRow = ref(null);
 const fileUpdata = (file) => {
     console.log(file);
     files.value = file;
 }
 
-const openDialog = async (row) => {
+const openDialog = async (row,dialogType) => {
+    curDialogType.value = dialogType;
 
     try {
         if(row){
             files.value = row.picture;
+            curEditRow.value = row;
         }
 
     } catch (error) {
@@ -126,14 +130,26 @@ const handleDelete = (ids) => {
 const submitForm = () => {
     console.log('submit', files.value);
     const parmas = JSON.parse(JSON.stringify(files.value))
-    add({picture: parmas }).then(res => {
+    if(curDialogType.value == "add"){
+      add({picture: parmas }).then(res => {
         if (res.code === 200) {
-            proxy.$modal.msgSuccess("新增成功");
-            cancel()
-            return;
+          proxy.$modal.msgSuccess("编辑成功");
+          cancel()
+          return;
         }
         proxy.$modal.msgSuccess(res.msg);
-    })
+      })
+    }else{
+      update({slideshowId: curEditRow.value.slideshowId, picture: parmas }).then(res => {
+        if (res.code === 200) {
+          proxy.$modal.msgSuccess("编辑成功");
+          cancel()
+          return;
+        }
+        proxy.$modal.msgSuccess(res.msg);
+      })
+    }
+
 }
 const cancel = () => {
     userTableRef.value.resetForm();