add util.js
authorHongyuan Ma <CS_MaleicAcid@163.com>
Thu, 17 May 2018 14:30:23 +0000 (22:30 +0800)
committerHongyuan Ma <CS_MaleicAcid@163.com>
Thu, 17 May 2018 14:30:23 +0000 (22:30 +0800)
front-end/src/util/util.js [new file with mode: 0644]

diff --git a/front-end/src/util/util.js b/front-end/src/util/util.js
new file mode 100644 (file)
index 0000000..2691aed
--- /dev/null
@@ -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