Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(site): add smb design-config support #2599

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/sites/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@opentiny/vue-common": "workspace:~",
"@opentiny/vue-design-aurora": "workspace:~",
"@opentiny/vue-design-saas": "workspace:~",
"@opentiny/vue-design-smb": "workspace:~",
"@opentiny/vue-directive": "workspace:~",
"@opentiny/vue-hooks": "workspace:~",
"@opentiny/vue-icon": "workspace:~",
Expand Down
7 changes: 6 additions & 1 deletion examples/sites/src/tools/useTheme.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { watch, computed } from 'vue'
import { hooks } from '@opentiny/vue-common'
import designSaasConfig from '@opentiny/vue-design-saas'
import designSMBConfig from '@opentiny/vue-design-smb'
import { router } from '@/router'
import { appData } from './appData'
import { THEME_ROUTE_MAP, CURRENT_THEME_KEY, DEFAULT_THEME, AURORA_THEME, SMB_THEME, INFINITY_THEME } from '../const'
Expand Down Expand Up @@ -71,7 +72,11 @@ const designConfig = computed(() => {
if (import.meta.env.VITE_TINY_THEME === 'saas') {
return designSaasConfig
}
return designConfigMap[currentThemeKey.value]
if (router.currentRoute.value.params.theme === 'smb-theme') {
return designSMBConfig
}

return {}
Comment on lines +75 to +79
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve theme configuration fallback logic

The current implementation has several potential issues:

  1. Direct URL parameter check ('smb-theme') doesn't align with the SMB_THEME constant
  2. Missing fallback to designConfigMap[currentThemeKey.value]
  3. Empty object fallback could cause unexpected behavior

Consider this improved implementation:

  if (import.meta.env.VITE_TINY_THEME === 'saas') {
    return designSaasConfig
  }
- if (router.currentRoute.value.params.theme === 'smb-theme') {
+ if (router.currentRoute.value.params.theme === THEME_ROUTE_MAP[SMB_THEME]) {
    return designSMBConfig
  }
- return {}
+ return designConfigMap[currentThemeKey.value] || {}

Committable suggestion skipped: line range outside the PR's diff.

})

const changeTheme = (themeKey) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/vue-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ export const setup = ({ props, context, renderless, api, extendOptions = {}, mon
const render = typeof props.tiny_renderless === 'function' ? props.tiny_renderless : renderless

// 获取组件级配置和全局配置(inject需要带有默认值,否则控制台会报警告)
const globalDesignConfig: DesignConfig = customDesignConfig.designConfig || hooks.inject(design.configKey, {})
let globalDesignConfig: DesignConfig = customDesignConfig.designConfig || hooks.inject(design.configKey, {})
// globalDesignConfig 可能是响应式对象,比如 computed
globalDesignConfig = globalDesignConfig.value || globalDesignConfig
const designConfig = globalDesignConfig?.components?.[getComponentName().replace($prefix, '')]

const utils = {
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/src/config-provider/src/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export default defineComponent({
})
},
setup(props, { slots }) {
const { direction } = hooks.toRefs(props)
provideDesignConfig(props.design)
const { direction, design } = hooks.toRefs(props)
provideDesignConfig(design)
const isRTL = hooks.computed(() => direction.value === 'rtl')
const cssVar = hooks.computed(() => {
return {
Expand Down
Loading