guhongwei 2 jaren geleden
bovenliggende
commit
cd91e4adb1
4 gewijzigde bestanden met toevoegingen van 184 en 203 verwijderingen
  1. 92 95
      pages/login/index.js
  2. 46 69
      project.config.json
  3. 7 0
      project.private.config.json
  4. 39 39
      utils/httpUtil.js

+ 92 - 95
pages/login/index.js

@@ -3,115 +3,112 @@ import WxValidate from '../../utils/wxValidate'
 const app = getApp()
 Page({
 
-  /**
-   * 页面的初始数据
-   */
-  data: {
-    height: app.globalData.height * 2 + 25,
-    background: '',
-    form: {
-      phone: '17319450324',
-      password: '1'
-    },
+    /**
+     * 页面的初始数据
+     */
+    data: {
+        height: app.globalData.height * 2 + 25,
+        background: '',
+        form: {},
 
-  },
-  initValidate() {
-    const rules = {
-      phone: { required: false, tel: true },
-      password: { required: false, },
-    }
-    // 验证字段的提示信息,若不传则调用默认的信息
-    const messages = {
-      phone: { required: '请输入账号', },
-      password: { required: '请输入密码', },
-    };
-    this.WxValidate = new WxValidate(rules, messages)
-  },
-  formSubmit: function (e) {
-    const params = e.detail.value;
-    if (!this.WxValidate.checkForm(params)) {
-      const error = this.WxValidate.errorList[0];
-      wx.showToast({
-        title: error.msg,
-        icon: 'error',
-        duration: 2000
-      })
-      return false
-    } else {
-      wx.switchTab({
-        url: '/pages/home/index',
-      })
-    }
-  },
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad: function (options) {
-    this.initValidate()//验证规则函数
-    wx.request({
-      url: `${app.globalData.publicUrl}/api/st/system/tenant/getTenant/${app.globalData.tenant}`,
-      method: "get",
-      header: { 'x-tenant': app.globalData.tenant },
-      data: {},
-      success: res => {
-        const { data } = res.data;
-        this.setData({ background: `${app.globalData.fileUrl}` + data.img.login })
-      },
-      error: err => {
-        wx.showToast({
-          title: err.msg,
-          icon: 'error'
+    },
+    initValidate() {
+        const rules = {
+            phone: { required: false, tel: true },
+            password: { required: false, },
+        }
+        // 验证字段的提示信息,若不传则调用默认的信息
+        const messages = {
+            phone: { required: '请输入账号', },
+            password: { required: '请输入密码', },
+        };
+        this.WxValidate = new WxValidate(rules, messages)
+    },
+    formSubmit: function (e) {
+        const params = e.detail.value;
+        if (!this.WxValidate.checkForm(params)) {
+            const error = this.WxValidate.errorList[0];
+            wx.showToast({
+                title: error.msg,
+                icon: 'error',
+                duration: 2000
+            })
+            return false
+        } else {
+            wx.switchTab({
+                url: '/pages/home/index',
+            })
+        }
+    },
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onLoad: function (options) {
+        this.initValidate()//验证规则函数
+        wx.request({
+            url: `${app.globalData.publicUrl}/api/st/system/tenant/getTenant/${app.globalData.tenant}`,
+            method: "get",
+            header: { 'x-tenant': app.globalData.tenant },
+            data: {},
+            success: res => {
+                const { data } = res.data;
+                this.setData({ background: `${app.globalData.fileUrl}` + data.img.login })
+            },
+            error: err => {
+                wx.showToast({
+                    title: err.msg,
+                    icon: 'error'
+                })
+            }
         })
-      }
-    })
-  },
+    },
 
-  /**
-   * 生命周期函数--监听页面初次渲染完成
-   */
-  onReady: function () {
+    /**
+     * 生命周期函数--监听页面初次渲染完成
+     */
+    onReady: function () {
 
-  },
+    },
 
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow: function () {
+    /**
+     * 生命周期函数--监听页面显示
+     */
+    onShow: function () {
 
-  },
+    },
 
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  onHide: function () {
+    /**
+     * 生命周期函数--监听页面隐藏
+     */
+    onHide: function () {
 
-  },
+    },
 
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload: function () {
+    /**
+     * 生命周期函数--监听页面卸载
+     */
+    onUnload: function () {
 
-  },
+    },
 
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh: function () {
+    /**
+     * 页面相关事件处理函数--监听用户下拉动作
+     */
+    onPullDownRefresh: function () {
 
-  },
+    },
 
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom: function () {
+    /**
+     * 页面上拉触底事件的处理函数
+     */
+    onReachBottom: function () {
 
-  },
+    },
 
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage: function () {
+    /**
+     * 用户点击右上角分享
+     */
+    onShareAppMessage: function () {
 
-  }
+    }
 })

+ 46 - 69
project.config.json

@@ -1,74 +1,51 @@
 {
-  "description": "项目配置文件",
-  "packOptions": {
-    "ignore": []
-  },
-  "setting": {
-    "urlCheck": false,
-    "es6": true,
-    "enhance": true,
-    "postcss": true,
-    "preloadBackgroundData": false,
-    "minified": true,
-    "newFeature": false,
-    "coverView": true,
-    "nodeModules": true,
-    "autoAudits": false,
-    "showShadowRootInWxmlPanel": true,
-    "scopeDataCheck": false,
-    "uglifyFileName": false,
-    "checkInvalidKey": true,
-    "checkSiteMap": true,
-    "uploadWithSourceMap": true,
-    "compileHotReLoad": false,
-    "useMultiFrameRuntime": true,
-    "useApiHook": true,
-    "useApiHostProcess": false,
-    "babelSetting": {
-      "ignore": [],
-      "disablePlugins": [],
-      "outputPath": ""
+    "description": "项目配置文件",
+    "packOptions": {
+        "ignore": [],
+        "include": []
     },
-    "enableEngineNative": false,
-    "useIsolateContext": true,
-    "useCompilerModule": true,
-    "userConfirmedUseCompilerModuleSwitch": false,
-    "userConfirmedBundleSwitch": false,
-    "packNpmManually": false,
-    "packNpmRelationList": [],
-    "minifyWXSS": true
-  },
-  "compileType": "miniprogram",
-  "libVersion": "2.17.3",
-  "appid": "wxe8b4c4d5e87a7d31",
-  "projectname": "smart-canteen",
-  "debugOptions": {
-    "hidedInDevtools": []
-  },
-  "scripts": {},
-  "staticServerOptions": {
-    "baseURL": "",
-    "servePath": ""
-  },
-  "isGameTourist": false,
-  "condition": {
-    "search": {
-      "list": []
+    "setting": {
+        "urlCheck": false,
+        "es6": true,
+        "enhance": true,
+        "postcss": true,
+        "preloadBackgroundData": false,
+        "minified": true,
+        "newFeature": false,
+        "coverView": true,
+        "nodeModules": true,
+        "autoAudits": false,
+        "showShadowRootInWxmlPanel": true,
+        "scopeDataCheck": false,
+        "uglifyFileName": false,
+        "checkInvalidKey": true,
+        "checkSiteMap": true,
+        "uploadWithSourceMap": true,
+        "compileHotReLoad": false,
+        "useMultiFrameRuntime": true,
+        "useApiHook": true,
+        "useApiHostProcess": false,
+        "babelSetting": {
+            "ignore": [],
+            "disablePlugins": [],
+            "outputPath": ""
+        },
+        "enableEngineNative": false,
+        "useIsolateContext": true,
+        "useCompilerModule": true,
+        "userConfirmedUseCompilerModuleSwitch": false,
+        "userConfirmedBundleSwitch": false,
+        "packNpmManually": false,
+        "packNpmRelationList": [],
+        "minifyWXSS": true
     },
-    "conversation": {
-      "list": []
-    },
-    "game": {
-      "list": []
-    },
-    "plugin": {
-      "list": []
-    },
-    "gamePlugin": {
-      "list": []
-    },
-    "miniprogram": {
-      "list": []
+    "compileType": "miniprogram",
+    "libVersion": "2.17.3",
+    "appid": "wxe8b4c4d5e87a7d31",
+    "projectname": "smart-canteen",
+    "condition": {},
+    "editorSetting": {
+        "tabIndent": "insertSpaces",
+        "tabSize": 4
     }
-  }
 }

+ 7 - 0
project.private.config.json

@@ -0,0 +1,7 @@
+{
+    "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
+    "projectname": "%E9%A3%9F%E5%A0%82",
+    "setting": {
+        "compileHotReLoad": false
+    }
+}

+ 39 - 39
utils/httpUtil.js

@@ -1,57 +1,57 @@
 let baseUrl = "";
 const $get = (uri, data) => {
-  let app = getApp();
-  let tenant = app.tenant || "test";
-  return new Promise((resolve, reject) => {
-    wx.request({
-      url: `${baseUrl}${uri}`,
-      method: "get",
-      data,
-      header: { "x-tenant": tenant },
-      success: (res) => toResolve(resolve, res),
-      error: (e) => toReject(reject, e),
+    let app = getApp();
+    let tenant = app.tenant || "master";
+    return new Promise((resolve, reject) => {
+        wx.request({
+            url: `${baseUrl}${uri}`,
+            method: "get",
+            data,
+            header: { "x-tenant": tenant },
+            success: (res) => toResolve(resolve, res),
+            error: (e) => toReject(reject, e),
+        });
     });
-  });
 };
 const $post = (uri, data) => {
-  let app = getApp();
-  let tenant = app.tenant || "test";
-  return new Promise((resolve, reject) => {
-    wx.request({
-      url: `${baseUrl}${uri}`,
-      method: "post",
-      data,
-      header: { "x-tenant": tenant },
-      success: (res) => toResolve(resolve, res),
-      error: (e) => toReject(reject, e),
+    let app = getApp();
+    let tenant = app.tenant || "master";
+    return new Promise((resolve, reject) => {
+        wx.request({
+            url: `${baseUrl}${uri}`,
+            method: "post",
+            data,
+            header: { "x-tenant": tenant },
+            success: (res) => toResolve(resolve, res),
+            error: (e) => toReject(reject, e),
+        });
     });
-  });
 };
 const $delete = (uri, data) => {
-  let app = getApp();
-  let tenant = app.tenant || "test";
-  return new Promise((resolve, reject) => {
-    wx.request({
-      url: `${baseUrl}${uri}`,
-      method: "delete",
-      data,
-      header: { "x-tenant": tenant },
-      success: (res) => toResolve(resolve, res),
-      error: (e) => toReject(reject, e),
+    let app = getApp();
+    let tenant = app.tenant || "master";
+    return new Promise((resolve, reject) => {
+        wx.request({
+            url: `${baseUrl}${uri}`,
+            method: "delete",
+            data,
+            header: { "x-tenant": tenant },
+            success: (res) => toResolve(resolve, res),
+            error: (e) => toReject(reject, e),
+        });
     });
-  });
 };
 
 const toResolve = (resolve, result) => {
-  if (result.statusCode === 200) resolve(result.data);
-  else {
-    console.error("请求失败");
-  }
+    if (result.statusCode === 200) resolve(result.data);
+    else {
+        console.error("请求失败");
+    }
 };
 
 const toReject = (reject, result) => {
-  console.error(result);
-  reject(result);
+    console.error(result);
+    reject(result);
 };
 
 module.exports = { $get, $post, $delete };