Skip to content

Commit

Permalink
perf(component): ⚡ 优化组件加载、浏览器指纹生成
Browse files Browse the repository at this point in the history
  • Loading branch information
nongyehong committed Jan 18, 2025
1 parent c188aef commit 31cd2cb
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 199 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@tauri-apps/api": "2.2.0",
"@tauri-apps/plugin-autostart": "2.2.0",
"@tauri-apps/plugin-clipboard-manager": "2.2.0",
"@tauri-apps/plugin-dialog": "^2.2.0",
"@tauri-apps/plugin-fs": "~2.2.0",
"@tauri-apps/plugin-http": "2.2.0",
"@tauri-apps/plugin-notification": "^2.2.0",
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hula"
version = "2.6.0"
version = "2.6.1"
description = "hula"
authors = ["nongyehong"]
license = ""
Expand Down
1 change: 1 addition & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "HuLa",
"version": "2.6.1",
"identifier": "com.hula.pc",
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/InfoPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</div>

<p
class="text-(18px [--text-color])"
class="text-(18px [--chat-text-color])"

Check warning on line 32 in src/components/common/InfoPopover.vue

View check run for this annotation

Codecov / codecov/patch

src/components/common/InfoPopover.vue#L32

Added line #L32 was not covered by tests
style="
font-weight: bold !important;
font-family:
Expand Down
9 changes: 9 additions & 0 deletions src/components/common/LoadingSpinner.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>

Check warning on line 1 in src/components/common/LoadingSpinner.vue

View check run for this annotation

Codecov / codecov/patch

src/components/common/LoadingSpinner.vue#L1

Added line #L1 was not covered by tests
<div class="flex-center h-full">
<n-spin size="large" />

Check warning on line 3 in src/components/common/LoadingSpinner.vue

View check run for this annotation

Codecov / codecov/patch

src/components/common/LoadingSpinner.vue#L3

Added line #L3 was not covered by tests
</div>
</template>

<script setup lang="ts"></script>

<style scoped></style>
62 changes: 55 additions & 7 deletions src/layout/index.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
<template>
<div id="layout" class="flex size-full min-w-310px bg-[--right-bg-color]">
<Left />
<Center />
<Right v-if="!shrinkStatus" />
<Suspense>
<template #default>
<div class="flex size-full">
<!-- 使用keep-alive包裹异步组件 -->
<keep-alive>
<AsyncLeft />
</keep-alive>
<keep-alive>
<AsyncCenter />
</keep-alive>
<keep-alive>
<AsyncRight v-if="!shrinkStatus" />
</keep-alive>
</div>

Check warning on line 16 in src/layout/index.vue

View check run for this annotation

Codecov / codecov/patch

src/layout/index.vue#L3-L16

Added lines #L3 - L16 were not covered by tests
</template>
<template #fallback>
<div class="flex items-center justify-center size-full">
<LoadingSpinner />
</div>

Check warning on line 21 in src/layout/index.vue

View check run for this annotation

Codecov / codecov/patch

src/layout/index.vue#L18-L21

Added lines #L18 - L21 were not covered by tests
</template>
</Suspense>

Check warning on line 23 in src/layout/index.vue

View check run for this annotation

Codecov / codecov/patch

src/layout/index.vue#L23

Added line #L23 was not covered by tests
</div>

<AddFriendsModal />
<!-- 模态框也可以缓存 -->
<keep-alive>
<AsyncAddFriendsModal />
</keep-alive>

Check warning on line 29 in src/layout/index.vue

View check run for this annotation

Codecov / codecov/patch

src/layout/index.vue#L26-L29

Added lines #L26 - L29 were not covered by tests
</template>

<script setup lang="ts">
import Center from './center/index.vue'
import Left from './left/index.vue'
import Right from './right/index.vue'
import LoadingSpinner from '@/components/common/LoadingSpinner.vue'

Check warning on line 33 in src/layout/index.vue

View check run for this annotation

Codecov / codecov/patch

src/layout/index.vue#L33

Added line #L33 was not covered by tests
import { useMitt } from '@/hooks/useMitt.ts'
import { ChangeTypeEnum, MittEnum, OnlineEnum, RoomTypeEnum } from '@/enums'
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'
Expand All @@ -29,6 +48,34 @@ import { isPermissionGranted, requestPermission, sendNotification } from '@tauri
import { useUserInfo } from '@/hooks/useCached.ts'
import { emitTo } from '@tauri-apps/api/event'
import { useThrottleFn } from '@vueuse/core'
import apis from '@/services/apis.ts'
import { confirm } from '@tauri-apps/plugin-dialog'

