在线blog初步完成
This commit is contained in:
+1
-4
@@ -21,10 +21,7 @@ const get_blog = (params: any) => {
|
|||||||
const listAll = () => {
|
const listAll = () => {
|
||||||
return request({
|
return request({
|
||||||
url: '/author/blog/list',
|
url: '/author/blog/list',
|
||||||
method: 'get',
|
method: 'get'
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json;charsetset=UTF-8'
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ type Blog = {
|
|||||||
type BlogType = {
|
type BlogType = {
|
||||||
btId: string,
|
btId: string,
|
||||||
btName: string,
|
btName: string,
|
||||||
blog_list: Blog[]
|
blogs: Map<string, Blog>
|
||||||
}
|
}
|
||||||
|
|
||||||
type User = {
|
type User = {
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ router.beforeEach((to, from, next) => {
|
|||||||
break;
|
break;
|
||||||
case '/':
|
case '/':
|
||||||
const user = <User>(JSON.parse(getUser() as string))
|
const user = <User>(JSON.parse(getUser() as string))
|
||||||
if (url.search("edit_blog") != -1) {
|
if (url.search("write") != -1) {
|
||||||
next('/BlogEditer')
|
next('/BlogEditer')
|
||||||
} else {
|
} else {
|
||||||
router.push({
|
router.push({
|
||||||
|
|||||||
+102
-64
@@ -1,53 +1,75 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="blog_editer">
|
<div class="blog_editer" v-if="isReady">
|
||||||
<div class="tab_list">
|
<div class="bt_section">
|
||||||
<Tab :row_key="item.btId" :checked="handleCheck(item.btId)" :tab_text="item.btName" checked_color="" over_color=""
|
<el-button>增加</el-button>
|
||||||
leave_color="" @on-click="saveType" @click="onclickTypeTab(item.btId, index)"
|
<el-button class="bts" v-for="(value, key) of blogTypes" :key="key" @click="onclickBlogTab(value[0])">
|
||||||
v-for="(item, index) in blog_type_list">
|
<el-dropdown trigger="click">
|
||||||
</Tab>
|
<el-icon>
|
||||||
|
<edit />
|
||||||
|
</el-icon>
|
||||||
|
<template #dropdown>
|
||||||
|
<el-dropdown-menu>
|
||||||
|
<el-dropdown-item @click="handleEditBtName(value[1])">修改</el-dropdown-item>
|
||||||
|
<el-dropdown-item @click="true">退出</el-dropdown-item>
|
||||||
|
</el-dropdown-menu>
|
||||||
|
</template>
|
||||||
|
</el-dropdown>
|
||||||
|
{{ value[1].btName }}
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
<div class="b_section">
|
||||||
|
<el-button @click="insertBlogType">增加</el-button>
|
||||||
|
<el-button v-for="(blog, index) of blogTypes.get(checkedBlogIndex)?.blogs" @click="onclickTypeTab(blog[0])">
|
||||||
|
{{ blog[1].title }}
|
||||||
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Tab :row_key="item.bid" :checked="handleCheck(item.bid)" :tab_text="item.title" checked_color="" over_color=""
|
<md-editor theme="light" v-model="blog.content" @save="saveContent" />
|
||||||
leave_color="" @on-click="saveTitle" @click="onclickBlogTab(item.bid, index)"
|
|
||||||
v-for="(item, index) in blog_type_list[checkedIndex].blog_list">
|
|
||||||
</Tab>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<md-editor v-model="blog_type_list[checkedIndex].blog_list[checkedBlogIndex].content" @save="saveContent" />
|
|
||||||
</div>
|
</div>
|
||||||
|
<el-dialog v-model="dialogVisible" title="Tips" width="30%">
|
||||||
|
<el-input v-model="(blogTypes.get(checkedBlogIndex) as BlogType).btName"></el-input>
|
||||||
|
<template #footer>
|
||||||
|
<span class="dialog-footer">
|
||||||
|
<el-button @click="dialogVisible = false">Cancel</el-button>
|
||||||
|
<el-button type="primary" @click="saveType">Confirm</el-button>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, ref } from 'vue'
|
import { onBeforeMount, onMounted, reactive, ref, watch } from 'vue'
|
||||||
import MdEditor from 'md-editor-v3'
|
import MdEditor from 'md-editor-v3'
|
||||||
|
import { Edit } from "@element-plus/icons-vue";
|
||||||
import 'md-editor-v3/lib/style.css'
|
import 'md-editor-v3/lib/style.css'
|
||||||
import { Blog, BlogType } from '../../entity/index'
|
import { Blog, BlogType } from '../../entity/index'
|
||||||
import { updateBtName, updateContent, insert_blog_type, listAll } from '../../api/blog'
|
import { updateBtName, updateContent, listAll, insert_blog_type } from '../../api/blog'
|
||||||
import Tab from '../../components/common/Tab.vue'
|
|
||||||
|
|
||||||
let text = ref<string>("")
|
// const MD_SETTING = () => {
|
||||||
type Tab = {
|
// return {
|
||||||
id: string
|
// tools: [{ title: 'bold' }]
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
let type_tab = reactive<Tab>(<Tab>{
|
const blogTypes = reactive<Map<string, BlogType>>(new Map())
|
||||||
id: '1'
|
const blog = reactive<Blog>({} as Blog)
|
||||||
})
|
|
||||||
let bid = ref("")
|
let bid = ref("")
|
||||||
|
const dialogVisible = ref(false)
|
||||||
|
|
||||||
let checkedIndex = ref<number>(0)
|
let checkedIndex = ref<string>("")
|
||||||
let checkedBlogIndex = ref<number>(0)
|
let checkedBlogIndex = ref<string>("")
|
||||||
|
let isReady = ref(false)
|
||||||
const blog_type_list = reactive<BlogType[]>([])
|
const getTestData = async () => {
|
||||||
listAll().then(response => {
|
await listAll().then(response => {
|
||||||
console.log(response)
|
console.log(response)
|
||||||
response.data.forEach((element: any) => {
|
response.data.forEach((element: any) => {
|
||||||
const blog_type: BlogType = {
|
const blog_type: BlogType = {
|
||||||
btId: element.btId,
|
btId: element.btId,
|
||||||
btName: element.btName,
|
btName: element.btName,
|
||||||
blog_list: []
|
blogs: new Map<string, Blog>()
|
||||||
}
|
}
|
||||||
|
blogTypes.set(element.btId, blog_type)
|
||||||
element.blog_list.forEach((item: any) => {
|
element.blog_list.forEach((item: any) => {
|
||||||
const blog: Blog = {
|
const blog: Blog = {
|
||||||
bid: item.bid,
|
bid: item.bid,
|
||||||
@@ -57,39 +79,37 @@ listAll().then(response => {
|
|||||||
blog_prex: item.blog_prex,
|
blog_prex: item.blog_prex,
|
||||||
content: item.content
|
content: item.content
|
||||||
}
|
}
|
||||||
blog_type.blog_list.push(blog)
|
blog_type.blogs.set(item.bid, blog)
|
||||||
});
|
|
||||||
blog_type_list.push(blog_type)
|
|
||||||
});
|
|
||||||
bid.value = blog_type_list[0].blog_list[0].bid
|
|
||||||
text.value = blog_type_list[0].blog_list[0].content
|
|
||||||
}).then(() => {
|
|
||||||
if (blog_type_list.length == 0) {
|
|
||||||
const data = {
|
|
||||||
blog_type_name: '未分类'
|
|
||||||
}
|
|
||||||
insert_blog_type(data).then(response => {
|
|
||||||
if (response.data) {
|
|
||||||
blog_type_list.push({
|
|
||||||
btId: response.data.btId,
|
|
||||||
btName: response.data.btNmae,
|
|
||||||
blog_list: []
|
|
||||||
})
|
})
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
console.log(blogTypes)
|
||||||
})
|
})
|
||||||
const handleCheck = (id: string) => {
|
isReady.value = true
|
||||||
return type_tab.id == id
|
checkedBlogIndex.value = blogTypes.keys().next().value
|
||||||
}
|
}
|
||||||
const saveType = (params: any) => {
|
getTestData()
|
||||||
|
// watch(blogTypes, (newValue, oldValue) => {
|
||||||
|
// console.log(newValue, '新值', oldValue, '旧值')
|
||||||
|
// }, { deep: true })
|
||||||
|
const onclickTypeTab = (key: string) => {
|
||||||
|
checkedIndex.value = key
|
||||||
|
}
|
||||||
|
const onclickBlogTab = (key: string) => {
|
||||||
|
checkedBlogIndex.value = key
|
||||||
|
}
|
||||||
|
const handleEditBtName = (bt: BlogType) => {
|
||||||
|
dialogVisible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const saveType = () => {
|
||||||
const query = {
|
const query = {
|
||||||
btId: params.id,
|
btId: checkedBlogIndex.value,
|
||||||
btName: params.name
|
btName: (blogTypes.get(checkedBlogIndex.value) as BlogType).btName
|
||||||
}
|
}
|
||||||
updateBtName(query).then(response => {
|
updateBtName(query).then(response => {
|
||||||
|
dialogVisible.value = false
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
const saveTitle = (params: any) => {
|
const saveTitle = (params: any) => {
|
||||||
const query = {
|
const query = {
|
||||||
@@ -103,24 +123,42 @@ const saveTitle = (params: any) => {
|
|||||||
const saveContent = () => {
|
const saveContent = () => {
|
||||||
const query = {
|
const query = {
|
||||||
bid: bid.value,
|
bid: bid.value,
|
||||||
content: text.value
|
content: blog.content
|
||||||
}
|
}
|
||||||
updateContent(query).then(response => {
|
updateContent(query).then(response => {
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const onclickTypeTab = (id: string, index: number) => {
|
const insertBlogType = () => {
|
||||||
checkedIndex.value = index
|
dialogVisible.value = true
|
||||||
type_tab.id = id
|
|
||||||
}
|
|
||||||
const onclickBlogTab = (id: string, index: number) => {
|
|
||||||
bid.value = id
|
|
||||||
checkedBlogIndex.value = index
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.b_section {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bts {
|
||||||
|
margin-left: 0px;
|
||||||
|
padding-left: 0px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-dropdown {
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bt_section {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
width: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
<style>
|
|
||||||
.blog_editer {
|
.blog_editer {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const openBlog = () => {
|
|||||||
|
|
||||||
const openBlogEditer = () => {
|
const openBlogEditer = () => {
|
||||||
const { href } = router.resolve({
|
const { href } = router.resolve({
|
||||||
path: '/edit_blog=1'
|
path: '/write'
|
||||||
});
|
});
|
||||||
window.open(href, '_blank');
|
window.open(href, '_blank');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,63 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="dashboard">just a dashboard</div>
|
<div class="about" ref="bookmarks" id="bookmarks" :style="{
|
||||||
|
width: '600px',
|
||||||
|
height: '300px'
|
||||||
|
}"></div>
|
||||||
|
<div class="dashboard">这里我想分享的一些东西,无论是生活还是工作,还是学科</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import * as echarts from 'echarts'
|
||||||
|
import { onMounted, ref } from 'vue';
|
||||||
|
const bookmarks = ref<HTMLElement>()
|
||||||
|
onMounted(() => {
|
||||||
|
const myEcharts = echarts.init(bookmarks.value!)
|
||||||
|
const option = {
|
||||||
|
tooltip: {
|
||||||
|
trigger: 'item'
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
top: '5%',
|
||||||
|
left: 'center'
|
||||||
|
},
|
||||||
|
series: [
|
||||||
|
{
|
||||||
|
name: 'Access From',
|
||||||
|
type: 'pie',
|
||||||
|
radius: ['40%', '70%'],
|
||||||
|
avoidLabelOverlap: false,
|
||||||
|
itemStyle: {
|
||||||
|
borderRadius: 10,
|
||||||
|
borderColor: '#fff',
|
||||||
|
borderWidth: 2
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
show: false,
|
||||||
|
position: 'center'
|
||||||
|
},
|
||||||
|
emphasis: {
|
||||||
|
label: {
|
||||||
|
show: true,
|
||||||
|
fontSize: '25',
|
||||||
|
fontWeight: 'bold'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
labelLine: {
|
||||||
|
show: false
|
||||||
|
},
|
||||||
|
data: [
|
||||||
|
{ value: 1048, name: 'Java' },
|
||||||
|
{ value: 735, name: 'JavaScript' },
|
||||||
|
{ value: 580, name: 'Internet' },
|
||||||
|
{ value: 484, name: '数据结构' },
|
||||||
|
{ value: 300, name: '数据库' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
myEcharts.setOption(option)
|
||||||
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
Reference in New Issue
Block a user