Browse Source

'搭建开发框架'

王启雄 1 year ago
commit
7d3cfd7900

+ 31 - 0
.eslintrc.js

@@ -0,0 +1,31 @@
+/*
+ * Eslint config file
+ * Documentation: https://eslint.org/docs/user-guide/configuring/
+ * Install the Eslint extension before using this feature.
+ */
+module.exports = {
+  env: {
+    es6: true,
+    browser: true,
+    node: true,
+  },
+  ecmaFeatures: {
+    modules: true,
+  },
+  parserOptions: {
+    ecmaVersion: 2018,
+    sourceType: 'module',
+  },
+  globals: {
+    wx: true,
+    App: true,
+    Page: true,
+    getCurrentPages: true,
+    getApp: true,
+    Component: true,
+    requirePlugin: true,
+    requireMiniProgram: true,
+  },
+  // extends: 'eslint:recommended',
+  rules: {},
+}

+ 1 - 0
api/baseUrl.js

@@ -0,0 +1 @@
+export default "http://bufantec.com"

+ 20 - 0
api/home/index.js

@@ -0,0 +1,20 @@
+import request from "../request"
+
+function orderZhan(data){
+    return request({
+        url:"admin/xy/lite/student/orderZhan",
+        method:"post",
+        data
+    })
+}
+function doLogin(data){
+    return request({
+        url:"admin/xy/lite/student/doLogin",
+        method:"get",
+        data
+    })
+}
+export {
+    orderZhan,
+    doLogin
+}

+ 0 - 0
api/index/index.js


+ 28 - 0
api/request.js

@@ -0,0 +1,28 @@
+import baseURL from "./baseUrl"
+
+var fun = function(config){
+  return new Promise((resolve,rejected)=>{
+    wx.request({
+      url:baseURL + config.url,
+      timeout:5000,
+      data:config.data,
+      method:config.method,
+      header:{
+        "content-type":"application/x-www-form-urlencoded"
+      },
+      success(res){
+        resolve(res.data)
+        // console.log(res)
+        // _this.setData({
+        //   list:res.data.data.list
+        // })
+        // this.setData({
+        //   list:res.data.data.list
+        // })
+      }
+    })
+  })
+}
+
+
+export default fun;

+ 19 - 0
app.js

@@ -0,0 +1,19 @@
+// app.js
+App({
+  onLaunch() {
+    // 展示本地存储能力
+    const logs = wx.getStorageSync('logs') || []
+    logs.unshift(Date.now())
+    wx.setStorageSync('logs', logs)
+
+    // 登录
+    wx.login({
+      success: res => {
+        // 发送 res.code 到后台换取 openId, sessionKey, unionId
+      }
+    })
+  },
+  globalData: {
+    userInfo: null
+  }
+})

+ 22 - 0
app.json

@@ -0,0 +1,22 @@
+{
+    "pages": [
+        "pages/home/index",
+        "pages/index/index"
+    ],
+    "window": {
+        "backgroundTextStyle": "light",
+        "navigationBarBackgroundColor": "#fff",
+        "navigationBarTitleText": "Weixin",
+        "navigationBarTextStyle": "black"
+    },
+    "subpackages":[
+        {
+            "root":"packageLogs",
+            "pages":[
+                "pages/logs/logs"
+            ]
+        }
+    ],
+    "style": "v2",
+    "sitemapLocation": "sitemap.json"
+}

+ 10 - 0
app.wxss

@@ -0,0 +1,10 @@
+/**app.wxss**/
+.container {
+  height: 100%;
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  justify-content: space-between;
+  padding: 200rpx 0;
+  box-sizing: border-box;
+} 

+ 18 - 0
packageLogs/pages/logs/logs.js

@@ -0,0 +1,18 @@
+// logs.js
+const util = require('../../../utils/util.js')
+
+Page({
+  data: {
+    logs: []
+  },
+  onLoad() {
+    this.setData({
+      logs: (wx.getStorageSync('logs') || []).map(log => {
+        return {
+          date: util.formatTime(new Date(log)),
+          timeStamp: log
+        }
+      })
+    })
+  }
+})

+ 4 - 0
packageLogs/pages/logs/logs.json

@@ -0,0 +1,4 @@
+{
+  "navigationBarTitleText": "查看启动日志",
+  "usingComponents": {}
+}

+ 6 - 0
packageLogs/pages/logs/logs.wxml

