1- import { customElement , query } from "lit/decorators.js" ;
1+ import { customElement , query , state } from "lit/decorators.js" ;
22import { LitElement , html } from "lit" ;
3- import type { AutoStore } from "autostore" ;
3+ import { AutoStore , configurable } from "autostore" ;
4+
5+ const store1 = new AutoStore ( {
6+ order : {
7+ product : configurable ( "电脑" , {
8+ label : "产品" ,
9+ } ) ,
10+ price : configurable ( 100 , {
11+ label : "价格" ,
12+ widget : "number" ,
13+ } ) ,
14+ count : configurable ( 10 , {
15+ label : "数量" ,
16+ widget : "number" ,
17+ } ) ,
18+ total : ( order ) => order . price * order . count ,
19+ } ,
20+ } ) ;
21+ const store2 = new AutoStore ( {
22+ username : configurable ( "Bob" , {
23+ label : "用户名" ,
24+ } ) ,
25+ password : configurable ( 100 , {
26+ label : "密码" ,
27+ widget : "password" ,
28+ } ) ,
29+ age : configurable ( 10 , {
30+ label : "年龄" ,
31+ widget : "number" ,
32+ } ) ,
33+ sex : configurable ( "male" , {
34+ label : "性别" ,
35+ widget : "radio" ,
36+ select : [
37+ { label : "男" , value : "male" } ,
38+ { label : "女" , value : "female" } ,
39+ ] ,
40+ } ) ,
41+ } ) ;
442
543@customElement ( "auto-form-example-tabs" )
644class AutoFormExampleTabs extends LitElement {
@@ -11,9 +49,23 @@ class AutoFormExampleTabs extends LitElement {
1149 updated ( ) {
1250 this . tabs ?. bind ( store ) ;
1351 }
52+ //@ts -ignore
53+ @state ( )
54+ refStore : any = store1 ;
1455
56+ //@ts -ignore
57+ @state ( )
58+ count : number = 0 ;
1559 render ( ) {
1660 return html `
61+ < div style ="border: var(--auto-border);padding:1rem;margin-bottom:1rem; ">
62+ < auto-form .store =${ this . refStore } > </ auto-form >
63+ < button style ="margin:1rem;padding: 1rem " @click =${ ( ) => {
64+ this . refStore = this . count % 2 === 0 ? store2 : store1 ;
65+ this . count = this . count ++ ;
66+ } } > 切换Store</ button >
67+ </ div >
68+ < auto-form group ="car " icon ="car "> </ auto-form >
1769 < auto-form-tabs direction ="bottom " style ="border: var(--auto-border);height:500px ">
1870 < auto-form group ="general " icon ="settings "> </ auto-form >
1971 < auto-form group ="car " icon ="car "> </ auto-form >
0 commit comments