Browse Source

add new

master
panda 9 months ago
parent
commit
cc1627983c
  1. 153
      src/stores/index.ts
  2. 139
      src/views/admin/blogmange/BlogManageView.vue
  3. 14
      src/views/admin/classticmanage/ClassticManageView.vue

153
src/stores/index.ts

@ -2,6 +2,19 @@ import { reactive, ref } from 'vue'
import { defineStore } from 'pinia'
import { get } from "@/tools/request"
import dayjs from 'dayjs';
interface blogInterface {
key: string,
blogtitle: string,
create_at: Date,
readnum: number,
readminite: number,
wordcount: number,
img: string,
blogcontent: string,
typename: string,
labelnames: string
}
const bloglist = ref<blogInterface[]>([])
export const useAuthStore = defineStore("auth", () => {
const tokenValue = ref("")
@ -14,21 +27,9 @@ export const useAuthStore = defineStore("auth", () => {
return { setToken, removeToken }
})
// 博客列表接口
export const blogContentStore = defineStore("blog", () => {
interface blogInterface {
key: string,
blogtitle: string,
create_at: Date,
readnum: number,
readminite: number,
wordcount: number,
img: string,
blogcontent: string,
typename: string,
labelnames: string
}
const bloglist = ref<blogInterface[]>([])
async function blogList() {
try {
const response = await get("/blogs/list");
@ -57,54 +58,82 @@ export const blogContentStore = defineStore("blog", () => {
return { blogList, bloglist }
})
// 语录列表接口
export const classticContentStore = defineStore("classtic", () => {
interface classticInterface {
key: string,
header: string,
text: string,
descr: string
}
const classticlist = ref<classticInterface[]>([])
async function classticList() {
try {
const response = await get("/classtics/list")
if (response) {
classticlist.value = response.data.data.map((items: any, index: any) => ({
key: (index + 1).toString(),
header: items.header,
text: items.text,
descr: items.descr
}))
} else {
console.log("classtic is not exit")
}
} catch (error) {
console.log("classtic is error")
}
}
return { classticList, classticlist }
})
// 语录单查询
export const classticSearchStore = defineStore("classticSearch", () => {
const classticsearch = ref<{ header: string }>()
// 博客查询接口
export const blogSearchStore = defineStore('blogsearch', () => {
const searchValue = reactive({
blogtitle: '',
typename: '',
start_date: '',
end_date: ''
});
async function classticSearch() {
try {
const response = get(
"/classtics/search",
classticsearch.value?.header
)
if (response) {
classticsearch.value = (await response).data.data.map((items: any) => ({
header: items.header
}))
} else {
console.log("header is not exit")
}
} catch (error) {
console.log("header is error")
const onChange = (date: string, dateString: string[]) => {
if (date && dateString.length === 2) {
searchValue.start_date = dateString[0];
searchValue.end_date = dateString[1];
} else {
searchValue.start_date = '';
searchValue.end_date = '';
}
console.log(dateString[0]);
};
const blogSearch = async () => {
try {
const response = await get("/blogs/list/search", {
blogtitle: searchValue.blogtitle,
typename: searchValue.typename,
start_date: searchValue.start_date,
end_date: searchValue.end_date
});
if (response && response.data) {
bloglist.value = response.data.data.map((items: any, index: any) => ({
key: (index + 1).toString(),
blogtitle: items.blogtitle,
typename: items.typename,
blogcontent: items.blogcontent,
create_at: dayjs(items.create_at).format('YYYY-MM-DD HH:mm:ss'),
update_at: dayjs(items.update_at).format('YYYY-MM-DD HH:mm:ss'),
descr: items.descr
}));
console.log(response)
} else {
console.log("request has no data");
}
}
return { classticsearch, classticSearch }
})
} catch (error) {
console.error("request is exception", error);
}
};
return { searchValue, onChange, blogSearch };
});
// 语录列表接口
// export const classticContentStore = defineStore("classtic", () => {
// interface classticInterface {
// key: string,
// header: string,
// text: string,
// descr: string
// }
// const classticlist = ref<classticInterface[]>([])
// async function classticList() {
// try {
// const response = await get("/classtics/list")
// if (response) {
// classticlist.value = response.data.data.map((items: any, index: any) => ({
// key: (index + 1).toString(),
// header: items.header,
// text: items.text,
// descr: items.descr
// }))
// } else {
// console.log("classtic is not exit")
// }
// } catch (error) {
// console.log("classtic is error")
// }
// }
// return { classticList, classticlist }
// })

139
src/views/admin/blogmange/BlogManageView.vue

@ -2,18 +2,20 @@
<div class="content">
<div class="search">
<a-space>
<a-input v-model:value="searchList.blogtitle" placeholder="博客标题" />
<a-input v-model:value="searchList.typename" placeholder="分类名称" />
<a-range-picker :locale="locale" show-time @change="onChange" />
<a-input v-model:value="blogSearch.searchValue.blogtitle" placeholder="博客标题" />
<a-input v-model:value="blogSearch.searchValue.typename" placeholder="分类名称" />
<a-range-picker :locale="locale" show-time @change="blogSearch.onChange" />
</a-space>
<a-space style="margin-left: 16px;">
<a-button @click="blogSearch">查询</a-button>
<a-button @click="blogSearch.blogSearch">查询</a-button>
<a-button type="primary" ghost @click="blogAdd">新增</a-button>
</a-space>
</div>
<div class="table">
<a-table bordered :data-source="blogContent.bloglist" :columns="columns">
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'operation'">
<a-space>
<div>
@ -34,34 +36,47 @@
<script setup lang='ts'>
import { ref, reactive, onMounted } from 'vue';
import {blogContentStore} from "@/stores/index"
import 'dayjs/locale/zh-cn';
import locale from 'ant-design-vue/es/date-picker/locale/zh_CN';
import dayjs from 'dayjs';
import { useRouter } from "vue-router"
import { get, remove } from '@/tools/request';
import { message } from 'ant-design-vue';
import { blogContentStore,blogSearchStore } from '@/stores';
dayjs.locale('zh-cn');
const blogContent=blogContentStore()
const blogSearch=blogSearchStore()
const router = useRouter()
const searchList = reactive<{ blogtitle: string, typename: string, start_date: string, end_date: string }>({
blogtitle: '',
typename: '',
start_date: '',
end_date: ''
})
// const searchList = reactive<{ blogtitle: string, typename: string, start_date: string, end_date: string }>({
// blogtitle: '',
// typename: '',
// start_date: '',
// end_date: ''
// })
// interface BlogList {
// key: string;
// id: number;
// blogtitle: string;
// typename: string;
// blogcontent: string;
// create_at: string;
// update_at: string;
// descr: string
// }
// const dataSource = ref<BlogList[]>([]);;
//
const onChange = (date: string, dateString: string[]) => {
if (date && dateString.length === 2) {
searchList.start_date = (dateString[0]);
searchList.end_date = (dateString[1]);
} else {
searchList.start_date = '';
searchList.end_date = '';
}
console.log(dateString[0])
};
// const onChange = (date: string, dateString: string[]) => {
// if (date && dateString.length === 2) {
// searchList.start_date = (dateString[0]);
// searchList.end_date = (dateString[1]);
// } else {
// searchList.start_date = '';
// searchList.end_date = '';
// }
// console.log(dateString[0])
// };
const open = ref<boolean>(false);
const toDelete = reactive<{ key: string, id: number }>({
key: '',
@ -81,45 +96,57 @@ const blogAdd = function () {
//
onMounted(async () => {
// get("/blogs/list").then(response => {
// dataSource.value = (response as any).data.data.map((items: any, index: any) => ({
// key: (index + 1).toString(),
// id: items.id,
// blogtitle: items.blogtitle,
// typename: items.typename,
// blogcontent: items.blogcontent,
// create_at: dayjs(items.create_at).format('YYYY-MM-DD HH:mm:ss'), //
// update_at: dayjs(items.update_at).format('YYYY-MM-DD HH:mm:ss'), //
// descr: items.descr
// }))
// })
blogContent.blogList()
});
//
const blogSearch = () => {
get("/blogs/list/search", {
blogtitle: searchList.blogtitle,
typename: searchList.typename,
start_date: searchList.start_date,
end_date: searchList.end_date,
})
.then(response => {
dataSource.value = response.data.data.map((items: any, index: any) => ({
key: (index + 1).toString(),
blogtitle: items.blogtitle,
typename: items.typename,
blogcontent: items.blogcontent,
create_at: dayjs(items.create_at).format('YYYY-MM-DD HH:mm:ss'),
update_at: dayjs(items.update_at).format('YYYY-MM-DD HH:mm:ss'),
descr: items.descr
}));
})
.catch(error => {
console.error('There was an error seraching the blog!', error);
});
};
// const blogSearch = () => {
// get("/blogs/list/search", {
// blogtitle: searchList.blogtitle,
// typename: searchList.typename,
// start_date: searchList.start_date,
// end_date: searchList.end_date,
// })
// .then(response => {
// dataSource.value = response.data.data.map((items: any, index: any) => ({
// key: (index + 1).toString(),
// blogtitle: items.blogtitle,
// typename: items.typename,
// blogcontent: items.blogcontent,
// create_at: dayjs(items.create_at).format('YYYY-MM-DD HH:mm:ss'),
// update_at: dayjs(items.update_at).format('YYYY-MM-DD HH:mm:ss'),
// descr: items.descr
// }));
// })
// .catch(error => {
// console.error('There was an error seraching the blog!', error);
// });
// };
//
const ackDelete = async (record:{key:string,id:number}) => {
remove(`/blogs/delete/${toDelete.id}`).then((response) => {
if (response.status === 200) {
dataSource.value = dataSource.value.filter(item => item.key !== record.key);
open.value = false;
}
message.info("删除成功")
}).catch(error => {
console.error('There was an error deleting the blog!', error);
})
};
// const ackDelete = async (record:{key:string,id:number}) => {
// remove(`/blogs/delete/${toDelete.id}`).then((response) => {
// if (response.status === 200) {
// dataSource.value = dataSource.value.filter(item => item.key !== record.key);
// open.value = false;
// }
// message.info("")
// }).catch(error => {
// console.error('There was an error deleting the blog!', error);
// })
// };
//
const ackUpdate =async (record: { key: string, id: number }) => {
@ -146,10 +173,6 @@ const columns = [
title: '博客分类',
dataIndex: 'typename',
},
{
title: '博客标签',
dataIndex: 'labelname',
},
{
title: '发布时间',
dataIndex: 'create_at',

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

@ -5,8 +5,8 @@
<a-input v-model:value="searchList.classtictitle" placeholder="语录标题" />
</a-space>
<a-space style="margin-left: 16px;">
<a-button @click="classticSearch.classticSearch()">查询</a-button>
<a-button type="primary" ghost @click="classticAdd">新增</a-button>
<a-button >查询</a-button>
<a-button type="primary" ghost >新增</a-button>
</a-space>
</div>
<div class="table">
@ -16,12 +16,12 @@
<a-space>
<div>
<a-button size="small" danger @click="showModal(record.key, record.id)">删除</a-button>
<a-modal v-model:open="open" title="提示" @ok="ackDelete(record)" ok-text="确认" cancel-text="取消" @cancel="unDelete">
<a-modal v-model:open="open" title="提示" ok-text="确认" cancel-text="取消" @cancel="unDelete">
<p>确认删除吗</p>
</a-modal>
</div>
<a-button size="small" type="primary" ghost @click="ackUpdate(record)">编辑</a-button>
<a-button size="small" type="primary" ghost @click="ackWatch(record)">预览</a-button>
<a-button size="small" type="primary" ghost>编辑</a-button>
<a-button size="small" type="primary" ghost>预览</a-button>
</a-space>
</template>
</template>
@ -35,12 +35,11 @@ import { ref, reactive, onMounted } from 'vue';
import type { searchValue } from "@/api/admin"
import { useRouter } from "vue-router"
const router = useRouter()
import {classticContentStore,classticSearchStore} from "@/stores"
import {classticContentStore} from "@/stores"
const searchList = reactive<searchValue>({
classtictitle:""
})
const classticContent=classticContentStore()
const classticSearch=classticSearchStore()
const open = ref<boolean>(false);
const toDelete = reactive<{ key: string, id: number }>({
key: '',
@ -61,7 +60,6 @@ const blogAdd = function () {
onMounted(async () => {
classticContent.classticList()
});
const columns = [
{

Loading…
Cancel
Save