@@ -0,0 +1,6 @@
+<!--logs.wxml-->
+<view class="container log-list">
+  <block wx:for="{{logs}}" wx:key="timeStamp" wx:for-item="log">
+    <text class="log-item">{{index + 1}}. {{log.date}}</text>
+  </block>
+</view>

+ 8 - 0
packageLogs/pages/logs/logs.wxss

@@ -0,0 +1,8 @@
+.log-list {
+  display: flex;
+  flex-direction: column;
+  padding: 40rpx;
+}
+.log-item {
+  margin: 10rpx;
+}

+ 152 - 0
pages/home/index.js

@@ -0,0 +1,152 @@
+// pages/home/index.js
+
+import WxValidate from "../../utils/validate";
+
+import { orderZhan,doLogin } from "../../api/home/index"
+
+Page({
+
+    /**
+     * 页面的初始数据
+     */
+    data: {
+        isChecked:false,
+        array: ['高中', '大专', '本科', '本科及以上'],
+        index: 0,
+        date:"2023-02-17"
+    },
+    login(){
+      wx.login({
+        timeout:5000,
+        success(res){
+          doLogin({
+            code:res.code,
+            appid:"wx6a1adb1b9b8c2648"
+          })
+          .then(res1 =>{
+            wx.setStorageSync('token', res1.data.id)
+          })
+        }
+      })
+    },
+    submit(e){
+        console.log(e);
+        var params = e.detail.value
+        if (!this.WxValidate.checkForm(params)) {
+            //表单元素验证不通过,此处给出相应提示
+            let error = this.WxValidate.errorList;
+            console.log(error);
+            wx.showToast({ 
+                title:error[0].msg,
+                icon:"none",
+                duration:2000
+            })
+        }else{
+          params.id = wx.getStorage('token');
+          params.oldjob = "";
+          params.sex = params.sex ? 1 : 0;
+          orderZhan(params)
+          .then(res=>{
+            console.log(res);
+          })
+        }
+    },
+    bindPickerChange(e){
+        this.setData({
+            index:e.detail.value
+        })
+    },
+    bindRegionChange(){
+      this.setData({
+        index:e.detail.value
+      })
+    },
+    switchEvents(e){
+        this.setData({
+            isChecked:e.detail.value
+        })
+    },  
+    bindDateChange(e){
+        this.setData({
+            date:e.detail.value
+        })  
+    },
+
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onLoad: function (options) {
+        this.initValidate();
+    },
+    initValidate() {
+        let rules = {
+          age: {
+            required: true,
+            maxlength: [10,30]
+          },
+          sex: {
+            required: true
+          }
+        }
+    
+        let message = {
+          age: {
+            required: '请输入年龄',
+            maxlength: '报名的年龄在10-30岁之间'
+          },
+          sex:{
+            required:"性别必填"
+          }
+        }
+        //实例化当前的验证规则和提示消息
+        this.WxValidate = new WxValidate(rules, message);
+      },
+    /**
+     * 生命周期函数--监听页面初次渲染完成
+     */
+    onReady: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面显示
+     */
+    onShow: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面隐藏
+     */
+    onHide: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面卸载
+     */
+    onUnload: function () {
+
+    },
+
+    /**
+     * 页面相关事件处理函数--监听用户下拉动作
+     */
+    onPullDownRefresh: function () {
+
+    },
+
+    /**
+     * 页面上拉触底事件的处理函数
+     */
+    onReachBottom: function () {
+
+    },
+
+    /**
+     * 用户点击右上角分享
+     */
+    onShareAppMessage: function () {
+
+    }
+})

+ 3 - 0
pages/home/index.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 112 - 0
pages/home/index.wxml

