refactor: ♻️ 代码优化

This commit is contained in:
ray
2025-10-04 15:44:24 +08:00
parent f655954c99
commit 10c8b9fc75
14 changed files with 39 additions and 17 deletions

5
components.d.ts vendored
View File

@@ -24,8 +24,8 @@ declare module 'vue' {
WdCollapse: typeof import('wot-design-uni/components/wd-collapse/wd-collapse.vue')['default']
WdCollapseItem: typeof import('wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue')['default']
WdConfigProvider: typeof import('wot-design-uni/components/wd-config-provider/wd-config-provider.vue')['default']
WdDivider: typeof import('wot-design-uni/components/wd-divider/wd-divider.vue')['default']
WdForm: typeof import('wot-design-uni/components/wd-form/wd-form.vue')['default']
WdFormItem: typeof import('wot-design-uni/components/wd-form-item/wd-form-item.vue')['default']
WdGrid: typeof import('wot-design-uni/components/wd-grid/wd-grid.vue')['default']
WdGridItem: typeof import('wot-design-uni/components/wd-grid-item/wd-grid-item.vue')['default']
WdIcon: typeof import('wot-design-uni/components/wd-icon/wd-icon.vue')['default']
@@ -46,6 +46,9 @@ declare module 'vue' {
WdTabbar: typeof import('wot-design-uni/components/wd-tabbar/wd-tabbar.vue')['default']
WdTabbarItem: typeof import('wot-design-uni/components/wd-tabbar-item/wd-tabbar-item.vue')['default']
WdTag: typeof import('wot-design-uni/components/wd-tag/wd-tag.vue')['default']
WdText: typeof import('wot-design-uni/components/wd-text/wd-text.vue')['default']
WdTextarea: typeof import('wot-design-uni/components/wd-textarea/wd-textarea.vue')['default']
WdToast: typeof import('wot-design-uni/components/wd-toast/wd-toast.vue')['default']
WdUpload: typeof import('wot-design-uni/components/wd-upload/wd-upload.vue')['default']
}
}

View File

@@ -91,7 +91,7 @@
"@dcloudio/uni-mp-xhs": "3.0.0-4020420240722002",
"@dcloudio/uni-quickapp-webview": "3.0.0-4020420240722002",
"@stomp/stompjs": "^7.1.1",
"@uni-helper/uni-use": "^0.19.14",
"@uni-helper/uni-use": "^0.19.15",
"@vueuse/core": "9.13.0",
"pinia": "^2.2.2",
"vue": "^3.5.13",

View File

