fix: 清理掉了所有warn,优化了在移动端侧边栏的逻辑问题

This commit is contained in:
AnNingUI
2025-08-12 20:36:00 +08:00
parent a6874e9be3
commit 82475f71db
9 changed files with 46 additions and 30 deletions

View File

@@ -48,8 +48,16 @@ export default {
}
})
const handleMenuOutside = () => {
if (isMobile.value) menuVisible.value = false
const handleMenuOutside = (event) => {
// 检查点击事件是否来自菜单按钮
const menuBtn = document.querySelector('.menu-btn')
if (menuBtn && (menuBtn === event.target || menuBtn.contains(event.target))) {
return // 如果是菜单按钮的点击,不处理关闭
}
if (isMobile.value) {
menuVisible.value = false
}
}
return { menuVisible, hideMenu, handleMenuOutside }

View File

@@ -43,4 +43,9 @@ export default defineNuxtConfig({
],
},
},
vue: {
compilerOptions: {
isCustomElement: (tag) => ['l-hatch', 'l-hatch-spinner'].includes(tag),
},
},
})

View File

@@ -249,6 +249,7 @@ import TimeManager from '~/utils/time'
import { useRouter } from 'vue-router'
import { useIsMobile } from '~/utils/screen'
import Dropdown from '~/components/Dropdown.vue'
import { ClientOnly } from '#components'
export default {
name: 'PostPageView',
@@ -262,6 +263,7 @@ export default {
DropdownMenu,
VueEasyLightbox,
Dropdown,
ClientOnly,
},
async setup() {
const route = useRoute()

View File

@@ -297,27 +297,26 @@
</template>
<script>
import { ref, computed, onMounted, watch } from 'vue'
import { computed, onMounted, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { API_BASE_URL, toast } from '~/main'
import { getToken, authState } from '~/utils/auth'
import BaseTimeline from '~/components/BaseTimeline.vue'
import UserList from '~/components/UserList.vue'
import AchievementList from '~/components/AchievementList.vue'
import BasePlaceholder from '~/components/BasePlaceholder.vue'
import BaseTimeline from '~/components/BaseTimeline.vue'
import LevelProgress from '~/components/LevelProgress.vue'
import UserList from '~/components/UserList.vue'
import { API_BASE_URL, toast } from '~/main'
import { authState, getToken } from '~/utils/auth'
import { prevLevelExp } from '~/utils/level'
import { stripMarkdown, stripMarkdownLength } from '~/utils/markdown'
import TimeManager from '~/utils/time'
import { prevLevelExp } from '~/utils/level'
import AchievementList from '~/components/AchievementList.vue'
definePageMeta({
alias: ['/users/:id/'],
})
export default {
name: 'ProfileView',
components: { BaseTimeline, UserList, BasePlaceholder, LevelProgress, AchievementList },
setup() {
definePageMeta({
alias: ['/users/:id/'],
})
const route = useRoute()
const router = useRouter()
const username = route.params.id

View File

@@ -1,5 +1,5 @@
// plugins/ldrs.client.ts
import { defineNuxtPlugin } from '#app'
import { defineNuxtPlugin } from 'nuxt/app'
export default defineNuxtPlugin(async () => {
// 动态引入,防止打包时把 ldrs 拉进 SSR bundle

View File

@@ -1,5 +1,6 @@
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { defineNuxtPlugin } from 'nuxt/app'
export default defineNuxtPlugin((nuxtApp) => {
NProgress.configure({ showSpinner: false })
@@ -12,7 +13,7 @@ export default defineNuxtPlugin((nuxtApp) => {
NProgress.done()
})
nuxtApp.hook('page:error', () => {
nuxtApp.hook('app:error', () => {
NProgress.done()
})
})

View File

@@ -1,4 +1,4 @@
import { defineNuxtPlugin } from '#app'
import { defineNuxtPlugin } from 'nuxt/app'
import { initTheme } from '~/utils/theme'
export default defineNuxtPlugin(() => {

View File

@@ -1,4 +1,4 @@
import { defineNuxtPlugin } from '#app'
import { defineNuxtPlugin } from 'nuxt/app'
import 'vue-toastification/dist/index.css'
import '~/assets/toast.css'

View File

@@ -1,6 +1,6 @@
import MarkdownIt from 'markdown-it'
import hljs from 'highlight.js'
import 'highlight.js/styles/github.css'
import MarkdownIt from 'markdown-it'
import { toast } from '../main'
import { tiebaEmoji } from './tiebaEmoji'
@@ -86,18 +86,19 @@ export function handleMarkdownClick(e) {
export function stripMarkdown(text) {
const html = md.render(text || '')
// SSR 环境下没有 document
if (typeof window === 'undefined') {
// 用正则去除 HTML 标签
return html
.replace(/<[^>]+>/g, '')
.replace(/\s+/g, ' ')
.trim()
} else {
const el = document.createElement('div')
el.innerHTML = html
return el.textContent || el.innerText || ''
}
// 统一使用正则表达式方法,确保服务端和客户端行为一致
let plainText = html.replace(/<[^>]+>/g, '')
// 标准化空白字符处理
plainText = plainText
.replace(/\r\n/g, '\n') // Windows换行符转为Unix格式
.replace(/\r/g, '\n') // 旧Mac换行符转为Unix格式
.replace(/[ \t]+/g, ' ') // 合并空格和制表符为单个空格
.replace(/\n{3,}/g, '\n\n') // 最多保留两个连续换行(一个空行)
.trim()
return plainText
}
export function stripMarkdownLength(text, length) {