Compare commits
4 Commits
be50b1cc5f
...
ef061006a0
Author | SHA1 | Date | |
---|---|---|---|
ef061006a0 | |||
d0039feaf9 | |||
a2736a6385 | |||
7efa425c85 |
3
app.vue
3
app.vue
@ -1,7 +1,8 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const loading = ref<HTMLDivElement | null>(null)
|
const loading = ref<HTMLDivElement | null>(null)
|
||||||
|
const {$mitt} = useNuxtApp()
|
||||||
|
|
||||||
emitter.on('startLoading', on => {
|
$mitt.on('startLoading', on => {
|
||||||
if (on) {
|
if (on) {
|
||||||
loading.value?.classList.remove('stop')
|
loading.value?.classList.remove('stop')
|
||||||
removeMobileTopColor()
|
removeMobileTopColor()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
const {$mitt} = useNuxtApp()
|
||||||
const notifications = ref<INotification[]>([]);
|
const notifications = ref<INotification[]>([]);
|
||||||
|
|
||||||
const typeClasses = {
|
const typeClasses = {
|
||||||
success: 'bg-green-100 text-green-800 border border-green-400',
|
success: 'bg-green-100 text-green-800 border border-green-400',
|
||||||
error: 'bg-red-100 text-red-800 border border-red-400',
|
error: 'bg-red-100 text-red-800 border border-red-400',
|
||||||
@ -19,10 +19,10 @@ const addNotification = (notification: INotification) => {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
emitter.on('eventBus', addNotification)
|
$mitt.on('eventBus', addNotification)
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
emitter.off('eventBus', addNotification);
|
$mitt.off('eventBus', addNotification);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -5,13 +5,11 @@ const props = defineProps<{
|
|||||||
post: IPost
|
post: IPost
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const thumbUrl = computed(() => {
|
const pid = useAsyncData('pid', async () => (Math.floor(Math.random() * (7 - 1 + 1)) + 1).toString())
|
||||||
// 如果文章缩略图为空,则从本地随机获取默认缩略图
|
|
||||||
props.post.fields.thumb.value = props.post.fields.thumb.value ? props.post.fields.thumb.value : getAssetURL(
|
const thumbUrl = computed(() => props.post.fields.thumb.value)
|
||||||
`common/${Math.floor(Math.random() * (7 - 1 + 1)) + 1}.jpg`
|
|
||||||
)
|
const randomId = computed(() => pid.data.value!)
|
||||||
return props.post.fields.thumb.value
|
|
||||||
})
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -21,8 +19,9 @@ const thumbUrl = computed(() => {
|
|||||||
:to="{name: 'article-cid', params: {cid: post.cid}}">
|
:to="{name: 'article-cid', params: {cid: post.cid}}">
|
||||||
<!-- 图片 -->
|
<!-- 图片 -->
|
||||||
<div class="container h-full">
|
<div class="container h-full">
|
||||||
<img :src="thumbUrl" alt=""
|
<img v-if="thumbUrl" :src="thumbUrl" alt=""
|
||||||
class="h-full w-full object-cover object-center transition-all duration-300 hover:scale-110">
|
class="h-full w-full object-cover object-center transition-all duration-300 hover:scale-110">
|
||||||
|
<card-article-default-image :id="randomId"/>
|
||||||
</div>
|
</div>
|
||||||
<!-- 文字部分 -->
|
<!-- 文字部分 -->
|
||||||
<div class="container relative">
|
<div class="container relative">
|
||||||
|
21
components/card/ArticleDefaultImage.vue
Normal file
21
components/card/ArticleDefaultImage.vue
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{
|
||||||
|
id: string
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<img src="~/assets/images/common/1.jpg" alt="" v-if="id === '1'"/>
|
||||||
|
<img src="~/assets/images/common/2.jpg" alt="" v-else-if="id === '2'"/>
|
||||||
|
<img src="~/assets/images/common/3.jpg" alt="" v-else-if="id === '3'"/>
|
||||||
|
<img src="~/assets/images/common/4.jpg" alt="" v-else-if="id === '4'"/>
|
||||||
|
<img src="~/assets/images/common/5.jpg" alt="" v-else-if="id === '5'"/>
|
||||||
|
<img src="~/assets/images/common/6.jpg" alt="" v-else-if="id === '6'"/>
|
||||||
|
<img src="~/assets/images/common/7.jpg" alt="" v-else-if="id === '7'"/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
img {
|
||||||
|
@apply h-full w-full object-cover object-center transition-all duration-300 hover:scale-110
|
||||||
|
}
|
||||||
|
</style>
|
@ -11,11 +11,9 @@ defineProps<{
|
|||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.markdown-body {
|
.markdown-body {
|
||||||
.MathJax {
|
font-family: "LXGW WenKai", sans-serif;
|
||||||
* {
|
|
||||||
font-family: "LXGW WenKai", sans-serif !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
.MathJax {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
import mitt from 'mitt'
|
|
||||||
|
|
||||||
type Events = {
|
|
||||||
openPost: IPost
|
|
||||||
startLoading: boolean
|
|
||||||
eventBus: INotification
|
|
||||||
}
|
|
||||||
|
|
||||||
const emitter = mitt<Events>()
|
|
||||||
export default emitter
|
|
@ -2,6 +2,7 @@ import type { AsyncData, UseFetchOptions } from '#app'
|
|||||||
|
|
||||||
export function requestCore<DataT>(url: string, options: UseFetchOptions<DataT>) {
|
export function requestCore<DataT>(url: string, options: UseFetchOptions<DataT>) {
|
||||||
// const config = useRuntimeConfig()
|
// const config = useRuntimeConfig()
|
||||||
|
const {$mitt} = useNuxtApp()
|
||||||
return useFetch(url, {
|
return useFetch(url, {
|
||||||
baseURL: "https://cantyonion.site",
|
baseURL: "https://cantyonion.site",
|
||||||
retry: false,
|
retry: false,
|
||||||
@ -25,7 +26,7 @@ export function requestCore<DataT>(url: string, options: UseFetchOptions<DataT>)
|
|||||||
// }
|
// }
|
||||||
},
|
},
|
||||||
onResponseError({ response }) {
|
onResponseError({ response }) {
|
||||||
emitter.emit('eventBus', {
|
$mitt.emit('eventBus', {
|
||||||
level: 'error',
|
level: 'error',
|
||||||
title: `HTTP错误:${response.status}`,
|
title: `HTTP错误:${response.status}`,
|
||||||
message: response.statusText
|
message: response.statusText
|
||||||
|
10
error.vue
10
error.vue
@ -1,10 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { NuxtError } from '#app'
|
import type { NuxtError } from '#app'
|
||||||
|
import { setMobileTopColor } from '~/composables/function'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
error: Object as () => NuxtError
|
error: Object as () => NuxtError
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const {$mitt} = useNuxtApp()
|
||||||
|
|
||||||
const errorMessages: Record<string, { icon: string; title: string; message: string }> = {
|
const errorMessages: Record<string, { icon: string; title: string; message: string }> = {
|
||||||
'400': {
|
'400': {
|
||||||
icon: '❓',
|
icon: '❓',
|
||||||
@ -42,7 +45,12 @@ const errorContent = computed(() => errorMessages[props.error!.statusCode] || er
|
|||||||
console.error(props.error)
|
console.error(props.error)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
emitter.emit("startLoading", false)
|
$mitt.emit("startLoading", false)
|
||||||
|
setMobileTopColor()
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
removeMobileTopColor()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ export default defineNuxtConfig({
|
|||||||
components: true,
|
components: true,
|
||||||
css: [
|
css: [
|
||||||
'@fortawesome/fontawesome-svg-core/styles.css',
|
'@fortawesome/fontawesome-svg-core/styles.css',
|
||||||
'github-markdown-css/github-markdown.css',
|
'github-markdown-css/github-markdown-light.css',
|
||||||
'~/assets/css/main.scss'
|
'~/assets/css/main.scss'
|
||||||
],
|
],
|
||||||
postcss: {
|
postcss: {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
const {$mitt} = useNuxtApp()
|
||||||
|
|
||||||
onMounted( () => {
|
onMounted( () => {
|
||||||
emitter.emit('startLoading', false)
|
$mitt.emit('startLoading', false)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
const {$mitt} = useNuxtApp()
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
emitter.emit("startLoading", false)
|
$mitt.emit("startLoading", false)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import {computed, onMounted, ref} from "vue";
|
import {computed, onMounted, ref} from "vue";
|
||||||
|
|
||||||
|
const {$mitt} = useNuxtApp()
|
||||||
const recentPosts = ref<IPost[] | null>(null);
|
const recentPosts = ref<IPost[] | null>(null);
|
||||||
const recentActivities = ref<IActivity[] | null>(null);
|
const recentActivities = ref<IActivity[] | null>(null);
|
||||||
const isLoading = ref({
|
const isLoading = ref({
|
||||||
@ -76,7 +77,7 @@ await reloadPosts()
|
|||||||
await reloadActivities()
|
await reloadActivities()
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
emitter.emit('startLoading', false)
|
$mitt.emit('startLoading', false)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
19
plugins/mitt.ts
Normal file
19
plugins/mitt.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import mitt from 'mitt'
|
||||||
|
|
||||||
|
type Events = {
|
||||||
|
openPost: IPost
|
||||||
|
startLoading: boolean
|
||||||
|
eventBus: INotification
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export default defineNuxtPlugin(() => {
|
||||||
|
const emitter = mitt<Events>()
|
||||||
|
|
||||||
|
return {
|
||||||
|
provide: {
|
||||||
|
mitt: emitter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user