@@ -1,6 +1,6 @@
import type { ThemeColorOption, ThemeMode } from "@/composables/types/theme";
import { themeColorOptions } from "@/composables/types/theme";
import { useThemeStore } from "@/store/modules/theme.store";
import { useThemeStore } from "@/store";
export function useTheme() {
const store = useThemeStore();

View File

@@ -13,3 +13,7 @@ export const REFRESH_TOKEN_KEY = "refresh_token";
// 📊 用户缓存相关
export const USER_INFO_KEY = "user_info";
// 🎨 主题相关
export const THEME_MODE_KEY = "app-theme";
export const THEME_COLOR_KEY = "app-theme-color";

View File

@@ -12,6 +12,7 @@
{
"path": "pages/login/index",
"type": "page",
"name": "login",
"style": {
"navigationStyle": "custom"
}

View File

@@ -105,10 +105,17 @@
</view>
</template>
<route lang="json">
{
"name": "login",
"style": { "navigationStyle": "custom" }
}
</route>
<script lang="ts" setup>
import { onLoad } from "@dcloudio/uni-app";
import { type LoginData } from "@/api/auth";
import { useUserStore } from "@/store/modules/user.store";
import { useUserStore } from "@/store/modules/user-store";
import { useToast } from "wot-design-uni";
import { useWechat } from "@/composables/useWechat";

View File

@@ -155,7 +155,7 @@
import { ref, reactive, computed } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { useToast } from "wot-design-uni";
import { useUserStore } from "@/store/modules/user.store";
import { useUserStore } from "@/store";
import UserAPI, { type UserProfileForm } from "@/api/user";
import FileAPI, { type FileInfo } from "@/api/file";

View File

@@ -41,7 +41,7 @@
</template>
<script lang="ts" setup>
import { useUserStore } from "@/store/modules/user.store";
import { useUserStore } from "@/store";
import { checkLogin } from "@/utils/auth";
import { onLoad } from "@dcloudio/uni-app";

View File

@@ -8,6 +8,6 @@ export function setupStore(app: App<Element>) {
app.use(store);
}
export * from "./modules/user.store";
export * from "./modules/theme.store";
export * from "./modules/user-store";
export * from "./modules/theme-store";
export { store };

View File

@@ -1,11 +1,14 @@
import { defineStore } from "pinia";
import { useStorage } from "@uni-helper/uni-use";
import { Storage } from "@/utils/storage";
import { THEME_MODE_KEY, THEME_COLOR_KEY } from "@/constants";
import type { ThemeColorOption, ThemeMode } from "@/composables/types/theme";
import { themeColorOptions } from "@/composables/types/theme";
export const useThemeStore = defineStore("theme", () => {
const theme = useStorage<ThemeMode>("app-theme", "light");
const currentThemeColor = useStorage<ThemeColorOption>("app-theme-color", themeColorOptions[0]);
const theme = ref<ThemeMode>(Storage.get<ThemeMode>(THEME_MODE_KEY, "light"));
const currentThemeColor = ref<ThemeColorOption>(
Storage.get<ThemeColorOption>(THEME_COLOR_KEY, themeColorOptions[0])
);
// 主题变量(响应式对象)
const themeVars = reactive({
@@ -40,6 +43,7 @@ export const useThemeStore = defineStore("theme", () => {
*/
const toggleTheme = (mode?: ThemeMode) => {
theme.value = mode || (theme.value === "light" ? "dark" : "light");
Storage.set(THEME_MODE_KEY, theme.value);
setNavigationBarColor();
};
@@ -49,6 +53,7 @@ export const useThemeStore = defineStore("theme", () => {
*/
const setCurrentThemeColor = (color: ThemeColorOption) => {
currentThemeColor.value = color;
Storage.set(THEME_COLOR_KEY, color);
themeVars.colorTheme = color.primary;
console.log("主题色已设置:", color.name);
};

View File

@@ -174,10 +174,10 @@ declare global {
const useTabbar: typeof import('../composables/useTabbar')['useTabbar']
const useTemplateRef: typeof import('vue')['useTemplateRef']
const useTheme: typeof import('../composables/useTheme')['useTheme']
const useThemeStore: typeof import('../store/modules/theme.store')['useThemeStore']
const useThemeStore: typeof import('../store/modules/theme-store')['useThemeStore']
const useToast: typeof import('wot-design-uni')['useToast']
const useUploadFile: typeof import('@uni-helper/uni-use')['useUploadFile']
const useUserStore: typeof import('../store/modules/user.store')['useUserStore']
const useUserStore: typeof import('../store/modules/user-store')['useUserStore']
const useVisible: typeof import('@uni-helper/uni-use')['useVisible']
const useWechat: typeof import('../composables/useWechat')['useWechat']
const user: typeof import('../api/user')['default']
@@ -317,9 +317,9 @@ declare module 'vue' {
readonly useTabbar: UnwrapRef<typeof import('../composables/useTabbar')['useTabbar']>
readonly useTemplateRef: UnwrapRef<typeof import('vue')['useTemplateRef']>
readonly useTheme: UnwrapRef<typeof import('../composables/useTheme')['useTheme']>
readonly useThemeStore: UnwrapRef<typeof import('../store/modules/theme.store')['useThemeStore']>
readonly useThemeStore: UnwrapRef<typeof import('../store/modules/theme-store')['useThemeStore']>
readonly useToast: UnwrapRef<typeof import('wot-design-uni')['useToast']>
readonly useUserStore: UnwrapRef<typeof import('../store/modules/user.store')['useUserStore']>
readonly useUserStore: UnwrapRef<typeof import('../store/modules/user-store')['useUserStore']>
readonly useWechat: UnwrapRef<typeof import('../composables/useWechat')['useWechat']>
readonly user: UnwrapRef<typeof import('../api/user')['default']>
readonly watch: UnwrapRef<typeof import('vue')['watch']>

View File

@@ -1,4 +1,4 @@
import { useUserStore } from "@/store/modules/user.store";
import { useUserStore } from "@/store/modules/user-store";
import { Storage } from "./storage";
import { ACCESS_TOKEN_KEY, REFRESH_TOKEN_KEY } from "@/constants";

View File

@@ -33,7 +33,7 @@ export const Storage = {
};
// 为了向后兼容,导出具体的函数
import { ACCESS_TOKEN_KEY, USER_INFO_KEY } from "@/constants";
import { ACCESS_TOKEN_KEY, USER_INFO_KEY, THEME_MODE_KEY, THEME_COLOR_KEY } from "@/constants";
/**
* 获取令牌
@@ -69,4 +69,6 @@ export function setUserInfo(userInfo: any): void {
export function clearAll(): void {
Storage.remove(ACCESS_TOKEN_KEY);
Storage.remove(USER_INFO_KEY);
Storage.remove(THEME_MODE_KEY);
Storage.remove(THEME_COLOR_KEY);
}