From e3be0674d87dbec8f5b432d83f05e4d20677b41c Mon Sep 17 00:00:00 2001 From: simple321vip Date: Wed, 20 Apr 2022 22:48:23 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=92=8C=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=88=86=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/blog.ts | 3 + src/components/common/Tab.vue | 4 +- src/entity/index.ts | 7 +- src/main.ts | 37 +++++++---- src/router/index.ts | 7 -- src/store/user.ts | 6 +- src/utils/request.ts | 25 +++---- src/view/blog/createBlog.vue | 25 ++----- src/view/tools/cal.vue | 122 ---------------------------------- src/view/tools/frame.vue | 29 -------- src/view/tools/index.vue | 39 ----------- src/view/tools/unit.vue | 84 ----------------------- 12 files changed, 54 insertions(+), 334 deletions(-) delete mode 100644 src/view/tools/cal.vue delete mode 100644 src/view/tools/frame.vue delete mode 100644 src/view/tools/index.vue delete mode 100644 src/view/tools/unit.vue diff --git a/src/api/blog.ts b/src/api/blog.ts index 107beac..d19cfdd 100644 --- a/src/api/blog.ts +++ b/src/api/blog.ts @@ -33,6 +33,9 @@ const update_blog_type = (params: Object) => { return request({ url: '/blog/update_blog_type', method: 'post', + headers: { + 'Content-Type': 'application/json;charsetset=UTF-8' + }, data: params }) } diff --git a/src/components/common/Tab.vue b/src/components/common/Tab.vue index 4c699eb..d48f4f9 100644 --- a/src/components/common/Tab.vue +++ b/src/components/common/Tab.vue @@ -61,8 +61,8 @@ const emit = defineEmits(['on-click']) const clickTap = () => { is_edit.value = !is_edit.value const params = { - section_id: props.row_key, - section_name: props.tab_text + id: props.row_key, + name: props.tab_text } emit('on-click', params) onLeave() diff --git a/src/entity/index.ts b/src/entity/index.ts index f42e7d4..00c9491 100644 --- a/src/entity/index.ts +++ b/src/entity/index.ts @@ -12,4 +12,9 @@ type BlogType = { blog_list: Blog[] } -export { Blog, BlogType } +type User = { + id: string, + username: string +} + +export { Blog, BlogType, User } diff --git a/src/main.ts b/src/main.ts index 30cbd98..8520320 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,20 +3,18 @@ import App from './App.vue' import ElementPlus from "element-plus"; import 'element-plus/dist/index.css' import router from './router' - // vue store import { createPinia } from 'pinia' const store = createPinia() let app = createApp(App) - app.use(router) app.use(ElementPlus) app.use(store) - -import { getToken } from './utils/auth' -const whiteList = ['/', '/blog'] +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/') { @@ -44,21 +42,34 @@ router.beforeEach((to, from, next) => { console.log(from.path, to.path) const token = getToken() - if (to.path === '/login') { - if (token) { - next('/home') + if (typeof token === 'string') { + if (to.path === '/login') { + if (token) { + next('/') + } + } else if (to.path === '/') { + const user = (JSON.parse(getUser() as string)) + console.log(user) + if (user) { + router.push({ + path: '/home', + query: user + }) + } } else { next() } - } - - if (whiteList.includes(to.path)) { - next() } else { - next() + if (whiteList.includes(to.path)) { + next() + } else { + next('/login') + } + } + }) diff --git a/src/router/index.ts b/src/router/index.ts index f0199bb..b101e23 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -12,13 +12,6 @@ const routes: Array = [ name: '控制台' } }, - { - path: '/tools', - component: () => import('../view/tools/index.vue'), - meta: { - name: '工具' - } - }, { path: '/blog', component: () => import('../view/blog/index.vue'), diff --git a/src/store/user.ts b/src/store/user.ts index 0c2c804..49c1ee4 100644 --- a/src/store/user.ts +++ b/src/store/user.ts @@ -1,6 +1,7 @@ import { defineStore, acceptHMRUpdate } from 'pinia' import { authorize } from '../api/user' import { getToken, setToken, resetToken, setUser, getUser } from '../utils/auth' +import { User } from '../entity/index' /** * Simulate a login @@ -13,11 +14,6 @@ import { getToken, setToken, resetToken, setUser, getUser } from '../utils/auth' // return Promise.reject(new Error('invalid credentials')) // } -type User = { - id: string, - username: string -} - export const useUserStore = defineStore({ id: 'user', state: () => ({ diff --git a/src/utils/request.ts b/src/utils/request.ts index d82b481..d533cb7 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,4 +1,5 @@ import axios from 'axios' +import { getToken } from '../utils/auth' const service = axios.create( { @@ -8,18 +9,18 @@ const service = axios.create( } ) -// service.interceptors.request.use( -// config => { -// // if (true) { -// // config.headers['Authorization'] = 'Bearer' + getToken('user-token') -// // } -// // return config -// }, -// error => { -// console.log(error) -// return Promise.reject(error) -// } -// ) +service.interceptors.request.use( + config => { + if (typeof getToken() === 'string') { + (config as any).headers['Authorization'] = 'Bearer' + getToken() + } + return config + }, + error => { + console.log(error) + return Promise.reject(error) + } +) // service.interceptors.response.use( // response => { diff --git a/src/view/blog/createBlog.vue b/src/view/blog/createBlog.vue index e774053..eb2cd9b 100644 --- a/src/view/blog/createBlog.vue +++ b/src/view/blog/createBlog.vue @@ -43,24 +43,6 @@ let blog_tab = reactive({ const data_type_list = reactive([]) let checkedIndex = ref(0) -data_type_list.push({ - blog_type_id: '1', - blog_type_name: 'xxx', - blog_list: [] -}) -// data_type_list[0].blog_list.push({}) -data_type_list.push({ - blog_type_id: '2', - blog_type_name: 'yyy', - blog_list: [] -}) -data_type_list.push({ - blog_type_id: '3', - blog_type_name: 'zzz', - blog_list: [] -}) - - const blog_type_list = reactive([]) get_user_blogs({}).then(response => { @@ -87,8 +69,11 @@ const handleCheck = (id: string) => { return type_tab.id == id } const saveType = (params: any) => { - console.log(params) - update_blog_type(1).then(response => { + const query = { + blog_type_id: params.id, + blog_type_name: params.name + } + update_blog_type(query).then(response => { }) } diff --git a/src/view/tools/cal.vue b/src/view/tools/cal.vue deleted file mode 100644 index 3c75ced..0000000 --- a/src/view/tools/cal.vue +++ /dev/null @@ -1,122 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/view/tools/frame.vue b/src/view/tools/frame.vue deleted file mode 100644 index 59f497c..0000000 --- a/src/view/tools/frame.vue +++ /dev/null @@ -1,29 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/view/tools/index.vue b/src/view/tools/index.vue deleted file mode 100644 index 3f26012..0000000 --- a/src/view/tools/index.vue +++ /dev/null @@ -1,39 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/view/tools/unit.vue b/src/view/tools/unit.vue deleted file mode 100644 index e8453dd..0000000 --- a/src/view/tools/unit.vue +++ /dev/null @@ -1,84 +0,0 @@ - - - - - \ No newline at end of file