Skip to content

Commit 9453d1f

Browse files
committedJun 13, 2023
feat(client): support slot.disabled
1 parent 2e50419 commit 9453d1f

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed
 

‎packages/client/client/activity.ts

+3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export namespace Activity {
2121
authority?: number
2222
position?: 'top' | 'bottom'
2323
fields?: Field[]
24+
/** @deprecated */
2425
when?: () => boolean
26+
disabled?: () => boolean
2527
}
2628
}
2729

@@ -71,6 +73,7 @@ export class Activity {
7173
if (root.bail('activity', this)) return
7274
if (!this.fields.every(key => store[key])) return
7375
if (this.when && !this.when()) return
76+
if (this.disabled?.()) return
7477
return this.options.position ?? 'top'
7578
}
7679

‎packages/client/client/components/slot.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export interface SlotItem {
88

99
export interface SlotOptions extends SlotItem {
1010
type: string
11+
/** @deprecated */
1112
when?: () => boolean
13+
disabled?: () => boolean
1214
}
1315

1416
export const KSlot = defineComponent({
@@ -24,7 +26,7 @@ export const KSlot = defineComponent({
2426
.filter(node => node.type === KSlotItem)
2527
.map(node => ({ node, order: node.props?.order || 0 }))
2628
const external = [...ctx.internal.views[props.name] || []]
27-
.filter(item => !item.when || item.when())
29+
.filter(item => !item.disabled?.())
2830
.map(item => ({
2931
node: h(item.component, { data: props.data, ...props.data }, slots),
3032
order: item.order,

‎packages/client/client/context.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ export interface MenuItem {
6868
order?: number
6969
}
7070

71-
interface SettingOptions {
71+
interface SettingOptions extends Ordered {
7272
id: string
7373
title?: string
74-
order?: number
7574
disabled?: () => boolean
7675
schema?: Schema
7776
component?: Component
@@ -172,6 +171,7 @@ export class Context extends cordis.Context {
172171
slot(options: SlotOptions) {
173172
options.order ??= 0
174173
options.component = this.wrapComponent(options.component)
174+
if (options.when) options.disabled = () => !options.when()
175175
const list = this.internal.views[options.type] ||= []
176176
insert(list, options)
177177
return this.scope.collect('view', () => remove(list, options))
@@ -231,7 +231,7 @@ export class Context extends cordis.Context {
231231
for (const [type, component] of Object.entries(options.components || {})) {
232232
this.slot({
233233
type,
234-
when: () => config.value.theme[mode.value] === options.id,
234+
disabled: () => config.value.theme[mode.value] !== options.id,
235235
component,
236236
})
237237
}

‎packages/client/client/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { config } from './config'
66
import { initTask } from './loader'
77
import { Context } from './context'
88
import { createI18n } from 'vue-i18n'
9+
import { watchEffect } from 'vue'
910

1011
export * from './activity'
1112
export * from './components'
@@ -42,10 +43,13 @@ export const router = createRouter({
4243

4344
export const i18n = createI18n({
4445
legacy: false,
45-
locale: config.value.locale,
4646
fallbackLocale: 'zh-CN',
4747
})
4848

49+
watchEffect(() => {
50+
i18n.global.locale.value = config.value.locale
51+
})
52+
4953
root.app.use(install)
5054
root.app.use(i18n)
5155
root.app.use(router)

0 commit comments

Comments
 (0)
Please sign in to comment.