From b2b8dad778d1767ef9e609734694de97537762cf Mon Sep 17 00:00:00 2001
From: Tevin <tingquanren@163.com>
Date: Wed, 07 Apr 2021 11:47:09 +0800
Subject: [PATCH] 添加模拟数据模式

---
 common/Tools.js |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/common/Tools.js b/common/Tools.js
index 0c4fb41..3c235cd 100644
--- a/common/Tools.js
+++ b/common/Tools.js
@@ -22,6 +22,22 @@
     }
 
     /**
+     * URL参数解析
+     * @param {String} name
+     * @param {String} [search]
+     * @return {String|Null}
+     */
+    static getUrlParam(name, search = window.location.search) {
+        const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
+        const r = search.substr(1).match(reg);
+        if (r !== null) {
+            return decodeURIComponent(r[2]);
+        } else {
+            return null;
+        }
+    }
+
+    /**
      * 读取文件 base64
      * @param {File} file
      * @return {Promise<string>}
@@ -427,5 +443,19 @@
         return /^1[3456789]\d{9}$/.test('' + phone);
     }
 
+}
 
+// h5 中,实现 rem 转换 px
+if (process.env.NODE_ENV === 'development' && process.env.TARO_ENV === 'h5') {
+    const p1 = {
+        x: parseFloat(Taro.pxTransform(10, 750)), y: 10,
+    };
+    const p2 = {
+        x: parseFloat(Taro.pxTransform(1000, 750)), y: 1000,
+    };
+    window.rem = val => {
+        const value = typeof val === 'number' ? val : parseFloat(val);
+        const px = (value - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y;
+        console.info(Math.round(px) + 'px');
+    };
 }
\ No newline at end of file

--
Gitblit v1.9.1