refactor(components): 优化组件配置和主题处理逻辑

重构vite组件配置,添加自定义组件路径和类型声明文件
修复主题变量处理逻辑,添加默认值防止undefined错误
移动组件类型声明文件到src/types目录
This commit is contained in:
zhangtao
2025-10-08 04:51:24 +08:00
parent b4cb1d6cfc
commit a07d0658e6
4 changed files with 21 additions and 15 deletions
+2 -1
View File
@@ -113,10 +113,11 @@ import { useUserStore } from "@/store";
import { useToast } from "wot-design-uni";
import AuthAPI, { type LoginFormData, type CaptchaInfo } from "@/api/auth";
import { useThemeStore } from "@/store/modules/theme.store";
import { computed, ref, reactive } from "vue";
// 主题相关
const themeStore = useThemeStore();
const themeVars = themeStore.themeVars;
const themeVars = computed(() => themeStore.themeVars || { darkColor3: '#a0a0a0', colorTheme: '#4D7FFF' });
const loginFormRef = ref();
const toast = useToast();
+5 -4
View File
@@ -9,7 +9,7 @@
</view>
<view class="user-details">
<block v-if="isLogin">
<view class="nickname theme-text-primary">{{ userInfo!.name || "匿名用户" }}</view>
<view class="nickname theme-text-primary">{{ userInfo?.name || "匿名用户" }}</view>
<view class="user-id theme-text-secondary">ID: {{ userInfo?.username || "0000000" }}</view>
</block>
<block v-else>
@@ -152,7 +152,8 @@ const toast = useToast();
const userStore = useUserStore();
const themeStore = useThemeStore();
const themeVars = computed(() => themeStore.themeVars);
const currentThemeColor = computed(() => themeStore.currentThemeColor);
// 修复: 直接返回主题色对象,确保可以访问primary属性
const currentThemeColor = computed(() => themeStore.currentThemeColor || { primary: '#4D7FFF' });
// 强制重新渲染的key
const renderKey = ref(0);
@@ -164,8 +165,8 @@ const isLoading = ref(false);
const router = useRouter();
// 监听主题色变化
const handleThemeColorChange = (color: string) => {
// 监听主题色变化 - 使用下划线前缀标记未使用的参数
const handleThemeColorChange = (_color: string) => {
renderKey.value++;
};
+55
View File
@@ -0,0 +1,55 @@
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// Generated by vite-plugin-uni-components
// Read more: https://github.com/vuejs/core/pull/3399
export {}
declare module 'vue' {
export interface GlobalComponents {
CuDateQuery: typeof import('./../components/cu-date-query/index.vue')['default']
CuPicker: typeof import('./../components/cu-picker/index.vue')['default']
Loading1: typeof import('./../components/qiun-loading/loading1.vue')['default']
Loading2: typeof import('./../components/qiun-loading/loading2.vue')['default']
Loading3: typeof import('./../components/qiun-loading/loading3.vue')['default']
Loading4: typeof import('./../components/qiun-loading/loading4.vue')['default']
Loading5: typeof import('./../components/qiun-loading/loading5.vue')['default']
QiunDataCharts: typeof import('./../components/qiun-data-charts/qiun-data-charts.vue')['default']
QiunError: typeof import('./../components/qiun-error/qiun-error.vue')['default']
QiunLoading: typeof import('./../components/qiun-loading/qiun-loading.vue')['default']
WdBadge: typeof import('wot-design-uni/components/wd-badge/wd-badge.vue')['default']
WdButton: typeof import('wot-design-uni/components/wd-button/wd-button.vue')['default']
WdCard: typeof import('wot-design-uni/components/wd-card/wd-card.vue')['default']
WdCell: typeof import('wot-design-uni/components/wd-cell/wd-cell.vue')['default']
WdCellGroup: typeof import('wot-design-uni/components/wd-cell-group/wd-cell-group.vue')['default']
WdCheckbox: typeof import('wot-design-uni/components/wd-checkbox/wd-checkbox.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']
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']
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']
WdImg: typeof import('wot-design-uni/components/wd-img/wd-img.vue')['default']
WdImgCropper: typeof import('wot-design-uni/components/wd-img-cropper/wd-img-cropper.vue')['default']
WdInput: typeof import('wot-design-uni/components/wd-input/wd-input.vue')['default']
WdLoading: typeof import('wot-design-uni/components/wd-loading/wd-loading.vue')['default']
WdMessageBox: typeof import('wot-design-uni/components/wd-message-box/wd-message-box.vue')['default']
WdNoticeBar: typeof import('wot-design-uni/components/wd-notice-bar/wd-notice-bar.vue')['default']
WdNotify: typeof import('wot-design-uni/components/wd-notify/wd-notify.vue')['default']
WdPopup: typeof import('wot-design-uni/components/wd-popup/wd-popup.vue')['default']
WdProgress: typeof import('wot-design-uni/components/wd-progress/wd-progress.vue')['default']
WdRadio: typeof import('wot-design-uni/components/wd-radio/wd-radio.vue')['default']
WdRadioGroup: typeof import('wot-design-uni/components/wd-radio-group/wd-radio-group.vue')['default']
WdSwiper: typeof import('wot-design-uni/components/wd-swiper/wd-swiper.vue')['default']
WdSwitch: typeof import('wot-design-uni/components/wd-switch/wd-switch.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']
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']
}
}