소스 검색

公共库

bobo 3 년 전
부모
커밋
b3fb053021
3개의 변경된 파일82개의 추가작업 그리고 7개의 파일을 삭제
  1. 12 7
      utils/request.js
  2. 31 0
      utils/user.js
  3. 39 0
      utils/util.js

+ 12 - 7
utils/request.js

@@ -2,11 +2,12 @@ import util from './util.js'
 class request {
 
     //本地的
-    static BASE_URL = 'http://localhost:8014/'
+  static BASE_URL = 'http://localhost:8014/'
 //   pre环境的
 //   static BASE_URL = 'https://oapi.shpr.top/'
 //   正式的
-    // static BASE_URL = 'https://vapi.hsayi.com/'
+//   static BASE_URL = 'https://vapi.hsayi.com/'
+
 //   @todo需要修改正式的域名
 
   static HEAD = {
@@ -37,9 +38,9 @@ class request {
   /**
    * POST类型的网络请求
    */
-  static postRequest(url, data) {
+  static postRequest(url, data, notUseLoading) {
       let  headerSign = this.getSignHead();
-      return this.requestAll(url, data, headerSign, 'POST')
+      return this.requestAll(url, data, headerSign, 'POST', notUeLoading)
   }
 
   static upload(url, name, path, ortherData, header = this.HEAD){
@@ -93,12 +94,15 @@ class request {
     }
     return signHeadInfo;
   }
+
+
   /**
    * 网络请求
    */
-  static requestAll(url, data, header, method) {
-     
-      wx.showLoading()
+  static requestAll(url, data, header, method, notUseLoading) {
+      if (!notUseLoading) {
+        wx.showLoading()
+      }
       return new Promise((resolve, reject) => {
           wx.request({
               url: url,
@@ -113,6 +117,7 @@ class request {
                   } else {
                     wx.showToast({
                         title: res?.data?.msg,
+                        icon: "none"
                     })
                       //其它错误,提示用户错误信息
                       if (this._errorHandler != null) {

+ 31 - 0
utils/user.js

@@ -0,0 +1,31 @@
+function getUserInfo() {
+    return wx.getStorageSync('userInfo') || null;
+}
+
+function getMobileCache() {
+    const userInfo = getUserInfo()
+    if (userInfo != null) {
+        return userInfo.mobile || ''
+    }
+    return ''
+}
+
+function getPhoneNumber(e, func) {
+    var encryptedData = e.detail.encryptedData;
+    console.log(encryptedData);
+    var iv = e.detail.iv;
+    if (!encryptedData || encryptedData.length == 0 || !iv || iv.length == 0) {
+      return;
+    }
+    //获取手机号
+    getApp().doDecodePhone(encryptedData, iv, function () {
+      func(getMobileCache())
+    });
+}
+
+module.exports = {
+    getUserInfo,
+    getMobileCache,
+    getPhoneNumber
+}
+  

+ 39 - 0
utils/util.js

@@ -100,6 +100,44 @@ function getQueryVariable(variable,query)
        return(false);
 }
 
+function parseTime(time, cFormat) {
+  if (arguments.length === 0 || !time) {
+    return null
+  }
+  const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
+  let date
+  if (typeof time === 'object') {
+    date = time
+  } else {
+    if ((typeof time === 'string')) {
+      if ((/^[0-9]+$/.test(time))) {
+        time = parseInt(time)
+      } else {
+        time = time.replace(new RegExp(/-/gm), '/')
+      }
+    }
+    if ((typeof time === 'number') && (time.toString().length === 10)) {
+      time = time * 1000
+    }
+    date = new Date(time)
+  }
+  const formatObj = {
+    y: date.getFullYear(),
+    m: date.getMonth() + 1,
+    d: date.getDate(),
+    h: date.getHours(),
+    i: date.getMinutes(),
+    s: date.getSeconds(),
+    a: date.getDay()
+  }
+  const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
+    const value = formatObj[key]
+    if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] }
+    return value.toString().padStart(2, '0')
+  })
+  return time_str
+}
+
 function isEmpty(v, eZ) {
   if (typeof v == "undefined") {
     return true
@@ -123,6 +161,7 @@ module.exports = {
   format,
   add0,
   getQueryVariable,
+  parseTime,
   isEmpty
 }