Browse Source

add new

master
sunfree 9 months ago
parent
commit
8295cefbb5
  1. 18
      src/stores/index.ts
  2. 12
      src/views/admin/classticmanage/ClassticManageView.vue

18
src/stores/index.ts

@ -2,9 +2,7 @@ import { reactive, ref } from 'vue'
import { defineStore } from 'pinia'
import { get, post, put, remove } from "@/tools/request"
import dayjs from 'dayjs';
import { useRouter } from "vue-router"
import type { blogInterface, classticInterface, classticFormInterface } from '@/api/admin';
const router = useRouter()
// 博客列表
const bloglist = ref<blogInterface[]>([])
// 语录列表
@ -83,9 +81,21 @@ export const classticFormStore = defineStore("classform", () => {
})
const onSubmit = async (id?: any) => {
if (id) {
await put(`/classtics/update/${id}`,classticform)
const response = await put(`/classtics/update/${id}`, classticform)
const updatedClasstic = response.data.data;
const index = classticlist.value.findIndex(item => item.id === updatedClasstic.id)
if (index !== -1) {
updatedClasstic.key = classticlist.value[index].key;
classticlist.value[index] = updatedClasstic;
}
} else {
await post("/classtics/add",classticform)
const response=post("/classtics/add", classticform)
const newClasstic = {
...(await response).data.data,
key: (classticlist.value.length + 1).toString()
}
classticlist.value.push(newClasstic)
}
}
return { classticform, onSubmit }

12
src/views/admin/classticmanage/ClassticManageView.vue

@ -61,19 +61,21 @@ const formList = reactive({
mode: ""
})
const id = ref<any>();
const idRef = ref<any>();
const openModal = (mode: string, id?: any) => {
const openModal = (mode: string, itemid?: any) => {
formList.mode = mode
formOpen.value = true;
id.value = id;
idRef.value = itemid;
};
const formModal = () => {
if (id.value) {
onSubmit(id.value)
if (idRef.value) {
onSubmit(idRef.value)
formOpen.value = false;
} else {
onSubmit()
formOpen.value = false;
}
};

Loading…
Cancel
Save