Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry committed Jun 10, 2024
1 parent 8c75899 commit 2a47b46
Show file tree
Hide file tree
Showing 7 changed files with 5,982 additions and 4,615 deletions.
10 changes: 5 additions & 5 deletions components/MemoInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
</div>
<Button size="sm" class="mr-2" @click="importMusic">确定</Button>
<Button size="sm" variant="ghost"
@click="music163IfrUrl = ''; music163Url = ''; audioUrl = ''; music163Open = false;">清空</Button>
@click="music163Url = ''; audioUrl = ''; music163Open = false;">清空</Button>
</div>
</PopoverContent>
</Popover>
Expand Down Expand Up @@ -373,7 +373,6 @@ const externalFetchError = ref(false)
const externalTitleEditing = ref(false)
let musicBoxKey = ref(0)
const music163Url = ref('')
const musicType = ref('')
const musicId = ref('')
const musicPlatform = ref('netease')
Expand Down Expand Up @@ -442,7 +441,7 @@ const drop = (event: any, dropIndex: any) => {
const submitMemo = async () => {
if (content.value === '' && imgs.value.length === 0
&& music163IfrUrl.value === '' && bilibiliIfrUrl.value === ''
&& music163Url.value === '' && bilibiliIfrUrl.value === ''
&& videoIfrUrl.value === '' && youtubeIfrUrl.value === ''
&& externalUrl.value === '' && !doubanBook.value
&& !doubanMovie.value && localVideoUrl.value === '' && audioUrl.value === '') {
Expand All @@ -455,7 +454,7 @@ const submitMemo = async () => {
id: id.value,
content: content.value,
imgUrls: imgs.value,
music163Url: music163IfrUrl.value,
music163Url: music163Url.value,
bilibiliUrl: bilibiliIfrUrl.value,
location: location.value,
externalFavicon: externalFavicon.value,
Expand All @@ -478,7 +477,6 @@ const submitMemo = async () => {
showType.value = true
imgs.value = []
music163IfrUrl.value = ''
music163Url.value = ''
bilibiliIfrUrl.value = ''
bilibiliUrl.value = ''
Expand Down Expand Up @@ -630,6 +628,7 @@ const importMusic = () => {
music163Url.value = ''
}
music163Open.value = false
//@ts-expect-error
musicBoxKey++
}
music163Open.value = false
Expand Down Expand Up @@ -747,6 +746,7 @@ memoUpdateEvent.on((event: Memo & { index?: number }) => {
music163Url.value = ''
}
music163Open.value = false
//@ts-expect-error
musicBoxKey++
})
Expand Down
182 changes: 93 additions & 89 deletions layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,89 +1,93 @@
<template>
<div class="wrapper w-full h-full bg-[#f1f5f9] dark:bg-slate-800 rounded-md dark:text-[#C0BEBF]">
<ScrollArea class="h-full" type="hover">
<div class="main lg:w-[567px] mx-auto shadow-2xl bg-white dark:bg-[#181818]">
<HeaderImg />
<slot />
<Footer />
</div>
</ScrollArea>
</div>

<Toaster position="top-center" rich-colors />

</template>

<script setup lang="ts">
import { ScrollArea } from '@/components/ui/scroll-area';
import { Toaster } from '@/components/ui/sonner';
import { memoUpdateEvent } from '~/lib/event';
import type { Memo, PrivateConfig, PublicConfig, User } from '~/lib/types';
const { data } = await useFetch('/api/user/validateToken', {
method: 'POST'
})
if (!data.value?.success) {
const token = useCookie('token')
token.value = undefined
} else {
const privateConfigData = await useFetch('/api/config/private', {
method: 'POST'
})
useState<PrivateConfig | null>('privateConfig', () => privateConfigData.data.value!)
}
const publicConfigData = await useFetch('/api/config/public', {
method: 'POST'
})
const publicConfig = useState<PublicConfig | null>('publicConfig', () => publicConfigData.data.value!)
const userinfo = useState<User>('userinfo')
await callOnce(async () => {
const { data: res } = await useAsyncData('userinfo', async () => await $fetch('/api/user/settings/get'))
userinfo.value = res.value?.data as any as User
})
memoUpdateEvent.on((event: Memo & { index?: number }) => {
const target = document.querySelector('div[data-radix-scroll-area-viewport]')
if (target) {
target.scrollTop = 0
}
})
useHead({
link: [
{
rel: 'shortcut icon',
type: 'image/png',
href: userinfo.value?.favicon || '/favicon.png',
},
],
style: [
{
innerHTML: userinfo.value?.css || '',
}
],
script: [
{
type: 'text/javascript',
innerHTML: userinfo.value?.js || '',
}
]
})
if (publicConfig.value?.googleRecaptchaSiteKey) {
useHead({
script: [
{
type: 'text/javascript',
src: 'https://recaptcha.net/recaptcha/api.js?render=' + publicConfig.value?.googleRecaptchaSiteKey
}
]
})
}
</script>
<template>
<div class="wrapper w-full h-full bg-[#f1f5f9] dark:bg-slate-800 rounded-md dark:text-[#C0BEBF]">
<ScrollArea class="h-full" type="hover">
<div class="main lg:w-[567px] mx-auto shadow-2xl bg-white dark:bg-[#181818]">
<HeaderImg />
<slot />
<Footer />
</div>
</ScrollArea>
</div>

<Toaster position="top-center" rich-colors />

</template>

<script setup lang="ts">
import { ScrollArea } from '@/components/ui/scroll-area';
import { Toaster } from '@/components/ui/sonner';
import { memoUpdateEvent } from '~/lib/event';
import type { Memo, PrivateConfig, PublicConfig, User } from '~/lib/types';
const { data } = await useFetch('/api/user/validateToken', {
method: 'POST'
})
if (!data.value?.success) {
const token = useCookie('token')
token.value = undefined
} else {
const privateConfigData = await useFetch('/api/config/private', {
method: 'POST'
})
useState<PrivateConfig | null>('privateConfig', () => privateConfigData.data.value!)
}
const publicConfigData = await useFetch('/api/config/public', {
method: 'POST'
})
const publicConfig = useState<PublicConfig | null>('publicConfig', () => publicConfigData.data.value!)
const userinfo = useState<User>('userinfo')
await callOnce(async () => {
const { data: res } = await useAsyncData('userinfo', async () => await $fetch('/api/user/settings/get'))
userinfo.value = res.value?.data as any as User
})
memoUpdateEvent.on((event: Memo & { index?: number }) => {
const target = document.querySelector('div[data-radix-scroll-area-viewport]')
if (target) {
target.scrollTop = 0
}
})
useHead({
link: [
{
rel: 'shortcut icon',
type: 'image/png',
href: userinfo.value?.favicon || '/favicon.png',
},
// {
// rel: 'stylesheet',
// href: '/css/APlayer.min.css'
// }
],
style: [
{
innerHTML: userinfo.value?.css || '',
}
],
script: [
{
type: 'text/javascript',
innerHTML: userinfo.value?.js || '',
}
]
})
if (publicConfig.value?.googleRecaptchaSiteKey) {
useHead({
script: [
{
type: 'text/javascript',
src: 'https://recaptcha.net/recaptcha/api.js?render=' + publicConfig.value?.googleRecaptchaSiteKey
}
]
})
}
</script>
13 changes: 9 additions & 4 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@ export default defineNuxtConfig({
},
app: {
head: {
style: [
{ src: `https://unpkg.com/aplayer/dist/APlayer.min.css`, type: 'text/css' },
link: [
{ href: `/css/APlayer.min.css`, rel: 'stylesheet' },
],
script: [
{ src: `https://unpkg.com/aplayer/dist/APlayer.min.js`, type: 'text/javascript', async: true, defer: true },
{ src: `https://unpkg.com/@xizeyoupan/meting@latest/dist/Meting.min.js`, type: 'text/javascript', async: true, defer: true },
{ src: `/js/APlayer.min.js`, type: 'text/javascript', async: true, defer: true },
{ src: `/js/Meting.min.js`, type: 'text/javascript', async: true, defer: true },
]
}
},
plugins: [
'~/plugins/meting.ts'
],
vue: {
compilerOptions: {
isCustomElement: (tag:string) => ['meting-js'].includes(tag),
},
}
});
Loading

0 comments on commit 2a47b46

Please sign in to comment.