feat: 加个给我妹用的小工具

This commit is contained in:
539943419 committed 2025-01-15 18:44:45 +08:00
1 parent d7f1bf7d49
commit 24f910e12c
8 files changed
+391 -25

No files matched your search

+43 -2
View File
@@ -1,11 +1,17 @@
<!-- 若route.params.id为new则为新建而非修改 -->
<template>
<div class="post-editor-wrapper">
<div class="post-editor-header">
<div class="post-editor-header-back" @click="handleBack">
<chevronDown></chevronDown>
返回
</div>
</div>
<editor v-model:title="title" v-model:summary="summary" v-model:tags="tags" v-model:content="content" />
<el-row>
<el-col :span="24">
<div class="flex-end">
<el-text v-if="message" :type="message.type">{{ message.message }}</el-text>
<el-text v-if="message" :type="message.type" style="user-select: none;">{{ message.message }}</el-text>
<el-button @click="handleSubmit" style="margin-left: 10px;">
upload
</el-button>
@@ -20,6 +26,7 @@ import editor from '~/components/user/postEditor.vue';
import useDefaultStore from '~/hooks/pinia/useDefaultStore';
import useFetch from '~/hooks/useMiaoFetch';
import type { postItem } from '~/types/post';
import chevronDown from "~/components/icons/chevronDown.vue";
type resType = {
data: string
@@ -29,6 +36,7 @@ type resType = {
const { post: { getPost, updatePost, uploadPost } } = useFetch()
const route = useRoute()
const router = useRouter()
const id = ref<number>(-1)
const title = ref<string>('')
@@ -48,6 +56,10 @@ const handleSubmit = () => {
const handleUpload = async () => {
try {
message.value = {
type: 'info',
message: '上传中'
}
const response = await uploadPost({
title: title.value,
summary: summary.value,
@@ -80,6 +92,10 @@ const handleUpload = async () => {
const handleUpdate = async () => {
try {
message.value = {
type: 'info',
message: '上传中'
}
const response = await updatePost({
id: id.value,
title: title.value,
@@ -108,6 +124,10 @@ const handleUpdate = async () => {
}
}
const handleBack = () => {
router.back()
}
onMounted(async () => {
console.log('route', route.params.id, route.params.id === 'new')
if (route.params.id !== 'new') {
@@ -123,7 +143,7 @@ onMounted(async () => {
})
</script>
<style scoped>
<style lang="scss" scoped>
.post-editor-wrapper {
/* box-sizing: border-box; */
display: flex;
@@ -132,6 +152,27 @@ onMounted(async () => {
padding: 20px;
}
.post-editor-header {
&-back {
width: fit-content;
display: flex;
justify-content: space-between;
align-items: center;
user-select: none;
svg {
width: 18px;
transform: rotate(90deg) translateX(1px);
margin-right: 3px;
}
&:hover {
cursor: pointer;
}
}
}
.flex-end {
display: flex;
justify-content: flex-end;
+29 -17
View File
@@ -2,23 +2,8 @@
<div>
its the page which is used to test the api
<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>
<el-button @click="testAuth">
testAuth
<el-button v-for="item in Object.entries(testFunctionList)" @click="item[1]">
{{ item[0] }}
</el-button>
</div>
</div>
@@ -90,6 +75,33 @@ const testRefreshToken = async () => {
userStore.setToken(token)
}
const testToolShiquLikeApi = async () => {
const id = 29729408
const likes = 3
const sse = new EventSource(`/api/tools/shiqu/like?id=${id}&likes=${likes}`);
sse.onopen = function (event) {
console.log('Connection opened');
};
sse.onmessage = function (event) {
console.log('Received message:', event.data);
};
sse.onerror = function (event) {
console.error('Error occurred:', event);
sse.close()
};
}
const testFunctionList = {
uploadTest,
editTest,
testLogin,
testRegister,
testRefreshToken,
testToolShiquLikeApi
}
onMounted(() => {
// testAuth()
})