Skip to content

Commit adab6d7

Browse files
authored
Merge pull request #122 from Thixiaoxiao/master
避免重复配置
2 parents 45d380c + 482e004 commit adab6d7

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,29 @@ window.confirm = function(msg, callback){
4141
//判断是否为空
4242
function isBlank(value) {
4343
return !value || !/\S/.test(value)
44+
}
45+
46+
function setCookie(key, val, expire_second) {
47+
var d = new Date();
48+
var expires ="";
49+
if (expire_second){
50+
d.setDate(d.getTime()+(expire_second*1000));
51+
expires='; expires=' + d.toGMTSring();
52+
}
53+
document.cookie = key + "="+ val + expires;
54+
}
55+
56+
function getCookie(name) {
57+
var data = "";
58+
if (document.cookie){
59+
var arr = document.cookie.split(';');
60+
for (var str of arr) {
61+
var temp = str.split("=")
62+
if (temp[0].replace(/(^\s*)/g,'') === name){
63+
data = unescape(temp[1]);
64+
break
65+
}
66+
}
67+
}
68+
return data;
4469
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ const vm = new Vue({
123123
error("生成失败");
124124
return;
125125
}
126+
setAllCookie();
126127
//console.log(res.outputJson);
127128
vm.outputJson=res.outputJson;
128129
// console.log(vm.outputJson["bootstrap-ui"]);
@@ -154,3 +155,41 @@ const vm = new Vue({
154155
}
155156
});
156157

158+
/**
159+
* 将所有 需要 保留历史纪录的字段写入Cookie中
160+
*/
161+
function setAllCookie() {
162+
var arr = list_key_need_load();
163+
for (var str of arr){
164+
setOneCookie(str);
165+
}
166+
}
167+
168+
function setOneCookie(key) {
169+
setCookie(key, vm.formData.options[key]);
170+
}
171+
172+
/**
173+
* 将所有 历史纪录 重加载回页面
174+
*/
175+
function loadAllCookie() {
176+
//console.log(vm);
177+
var arr = list_key_need_load();
178+
for (var str of arr){
179+
loadOneCookie(str);
180+
}
181+
}
182+
183+
function loadOneCookie(key) {
184+
if (getCookie(key)!==""){
185+
vm.formData.options[key] = getCookie(key);
186+
}
187+
}
188+
189+
/**
190+
* 将 所有 需要 纪录的 字段写入数组
191+
* @returns {[string]}
192+
*/
193+
function list_key_need_load() {
194+
return ["authorName","packageName","returnUtilSuccess","returnUtilFailure","ignorePrefix","tinyintTransType","timeTransType"];
195+
}

generator-web/src/main/resources/templates/code-generator/jpa/jpacontroller.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.PostMapping;
1313
import org.springframework.web.bind.annotation.RestController;
1414
import java.util.List;
1515
import java.util.Map;
16+
import java.util.Optional;
17+
1618
</#if>
1719
/**
1820
* @description ${classInfo.classComment}

generator-web/src/main/resources/templates/code-generator/jpa/repository.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.mapper;</#if>
1+
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.repository;</#if>
22
<#if isAutoImport?exists && isAutoImport==true>import ${packageName}.entity.${classInfo.className};
33

44
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
vm.formData.options.returnUtilSuccess="${(value.returnUtilSuccess)!!}";
141141
vm.formData.options.returnUtilFailure="${(value.returnUtilFailure)!!}";
142142
vm.outputStr="${(value.outputStr)!!}";
143+
loadAllCookie()
143144
</script>
144145
</body>
145146
</html>

0 commit comments

Comments
 (0)