mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Update default values & export names
This commit is contained in:
parent
23dabcdab7
commit
3fc6b3130c
@ -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: '隐藏原版首页不需要的元素 / 分区.',
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@ -21,6 +21,8 @@ export interface SwitchOptions {
|
||||
iconPosition?: 'left' | 'right'
|
||||
}
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
export const createSwitchOptions = (options: SwitchOptions) => {
|
||||
if (options.radio === undefined) {
|
||||
options.radio = false
|
||||
|
||||
@ -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'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user