Check warning on line 52 in src/layout/index.vue

View check run for this annotation

Codecov / codecov/patch

src/layout/index.vue#L51-L52

Added lines #L51 - L52 were not covered by tests
// 异步加载组件时增加缓存配置
const AsyncLeft = defineAsyncComponent({
loader: async () => await import('./left/index.vue'),
delay: 600,
timeout: 3000
})

Check warning on line 59 in src/layout/index.vue

View check run for this annotation

Codecov / codecov/patch

src/layout/index.vue#L55-L59

Added lines #L55 - L59 were not covered by tests
// 其他异步组件也类似配置
const AsyncCenter = defineAsyncComponent({
loader: async () => await import('./center/index.vue'),
delay: 600,
timeout: 3000
})

Check warning on line 66 in src/layout/index.vue

View check run for this annotation

Codecov / codecov/patch

src/layout/index.vue#L62-L66

Added lines #L62 - L66 were not covered by tests
const AsyncRight = defineAsyncComponent({
loader: async () => await import('./right/index.vue'),
delay: 600,
timeout: 3000
})

Check warning on line 72 in src/layout/index.vue

View check run for this annotation

Codecov / codecov/patch

src/layout/index.vue#L68-L72

Added lines #L68 - L72 were not covered by tests
const AsyncAddFriendsModal = defineAsyncComponent({
loader: async () => await import('@/components/common/AddFriendsModal.vue'),
delay: 600,
timeout: 3000
})

Check warning on line 78 in src/layout/index.vue

View check run for this annotation

Codecov / codecov/patch

src/layout/index.vue#L74-L78

Added lines #L74 - L78 were not covered by tests
const globalStore = useGlobalStore()
const contactStore = useContactStore()
Expand Down Expand Up @@ -81,6 +128,7 @@ useMitt.on(WsResponseMessageType.TOKEN_EXPIRED, async (wsTokenExpire: WsTokenExp
await confirm('新设备已在' + (wsTokenExpire.ip ? wsTokenExpire.ip : '未知IP') + '登录')
// token已在后端清空,只需要返回登录页
await logout()
await apis.logout()

Check warning on line 131 in src/layout/index.vue

View check run for this annotation

Codecov / codecov/patch

src/layout/index.vue#L131

Added line #L131 was not covered by tests
userStore.isSign = false
userStore.userInfo = {}
localStorage.removeItem('user')
Expand Down
2 changes: 1 addition & 1 deletion src/layout/left/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const moreList = ref<OPT.L.MoreList[]>([
isSign: false
})
// 后端发布下线通知同时清除token
await apis.logout().catch(() => {})
await apis.logout()

Check warning on line 105 in src/layout/left/config.tsx

View check run for this annotation

Codecov / codecov/patch

src/layout/left/config.tsx#L105

Added line #L105 was not covered by tests
await logout()
// 如果没有设置自动登录,则清除用户信息
userStore.userInfo = {}
Expand Down
3 changes: 2 additions & 1 deletion src/layout/left/model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { relaunch } from '@tauri-apps/plugin-process'
import { useUserStore } from '@/stores/user.ts'
import { useSettingStore } from '@/stores/setting.ts'
import { AvatarUtils } from '@/utils/avatarUtils.ts'
import { confirm } from '@tauri-apps/plugin-dialog'

Check warning on line 28 in src/layout/left/model.tsx

View check run for this annotation

Codecov / codecov/patch

src/layout/left/model.tsx#L28

Added line #L28 was not covered by tests

const formRef = ref<FormInst | null>()
const formValue = ref({
Expand Down Expand Up @@ -192,7 +193,7 @@ export const CheckUpdate = defineComponent(() => {
}

const handleUpdate = async () => {
if (!(await window.confirm('确定更新吗'))) {
if (!(await confirm('确定更新吗'))) {

Check warning on line 196 in src/layout/left/model.tsx

View check run for this annotation

Codecov / codecov/patch

src/layout/left/model.tsx#L196

Added line #L196 was not covered by tests
return
}
text.value = '正在下载...'
Expand Down
Loading

0 comments on commit 31cd2cb

Please sign in to comment.