ブログ一時保存
This commit is contained in:
+50
-9
@@ -18,20 +18,19 @@ const get_blog = (params: any) => {
|
||||
})
|
||||
}
|
||||
|
||||
const get_user_blogs = (params: Object) => {
|
||||
const listAll = () => {
|
||||
return request({
|
||||
url: '/blog',
|
||||
url: '/author/blog/list',
|
||||
method: 'get',
|
||||
params: params,
|
||||
paramsSerializer: (params) => {
|
||||
return Qs.stringify(params, { arrayFormat: 'repeat' })
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charsetset=UTF-8'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const update_blog_type = (params: Object) => {
|
||||
const updateBtName = (params: Object) => {
|
||||
return request({
|
||||
url: '/blog/update_blog_type',
|
||||
url: '/author/blog/update_blog_type',
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charsetset=UTF-8'
|
||||
@@ -51,5 +50,47 @@ const insert_blog_type = (params: Object) => {
|
||||
})
|
||||
}
|
||||
|
||||
const getContent = (id: string) => {
|
||||
return request({
|
||||
url: '/author/blog/' + id + '/content',
|
||||
method: 'get',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charsetset=UTF-8'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export { get_blogs, get_blog, get_user_blogs, update_blog_type, insert_blog_type }
|
||||
const newBlog = (params: Object) => {
|
||||
return request({
|
||||
url: '/author/blog/createContent',
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charsetset=UTF-8'
|
||||
},
|
||||
data: params
|
||||
})
|
||||
}
|
||||
|
||||
const updateContent = (params: Object) => {
|
||||
return request({
|
||||
url: '/author/blog/updateContent',
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charsetset=UTF-8'
|
||||
},
|
||||
data: params
|
||||
})
|
||||
}
|
||||
|
||||
const deleteContent = (params: string) => {
|
||||
return request({
|
||||
url: '/author/blog/delete/' + params,
|
||||
method: 'get',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charsetset=UTF-8'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export { get_blogs, get_blog, listAll, updateBtName, insert_blog_type, getContent, newBlog, updateContent, deleteContent }
|
||||
+8
-7
@@ -1,14 +1,15 @@
|
||||
type Blog = {
|
||||
blog_id: string,
|
||||
blog_type_id: string,
|
||||
blog_type_name: string,
|
||||
blog_title: string,
|
||||
blog_prex: string
|
||||
bid: string,
|
||||
btId: string,
|
||||
btName: string,
|
||||
title: string,
|
||||
blog_prex: string,
|
||||
content: string
|
||||
}
|
||||
|
||||
type BlogType = {
|
||||
blog_type_id: string,
|
||||
blog_type_name: string,
|
||||
btId: string,
|
||||
btName: string,
|
||||
blog_list: Blog[]
|
||||
}
|
||||
|
||||
|
||||
+26
-38
@@ -16,51 +16,40 @@ import { getToken, getUser } from './utils/auth'
|
||||
import { User } from './entity/index'
|
||||
const whiteList = ['/login']
|
||||
let url = window.location.href
|
||||
console.log(url)
|
||||
if (url != 'http://localhost:3000/') {
|
||||
// if(url.search("blog=") != -1) {
|
||||
// let blog = {
|
||||
// blog_id: url.split("=")[1]
|
||||
// }
|
||||
// router.push({
|
||||
// path: '/feedback',
|
||||
// query: blog
|
||||
// })
|
||||
// }
|
||||
if (url.search("edit_blog=") != -1) {
|
||||
let blog = {
|
||||
blog_id: url.split("=")[1]
|
||||
}
|
||||
router.push({
|
||||
path: '/BlogEditer',
|
||||
query: blog
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* ルーター監視
|
||||
* 1、トーケン取得
|
||||
* 2、トーケンなし場合はログイン画面に遷移
|
||||
* 3、トーケンあり場合:
|
||||
* 既にログイン場合はデフォルト / に遷移
|
||||
*
|
||||
*/
|
||||
router.beforeEach((to, from, next) => {
|
||||
console.log(from.path, to.path)
|
||||
|
||||
const token = getToken()
|
||||
|
||||
|
||||
if (typeof token === 'string') {
|
||||
if (to.path === '/login') {
|
||||
if (token) {
|
||||
switch (to.path) {
|
||||
case '/login':
|
||||
next('/')
|
||||
}
|
||||
} else if (to.path === '/') {
|
||||
const user = <User>(JSON.parse(getUser() as string))
|
||||
console.log(user)
|
||||
if (user) {
|
||||
router.push({
|
||||
path: '/home',
|
||||
query: user
|
||||
})
|
||||
}
|
||||
} else {
|
||||
next()
|
||||
break;
|
||||
case '/':
|
||||
const user = <User>(JSON.parse(getUser() as string))
|
||||
if (url.search("edit_blog") != -1) {
|
||||
next('/BlogEditer')
|
||||
} else {
|
||||
router.push({
|
||||
path: '/home',
|
||||
query: user
|
||||
})
|
||||
}
|
||||
break;
|
||||
default:
|
||||
next()
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
if (whiteList.includes(to.path)) {
|
||||
next()
|
||||
@@ -69,7 +58,6 @@ router.beforeEach((to, from, next) => {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@ import { getToken } from '../utils/auth'
|
||||
|
||||
const service = axios.create(
|
||||
{
|
||||
baseURL: 'http://localhost:8081',
|
||||
// baseURL: 'http://49.233.4.79:8081',
|
||||
baseURL: import.meta.env.VITE_APP_URL as string,
|
||||
timeout: 5000
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,31 +1,29 @@
|
||||
<template>
|
||||
<div class="blog_editer">
|
||||
<div class="tab_list">
|
||||
<Tab :row_key="item.blog_type_id" :checked="handleCheck(item.blog_type_id)" :tab_text="item.blog_type_name"
|
||||
checked_color="" over_color="" leave_color="" @on-click="saveType"
|
||||
@click="onclickTypeTab(item.blog_type_id, index)" v-for="(item, index) in data_type_list">
|
||||
<Tab :row_key="item.btId" :checked="handleCheck(item.btId)" :tab_text="item.btName" checked_color="" over_color=""
|
||||
leave_color="" @on-click="saveType" @click="onclickTypeTab(item.btId, index)"
|
||||
v-for="(item, index) in blog_type_list">
|
||||
</Tab>
|
||||
</div>
|
||||
<div>
|
||||
<Tab :row_key="item.blog_type_id" :checked="handleCheck(item.blog_type_id)" :tab_text="item.blog_type_name"
|
||||
checked_color="" over_color="" leave_color="" @on-click="saveBlog"
|
||||
@click="onclickBlogTab(item.blog_type_id, index)"
|
||||
v-for="(item, index) in data_type_list[checkedIndex].blog_list">
|
||||
<Tab :row_key="item.bid" :checked="handleCheck(item.bid)" :tab_text="item.title" checked_color="" over_color=""
|
||||
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="text" />
|
||||
<md-editor v-model="blog_type_list[checkedIndex].blog_list[checkedBlogIndex].content" @save="saveContent" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from 'vue';
|
||||
import MdEditor from 'md-editor-v3';
|
||||
import 'md-editor-v3/lib/style.css';
|
||||
import { get_user_blogs } from '../../api/blog'
|
||||
import { reactive, ref } from 'vue'
|
||||
import MdEditor from 'md-editor-v3'
|
||||
import 'md-editor-v3/lib/style.css'
|
||||
import { Blog, BlogType } from '../../entity/index'
|
||||
import { update_blog_type, insert_blog_type } from '../../api/blog'
|
||||
import { updateBtName, updateContent, insert_blog_type, listAll } from '../../api/blog'
|
||||
import Tab from '../../components/common/Tab.vue'
|
||||
|
||||
let text = ref<string>("")
|
||||
@@ -36,34 +34,35 @@ type Tab = {
|
||||
let type_tab = reactive<Tab>(<Tab>{
|
||||
id: '1'
|
||||
})
|
||||
let blog_tab = reactive<Tab>(<Tab>{
|
||||
id: '1'
|
||||
})
|
||||
let bid = ref("")
|
||||
|
||||
const data_type_list = reactive<BlogType[]>([])
|
||||
let checkedIndex = ref<number>(0)
|
||||
let checkedBlogIndex = ref<number>(0)
|
||||
|
||||
const blog_type_list = reactive<BlogType[]>([])
|
||||
get_user_blogs({}).then(response => {
|
||||
|
||||
listAll().then(response => {
|
||||
console.log(response)
|
||||
response.data.forEach((element: any) => {
|
||||
const blog_type: BlogType = {
|
||||
blog_type_id: element.blog_type_id,
|
||||
blog_type_name: element.blog_type_id,
|
||||
btId: element.btId,
|
||||
btName: element.btName,
|
||||
blog_list: []
|
||||
}
|
||||
element.blog_list.forEach((item: any) => {
|
||||
const blog: Blog = {
|
||||
blog_id: item.blog_id,
|
||||
blog_type_id: item.blog_type_id,
|
||||
blog_type_name: item.blog_type_name,
|
||||
blog_title: item.blog_title,
|
||||
blog_prex: item.blog_prex
|
||||
bid: item.bid,
|
||||
btId: item.btId,
|
||||
btName: item.btName,
|
||||
title: item.title,
|
||||
blog_prex: item.blog_prex,
|
||||
content: item.content
|
||||
}
|
||||
blog_type.blog_list.push(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 = {
|
||||
@@ -72,8 +71,8 @@ get_user_blogs({}).then(response => {
|
||||
insert_blog_type(data).then(response => {
|
||||
if (response.data) {
|
||||
blog_type_list.push({
|
||||
blog_type_id: response.data.blog_type_id,
|
||||
blog_type_name: response.data.blog_type_id,
|
||||
btId: response.data.btId,
|
||||
btName: response.data.btNmae,
|
||||
blog_list: []
|
||||
})
|
||||
}
|
||||
@@ -85,16 +84,28 @@ const handleCheck = (id: string) => {
|
||||
}
|
||||
const saveType = (params: any) => {
|
||||
const query = {
|
||||
blog_type_id: params.id,
|
||||
blog_type_name: params.name
|
||||
btId: params.id,
|
||||
btName: params.name
|
||||
}
|
||||
update_blog_type(query).then(response => {
|
||||
updateBtName(query).then(response => {
|
||||
|
||||
})
|
||||
}
|
||||
const saveBlog = (params: any) => {
|
||||
console.log(params)
|
||||
update_blog_type(1).then(response => {
|
||||
const saveTitle = (params: any) => {
|
||||
const query = {
|
||||
bid: params.id,
|
||||
title: params.name
|
||||
}
|
||||
updateContent(query).then(response => {
|
||||
|
||||
})
|
||||
}
|
||||
const saveContent = () => {
|
||||
const query = {
|
||||
bid: bid.value,
|
||||
content: text.value
|
||||
}
|
||||
updateContent(query).then(response => {
|
||||
|
||||
})
|
||||
}
|
||||
@@ -103,7 +114,8 @@ const onclickTypeTab = (id: string, index: number) => {
|
||||
type_tab.id = id
|
||||
}
|
||||
const onclickBlogTab = (id: string, index: number) => {
|
||||
blog_tab.id = id
|
||||
bid.value = id
|
||||
checkedBlogIndex.value = index
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
+38
-3
@@ -1,7 +1,12 @@
|
||||
<template>
|
||||
<el-button @click="openBlogEditer">++++++</el-button>
|
||||
<el-button @click="openBlogEditer">进入博客小作坊</el-button>
|
||||
<el-button @click="test">获取博客内容</el-button>
|
||||
<el-button @click="test1">新增博客</el-button>
|
||||
<el-button @click="test2">更新博客</el-button>
|
||||
<el-button @click="test3">削除博客</el-button>
|
||||
|
||||
<div class="blog_list" v-for="item in data_list">
|
||||
<h3 style="cursor: pointer;" @click="openBlog">{{ item.blog_title }}</h3>
|
||||
<h3 style="cursor: pointer;" @click="openBlog">{{ item.title }}</h3>
|
||||
<span style="font-size: 12px;">{{ item.blog_prex }}</span>
|
||||
</div>
|
||||
|
||||
@@ -10,7 +15,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from 'vue';
|
||||
import { get_blogs } from '../../api/blog'
|
||||
import { get_blogs, getContent, newBlog, updateContent, deleteContent } from '../../api/blog'
|
||||
import router from '../../router/index'
|
||||
|
||||
import { Blog, BlogType } from '../../entity/index'
|
||||
@@ -42,6 +47,36 @@ const openBlogEditer = () => {
|
||||
});
|
||||
window.open(href, '_blank');
|
||||
}
|
||||
const test = () => {
|
||||
getContent('123456').then(response => {
|
||||
console.log(response)
|
||||
})
|
||||
}
|
||||
const test1 = () => {
|
||||
const params = {
|
||||
blog_type_id: "2808000",
|
||||
title: "dddddddd"
|
||||
}
|
||||
newBlog(params).then(response => {
|
||||
console.log(response)
|
||||
})
|
||||
}
|
||||
const test2 = () => {
|
||||
const params = {
|
||||
bid: "22222",
|
||||
title: "22222222222",
|
||||
content: "dddddddddddddddddddddddddddd"
|
||||
}
|
||||
updateContent(params).then(response => {
|
||||
console.log(response)
|
||||
})
|
||||
}
|
||||
|
||||
const test3 = () => {
|
||||
deleteContent('22222').then(response => {
|
||||
console.log(response)
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
Reference in New Issue
Block a user