@@ -8,16 +8,19 @@ import { createContext, type JSX, type ParentProps, splitProps, useContext } fro
88import { createStore } from 'solid-js/store' ;
99
1010import { LocaleProvider } from '@components/context/locale' ;
11- import type { ReqOptions } from './options' ;
12-
13- const localeKey = 'locale' ;
14- const displayStyleKey = 'display-style' ;
15- const schemeKey = 'scheme' ;
16- const modeKey = 'mode' ;
17- const tzKey = 'timezone' ;
18- const staysKey = 'stays' ;
19- const fontSizeKey = 'font-size' ;
20- const transitionDurationKey = 'transition-duration' ;
11+ import type { ConfigurableOptions , NotifyPosition , ReqOptions } from './options' ;
12+
13+ const keys : Record < keyof ConfigurableOptions , string > = {
14+ fontSize : 'font-size' ,
15+ scheme : 'scheme' ,
16+ mode : 'mode' ,
17+ transitionDuration : 'transition-duration' ,
18+ locale : 'locale' ,
19+ displayStyle : 'display-style' ,
20+ timezone : 'timezone' ,
21+ stays : 'stays' ,
22+ notifyPosition : 'notify-position' ,
23+ } as const ;
2124
2225/**
2326 * 提供了对全局配置的存取功能
@@ -83,19 +86,21 @@ export function buildAccessor(o: ReqOptions) {
8386 stays : o . stays ,
8487 fontSize : o . fontSize ,
8588 transitionDuration : o . transitionDuration ,
89+ notifyPosition : o . notifyPosition ,
8690 } ) ;
8791
8892 const read = ( ) => {
8993 // 从配置内容中读取
9094 set ( {
91- scheme : conf . get ( schemeKey ) ?? val . scheme ,
92- mode : conf . get ( modeKey ) ?? val . mode ,
93- locale : conf . get ( localeKey ) ?? val . locale ,
94- displayStyle : conf . get ( displayStyleKey ) ?? val . displayStyle ,
95- timezone : conf . get ( tzKey ) ?? val . timezone ,
96- stays : conf . get ( staysKey ) ?? val . stays ,
97- fontSize : conf . get ( fontSizeKey ) ?? val . fontSize ,
98- transitionDuration : conf . get ( transitionDurationKey ) ?? val . transitionDuration ,
95+ scheme : conf . get ( keys . scheme ) ?? val . scheme ,
96+ mode : conf . get ( keys . mode ) ?? val . mode ,
97+ locale : conf . get ( keys . locale ) ?? val . locale ,
98+ displayStyle : conf . get ( keys . displayStyle ) ?? val . displayStyle ,
99+ timezone : conf . get ( keys . timezone ) ?? val . timezone ,
100+ stays : conf . get ( keys . stays ) ?? val . stays ,
101+ fontSize : conf . get ( keys . fontSize ) ?? val . fontSize ,
102+ transitionDuration : conf . get ( keys . transitionDuration ) ?? val . transitionDuration ,
103+ notifyPosition : conf . get ( keys . notifyPosition ) ?? val . notifyPosition ,
99104 } ) ;
100105
101106 if ( val . fontSize !== document . documentElement . style . fontSize ) {
@@ -150,7 +155,7 @@ export function buildAccessor(o: ReqOptions) {
150155 */
151156 setFontSize ( size : string ) : void {
152157 set ( { fontSize : size } ) ;
153- conf . set ( fontSizeKey , size ) ;
158+ conf . set ( keys . fontSize , size ) ;
154159 document . documentElement . style . fontSize = size ;
155160 } ,
156161
@@ -163,7 +168,7 @@ export function buildAccessor(o: ReqOptions) {
163168 */
164169 setTransitionDuration ( duration : number ) : void {
165170 set ( { transitionDuration : duration } ) ;
166- conf . set ( transitionDurationKey , duration ) ;
171+ conf . set ( keys . transitionDuration , duration ) ;
167172 document . documentElement . style . setProperty ( '--default-transition-duration' , `${ duration } ms` ) ;
168173 } ,
169174
@@ -178,7 +183,7 @@ export function buildAccessor(o: ReqOptions) {
178183 */
179184 setLocale ( id : string ) : void {
180185 set ( { locale : id } ) ;
181- conf . set ( localeKey , id ) ;
186+ conf . set ( keys . locale , id ) ;
182187 document . documentElement . lang = id ;
183188 } ,
184189
@@ -191,7 +196,7 @@ export function buildAccessor(o: ReqOptions) {
191196 */
192197 setDisplayStyle ( style : DisplayStyle ) : void {
193198 set ( { displayStyle : style } ) ;
194- conf . set ( displayStyleKey , style ) ;
199+ conf . set ( keys . displayStyle , style ) ;
195200 } ,
196201
197202 getDisplayStyle ( ) : DisplayStyle {
@@ -203,7 +208,7 @@ export function buildAccessor(o: ReqOptions) {
203208 */
204209 setTimezone ( tz : string ) : void {
205210 set ( { timezone : tz } ) ;
206- conf . set ( tzKey , tz ) ;
211+ conf . set ( keys . timezone , tz ) ;
207212 } ,
208213
209214 getTimezone ( ) : string {
@@ -223,7 +228,7 @@ export function buildAccessor(o: ReqOptions) {
223228 }
224229
225230 set ( { scheme : s } ) ;
226- conf . set ( schemeKey , s ) ;
231+ conf . set ( keys . scheme , s ) ;
227232 } ,
228233
229234 getScheme ( ) : Scheme {
@@ -235,7 +240,7 @@ export function buildAccessor(o: ReqOptions) {
235240 */
236241 setMode ( mode : Mode ) : void {
237242 set ( { mode : mode } ) ;
238- conf . set ( modeKey , mode ) ;
243+ conf . set ( keys . mode , mode ) ;
239244 } ,
240245
241246 getMode ( ) : Mode {
@@ -247,13 +252,25 @@ export function buildAccessor(o: ReqOptions) {
247252 */
248253 setStays ( stay : number ) : void {
249254 set ( { stays : stay } ) ;
250- conf . set ( staysKey , stay ) ;
255+ conf . set ( keys . stays , stay ) ;
251256 } ,
252257
253258 getStays ( ) : number {
254259 return val . stays ;
255260 } ,
256261
262+ /**
263+ * 设置当前配置中通知的显示位置
264+ */
265+ setNotifyPosition ( position : NotifyPosition ) : void {
266+ set ( { notifyPosition : position } ) ;
267+ conf . set ( keys . notifyPosition , position ) ;
268+ } ,
269+
270+ getNotifyPosition ( ) : NotifyPosition {
271+ return val . notifyPosition ;
272+ } ,
273+
257274 /**
258275 * 清除当前用户的配置
259276 */
0 commit comments