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 { sq } from '@/core/spin-query'
@ -9,11 +9,6 @@ import { mainSiteUrls } from '@/core/utils/urls'
const switchMetadata = defineSwitchMetadata({
name: 'simplifyOptions',
dimAt: 'checked',
switchProps: {
checkedIcon: 'mdi-eye-off-outline',
notCheckedIcon: 'mdi-eye-outline',
},
switches: {
categories: {
defaultValue: false,
@ -47,7 +42,7 @@ const switchMetadata = defineSwitchMetadata({
})
const console = useScopedConsole('简化首页')
export const component = newSwitchComponentWrapper(switchMetadata)({
export const component = wrapSwitchOptions(switchMetadata)({
name: 'simplifyHome',
displayName: '简化首页',
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 { liveUrls } from '@/core/utils/urls'
export const component = newSwitchComponentWrapper({
export const component = wrapSwitchOptions({
name: 'simplifyOptions',
dimAt: 'checked',
switchProps: {
checkedIcon: 'mdi-eye-off-outline',
notCheckedIcon: 'mdi-eye-outline',
},
switches: {
vip: {
defaultValue: true,

View File

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

View File

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

View File

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