feat: 完成用户鉴权相关api
This commit is contained in:
1 parent
79cc9c34d6
commit
4c69f57aaa
22 files changed
+903
-68
No files matched your search
+80
-3
@@ -1,13 +1,90 @@
|
||||
<template>
|
||||
<div>
|
||||
index
|
||||
<div>
|
||||
<el-button @click="uploadTest">
|
||||
uploadPostTest
|
||||
</el-button>
|
||||
<el-button @click="editTest">
|
||||
editPostTest
|
||||
</el-button>
|
||||
<el-button @click="testLogin">
|
||||
testLogin
|
||||
</el-button>
|
||||
<el-button @click="testRegister">
|
||||
testRegister
|
||||
</el-button>
|
||||
<el-button @click="testRefreshToken">
|
||||
testRefreshToken
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import useUserStore from '~/hooks/pinia/useUserStore';
|
||||
import { uploadPost, updatePost } from '~/hooks/useFetch';
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
const uploadTest = () => {
|
||||
uploadPost({
|
||||
title: `测试上传`,
|
||||
summary: `测试摘要测试摘要测试摘要测试摘要测试摘要测试摘要测试摘要测试摘要测试摘要测试摘要测试摘要`,
|
||||
type:'markdown',
|
||||
tags: ['test', 'test1'],
|
||||
url: '',
|
||||
date: parseInt(new Date().getTime().toFixed()),
|
||||
content: '测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传'
|
||||
})
|
||||
}
|
||||
|
||||
const editTest = () => {
|
||||
updatePost({
|
||||
id: 1,
|
||||
title: `测试上传`,
|
||||
summary: `测试摘要测试摘要测试摘要测试摘要测试摘要测试摘要测试摘要测试摘要测试摘要测试摘要测试摘要`,
|
||||
type:'markdown',
|
||||
tags: ['test', 'test1'],
|
||||
url: '',
|
||||
date: parseInt(new Date().getTime().toFixed()),
|
||||
content: '测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传测试上传'
|
||||
})
|
||||
}
|
||||
|
||||
const testLogin = async () => {
|
||||
const response = await $fetch('/api/user/login', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
username: 'admin',
|
||||
password: 'admin'
|
||||
}
|
||||
})
|
||||
const token = response.token
|
||||
userStore.setToken(token)
|
||||
}
|
||||
|
||||
const testRegister = () => {
|
||||
$fetch('/api/user/register', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
username: 'admin',
|
||||
password: 'admin'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const testRefreshToken = async () => {
|
||||
const response = await $fetch('/api/user/refreshToken', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
token: userStore.token
|
||||
}
|
||||
})
|
||||
const token = response.token
|
||||
userStore.setToken(token)
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
</style>
|
||||
<style lang="scss" scoped></style>
|
||||
Reference in new issue
Block a user