Update default values & export names

This commit is contained in:
the1812 2023-07-29 14:22:59 +08:00
parent 23dabcdab7
commit 3fc6b3130c
5 changed files with 32 additions and 27 deletions

View File

@ -1,4 +1,4 @@
import { newSwitchComponentWrapper, defineSwitchMetadata } from '@/components/switch-options' import { wrapSwitchOptions, defineSwitchMetadata } from '@/components/switch-options'
import { addComponentListener, getComponentSettings } from '@/core/settings' import { addComponentListener, getComponentSettings } from '@/core/settings'
import { sq } from '@/core/spin-query' import { sq } from '@/core/spin-query'
@ -9,11 +9,6 @@ import { mainSiteUrls } from '@/core/utils/urls'
const switchMetadata = defineSwitchMetadata({ const switchMetadata = defineSwitchMetadata({
name: 'simplifyOptions', name: 'simplifyOptions',
dimAt: 'checked',
switchProps: {
checkedIcon: 'mdi-eye-off-outline',
notCheckedIcon: 'mdi-eye-outline',
},
switches: { switches: {
categories: { categories: {
defaultValue: false, defaultValue: false,
@ -47,7 +42,7 @@ const switchMetadata = defineSwitchMetadata({
}) })
const console = useScopedConsole('简化首页') const console = useScopedConsole('简化首页')
export const component = newSwitchComponentWrapper(switchMetadata)({ export const component = wrapSwitchOptions(switchMetadata)({
name: 'simplifyHome', name: 'simplifyHome',
displayName: '简化首页', displayName: '简化首页',
description: '隐藏原版首页不需要的元素 / 分区.', description: '隐藏原版首页不需要的元素 / 分区.',

View File

@ -1,14 +1,9 @@
import { newSwitchComponentWrapper } from '@/components/switch-options' import { wrapSwitchOptions } from '@/components/switch-options'
import { styledComponentEntry } from '@/components/styled-component' import { styledComponentEntry } from '@/components/styled-component'
import { liveUrls } from '@/core/utils/urls' import { liveUrls } from '@/core/utils/urls'
export const component = newSwitchComponentWrapper({ export const component = wrapSwitchOptions({
name: 'simplifyOptions', name: 'simplifyOptions',
dimAt: 'checked',
switchProps: {
checkedIcon: 'mdi-eye-off-outline',
notCheckedIcon: 'mdi-eye-outline',
},
switches: { switches: {
vip: { vip: {
defaultValue: true, defaultValue: true,

View File

@ -21,7 +21,7 @@
v-for="name of Object.keys(options.switches)" v-for="name of Object.keys(options.switches)"
:key="name" :key="name"
:class="{ dim: isDim(name) }" :class="{ dim: isDim(name) }"
v-bind="options.switchProps || {}" v-bind="mergedSwitchProps"
:checked="componentOptions[`switch-${name}`]" :checked="componentOptions[`switch-${name}`]"
@change="componentOptions[`switch-${name}`] = $event" @change="componentOptions[`switch-${name}`] = $event"
> >
@ -36,7 +36,7 @@
v-for="name of Object.keys(options.switches)" v-for="name of Object.keys(options.switches)"
:key="name" :key="name"
:class="{ dim: isDim(name) }" :class="{ dim: isDim(name) }"
v-bind="options.switchProps || {}" v-bind="mergedSwitchProps"
:checked="componentOptions[`switch-${name}`]" :checked="componentOptions[`switch-${name}`]"
@change="componentOptions[`switch-${name}`] = $event" @change="componentOptions[`switch-${name}`] = $event"
> >
@ -82,6 +82,15 @@ export default Vue.extend({
componentOptions, componentOptions,
} }
}, },
computed: {
mergedSwitchProps() {
return {
checkedIcon: 'mdi-eye-off-outline',
notCheckedIcon: 'mdi-eye-outline',
...this.options.switchProps,
}
},
},
watch: { watch: {
options() { options() {
this.updateColumnsCount() this.updateColumnsCount()
@ -97,10 +106,13 @@ export default Vue.extend({
element.style.setProperty('--columns', columns.toString()) element.style.setProperty('--columns', columns.toString())
}, },
isDim(name: string) { isDim(name: string) {
return ( if (this.options.dimAt === 'checked' || this.options.dimAt === undefined) {
(this.componentOptions[`switch-${name}`] && this.options.dimAt === 'checked') || return this.componentOptions[`switch-${name}`]
this.options.dimAt === 'notChecked' }
) if (this.options.dimAt === 'notChecked') {
return !this.componentOptions[`switch-${name}`]
}
return false
}, },
}, },
}) })

View File

@ -21,6 +21,8 @@ export interface SwitchOptions {
iconPosition?: 'left' | 'right' iconPosition?: 'left' | 'right'
} }
} }
/** @deprecated */
export const createSwitchOptions = (options: SwitchOptions) => { export const createSwitchOptions = (options: SwitchOptions) => {
if (options.radio === undefined) { if (options.radio === undefined) {
options.radio = false options.radio = false

View File

@ -68,13 +68,13 @@ export interface SwitchMetadata<N extends string, S extends string> {
/** /**
* *
* *
* `undefined`: * `false`:
* `'checked'`: * `'checked'`:
* `'notChecked'`: * `'notChecked'`:
* *
* @default undefined * @default 'checked'
*/ */
dimAt?: undefined | 'checked' | 'notChecked' dimAt?: false | 'checked' | 'notChecked'
/** 配置每个开关的图标 */ /** 配置每个开关的图标 */
switchProps?: { switchProps?: {
checkedIcon?: string checkedIcon?: string
@ -102,7 +102,7 @@ export interface SwitchMetadataOption<N extends string, S extends string> {
name: N name: N
switches: SwitchItemsMetadata<S> switches: SwitchItemsMetadata<S>
radio: boolean radio: boolean
dimAt: undefined | 'checked' | 'notChecked' dimAt: false | 'checked' | 'notChecked'
switchProps?: { switchProps?: {
checkedIcon?: string checkedIcon?: string
notCheckedIcon?: string notCheckedIcon?: string
@ -291,7 +291,7 @@ export type SwitchComponentWrapper<N extends string, S extends string> = <O exte
* @param metadata - 使 {@link defineSwitchMetadata} * @param metadata - 使 {@link defineSwitchMetadata}
* @returns * @returns
*/ */
export const newSwitchComponentWrapper = <N extends string, S extends string>( export const wrapSwitchOptions = <N extends string, S extends string>(
metadata: SwitchMetadata<N, S>, metadata: SwitchMetadata<N, S>,
): SwitchComponentWrapper<N, S> => { ): SwitchComponentWrapper<N, S> => {
const extendOptions = newSwitchOptionsMetadataExtender(metadata.switches) const extendOptions = newSwitchOptionsMetadataExtender(metadata.switches)
@ -313,5 +313,6 @@ export const newSwitchComponentWrapper = <N extends string, S extends string>(
return component as SwitchComponentMetadata<O, N, S> return component as SwitchComponentMetadata<O, N, S>
} }
} }
export const newSwitchComponentWrapper = wrapSwitchOptions
export { createSwitchOptions } from './switch-options-old' export { createSwitchOptions } from './switch-options-old'