@@ -60,6 +60,7 @@ const vm = new Vue({
60
60
}
61
61
} ,
62
62
templates :[ { } ] ,
63
+ historicalData :[ ] ,
63
64
outputStr : "xxx" ,
64
65
outputJson : { }
65
66
} ,
@@ -73,6 +74,23 @@ const vm = new Vue({
73
74
//console.log(vm.outputStr);
74
75
$ . outputArea . setSize ( 'auto' , 'auto' ) ;
75
76
} ,
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
+ } ,
76
94
//request with formData to generate the code 根据参数生成代码
77
95
generate : function ( ) {
78
96
//get value from codemirror
@@ -86,6 +104,25 @@ const vm = new Vue({
86
104
//console.log(vm.outputStr);
87
105
$ . outputArea . setValue ( vm . outputStr ) ;
88
106
$ . 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);
89
126
} ) ;
90
127
} ,
91
128
copy : function ( ) {
@@ -99,7 +136,7 @@ const vm = new Vue({
99
136
} ) . then ( function ( res ) {
100
137
//console.log(res.templates);
101
138
vm . templates = JSON . parse ( res . templates ) ;
102
- console . log ( vm . templates ) ;
139
+ // console.log(vm.templates);
103
140
} ) ;
104
141
} ,
105
142
updated : function ( ) {
0 commit comments