@@ -0,0 +1,112 @@
+<!--pages/home/index.wxml-->
+<button bindtap="login">
+    登录
+</button>
+<form bindsubmit="submit">
+    <view class="item">
+        <view class="left">
+            姓名:
+        </view>
+        <view class="right">
+            <input type="text" value="张三" name="name" />
+        </view>
+    </view>
+    <view class="item">
+        <view class="left">
+            年龄:
+        </view>
+        <view class="right">
+            <input type="text" value="19" name="age" />
+        </view>
+    </view>
+    <view class="item">
+        <view class="left">
+            性别:
+        </view>
+        <view class="right">
+            <switch name="sex" bindchange="switchEvents" checked="{{isChecked}}"> {{isChecked?'男':'女'}}</switch>
+        </view>
+    </view>
+    <view class="item">
+        <view class="left">
+            电话:
+        </view>
+        <view class="right">
+            <input type="text" name="tel" value="18101000992" />
+        </view>
+    </view>
+    <view class="item">
+        <view class="left">
+            学历:
+        </view>
+        <view class="right">
+            <picker name="education" bindchange="bindPickerChange" value="{{index}}" range="{{array}}">
+                <view class="picker">
+                    当前选择:{{array[index]}}
+                </view>
+            </picker>
+        </view>
+    </view>
+    <view class="item">
+        <view class="left">
+            专业:
+        </view>
+        <view class="right">
+            <input type="text" name="major" value="计算机网络工程" />
+        </view>
+    </view>
+    <view class="item">
+        <view class="left">
+            毕业院校:
+        </view>
+        <view class="right">
+            <input type="text" name="school" value="五道口职业学院" />
+        </view>
+    </view>
+    <!-- <view class="item">
+        <view class="left">
+            是否已参加工作:
+        </view>
+        <view class="right">
+            <switch checked="{{false}}"></switch>
+        </view>
+    </view> -->
+    <view class="item">
+        <view class="left">
+            课程选择:
+        </view>
+        <view class="right">
+            <radio-group name="classType" bindchange="radioChange">
+                <radio value="0" checked="true" />UI
+                <radio value="1" />前端
+            </radio-group>
+        </view>
+    </view>
+    <view class="item">
+        <view class="left">
+            选择日期:
+        </view>
+        <view class="right">
+            <picker name="startDate" mode="date" value="{{date}}" start="2015-09-01" end="2017-09-01" bindchange="bindDateChange">
+                <view class="picker">
+                    当前选择: {{date}}
+                </view>
+            </picker>
+        </view>
+    </view>
+    <view class="item">
+        <view class="left">
+            学历:
+        </view>
+        <view class="right">
+            <picker mode="region" bindchange="bindRegionChange">
+                <view class="picker">
+                    当前选择:{{region[0]}},{{region[1]}},{{region[2]}}
+                </view>
+            </picker>
+        </view>
+    </view>
+    <button form-type="submit">
+        提交
+    </button>
+</form>

+ 14 - 0
pages/home/index.wxss

@@ -0,0 +1,14 @@
+/* pages/home/index.wxss */
+.item{
+    display: flex;
+    align-items: center;
+    padding: 10px;
+    justify-content: space-between;
+    border-bottom: 1px solid #ccc;
+}
+.item .left{
+    margin-right: 10px;
+}
+.item .right input{
+    text-align: right;
+}

+ 21 - 0
pages/index/index.js

@@ -0,0 +1,21 @@
+// index.js
+// 获取应用实例
+const app = getApp()
+
+Page({
+  data: {
+  
+  },
+  getFormVal(){
+    
+  },
+  onLoad() {
+    
+  },
+  getUserProfile(e) {
+    
+  },
+  getUserInfo(e) {
+  
+  }
+})

+ 3 - 0
pages/index/index.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 9 - 0
pages/index/index.wxml

@@ -0,0 +1,9 @@
+<!--index.wxml-->
+<form bindsubmit="getFormVal">
+  <input type="text" placeholder="请输入内容" bindtap="getIptVal" name="age" />
+  <input type="text" placeholder="请输入内容" bindtap="getIptVal" name="name" />
+  <input type="text" placeholder="请输入内容" bindtap="getIptVal" name="likes" />
+  <button form-type="submit">
+    提交
+  </button>
+</form>

+ 19 - 0
pages/index/index.wxss

@@ -0,0 +1,19 @@
+/**index.wxss**/
+.userinfo {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  color: #aaa;
+}
+
+.userinfo-avatar {
+  overflow: hidden;
+  width: 128rpx;
+  height: 128rpx;
+  margin: 20rpx;
+  border-radius: 50%;
+}
+
+.usermotto {
+  margin-top: 200px;
+}

+ 82 - 0
project.config.json

