6 changed files with 197 additions and 83 deletions
-
18src/api/admin/classtic.ts
-
5src/api/index.ts
-
82src/services/admin/classtic.ts
-
65src/stores/index.ts
-
31src/views/admin/classticmanage/ClassticFormView.vue
-
79src/views/admin/classticmanage/ClassticManageView.vue
@ -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 |
||||
|
} |
@ -0,0 +1,5 @@ |
|||||
|
// 公共api
|
||||
|
export interface indexInterface { |
||||
|
modaOpen: boolean, |
||||
|
title: string, |
||||
|
} |
@ -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<classticInterface[]>([]) |
||||
|
const classticform = reactive<classticFormInterface>({ |
||||
|
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 } |
@ -0,0 +1,31 @@ |
|||||
|
<template> |
||||
|
<a-modal v-model:open="modal.open" :title="modal.title" cancelText="取消" okText="确定" @ok="submit"> |
||||
|
<a-form :model="classticform" name="basic" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }"> |
||||
|
<a-form-item label="语录标题" name="header" |
||||
|
:rules="[{ required: true, message: 'Please input your username!' }]"> |
||||
|
<a-input v-model:value="classticform.header" /> |
||||
|
</a-form-item> |
||||
|
<a-form-item label="语录内容" name="text" :rules="[{ required: true, message: 'Please input your username!' }]"> |
||||
|
<a-input v-model:value="classticform.text" /> |
||||
|
</a-form-item> |
||||
|
<a-form-item label="备注" name="descr" :rules="[{ required: true, message: 'Please input your username!' }]"> |
||||
|
<a-input v-model:value="classticform.descr" /> |
||||
|
</a-form-item> |
||||
|
</a-form> |
||||
|
</a-modal> |
||||
|
</template> |
||||
|
|
||||
|
<script setup lang='ts'> |
||||
|
import {indexStore} from "@/stores/index" |
||||
|
import { onSubmit,classticform } from "@/services/admin/classtic" |
||||
|
const {modal}=indexStore() |
||||
|
const submit = () => { |
||||
|
if (modal.ids) { |
||||
|
onSubmit(modal.ids) |
||||
|
} else { |
||||
|
onSubmit() |
||||
|
} |
||||
|
}; |
||||
|
</script> |
||||
|
|
||||
|
<style></style> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue