diff --git a/src/api/admin/classtic.ts b/src/api/admin/classtic.ts new file mode 100644 index 0000000..c90e437 --- /dev/null +++ b/src/api/admin/classtic.ts @@ -0,0 +1,18 @@ +// 语录管理 +export interface classticInterface { + key: string, + id?: number, + header: string, + text: string, + descr: string +} + +export interface classticSearchInterface { + title: string +} + +export interface classticFormInterface { + header: string, + text: string, + descr: string +} \ No newline at end of file diff --git a/src/api/index.ts b/src/api/index.ts new file mode 100644 index 0000000..4012b68 --- /dev/null +++ b/src/api/index.ts @@ -0,0 +1,5 @@ +// 公共api +export interface indexInterface { + modaOpen: boolean, + title: string, + } \ No newline at end of file diff --git a/src/services/admin/classtic.ts b/src/services/admin/classtic.ts new file mode 100644 index 0000000..79f0cdd --- /dev/null +++ b/src/services/admin/classtic.ts @@ -0,0 +1,82 @@ +import { get, remove, put, post } from "@/tools/request" +import { reactive, ref } from "vue"; +import type { classticInterface, classticFormInterface } from "@/api/admin/classtic" +import { classticStore } from "@/stores"; +const { searchValue } = classticStore() + +const classticlist = ref([]) +const classticform = reactive({ + header: "", + text: "", + descr: "" +}) +const classticList = async () => { + try { + const response = await get("/classtics/list"); + if (response) { + classticlist.value = response.data.data.map((item: any, index: any) => ({ + key: (index + 1).toString(), + id: item.id, + header: item.header, + text: item.text, + descr: item.descr + })); + } else { + console.error("Response data structure is not as expected"); + } + } catch (error) { + console.error("Failed to fetch data", error); + } +} + +const classticSearch = async () => { + try { + const response = await get( + "/classtics/list/search", + { header: searchValue.title } + ) + if (response) { + classticlist.value = response.data.data.map((items: any, index: any) => ({ + key: (index + 1).toString(), + id: items.id, + header: items.header, + text: items.text, + descr: items.descr + })) + } else { + console.log("classtic request is nulll") + } + } catch (error) { + console.log("classtic request is error") + } +} + +const classticDel = async (id: any) => { + try { + if (id) { + remove(`/classtics/delete/${id}`) + } else { + console.log("id is null") + } + await classticList() + } catch (error) { + console.log("request is error") + } + +} + +const onSubmit = async (id?: any) => { + if (id) { + await put(`/classtics/update/${id}`, classticform) + + } else { + const response = post("/classtics/add", classticform) + const newClasstic = { + ...(await response).data.data, + key: (classticlist.value.length + 1).toString() + } + classticlist.value.push(newClasstic) + + } +} +export { classticlist, classticform, classticList, classticSearch, classticDel, onSubmit } \ No newline at end of file diff --git a/src/stores/index.ts b/src/stores/index.ts index 4f4fbc4..2be6ae7 100644 --- a/src/stores/index.ts +++ b/src/stores/index.ts @@ -3,6 +3,44 @@ import { defineStore } from 'pinia' import { get, post, put, remove } from "@/tools/request" import dayjs from 'dayjs'; import type { blogInterface, classticInterface, classticFormInterface } from '@/api/admin'; +import type { classticSearchInterface } from '@/api/admin/classtic'; +export const indexStore=defineStore("index",()=>{ + const modal=reactive({ + // 控制对话框开关 + open:false, + // 控制对话框title + title:"", + // 控制对话框点击事件标识 + mode:"", + // 通过ids控制哪个功能事件 + ids:"" + }) + return {modal} +}) + +export const classticStore = defineStore("classtic", () => { + const searchValue = reactive({ + title: "" + }) + const classticForm = reactive({ + header: "", + text: "", + descr: "" + }) + return { searchValue,classticForm } +}) + + + + + + + + + + + + // 博客列表 const bloglist = ref([]) // 语录列表 @@ -72,34 +110,7 @@ export const classticSearchStore = defineStore("chassticsearch", () => { } return { classticSearch, searchValue } }) -// 语录新增/编辑接口 -export const classticFormStore = defineStore("classform", () => { - const classticform = reactive({ - header: "", - text: "", - descr: "" - }) - const onSubmit = async (id?: any) => { - if (id) { - 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 } -}) // 语录删除 export const classticDelStore = defineStore("classticdel", () => { diff --git a/src/views/admin/classticmanage/ClassticFormView.vue b/src/views/admin/classticmanage/ClassticFormView.vue new file mode 100644 index 0000000..4b30f99 --- /dev/null +++ b/src/views/admin/classticmanage/ClassticFormView.vue @@ -0,0 +1,31 @@ + + + + + \ No newline at end of file diff --git a/src/views/admin/classticmanage/ClassticManageView.vue b/src/views/admin/classticmanage/ClassticManageView.vue index 9a61845..bfc773e 100644 --- a/src/views/admin/classticmanage/ClassticManageView.vue +++ b/src/views/admin/classticmanage/ClassticManageView.vue @@ -7,39 +7,22 @@ 查询 新增 - - - - - - - - - - - - - +
- + @@ -49,51 +32,35 @@