@@ -0,0 +1,82 @@
+{
+    "description": "项目配置文件",
+    "packOptions": {
+        "ignore": [
+            {
+                "type": "file",
+                "value": ".eslintrc.js"
+            }
+        ]
+    },
+    "setting": {
+        "urlCheck": false,
+        "es6": true,
+        "enhance": true,
+        "postcss": true,
+        "preloadBackgroundData": false,
+        "minified": true,
+        "newFeature": false,
+        "coverView": true,
+        "nodeModules": false,
+        "autoAudits": false,
+        "showShadowRootInWxmlPanel": true,
+        "scopeDataCheck": false,
+        "uglifyFileName": false,
+        "checkInvalidKey": true,
+        "checkSiteMap": true,
+        "uploadWithSourceMap": true,
+        "compileHotReLoad": true,
+        "lazyloadPlaceholderEnable": false,
+        "useMultiFrameRuntime": true,
+        "useApiHook": true,
+        "useApiHostProcess": true,
+        "babelSetting": {
+            "ignore": [],
+            "disablePlugins": [],
+            "outputPath": ""
+        },
+        "useIsolateContext": true,
+        "userConfirmedBundleSwitch": false,
+        "packNpmManually": false,
+        "packNpmRelationList": [],
+        "minifyWXSS": true,
+        "disableUseStrict": false,
+        "minifyWXML": true,
+        "showES6CompileOption": false,
+        "useCompilerPlugins": false,
+        "ignoreUploadUnusedFiles": true
+    },
+    "compileType": "miniprogram",
+    "libVersion": "2.19.4",
+    "appid": "wx6a1adb1b9b8c2648",
+    "projectname": "miniprogram-6",
+    "debugOptions": {
+        "hidedInDevtools": []
+    },
+    "scripts": {},
+    "staticServerOptions": {
+        "baseURL": "",
+        "servePath": ""
+    },
+    "isGameTourist": false,
+    "condition": {
+        "search": {
+            "list": []
+        },
+        "conversation": {
+            "list": []
+        },
+        "game": {
+            "list": []
+        },
+        "plugin": {
+            "list": []
+        },
+        "gamePlugin": {
+            "list": []
+        },
+        "miniprogram": {
+            "list": []
+        }
+    }
+}

+ 7 - 0
sitemap.json

@@ -0,0 +1,7 @@
+{
+  "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
+  "rules": [{
+  "action": "allow",
+  "page": "*"
+  }]
+}

+ 19 - 0
utils/util.js

@@ -0,0 +1,19 @@
+const formatTime = date => {
+  const year = date.getFullYear()
+  const month = date.getMonth() + 1
+  const day = date.getDate()
+  const hour = date.getHours()
+  const minute = date.getMinutes()
+  const second = date.getSeconds()
+
+  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
+}
+
+const formatNumber = n => {
+  n = n.toString()
+  return n[1] ? n : `0${n}`
+}
+
+module.exports = {
+  formatTime
+}

+ 418 - 0
utils/validate.js

