From ab705bfa2fee815831d47f5d302094cf5b86628d Mon Sep 17 00:00:00 2001 From: thj <18883325829@163.com> Date: Fri, 1 Oct 2021 09:17:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E6=9C=9F=20:=202021?= =?UTF-8?q?-10-01=20=E8=83=8C=E6=99=AF=20:=20=E5=BD=93=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E6=89=93=E5=BC=80=E4=B8=80=E4=B8=AA=E9=A1=B5=E9=9D=A2=E6=97=B6?= =?UTF-8?q?,=E6=9C=89=E5=BE=88=E5=A4=9A=E8=AE=BE=E7=BD=AE=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E9=87=8D=E5=A4=8D=E6=93=8D=E4=BD=9C,=E6=B5=AA?= =?UTF-8?q?=E8=B4=B9=E6=97=B6=E9=97=B4=20=E4=BF=AE=E6=94=B9=20:=20=20=20?= =?UTF-8?q?=20=201=20main.html:=20=E5=A2=9E=E5=8A=A0=20=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=20cookie=20=E7=9A=84=E9=80=BB=E8=BE=91=20=20=20=20=202=20commo?= =?UTF-8?q?n.js:=20=E5=A2=9E=E5=8A=A0=20cookie=20=E8=AE=BE=E7=BD=AE=20?= =?UTF-8?q?=E5=92=8C=20get=20=E7=9A=84=20=E9=80=9A=E7=94=A8=E9=80=BB?= =?UTF-8?q?=E8=BE=91=20=20=20=20=203=20main.js:=20=E5=A2=9E=E5=8A=A0=20?= =?UTF-8?q?=E5=B0=86=E6=89=80=E6=9C=89=E9=9C=80=E8=A6=81=E7=BA=AA=E5=BD=95?= =?UTF-8?q?=E7=9A=84=E5=AD=97=E6=AE=B5=E5=86=99=E5=85=A5cookie=E9=80=BB?= =?UTF-8?q?=E8=BE=91,=E5=B9=B6=E5=8A=A0=E8=BD=BD=E5=88=B0=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/statics/js/common.js | 25 ++++++++++++ .../src/main/resources/statics/js/main.js | 39 +++++++++++++++++++ .../src/main/resources/templates/main.html | 1 + 3 files changed, 65 insertions(+) diff --git a/generator-web/src/main/resources/statics/js/common.js b/generator-web/src/main/resources/statics/js/common.js index 48030c1..8900e5f 100644 --- a/generator-web/src/main/resources/statics/js/common.js +++ b/generator-web/src/main/resources/statics/js/common.js @@ -41,4 +41,29 @@ window.confirm = function(msg, callback){ //判断是否为空 function isBlank(value) { return !value || !/\S/.test(value) +} + +function setCookie(key, val, expire_second) { + var d = new Date(); + var expires =""; + if (expire_second){ + d.setDate(d.getTime()+(expire_second*1000)); + expires='; expires=' + d.toGMTSring(); + } + document.cookie = key + "="+ val + expires; +} + +function getCookie(name) { + var data = ""; + if (document.cookie){ + var arr = document.cookie.split(';'); + for (var str of arr) { + var temp = str.split("=") + if (temp[0].replace(/(^\s*)/g,'') === name){ + data = unescape(temp[1]); + break + } + } + } + return data; } \ No newline at end of file diff --git a/generator-web/src/main/resources/statics/js/main.js b/generator-web/src/main/resources/statics/js/main.js index aab5880..9748449 100644 --- a/generator-web/src/main/resources/statics/js/main.js +++ b/generator-web/src/main/resources/statics/js/main.js @@ -123,6 +123,7 @@ const vm = new Vue({ error("生成失败"); return; } + setAllCookie(); //console.log(res.outputJson); vm.outputJson=res.outputJson; // console.log(vm.outputJson["bootstrap-ui"]); @@ -154,3 +155,41 @@ const vm = new Vue({ } }); +/** + * 将所有 需要 保留历史纪录的字段写入Cookie中 + */ +function setAllCookie() { + var arr = list_key_need_load(); + for (var str of arr){ + setOneCookie(str); + } +} + +function setOneCookie(key) { + setCookie(key, vm.formData.options[key]); +} + +/** + * 将所有 历史纪录 重加载回页面 + */ +function loadAllCookie() { + //console.log(vm); + var arr = list_key_need_load(); + for (var str of arr){ + loadOneCookie(str); + } +} + +function loadOneCookie(key) { + if (getCookie(key)!==""){ + vm.formData.options[key] = getCookie(key); + } +} + +/** + * 将 所有 需要 纪录的 字段写入数组 + * @returns {[string]} + */ +function list_key_need_load() { + return ["authorName","packageName","returnUtilSuccess","returnUtilFailure","ignorePrefix","tinyintTransType","timeTransType"]; +} \ No newline at end of file diff --git a/generator-web/src/main/resources/templates/main.html b/generator-web/src/main/resources/templates/main.html index c87313b..4ed0486 100644 --- a/generator-web/src/main/resources/templates/main.html +++ b/generator-web/src/main/resources/templates/main.html @@ -140,6 +140,7 @@ vm.formData.options.returnUtilSuccess="${(value.returnUtilSuccess)!!}"; vm.formData.options.returnUtilFailure="${(value.returnUtilFailure)!!}"; vm.outputStr="${(value.outputStr)!!}"; + loadAllCookie() \ No newline at end of file