Skip to content

Commit c2edc16

Browse files
committed
support switching historical data
1 parent 004404f commit c2edc16

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

generator-web/src/main/resources/statics/js/main.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 () {

generator-web/src/main/resources/templates/main.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
/*.el-form-item--mini .el-form-item__content, .el-form-item--mini .el-form-item__label{
1010
line-height : 10px;
1111
}*/
12+
.el-button-group-top {
13+
padding-top: 5px;
14+
}
1215
</style>
1316
</head>
1417
<body>
@@ -95,6 +98,14 @@
9598
<!--generate button-->
9699
<el-button type="primary" icon="el-icon-caret-right" @click="generate">生成</el-button>
97100
<el-button type="primary" icon="el-icon-document-copy" @click="copy" plain>复制</el-button>
101+
<span v-if="historicalData.length>0" >
102+
<el-button-group>
103+
<el-button type="primary" plain disabled round>历史记录</el-button>
104+
<span v-for="(item, index) in historicalData" :key="index">
105+
<el-button @click="switchHistoricalData" >{{item}}</el-button>
106+
</span>
107+
</el-button-group>
108+
</span>
98109
<hr>
99110
<!--templates area-->
100111
<el-form ref="form" :inline="true" :model="formData" label-width="100px" size="mini">

0 commit comments

Comments
 (0)