refactor: ♻️ 代码优化
This commit is contained in:
5
components.d.ts
vendored
5
components.d.ts
vendored
@@ -24,8 +24,8 @@ declare module 'vue' {
|
|||||||
WdCollapse: typeof import('wot-design-uni/components/wd-collapse/wd-collapse.vue')['default']
|
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']
|
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']
|
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']
|
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']
|
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']
|
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']
|
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']
|
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']
|
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']
|
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']
|
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']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@
|
|||||||
"@dcloudio/uni-mp-xhs": "3.0.0-4020420240722002",
|
"@dcloudio/uni-mp-xhs": "3.0.0-4020420240722002",
|
||||||
"@dcloudio/uni-quickapp-webview": "3.0.0-4020420240722002",
|
"@dcloudio/uni-quickapp-webview": "3.0.0-4020420240722002",
|
||||||
"@stomp/stompjs": "^7.1.1",
|
"@stomp/stompjs": "^7.1.1",
|
||||||
"@uni-helper/uni-use": "^0.19.14",
|
"@uni-helper/uni-use": "^0.19.15",
|
||||||
"@vueuse/core": "9.13.0",
|
"@vueuse/core": "9.13.0",
|
||||||
"pinia": "^2.2.2",
|
"pinia": "^2.2.2",
|
||||||
"vue": "^3.5.13",
|
"vue": "^3.5.13",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { ThemeColorOption, ThemeMode } from "@/composables/types/theme";
|
import type { ThemeColorOption, ThemeMode } from "@/composables/types/theme";
|
||||||
import { themeColorOptions } from "@/composables/types/theme";
|
import { themeColorOptions } from "@/composables/types/theme";
|
||||||
import { useThemeStore } from "@/store/modules/theme.store";
|
import { useThemeStore } from "@/store";
|
||||||
|
|
||||||
export function useTheme() {
|
export function useTheme() {
|
||||||
const store = useThemeStore();
|
const store = useThemeStore();
|
||||||
|
|||||||
@@ -13,3 +13,7 @@ export const REFRESH_TOKEN_KEY = "refresh_token";
|
|||||||
|
|
||||||
// 📊 用户缓存相关
|
// 📊 用户缓存相关
|
||||||
export const USER_INFO_KEY = "user_info";
|
export const USER_INFO_KEY = "user_info";
|
||||||
|
|
||||||
|
// 🎨 主题相关
|
||||||
|
export const THEME_MODE_KEY = "app-theme";
|
||||||
|
export const THEME_COLOR_KEY = "app-theme-color";
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
{
|
{
|
||||||
"path": "pages/login/index",
|
"path": "pages/login/index",
|
||||||
"type": "page",
|
"type": "page",
|
||||||
|
"name": "login",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationStyle": "custom"
|
"navigationStyle": "custom"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,10 +105,17 @@
|
|||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<route lang="json">
|
||||||
|
{
|
||||||
|
"name": "login",
|
||||||
|
"style": { "navigationStyle": "custom" }
|
||||||
|
}
|
||||||
|
</route>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { onLoad } from "@dcloudio/uni-app";
|
import { onLoad } from "@dcloudio/uni-app";
|
||||||
import { type LoginData } from "@/api/auth";
|
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 { useToast } from "wot-design-uni";
|
||||||
import { useWechat } from "@/composables/useWechat";
|
import { useWechat } from "@/composables/useWechat";
|
||||||
|
|
||||||
|
|||||||
@@ -155,7 +155,7 @@
|
|||||||
import { ref, reactive, computed } from "vue";
|
import { ref, reactive, computed } from "vue";
|
||||||
import { onLoad } from "@dcloudio/uni-app";
|
import { onLoad } from "@dcloudio/uni-app";
|
||||||
import { useToast } from "wot-design-uni";
|
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 UserAPI, { type UserProfileForm } from "@/api/user";
|
||||||
import FileAPI, { type FileInfo } from "@/api/file";
|
import FileAPI, { type FileInfo } from "@/api/file";
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useUserStore } from "@/store/modules/user.store";
|
import { useUserStore } from "@/store";
|
||||||
import { checkLogin } from "@/utils/auth";
|
import { checkLogin } from "@/utils/auth";
|
||||||
import { onLoad } from "@dcloudio/uni-app";
|
import { onLoad } from "@dcloudio/uni-app";
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ export function setupStore(app: App<Element>) {
|
|||||||
app.use(store);
|
app.use(store);
|
||||||
}
|
}
|
||||||
|
|
||||||
export * from "./modules/user.store";
|
export * from "./modules/user-store";
|
||||||
export * from "./modules/theme.store";
|
export * from "./modules/theme-store";
|
||||||
export { store };
|
export { store };
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import { defineStore } from "pinia";
|
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 type { ThemeColorOption, ThemeMode } from "@/composables/types/theme";
|
||||||
import { themeColorOptions } from "@/composables/types/theme";
|
import { themeColorOptions } from "@/composables/types/theme";
|
||||||
|
|
||||||
export const useThemeStore = defineStore("theme", () => {
|
export const useThemeStore = defineStore("theme", () => {
|
||||||
const theme = useStorage<ThemeMode>("app-theme", "light");
|
const theme = ref<ThemeMode>(Storage.get<ThemeMode>(THEME_MODE_KEY, "light"));
|
||||||
const currentThemeColor = useStorage<ThemeColorOption>("app-theme-color", themeColorOptions[0]);
|
const currentThemeColor = ref<ThemeColorOption>(
|
||||||
|
Storage.get<ThemeColorOption>(THEME_COLOR_KEY, themeColorOptions[0])
|
||||||
|
);
|
||||||
|
|
||||||
// 主题变量(响应式对象)
|
// 主题变量(响应式对象)
|
||||||
const themeVars = reactive({
|
const themeVars = reactive({
|
||||||
@@ -40,6 +43,7 @@ export const useThemeStore = defineStore("theme", () => {
|
|||||||
*/
|
*/
|
||||||
const toggleTheme = (mode?: ThemeMode) => {
|
const toggleTheme = (mode?: ThemeMode) => {
|
||||||
theme.value = mode || (theme.value === "light" ? "dark" : "light");
|
theme.value = mode || (theme.value === "light" ? "dark" : "light");
|
||||||
|
Storage.set(THEME_MODE_KEY, theme.value);
|
||||||
setNavigationBarColor();
|
setNavigationBarColor();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -49,6 +53,7 @@ export const useThemeStore = defineStore("theme", () => {
|
|||||||
*/
|
*/
|
||||||
const setCurrentThemeColor = (color: ThemeColorOption) => {
|
const setCurrentThemeColor = (color: ThemeColorOption) => {
|
||||||
currentThemeColor.value = color;
|
currentThemeColor.value = color;
|
||||||
|
Storage.set(THEME_COLOR_KEY, color);
|
||||||
themeVars.colorTheme = color.primary;
|
themeVars.colorTheme = color.primary;
|
||||||
console.log("主题色已设置:", color.name);
|
console.log("主题色已设置:", color.name);
|
||||||
};
|
};
|
||||||
8
src/types/auto-imports.d.ts
vendored
8
src/types/auto-imports.d.ts
vendored
@@ -174,10 +174,10 @@ declare global {
|
|||||||
const useTabbar: typeof import('../composables/useTabbar')['useTabbar']
|
const useTabbar: typeof import('../composables/useTabbar')['useTabbar']
|
||||||
const useTemplateRef: typeof import('vue')['useTemplateRef']
|
const useTemplateRef: typeof import('vue')['useTemplateRef']
|
||||||
const useTheme: typeof import('../composables/useTheme')['useTheme']
|
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 useToast: typeof import('wot-design-uni')['useToast']
|
||||||
const useUploadFile: typeof import('@uni-helper/uni-use')['useUploadFile']
|
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 useVisible: typeof import('@uni-helper/uni-use')['useVisible']
|
||||||
const useWechat: typeof import('../composables/useWechat')['useWechat']
|
const useWechat: typeof import('../composables/useWechat')['useWechat']
|
||||||
const user: typeof import('../api/user')['default']
|
const user: typeof import('../api/user')['default']
|
||||||
@@ -317,9 +317,9 @@ declare module 'vue' {
|
|||||||
readonly useTabbar: UnwrapRef<typeof import('../composables/useTabbar')['useTabbar']>
|
readonly useTabbar: UnwrapRef<typeof import('../composables/useTabbar')['useTabbar']>
|
||||||
readonly useTemplateRef: UnwrapRef<typeof import('vue')['useTemplateRef']>
|
readonly useTemplateRef: UnwrapRef<typeof import('vue')['useTemplateRef']>
|
||||||
readonly useTheme: UnwrapRef<typeof import('../composables/useTheme')['useTheme']>
|
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 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 useWechat: UnwrapRef<typeof import('../composables/useWechat')['useWechat']>
|
||||||
readonly user: UnwrapRef<typeof import('../api/user')['default']>
|
readonly user: UnwrapRef<typeof import('../api/user')['default']>
|
||||||
readonly watch: UnwrapRef<typeof import('vue')['watch']>
|
readonly watch: UnwrapRef<typeof import('vue')['watch']>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useUserStore } from "@/store/modules/user.store";
|
import { useUserStore } from "@/store/modules/user-store";
|
||||||
import { Storage } from "./storage";
|
import { Storage } from "./storage";
|
||||||
import { ACCESS_TOKEN_KEY, REFRESH_TOKEN_KEY } from "@/constants";
|
import { ACCESS_TOKEN_KEY, REFRESH_TOKEN_KEY } from "@/constants";
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
export function clearAll(): void {
|
||||||
Storage.remove(ACCESS_TOKEN_KEY);
|
Storage.remove(ACCESS_TOKEN_KEY);
|
||||||
Storage.remove(USER_INFO_KEY);
|
Storage.remove(USER_INFO_KEY);
|
||||||
|
Storage.remove(THEME_MODE_KEY);
|
||||||
|
Storage.remove(THEME_COLOR_KEY);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user