From 51ac21526dbf62affd5fd97c70a998a431c1ed03 Mon Sep 17 00:00:00 2001 From: panda <7934952@qq.com> Date: Wed, 26 Jun 2024 17:15:28 +0800 Subject: [PATCH] add new --- src/api/admin.ts | 42 ++++--- src/stores/index.ts | 49 +++++--- .../classticmanage/ClassticManageView.vue | 106 ++++++++---------- 3 files changed, 104 insertions(+), 93 deletions(-) diff --git a/src/api/admin.ts b/src/api/admin.ts index 6dad6f3..40ee926 100644 --- a/src/api/admin.ts +++ b/src/api/admin.ts @@ -1,22 +1,28 @@ // 博客管理 export interface blogInterface { - key: string, - blogtitle: string, - create_at: Date, - readnum: number, - readminite: number, - wordcount: number, - img: string, - blogcontent: string, - typename: string, - labelnames: string - } + key: string, + blogtitle: string, + create_at: Date, + readnum: number, + readminite: number, + wordcount: number, + img: string, + blogcontent: string, + typename: string, + labelnames: string +} // 语录管理 -export interface classticInterface { - key:string, - id?:number, - header: string, - text: string, - descr: string - } \ No newline at end of file +export interface classticInterface { + key: string, + id?: number, + header: string, + text: string, + descr: string +} + +export interface classticFormInterface { + header: string, + text: string, + descr: string +} \ No newline at end of file diff --git a/src/stores/index.ts b/src/stores/index.ts index ddc0226..b1679f9 100644 --- a/src/stores/index.ts +++ b/src/stores/index.ts @@ -1,20 +1,15 @@ import { reactive, ref } from 'vue' import { defineStore } from 'pinia' -import { get, post, put } from "@/tools/request" +import { get, post, put, remove } from "@/tools/request" import dayjs from 'dayjs'; import { useRouter } from "vue-router" -import type { blogInterface, classticInterface } from '@/api/admin'; +import type { blogInterface, classticInterface, classticFormInterface } from '@/api/admin'; const router = useRouter() // 博客列表 const bloglist = ref([]) // 语录列表 const classticlist = ref([]) // 语录新增 -const classticadd=reactive({ - header:"", - text:"", - descr:"" -}) export const useAuthStore = defineStore("auth", () => { const tokenValue = ref("") @@ -80,19 +75,39 @@ export const classticSearchStore = defineStore("chassticsearch", () => { return { classticSearch, searchValue } }) // 语录新增/编辑接口 -export const classticAddStore=defineStore("classticadd",()=>{ - const onSubmit=async ()=>{ - await post("/classtics/add", - { - header:classticadd.header, - text:classticadd.text, - descr:classticadd.descr - } - ) +export const classticFormStore = defineStore("classform", () => { + const classticform = reactive({ + header: "", + text: "", + descr: "" + }) + const onSubmit = async (id?: any) => { + if (id) { + await put(`/classtics/update/${id}`,classticform) + }else{ + await post("/classtics/add",classticform) + } } - return {onSubmit,classticadd} + return {classticform,onSubmit} }) +// 语录删除 +export const classticDelStore = defineStore("classticdel", () => { + const classticDel = (id: any) => { + try { + if (id) { + remove(`/classtics/delete/${id}`) + classticlist.value = classticlist.value.filter(item => item.id !== id); + } else { + console.log("id is null") + } + } catch (error) { + console.log("request is error") + } + + } + return { classticDel } +}) // 链接接口 export const comLinkContentStore = defineStore("comlink", () => { diff --git a/src/views/admin/classticmanage/ClassticManageView.vue b/src/views/admin/classticmanage/ClassticManageView.vue index 4760834..377adb7 100644 --- a/src/views/admin/classticmanage/ClassticManageView.vue +++ b/src/views/admin/classticmanage/ClassticManageView.vue @@ -2,25 +2,24 @@