@@ -0,0 +1,418 @@
+/**
+ * 表单验证
+ *
+ * @param {Object} rules 验证字段的规则
+ * @param {Object} messages 验证字段的提示信息
+ *
+ */
+class WxValidate {
+    constructor(rules = {}, messages = {}) {
+        Object.assign(this, {
+            data: {},
+            rules,
+            messages,
+        })
+        this.__init()
+    }
+
+    /**
+     * __init
+     */
+    __init() {
+        this.__initMethods()
+        this.__initDefaults()
+        this.__initData()
+    }
+
+    /**
+     * 初始化数据
+     */
+    __initData() {
+        this.form = {}
+        this.errorList = []
+    }
+
+    /**
+     * 初始化默认提示信息
+     */
+    __initDefaults() {
+        this.defaults = {
+            messages: {
+                required: '这是必填字段。',
+                email: '请输入有效的电子邮件地址。',
+                tel: '请输入11位的手机号码。',
+                url: '请输入有效的网址。',
+                date: '请输入有效的日期。',
+                dateISO: '请输入有效的日期(ISO),例如:2009-06-23,1998/01/22。',
+                number: '请输入有效的数字。',
+                digits: '只能输入数字。',
+                idcard: '请输入18位的有效身份证。',
+                equalTo: this.formatTpl('输入值必须和 {0} 相同。'),
+                contains: this.formatTpl('输入值必须包含 {0}。'),
+                minlength: this.formatTpl('最少要输入 {0} 个字符。'),
+                maxlength: this.formatTpl('最多可以输入 {0} 个字符。'),
+                rangelength: this.formatTpl('请输入长度在 {0} 到 {1} 之间的字符。'),
+                min: this.formatTpl('请输入不小于 {0} 的数值。'),
+                max: this.formatTpl('请输入不大于 {0} 的数值。'),
+                range: this.formatTpl('请输入范围在 {0} 到 {1} 之间的数值。'),
+            }
+        }
+    }
+
+    /**
+     * 初始化默认验证方法
+     */
+    __initMethods() {
+        const that = this
+        that.methods = {
+            /**
+             * 验证必填元素
+             */
+            required(value, param) {
+                if (!that.depend(param)) {
+                    return 'dependency-mismatch'
+                } else if (typeof value === 'number') {
+                    value = value.toString()
+                } else if (typeof value === 'boolean') {
+                    return !0
+                }
+
+                return value.length > 0
+            },
+            /**
+             * 验证电子邮箱格式
+             */
+            email(value) {
+                return that.optional(value) || /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(value)
+            },
+            /**
+             * 验证手机格式
+             */
+            tel(value) {
+                return that.optional(value) || /^1[34578]\d{9}$/.test(value)
+            },
+            /**
+             * 验证URL格式
+             */
+            url(value) {
+                return that.optional(value) || /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(value)
+            },
+            /**
+             * 验证日期格式
+             */
+            date(value) {
+                return that.optional(value) || !/Invalid|NaN/.test(new Date(value).toString())
+            },
+            /**
+             * 验证ISO类型的日期格式
+             */
+            dateISO(value) {
+                return that.optional(value) || /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(value)
+            },
+            /**
+             * 验证十进制数字
+             */
+            number(value) {
+                return that.optional(value) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(value)
+            },
+            /**
+             * 验证整数
+             */
+            digits(value) {
+                return that.optional(value) || /^\d+$/.test(value)
+            },
+            /**
+             * 验证身份证号码
+             */
+            idcard(value) {
+                return that.optional(value) || /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(value)
+            },
+            /**
+             * 验证两个输入框的内容是否相同
+             */
+            equalTo(value, param) {
+                return that.optional(value) || value === that.data[param]
+            },
+            /**
+             * 验证是否包含某个值
+             */
+            contains(value, param) {
+                return that.optional(value) || value.indexOf(param) >= 0
+            },
+            /**
+             * 验证最小长度
+             */
+            minlength(value, param) {
+                return that.optional(value) || value.length >= param
+            },
+            /**
+             * 验证最大长度
+             */
+            maxlength(value, param) {
+                return that.optional(value) || value.length <= param
+            },
+            /**
+             * 验证一个长度范围[min, max]
+             */
+            rangelength(value, param) {
+                return that.optional(value) || (value.length >= param[0] && value.length <= param[1])
+            },
+            /**
+             * 验证最小值
+             */
+            min(value, param) {
+                return that.optional(value) || value >= param
+            },
+            /**
+             * 验证最大值
+             */
+            max(value, param) {
+                return that.optional(value) || value <= param
+            },
+            /**
+             * 验证一个值范围[min, max]
+             */
+            range(value, param) {
+                return that.optional(value) || (value >= param[0] && value <= param[1])
+            },
+        }
+    }
+
+    /**
+     * 添加自定义验证方法
+     * @param {String} name 方法名
+     * @param {Function} method 函数体,接收两个参数(value, param),value表示元素的值,param表示参数
+     * @param {String} message 提示信息
+     */
+    addMethod(name, method, message) {
+        this.methods[name] = method
+        this.defaults.messages[name] = message !== undefined ? message : this.defaults.messages[name]
+    }
+
+    /**
+     * 判断验证方法是否存在
+     */
+    isValidMethod(value) {
+        let methods = []
+        for (let method in this.methods) {
+            if (method && typeof this.methods[method] === 'function') {
+                methods.push(method)
+            }
+        }
+        return methods.indexOf(value) !== -1
+    }
+
+    /**
+     * 格式化提示信息模板
+     */
+    formatTpl(source, params) {
+        const that = this
+        if (arguments.length === 1) {
+            return function() {
+                let args = Array.from(arguments)
+                args.unshift(source)
+                return that.formatTpl.apply(this, args)
+            }
+        }
+        if (params === undefined) {
+            return source
+        }
+        if (arguments.length > 2 && params.constructor !== Array) {
+            params = Array.from(arguments).slice(1)
+        }
+        if (params.constructor !== Array) {
+            params = [params]
+        }
+        params.forEach(function(n, i) {
+            source = source.replace(new RegExp("\\{" + i + "\\}", "g"), function() {
+                return n
+            })
+        })
+        return source
+    }
+
+    /**
+     * 判断规则依赖是否存在
+     */
+    depend(param) {
+        switch (typeof param) {
+            case 'boolean':
+                param = param
+                break
+            case 'string':
+                param = !!param.length
+                break
+            case 'function':
+                param = param()
+            default:
+                param = !0
+        }
+        return param
+    }
+
+    /**
+     * 判断输入值是否为空
+     */
+    optional(value) {
+        return !this.methods.required(value) && 'dependency-mismatch'
+    }
+
+    /**
+     * 获取自定义字段的提示信息
+     * @param {String} param 字段名
+     * @param {Object} rule 规则
+     */
+    customMessage(param, rule) {
+        const params = this.messages[param]
+        const isObject = typeof params === 'object'
+        if (params && isObject) return params[rule.method]
+    }
+
+    /**
+     * 获取某个指定字段的提示信息
+     * @param {String} param 字段名
+     * @param {Object} rule 规则
+     */
+    defaultMessage(param, rule) {
+        let message = this.customMessage(param, rule) || this.defaults.messages[rule.method]
+        let type = typeof message
+
+        if (type === 'undefined') {
+            message = `Warning: No message defined for ${rule.method}.`
+        } else if (type === 'function') {
+            message = message.call(this, rule.parameters)
+        }
+
+        return message
+    }
+
+    /**
+     * 缓存错误信息
+     * @param {String} param 字段名
+     * @param {Object} rule 规则
+     * @param {String} value 元素的值
+     */
+    formatTplAndAdd(param, rule, value) {
+        let msg = this.defaultMessage(param, rule)
+
+        this.errorList.push({
+            param: param,
+            msg: msg,
+            value: value,
+        })
+    }
+
+    /**
+     * 验证某个指定字段的规则
+     * @param {String} param 字段名
+     * @param {Object} rules 规则
+     * @param {Object} data 需要验证的数据对象
+     */
+    checkParam(param, rules, data) {
+
+        // 缓存数据对象
+        this.data = data
+
+        // 缓存字段对应的值
+        const value = data[param] !== null && data[param] !== undefined ? data[param] : ''
+
+        // 遍历某个指定字段的所有规则,依次验证规则,否则缓存错误信息
+        for (let method in rules) {
+
+            // 判断验证方法是否存在
+            if (this.isValidMethod(method)) {
+
+                // 缓存规则的属性及值
+                const rule = {
+                    method: method,
+                    parameters: rules[method]
+                }
+
+                // 调用验证方法
+                const result = this.methods[method](value, rule.parameters)
+
+                // 若result返回值为dependency-mismatch,则说明该字段的值为空或非必填字段
+                if (result === 'dependency-mismatch') {
+                    continue
+                }
+
+                this.setValue(param, method, result, value)
+
+                // 判断是否通过验证,否则缓存错误信息,跳出循环
+                if (!result) {
+                    this.formatTplAndAdd(param, rule, value)
+                    break
+                }
+            }
+        }
+    }
+
+    /**
+     * 设置字段的默认验证值
+     * @param {String} param 字段名
+     */
+    setView(param) {
+        this.form[param] = {
+            $name: param,
+            $valid: true,
+            $invalid: false,
+            $error: {},
+            $success: {},
+            $viewValue: ``,
+        }
+    }
+
+    /**
+     * 设置字段的验证值
+     * @param {String} param 字段名
+     * @param {String} method 字段的方法
+     * @param {Boolean} result 是否通过验证
+     * @param {String} value 字段的值
+     */
+    setValue(param, method, result, value) {
+        const params = this.form[param]
+        params.$valid = result
+        params.$invalid = !result
+        params.$error[method] = !result
+        params.$success[method] = result
+        params.$viewValue = value
+    }
+
+    /**
+     * 验证所有字段的规则,返回验证是否通过
+     * @param {Object} data 需要验证数据对象
+     */
+    checkForm(data) {
+        this.__initData()
+
+        for (let param in this.rules) {
+            this.setView(param)
+            this.checkParam(param, this.rules[param], data)
+        }
+
+        return this.valid()
+    }
+
+    /**
+     * 返回验证是否通过
+     */
+    valid() {
+        return this.size() === 0
+    }
+
+    /**
+     * 返回错误信息的个数
+     */
+    size() {
+        return this.errorList.length
+    }
+
+    /**
+     * 返回所有错误信息
+     */
+    validationErrors() {
+        return this.errorList
+    }
+}
+
+export default WxValidate