From ebcd99ce031958d615901d3b601d724d94d58602 Mon Sep 17 00:00:00 2001 From: Hongyuan Ma Date: Thu, 17 May 2018 22:30:23 +0800 Subject: [PATCH] add util.js --- front-end/src/util/util.js | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 front-end/src/util/util.js diff --git a/front-end/src/util/util.js b/front-end/src/util/util.js new file mode 100644 index 0000000..2691aed --- /dev/null +++ b/front-end/src/util/util.js @@ -0,0 +1,45 @@ +class PGUtil{ + request(){ + //todo + } + // success tips + successTips(successMsg){ + alert(successMsg); + } + // error tips + errorTips(errMsg){ + alert(errMsg); + } + // set local storage + setStorage(name, data){ + let dataType = typeof data; + // json obj + if(dataType === 'object'){ + window.localStorage.setItem(name, JSON.stringify(data)); + } + // basical type + else if(['number','string','boolean'].indexOf(dataType) >= 0){ + window.localStorage.setItem(name, data); + } + // other unacceptable type + else{ + alert('type unacceptabled'); + } + } + // get local storage + getStorage(name){ + let data = window.localStorage.getItem(name); + if(data){ + return JSON.parse(data); + } + else{ + return ''; + } + } + // remove local storage + removeStorage(name){ + window.localStorage.removeItem(name); + } +} + +export default PGUtil; \ No newline at end of file -- 2.39.5