Browse Source

Merge remote-tracking branch 'origin/master'

yindan 2 years ago
parent
commit
d19d0d7878
8 changed files with 111 additions and 5 deletions
  1. 8 0
      app.js
  2. 1 0
      app.json
  3. 16 0
      components/back/back.js
  4. 5 0
      components/back/back.json
  5. 4 0
      components/back/back.wxml
  6. 10 0
      components/back/back.wxss
  7. 6 4
      utils/storage.js
  8. 61 1
      utils/utils.js

+ 8 - 0
app.js

@@ -31,4 +31,12 @@ App({
         UpdateManager.update();
     },
     Base: basePage,
+    // 备注:为实现dayjs插件功能 需要在node_modules/dayjs/package.json,最外层添加代码
+    // "miniprogram": "esm",
+    // import localeData from "dayjs/plugin/localeData"
+    // dayjs.extend(localeData)
+
+    // dayjs.locale('zh-cn')
+    // dayjs.months()[dayjs().month()]//获取中文月份
+    // dayjs.locale('en')
 })

+ 1 - 0
app.json

@@ -48,6 +48,7 @@
     "edu-safe-area": "/components/safe-area/safe-area",
     "edu-msg-card": "/components/msg-card/msg-card",
     "edu-code": "/components/code/code",
+    "edu-back": "/components/back/back",
     "edu-button": "/components/button/button",
     "edu-painter": "/components/painter/painter",
     "edu-txt": "/components/txt/txt",

+ 16 - 0
components/back/back.js

@@ -0,0 +1,16 @@
+Component({
+    //使用在自定义头部 导航 沉浸式 显示后退按钮
+    properties: {
+        ticketInfo:Object,
+        price:String
+    },
+    data: {
+        backTop: wx.getMenuButtonBoundingClientRect().bottom - wx.getMenuButtonBoundingClientRect().height,
+        backHeight: wx.getMenuButtonBoundingClientRect().height
+    },
+    methods: {
+        back() {
+            wx.navigateBack();
+        },
+    },
+});

+ 5 - 0
components/back/back.json

@@ -0,0 +1,5 @@
+{
+  "component": true,
+  "usingComponents": {
+  }
+}

+ 4 - 0
components/back/back.wxml

@@ -0,0 +1,4 @@
+<view class="back" bind:tap="back"
+      style="{{'top:'+backTop+'px;height:'+backHeight+'px;'}}">
+    <van-icon name="arrow-left" color="black" size="40rpx"/>
+</view>

+ 10 - 0
components/back/back.wxss

@@ -0,0 +1,10 @@
+.back {
+    position: fixed;
+    left: 0;
+    width: 60rpx;
+    padding-left: 30rpx;
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    z-index: 99;
+}

+ 6 - 4
utils/storage.js

@@ -23,11 +23,13 @@ export default {
         const storage = this.getStorage();
         const exObj = this.getStorage(EXSPACE);
         if (isUp){
-            if (exObj && exObj[key] && exObj[key] > dayjs().valueOf()){
+            if (exObj && exObj[key] ) {
+                if (exObj[key] > dayjs().valueOf()){
 
-            }else {
-                this.clearItem(key)
-                return null;
+                }else {
+                    this.clearItem(key)
+                    return null;
+                }
             }
         }
         return storage[key];

+ 61 - 1
utils/utils.js

@@ -159,13 +159,73 @@ function formatYMD2(str) {
  * @returns {*}
  */
 function handleRichTextImgAuto(content) {
-    return content.replace(/\<img/gi, '<img style="max-width:100%;height:auto')
+    return content.replace(/\<img/gi, '<img style="max-width:100%;height:auto').replace(/&nbsp;/g,'&ensp;&ensp;')
 }
 
 function getNowDate() {
     return dayjs().format("YYYYMMDD")
 }
 
+
+/**
+ * 计算小数
+ * @param f
+ * @param digit
+ * @returns {number}
+ */
+function formatNum(f, digit = 5) {
+    var m = Math.pow(10, digit);
+    return parseInt(f * m, 10) / m;
+}
+
+function formatSize(fileSize) {
+    let newSize = fileSize + "b";
+    if (fileSize > 1024) {
+        newSize = (fileSize / 1024).toFixed(1);
+        fileSize = newSize + "kb"
+    }
+    if (newSize > 1024) {
+        newSize = (newSize / 1024).toFixed(1);
+        fileSize = newSize + "mb"
+    }
+    if (newSize > 1024) {
+        newSize = (newSize / 1024).toFixed(1);
+        fileSize = "大于1gb"
+    }
+    return fileSize
+}
+
+/**
+ * 判断是否邮箱
+ * @param email
+ * @returns {boolean}
+ */
+function isEmail(email) {
+    if (!email.trim()) {
+        return false;
+    }
+    const reg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
+    if (!reg.test(email)) {
+        return false
+    }
+    return true
+}
+
+/**
+ * 扩展获取字典项方法,使用storage 缓存失效来实现在一定时间内不重复加载字典
+ */
+async function getDict(dictType){
+    // let data = storage.getItem(dictType);
+    // if (data){
+    //     return data;
+    // }else{
+    //     const dictData = await Api.getDict(dictType);
+    //     storage.setItem(dictType,dictData.data,DICT_CACHE_TIME)
+    //     return dictData.data;
+    // }
+}
+
+
 export {
     throttle,
     getDataSet,