Procházet zdrojové kódy

feature:增加util类

zeng.chen před 8 měsíci
rodič
revize
31b088e513
5 změnil soubory, kde provedl 175 přidání a 4 odebrání
  1. 23 0
      request/deviceListRequest.js
  2. 16 0
      utils/route_constant.js
  3. 105 0
      utils/route_util.js
  4. 22 0
      utils/toast_util.js
  5. 9 4
      utils/util.js

+ 23 - 0
request/deviceListRequest.js

@@ -0,0 +1,23 @@
+const {request} = require('../utils/util.js')
+import util from "../utils/util.js";
+
+module.exports={
+  // 设备列表
+  deviceList:(data)=>{
+    return request("/mini/wx/device/base/deviceList", data, "GET", util.jsonType, false)
+	},
+	
+  // 设备类型列表
+  deviceTypeList:(data)=>{
+    return request("/mini/wx/device/base/typeList", data, "GET", util.jsonType, false)
+  },
+  // 设备分类列表
+  deviceCategoryList:(data)=>{
+    return request("/mini/wx/device/base/categoryList", data, "GET",)
+  },
+  // 设备版本 OTA
+  deviceVersion:(data)=>{
+    return request("/mini/wx/device/base/appDeviceVersionGet", data, "GET",)
+  },
+  
+}

+ 16 - 0
utils/route_constant.js

@@ -0,0 +1,16 @@
+
+/// 抽奖记录
+const deviceList = "../deviceList/devices";
+// /// 抽奖详情
+// const detail = "../detail/detail";
+// // 主页
+// const home = "../home/home";
+// // 主页
+// const order = "../order/order";
+module.exports = {
+
+    deviceList: deviceList,
+    // order: order,
+    // deviceList: detail,
+    // home: home
+}

+ 105 - 0
utils/route_util.js

@@ -0,0 +1,105 @@
+// import loginUtil from './login_util.js';
+
+//返回页面个数
+async function goBack(pages) {
+
+    const cPages = getCurrentPages();
+    const currentPage = cPages[cPages.length - 1];
+
+    if (currentPage.route.lastIndexOf("detail/detail")) {
+        setTimeout(() => {
+            wx.switchTab({
+                url: '../pages/index/index'
+            });
+        }, 300);
+    } else {
+        // 执行返回操作
+        if (pages == null) pages = 1;
+        await wx.navigateBack({
+            delta: pages,
+        });
+    }
+
+};
+
+///跳转界面
+async function jump(url) {
+    await wx.navigateTo({
+        url: url,
+    })
+};
+
+async function jumpParam(url, param) {
+    if (param) {
+        await wx.navigateTo({
+            url: url + "?param=" + param,
+        });
+    } else {
+        await jump(url);
+    }
+};
+
+//界面跳转
+async function jumpLogin(url, isNeedLogin) {
+    if (isNeedLogin) {
+        // if (loginUtil.getUserBean() == null) {
+        //     return;
+        // }
+    }
+    await wx.navigateTo({
+        url: url,
+    });
+};
+
+//跳转到Tab页面
+async function switchTo(url) {
+    console.log(url)
+    await wx.switchTab({
+        //跳转目标
+        url: url,
+        //跳转成功后
+        success: function () {
+            //让多个tabl显示出来
+            // wx.showTabBar({
+            //     animation: false,
+            // });
+        }, fail: function (res) {
+            console.log(res)
+        }
+    })
+};
+
+//跳转摧毁当前界面
+async function redirectTo(url) {
+    await wx.redirectTo({
+        url: url,
+    });
+};
+
+/**
+ * 跳转到其他小程序
+ * @param {*} item
+ */
+function jump2Other(item) {
+    wx.navigateToMiniProgram({
+        appId: item.app_id,
+        path: item.page_path,
+        // extraData: {
+        //   foo: 'bar'
+        // },
+        // envVersion: 'develop',
+        envVersion: 'release',
+        success() { },
+        fail() { }
+    });
+};
+
+module.exports = {
+    jump: jump,
+    jumpParam: jumpParam,
+    goBack: goBack,
+    switchTo: switchTo,
+    jump2Other: jump2Other,
+    redirectTo: redirectTo,
+    jumpLogin: jumpLogin,
+}

+ 22 - 0
utils/toast_util.js

@@ -0,0 +1,22 @@
+function show(title,icon="none", duration) {
+    wx.hideLoading();
+    setTimeout(() => {
+        if (duration == null) {
+            wx.showToast({
+                icon: icon,
+                title: title,
+            });
+        } else {
+            wx.showToast({
+                icon: icon,
+                title: title,
+                duration: 1000,
+            });
+        }
+    }, 300)
+
+}
+
+module.exports = {
+    show,
+}

+ 9 - 4
utils/util.js

@@ -1,8 +1,10 @@
-const { baseUrl } = require('./env.js').prod; // 正式
-// const { baseUrl } = require('./env.js').test; // 测试
+// const { baseUrl } = require('./env.js').prod; // 正式
+const { baseUrl } = require('./env.js').test; // 测试
 
 // token
 let Authorization = "";
+const jsonType = {"content-type":"application/json"}
+const urlencodeType = {"content-type":"application/x-www-form-urlencoded"}
 
 // 错误类型
 let statusCode = {
@@ -45,7 +47,7 @@ function _show_error(error_code) {
 }
 
 // 
-function request(url,data={},method="GET", header={}, isToken=true) {
+function request(url,data={},method="GET", header=urlencodeType, isToken=true) {
 
   if(isToken) {
     try {
@@ -75,6 +77,7 @@ function request(url,data={},method="GET", header={}, isToken=true) {
           "Authorization": isToken ? Authorization : undefined
         }, header),
         success(res){
+          // console.log("接口:",fullurl, res)
           wx.hideLoading();
           if(res.statusCode !== 200 ) {
             wx.showToast({
@@ -121,5 +124,7 @@ module.exports = {
   formatTime,
   request,
   formatNumber,
-  isCN
+  isCN,
+  urlencodeType,
+  jsonType
 }