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, classticForm } = classticStore() const classticlist = ref([]) const classticOneData = ref({ 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 onSubmit = async (id?: any) => { if (id) { await put(`/classtics/update/${id}`, classticForm) await classticList() } else { await post("/classtics/add", classticForm) await classticList() } } const classticDel = async (id: any) => { try { if (id) { await remove(`/classtics/delete/${id}`) await classticList() } else { console.log("id is null") } } catch (error) { console.log("request is error") } } const classticOne = async (id: any) => { try { const response=await get(`classtics/list/search/${id}`) if (response) { classticOneData.value=response.data.data; } else { console.log("classtic one data is null") } } catch (error) { console.log("classtic one data is error") } } export { classticlist, classticForm, classticOneData, classticList, classticSearch, classticDel, onSubmit, classticOne }