@@ -60,6 +60,7 @@ const vm = new Vue({
6060 }
6161 } ,
6262 templates :[ { } ] ,
63+ historicalData :[ ] ,
6364 outputStr : "xxx" ,
6465 outputJson : { }
6566 } ,
@@ -73,6 +74,23 @@ const vm = new Vue({
7374 //console.log(vm.outputStr);
7475 $ . outputArea . setSize ( 'auto' , 'auto' ) ;
7576 } ,
77+ //switch HistoricalData
78+ switchHistoricalData : function ( event ) {
79+ const tableName = event . target . innerText . trim ( ) ;
80+ console . log ( tableName ) ;
81+ if ( window . sessionStorage ) {
82+ const valueSession = sessionStorage . getItem ( tableName ) ;
83+ vm . outputJson = JSON . parse ( valueSession ) ;
84+ console . log ( valueSession ) ;
85+ alert ( "切换历史记录成功:" + tableName ) ;
86+ } else {
87+ alert ( "浏览器不支持sessionStorage" ) ;
88+ }
89+ vm . outputStr = vm . outputJson [ "plusentity" ] ;
90+ $ . outputArea . setValue ( vm . outputStr ) ;
91+ //console.log(vm.outputStr);
92+ $ . outputArea . setSize ( 'auto' , 'auto' ) ;
93+ } ,
7694 //request with formData to generate the code 根据参数生成代码
7795 generate : function ( ) {
7896 //get value from codemirror
@@ -86,6 +104,25 @@ const vm = new Vue({
86104 //console.log(vm.outputStr);
87105 $ . outputArea . setValue ( vm . outputStr ) ;
88106 $ . outputArea . setSize ( 'auto' , 'auto' ) ;
107+ //add to historicalData
108+ const tableName = res . outputJson . tableName ;
109+ //add new table only
110+ if ( vm . historicalData . indexOf ( tableName ) < 0 ) {
111+ vm . historicalData . unshift ( tableName ) ;
112+ }
113+ //remove last record , if more than N
114+ if ( vm . historicalData . length > 9 ) {
115+ vm . historicalData . splice ( 9 , 1 ) ;
116+ }
117+ //get and set to session data
118+ const valueSession = sessionStorage . getItem ( tableName ) ;
119+ //remove if exists
120+ if ( valueSession !== undefined && valueSession != null ) {
121+ sessionStorage . removeItem ( tableName ) ;
122+ }
123+ //set data to session
124+ sessionStorage . setItem ( tableName , JSON . stringify ( vm . outputJson ) ) ;
125+ //console.log(vm.historicalData);
89126 } ) ;
90127 } ,
91128 copy : function ( ) {
@@ -99,7 +136,7 @@ const vm = new Vue({
99136 } ) . then ( function ( res ) {
100137 //console.log(res.templates);
101138 vm . templates = JSON . parse ( res . templates ) ;
102- console . log ( vm . templates ) ;
139+ // console.log(vm.templates);
103140 } ) ;
104141 } ,
105142 updated : function ( ) {
0 commit comments