Browse Source

add new

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

22
src/stores/index.ts

@ -2,9 +2,7 @@ import { reactive, ref } from 'vue'
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { get, post, put, remove } from "@/tools/request" import { get, post, put, remove } from "@/tools/request"
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { useRouter } from "vue-router"
import type { blogInterface, classticInterface, classticFormInterface } from '@/api/admin'; import type { blogInterface, classticInterface, classticFormInterface } from '@/api/admin';
const router = useRouter()
// 博客列表 // 博客列表
const bloglist = ref<blogInterface[]>([]) const bloglist = ref<blogInterface[]>([])
// 语录列表 // 语录列表
@ -83,12 +81,24 @@ export const classticFormStore = defineStore("classform", () => {
}) })
const onSubmit = async (id?: any) => { const onSubmit = async (id?: any) => {
if (id) { if (id) {
await put(`/classtics/update/${id}`,classticform)
}else{
await post("/classtics/add",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 {
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}
return { classticform, onSubmit }
}) })
// 语录删除 // 语录删除

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

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

Loading…
Cancel
Save