陈龙 11 kuukautta sitten
vanhempi
commit
414302b1b9

+ 529 - 527
src/app.js

@@ -3,531 +3,533 @@ const util = require("utils/util");
 const jsonlint = require("utils/jsonlint");
 
 App({
-	onLaunch: function () {
-		// 获取系统状态栏信息
-		wx.getSystemInfo({
-			success: e => {
-				this.globalData.StatusBar = e.statusBarHeight;
-				let capsule = wx.getMenuButtonBoundingClientRect();
-				if (capsule) {
-					this.globalData.Custom = capsule;
-					// this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
-					// this.globalData.CustomBar = (capsule.top - e.statusBarHeight) * 2 + capsule.height + e.statusBarHeight;
-					// this.globalData.CustomBar = capsule.height + e.statusBarHeight + capsule.top;
-					this.globalData.CustomBar = 44 + e.statusBarHeight;
-				  } else {
-					this.globalData.CustomBar = e.statusBarHeight + 50;
-				  }
-			}
-		});
-	},
-
-	/**
-	 * 全局数据
-	 */
-	globalData: {
-		Custom: 50,
-		userInfo: null,
-		code: "",
-		isWxLogin: false,
-		openid: "",
-		session_key: "",
-		token_type: "",
-		access_token: "",
-		username: "",
-		password: ""
-	},
-
-	/**
-	 * 获取域
-	 * @param {string} param 参数
-	 */
-	GetDomain: function (param) {
-		var domain = '';
-		param = typeof param !== 'string' ? '' : param.toUpperCase();
-		switch (param) {
-			// 本地
-			// case 'AUTHSERVER':
-			// 	domain = 'http://localhost:5100';
-			// 	break;
-			// case 'HOST':
-			// default:
-			// 	domain = 'http://localhost:5101';
-
-			// 程雪阳
-			// case 'AUTHSERVER':
-			// 	domain = 'http://192.168.3.154:5100';
-			// 	break;
-			// case 'HOST':
-			// default:
-			// 	domain = 'http://192.168.3.154:5101';
-
-			// 测试
-			// case 'AUTHSERVER':
-			// 	domain = 'https://www.befrisoft.com:6100';
-			// 	break;
-			// case 'HOST':
-			// default:
-			// 	domain = 'https://www.befrisoft.com:6101';
-
-			// 正式
-			case 'AUTHSERVER':
-				domain = 'https://www.sun-hoo.cn:6100';
-				break;
-			case 'HOST':
-			default:
-				domain = 'https://www.sun-hoo.cn:6101';
-		}
-		return domain;
-	},
-
-	/**
-	 * 授权
-	 */
-	Authorize: function (paramenter) {
-		wx.getSetting({
-			success: function (res) {
-				/**
-				 * 如果没有授权,进行授权操作
-				 * 授权成功后,调用授权完成方法
-				 * 如果已授权,调用授权完成方法
-				 */
-				if (!res.authSetting["scope." + paramenter.scope]) {
-					wx.authorize({
-						scope: paramenter.scope,
-						success: function (res) {
-							if (typeof paramenter.success === "function") {
-								paramenter.success(res);
-							}
-						},
-						fail: function () {
-							if (typeof paramenter.fail === "function") {
-								paramenter.fail();
-							}
-						}
-					});
-				} else if (typeof paramenter.success === "function") {
-					paramenter.success();
-				}
-			}
-		});
-	},
-
-	/**
-	 * 请求
-	 */
-	Request: function (options, notVerify) {
-		var app = this;
-		if (!(typeof options.url === 'string' && options.url.length > 0)) {
-			return;
-		}
-		options.url += (options.url.indexOf('?') > 0 ? '&' : '?') + 'v=' + Date.now().toString();
-		options.header = typeof options.header === 'object' ? options.header : {};
-		options.method = options.method || 'get';
-		options.header['content-type'] = util.stringIsNullOrWhiteSpace(options.header['content-type']) ? 'application/json' : options.header['content-type'];
-		switch (options.header['content-type']) {
-			case 'application/json':
-				switch (options.method) {
-					case 'post':
-					case 'put':
-					case 'delete':
-						if (typeof options.data === 'object') {
-							options.data = JSON.stringify(options.data);
-						}
-						break;
-					default:
-						if (typeof options.data === 'object') {
-							options.data = util.encodeObject(options.data);
-						}
-				}
-				break;
-		}
-		if (notVerify) {
-			Send();
-		} else {
-			app.GetAuth({
-				success: res => {
-					options.header.Authorization = res.token_type + ' ' + res.access_token;
-					Send();
-				},
-				fail: res => {
-					options.fail(res);
-				}
-			});
-		}
-
-		/**
-		 * 发送请求方法
-		 */
-		function Send() {
-			wx.request({
-				url: options.url || "",
-				method: options.method || "get",
-				header: options.header || null,
-				data: options.data || {},
-				dataType: options.dataType || 'text',
-				enableCache: false,
-				success: res => {
-					try {
-						if (res.statusCode === 200) {
-							var result = {};
-							if (!util.stringIsNullOrWhiteSpace(res.data)) {
-								if (options.jsonlint) {
-									result = jsonlint.parse(res.data);
-								} else {
-									result = JSON.parse(res.data);
-								}
-							} else {
-								result = res.data;
-							}
-							options.success(result);
-						} else {
-							options.fail(util.formatError(res));
-						}
-					} catch (ex) {
-						wx.showModal({
-							title: '提示',
-							content: util.formatError(ex).errMsg
-						});
-					}
-				},
-				fail: res => {
-					try {
-						options.fail(util.formatError(res));
-					} catch (ex) {
-						wx.showModal({
-							title: '提示',
-							content: util.formatError(ex).errMsg
-						});
-					}
-				}
-			});
-		}
-	},
-
-	/**
-	 * 登录
-	 */
-	Login: function (options) {
-		var app = this;
-		if (util.objectIsNullOrEmpty(options) || util.objectIsNullOrEmpty(options.data)) {
-			return options.fail({
-				errMsg: '参数不正确'
-			});
-		}
-		if (util.stringIsNullOrWhiteSpace(options.data.username)) {
-			return options.fail({
-				errMsg: '账号为空'
-			});
-		}
-		if (util.stringIsNullOrWhiteSpace(options.data.password)) {
-			return options.fail({
-				errMsg: '密码为空'
-			});
-		}
-		options.data.grant_type = 'password';
-		options.data.client_id = 'sunhooDeskApp';
-		//options.data.client_id = 'SunhooWeb';
-		options.data.client_secret = 'sunhoo';
-		//options.data.client_secret = 'Sunhoo';
-		options.header = typeof options.header === 'object' ? options.header : {};
-		options.header['content-type'] = 'application/x-www-form-urlencoded';
-		this.Request({
-			url: app.GetDomain('authserver') + '/connect/token',
-			method: options.type || 'post',
-			header: options.header,
-			data: options.data,
-			dataType: options.dataType,
-			success: res => {
-				app.SetAuth(res);
-				// 获取用户信息
-				app.GetCurrentUser({
-					success: result => {
-						app.SetAccount({
-							username: options.data.username,
-							password: options.data.password
-						});
-						app.SetUser(result);
-						options.success(res);
-					},
-					fail: result => {
-						options.fail(result);
-					}
-				});
-			},
-			fail: res => {
-				options.fail(res);
-			}
-		}, true);
-	},
-
-	/**
-	 * 重新登录
-	 */
-	Relogin: function (options) {
-		var app = this;
-		this.GetAccount({
-			success: function (res) {
-				app.Login({
-					data: res,
-					success: function (res) {
-						app.SetAuth(res);
-						if (typeof options.success === 'function') {
-							options.success(res);
-						}
-					},
-					fail: function (res) {
-						app.RemoveAuth();
-						options.fail(res);
-					}
-				});
-			},
-			fail: res => {
-				options.fail(res);
-			}
-		});
-	},
-
-	/**
-	 * 登出
-	 */
-	Logout: function (options) {
-		try {
-			this.RemoveAuth();
-			this.RemoveAccount();
-			this.RemoveUser();
-			if (typeof options.success === 'function') {
-				options.success();
-			}
-		} catch (ex) {
-			if (typeof options.fail === 'function') {
-				options.fail(util.formatError(res));
-			}
-		}
-	},
-
-	/**
-	 * 获取当前用户信息
-	 */
-	GetCurrentUser: function (options) {
-		var app = this;
-		this.Request({
-			jsonlint: true,
-			url: this.GetDomain() + '/api/BefriUser/CurrentUser',
-			success: res => {
-				app.SetUser(res);
-				options.success(res);
-			},
-			fail: res => {
-				options.fail(res);
-			}
-		});
-	},
-
-	/**
-	 * 设置认证信息
-	 */
-	SetAuth: function (data) {
-		wx.setStorage({
-			key: 'auth',
-			data: data || '',
-		});
-	},
-
-	/**
-	 * 获取认证信息
-	 */
-	GetAuth: function (data) {
-		wx.getStorage({
-			key: 'auth',
-			success: res => {
-				data.success(res.data);
-			},
-			fail: res => {
-				data.fail(util.formatError(res));
-			}
-		});
-	},
-
-	/**
-	 * 删除认证信息
-	 */
-	RemoveAuth: function () {
-		wx.removeStorage({
-			key: 'auth'
-		});
-	},
-
-	/**
-	 * 判断认证是否过期
-	 * */
-	AuthIsExpires: function (data) {
-		this.GetAuth({
-			success: function (res) {
-				try {
-					if (typeof res === 'object' && res.date > new Date()) {
-						data.success();
-					} else {
-						data.fail();
-					}
-				} catch (ex) {
-					data.fail(ex);
-				}
-			}
-		});
-	},
-
-	/**
-	 * 设置账户信息
-	 */
-	SetAccount: function (data) {
-		wx.setStorage({
-			key: 'account',
-			data: data || '',
-		});
-	},
-
-	/**
-	 * 获取账户信息
-	 */
-	GetAccount: function (data) {
-		wx.getStorage({
-			key: 'account',
-			success: res => {
-				data.success(res.data);
-			},
-			fail: res => {
-				data.fail(util.formatError(res));
-			}
-		})
-	},
-
-	/**
-	 * 删除账户信息
-	 */
-	RemoveAccount: function () {
-		wx.removeStorage({
-			key: 'account'
-		});
-	},
-
-	/**
-	 * 设置用户信息
-	 */
-	SetUser: function (data) {
-		wx.setStorage({
-			key: 'user',
-			data: data || '',
-		});
-	},
-
-	/**
-	 * 获取用户信息
-	 */
-	GetUser: function (data) {
-		wx.getStorage({
-			key: 'user',
-			success: res => {
-				data.success(res.data);
-			},
-			fail: res => {
-				data.fail(util.formatError(res));
-			}
-		})
-	},
-
-	/**
-	 * 删除用户信息
-	 */
-	RemoveUser: function () {
-		wx.removeStorage({
-			key: 'user'
-		});
-	},
-
-	/**
-	 * 验证
-	 */
-	Validate: {
-		//验证邮箱
-		Email: function (value) {
-			return /^[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);
-		},
-
-		//验证 url 地址
-		Url: function (value) {
-			return /^(?:(?:(?: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: function (value) {
-			return !/Invalid|NaN/.test(new Date(value).toString());
-		},
-
-		//验证 ISO 格式日期
-		DateISO: function (value) {
-			return /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(value);
-		},
-
-		//验证数字
-		Number: function (value) {
-			return /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(value);
-		},
-
-		//验证整数
-		Digits: function (value) {
-			return /^\d+$/.test(value);
-		},
-
-		//比较最小长度
-		Minlength: function (value, param) {
-			var length = value instanceof Array ? value.length : typeof value == 'string' ? value.length : 0;
-			return length >= param;
-		},
-
-		//比较最大长度
-		Maxlength: function (value, param) {
-			var length = value instanceof Array ? value.length : typeof value == 'string' ? value.length : 0;
-			return length <= param;
-		},
-
-		//验证长度区间
-		Rangelength: function (value, param) {
-			var length = value instanceof Array ? value.length : typeof value == 'string' ? value.length : 0;
-			return length >= param[0] && length <= param[1];
-		},
-
-		//比较最小值
-		Min: function (value, param) {
-			return value >= param;
-		},
-
-		//比较最大值
-		Max: function (value, param) {
-			return value <= param;
-		},
-
-		//验证数字区间
-		Range: function (value, param) {
-			return value >= param[0] && value <= param[1];
-		},
-
-		// 验证手机号
-		PhoneNumber: function (value) {
-			return /^1(3|4|5|7|8|9)\d{9}$/.test(value);
-		},
-
-		// 验证身份证
-		IDCard: function (value) {
-			return /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/.test(value);
-		},
-
-		// 验证密码
-		Password: function (value, min, max) {
-			min = Number.IsNullOrEmpty(min) ? 1 : min;
-			max = Number.IsNullOrEmpty(max) ? 256 : max;
-			var regexp = eval('/^([a-z]|[A-Z]|[0-9]|[_-]){' + min + ',' + max + '}$/');
-			return regexp.test(value);
-		}
-	}
+    onLaunch: function () {
+        // 获取系统状态栏信息
+        wx.getSystemInfo({
+            success: e => {
+                this.globalData.StatusBar = e.statusBarHeight;
+                let capsule = wx.getMenuButtonBoundingClientRect();
+                if (capsule) {
+                    this.globalData.Custom = capsule;
+                    // this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
+                    // this.globalData.CustomBar = (capsule.top - e.statusBarHeight) * 2 + capsule.height + e.statusBarHeight;
+                    // this.globalData.CustomBar = capsule.height + e.statusBarHeight + capsule.top;
+                    this.globalData.CustomBar = 44 + e.statusBarHeight;
+                } else {
+                    this.globalData.CustomBar = e.statusBarHeight + 50;
+                }
+            }
+        });
+    },
+
+    /**
+     * 全局数据
+     */
+    globalData: {
+        Custom: 50,
+        userInfo: null,
+        code: "",
+        isLogin: false,
+        isWxLogin: false,
+        openid: "",
+        session_key: "",
+        token_type: "",
+        access_token: "",
+        username: "",
+        password: ""
+    },
+
+    /**
+     * 获取域
+     * @param {string} param 参数
+     */
+    GetDomain: function (param) {
+        var domain = '';
+        param = typeof param !== 'string' ? '' : param.toUpperCase();
+        switch (param) {
+            // 本地
+            // case 'AUTHSERVER':
+            //     domain = 'http://localhost:5100';
+            //     break;
+            // case 'HOST':
+            // default:
+            //     domain = 'http://localhost:5101';
+
+            // 程雪阳
+            // case 'AUTHSERVER':
+            //     domain = 'http://192.168.3.154:5100';
+            //     break;
+            // case 'HOST':
+            // default:
+            //     domain = 'http://192.168.3.154:5101';
+
+            // 测试
+            // case 'AUTHSERVER':
+            //     domain = 'https://www.befrisoft.com:6100';
+            //     break;
+            // case 'HOST':
+            // default:
+            //     domain = 'https://www.befrisoft.com:6101';
+
+            // 正式
+            case 'AUTHSERVER':
+                domain = 'https://www.sun-hoo.cn:6100';
+                break;
+            case 'HOST':
+            default:
+                domain = 'https://www.sun-hoo.cn:6101';
+        }
+        return domain;
+    },
+
+    /**
+     * 授权
+     */
+    Authorize: function (paramenter) {
+        wx.getSetting({
+            success: function (res) {
+                /**
+                 * 如果没有授权,进行授权操作
+                 * 授权成功后,调用授权完成方法
+                 * 如果已授权,调用授权完成方法
+                 */
+                if (!res.authSetting["scope." + paramenter.scope]) {
+                    wx.authorize({
+                        scope: paramenter.scope,
+                        success: function (res) {
+                            if (typeof paramenter.success === "function") {
+                                paramenter.success(res);
+                            }
+                        },
+                        fail: function () {
+                            if (typeof paramenter.fail === "function") {
+                                paramenter.fail();
+                            }
+                        }
+                    });
+                } else if (typeof paramenter.success === "function") {
+                    paramenter.success();
+                }
+            }
+        });
+    },
+
+    /**
+     * 请求
+     */
+    Request: function (options, notVerify) {
+        var app = this;
+        if (!(typeof options.url === 'string' && options.url.length > 0)) {
+            return;
+        }
+        options.url += (options.url.indexOf('?') > 0 ? '&' : '?') + 'v=' + Date.now().toString();
+        options.header = typeof options.header === 'object' ? options.header : {};
+        options.method = options.method || 'get';
+        options.header['content-type'] = util.stringIsNullOrWhiteSpace(options.header['content-type']) ? 'application/json' : options.header['content-type'];
+        switch (options.header['content-type']) {
+            case 'application/json':
+                switch (options.method) {
+                    case 'post':
+                    case 'put':
+                    case 'delete':
+                        if (typeof options.data === 'object') {
+                            options.data = JSON.stringify(options.data);
+                        }
+                        break;
+                    default:
+                        if (typeof options.data === 'object') {
+                            options.data = util.encodeObject(options.data);
+                        }
+                }
+                break;
+        }
+        if (notVerify) {
+            Send();
+        } else {
+            app.GetAuth({
+                success: res => {
+                    options.header.Authorization = res.token_type + ' ' + res.access_token;
+                    Send();
+                },
+                fail: res => {
+                    options.fail(res);
+                }
+            });
+        }
+
+        /**
+         * 发送请求方法
+         */
+        function Send() {
+            wx.request({
+                url: options.url || "",
+                method: options.method || "get",
+                header: options.header || null,
+                data: options.data || {},
+                dataType: options.dataType || 'text',
+                enableCache: false,
+                success: res => {
+                    try {
+                        if (res.statusCode === 200) {
+                            var result = {};
+                            if (!util.stringIsNullOrWhiteSpace(res.data)) {
+                                if (options.jsonlint) {
+                                    result = jsonlint.parse(res.data);
+                                } else {
+                                    result = JSON.parse(res.data);
+                                }
+                            } else {
+                                result = res.data;
+                            }
+                            options.success(result);
+                        } else {
+                            options.fail(util.formatError(res));
+                        }
+                    } catch (ex) {
+                        wx.showModal({
+                            title: '提示',
+                            content: util.formatError(ex).errMsg
+                        });
+                    }
+                },
+                fail: res => {
+                    try {
+                        options.fail(util.formatError(res));
+                    } catch (ex) {
+                        wx.showModal({
+                            title: '提示',
+                            content: util.formatError(ex).errMsg
+                        });
+                    }
+                }
+            });
+        }
+    },
+
+    /**
+     * 登录
+     */
+    Login: function (options) {
+        var app = this;
+        if (util.objectIsNullOrEmpty(options) || util.objectIsNullOrEmpty(options.data)) {
+            return options.fail({
+                errMsg: '参数不正确'
+            });
+        }
+        if (util.stringIsNullOrWhiteSpace(options.data.username)) {
+            return options.fail({
+                errMsg: '账号为空'
+            });
+        }
+        if (util.stringIsNullOrWhiteSpace(options.data.password)) {
+            return options.fail({
+                errMsg: '密码为空'
+            });
+        }
+        options.data.grant_type = 'password';
+        options.data.client_id = 'sunhooDeskApp';
+        //options.data.client_id = 'SunhooWeb';
+        options.data.client_secret = 'sunhoo';
+        //options.data.client_secret = 'Sunhoo';
+        options.header = typeof options.header === 'object' ? options.header : {};
+        options.header['content-type'] = 'application/x-www-form-urlencoded';
+        this.Request({
+            url: app.GetDomain('authserver') + '/connect/token',
+            method: options.type || 'post',
+            header: options.header,
+            data: options.data,
+            dataType: options.dataType,
+            success: res => {
+                app.SetAuth(res);
+                // 获取用户信息
+                app.GetCurrentUser({
+                    success: result => {
+                        app.SetAccount({
+                            username: options.data.username,
+                            password: options.data.password
+                        });
+                        app.SetUser(result);
+                        app.globalData.isLogin = true;
+                        options.success(res);
+                    },
+                    fail: result => {
+                        options.fail(result);
+                    }
+                });
+            },
+            fail: res => {
+                options.fail(res);
+            }
+        }, true);
+    },
+
+    /**
+     * 重新登录
+     */
+    Relogin: function (options) {
+        var app = this;
+        this.GetAccount({
+            success: function (res) {
+                app.Login({
+                    data: res,
+                    success: function (res) {
+                        app.SetAuth(res);
+                        if (typeof options.success === 'function') {
+                            options.success(res);
+                        }
+                    },
+                    fail: function (res) {
+                        app.RemoveAuth();
+                        options.fail(res);
+                    }
+                });
+            },
+            fail: res => {
+                options.fail(res);
+            }
+        });
+    },
+
+    /**
+     * 登出
+     */
+    Logout: function (options) {
+        try {
+            this.RemoveAuth();
+            this.RemoveAccount();
+            this.RemoveUser();
+            if (typeof options.success === 'function') {
+                options.success();
+            }
+        } catch (ex) {
+            if (typeof options.fail === 'function') {
+                options.fail(util.formatError(res));
+            }
+        }
+    },
+
+    /**
+     * 获取当前用户信息
+     */
+    GetCurrentUser: function (options) {
+        var app = this;
+        this.Request({
+            jsonlint: true,
+            url: this.GetDomain() + '/api/BefriUser/CurrentUser',
+            success: res => {
+                app.SetUser(res);
+                options.success(res);
+            },
+            fail: res => {
+                options.fail(res);
+            }
+        });
+    },
+
+    /**
+     * 设置认证信息
+     */
+    SetAuth: function (data) {
+        wx.setStorage({
+            key: 'auth',
+            data: data || '',
+        });
+    },
+
+    /**
+     * 获取认证信息
+     */
+    GetAuth: function (data) {
+        wx.getStorage({
+            key: 'auth',
+            success: res => {
+                data.success(res.data);
+            },
+            fail: res => {
+                data.fail(util.formatError(res));
+            }
+        });
+    },
+
+    /**
+     * 删除认证信息
+     */
+    RemoveAuth: function () {
+        wx.removeStorage({
+            key: 'auth'
+        });
+    },
+
+    /**
+     * 判断认证是否过期
+     * */
+    AuthIsExpires: function (data) {
+        this.GetAuth({
+            success: function (res) {
+                try {
+                    if (typeof res === 'object' && res.date > new Date()) {
+                        data.success();
+                    } else {
+                        data.fail();
+                    }
+                } catch (ex) {
+                    data.fail(ex);
+                }
+            }
+        });
+    },
+
+    /**
+     * 设置账户信息
+     */
+    SetAccount: function (data) {
+        wx.setStorage({
+            key: 'account',
+            data: data || '',
+        });
+    },
+
+    /**
+     * 获取账户信息
+     */
+    GetAccount: function (data) {
+        wx.getStorage({
+            key: 'account',
+            success: res => {
+                data.success(res.data);
+            },
+            fail: res => {
+                data.fail(util.formatError(res));
+            }
+        })
+    },
+
+    /**
+     * 删除账户信息
+     */
+    RemoveAccount: function () {
+        wx.removeStorage({
+            key: 'account'
+        });
+    },
+
+    /**
+     * 设置用户信息
+     */
+    SetUser: function (data) {
+        wx.setStorage({
+            key: 'user',
+            data: data || '',
+        });
+    },
+
+    /**
+     * 获取用户信息
+     */
+    GetUser: function (data) {
+        wx.getStorage({
+            key: 'user',
+            success: res => {
+                data.success(res.data);
+            },
+            fail: res => {
+                data.fail(util.formatError(res));
+            }
+        })
+    },
+
+    /**
+     * 删除用户信息
+     */
+    RemoveUser: function () {
+        wx.removeStorage({
+            key: 'user'
+        });
+    },
+
+    /**
+     * 验证
+     */
+    Validate: {
+        //验证邮箱
+        Email: function (value) {
+            return /^[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);
+        },
+
+        //验证 url 地址
+        Url: function (value) {
+            return /^(?:(?:(?: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: function (value) {
+            return !/Invalid|NaN/.test(new Date(value).toString());
+        },
+
+        //验证 ISO 格式日期
+        DateISO: function (value) {
+            return /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(value);
+        },
+
+        //验证数字
+        Number: function (value) {
+            return /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(value);
+        },
+
+        //验证整数
+        Digits: function (value) {
+            return /^\d+$/.test(value);
+        },
+
+        //比较最小长度
+        Minlength: function (value, param) {
+            var length = value instanceof Array ? value.length : typeof value == 'string' ? value.length : 0;
+            return length >= param;
+        },
+
+        //比较最大长度
+        Maxlength: function (value, param) {
+            var length = value instanceof Array ? value.length : typeof value == 'string' ? value.length : 0;
+            return length <= param;
+        },
+
+        //验证长度区间
+        Rangelength: function (value, param) {
+            var length = value instanceof Array ? value.length : typeof value == 'string' ? value.length : 0;
+            return length >= param[0] && length <= param[1];
+        },
+
+        //比较最小值
+        Min: function (value, param) {
+            return value >= param;
+        },
+
+        //比较最大值
+        Max: function (value, param) {
+            return value <= param;
+        },
+
+        //验证数字区间
+        Range: function (value, param) {
+            return value >= param[0] && value <= param[1];
+        },
+
+        // 验证手机号
+        PhoneNumber: function (value) {
+            return /^1(3|4|5|7|8|9)\d{9}$/.test(value);
+        },
+
+        // 验证身份证
+        IDCard: function (value) {
+            return /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/.test(value);
+        },
+
+        // 验证密码
+        Password: function (value, min, max) {
+            min = Number.IsNullOrEmpty(min) ? 1 : min;
+            max = Number.IsNullOrEmpty(max) ? 256 : max;
+            var regexp = eval('/^([a-z]|[A-Z]|[0-9]|[_-]){' + min + ',' + max + '}$/');
+            return regexp.test(value);
+        }
+    }
 });

+ 32 - 30
src/pages/account/index.wxml

@@ -1,32 +1,34 @@
-<view class="flex align-center justify-center" style="height: 100vh">
-	<view style="width: 100vw">
-		<!-- 标志 -->
-		<view class="flex align-center justify-center" style="padding-top:10px; padding-bottom:10px">
-			<image class="logo" mode="widthFix" src="/assets/images/logo.png"></image>
-		</view>
+<defaultTitle name="登录" bgColor="bg-gradualBlue" isBack="{{isFirst ? false : true}}"></defaultTitle>
 
-		<!-- 登录表单 -->
-		<view class="layout account">
-			<view class="row line flex">
-				<input placeholder="请输入账号" type="text" bindinput="ChangeAccount" bind></input>
-			</view>
-			<view class="row line flex">
-				<view class="grow-1">
-					<input placeholder="请输入密码" type="{{passwordType}}" bindinput="ChangePassword" confirm-type="go" bindconfirm="Login"></input>
-				</view>
-				<view class="input-icon padding-left" bindtap="ShowPassword">
-					<text class="cuIcon-{{passwordIcon}}"></text>
-				</view>
-			</view>
-		</view>
-		<view class="layout" style="margin-bottom: 0">
-			<view class="row flex justify-center">
-				<view class="cu-btn bg-orange max round" bindtap="Login">{{loginButtonText}}</view>
-			</view>
-		</view>
-		<view class="layout" style="margin: 0">
-			<text class="cuIcon-infofill text-blue"></text>
-			<text class="text-gray" style="padding-left: 5px">该软件仅限公司内部使用,请向管理人员询问账号和密码。</text>
-		</view>
-	</view>
+<view class="flex align-center justify-center" style="height: calc(100vh - {{CustomBar}}px)">
+    <view style="width: 100vw">
+        <!-- 标志 -->
+        <view class="flex align-center justify-center" style="padding-top:30px; padding-bottom:10px">
+            <image class="logo" mode="widthFix" src="/assets/images/logo.png"></image>
+        </view>
+
+        <!-- 登录表单 -->
+        <view class="layout account">
+            <view class="row line flex">
+                <input placeholder="请输入账号" type="text" bindinput="ChangeAccount" bind></input>
+            </view>
+            <view class="row line flex">
+                <view class="grow-1">
+                    <input placeholder="请输入密码" type="{{passwordType}}" bindinput="ChangePassword" confirm-type="go" bindconfirm="Login"></input>
+                </view>
+                <view class="input-icon padding-left" bindtap="ShowPassword">
+                    <text class="cuIcon-{{passwordIcon}}"></text>
+                </view>
+            </view>
+        </view>
+        <view class="layout" style="margin-bottom: 0">
+            <view class="row flex justify-center">
+                <view class="cu-btn bg-orange max round" bindtap="Login">{{loginButtonText}}</view>
+            </view>
+        </view>
+        <view class="layout" style="margin: 0">
+            <text class="cuIcon-infofill text-blue"></text>
+            <text class="text-gray" style="padding-left: 5px">该软件仅限公司内部使用,请向管理人员询问账号和密码。</text>
+        </view>
+    </view>
 </view>

+ 4 - 0
src/pages/home/index/index.js

@@ -26,6 +26,10 @@ Page({
      * 生命周期函数--监听页面加载
      */
 	onLoad: function (options) {
+        if (!app.globalData.isLogin) {
+            this.data.loadText = '未登录';
+            return;
+        }
 		var page = this;
 		var noticeOption = page.data.noticeOption;
 		noticeOption.pageIndex = 1;

+ 1 - 1
src/pages/index/index.js

@@ -134,4 +134,4 @@ Page({
 				break;
 		}
 	},
-})
+});

+ 46 - 42
src/pages/launch/launch.js

@@ -2,48 +2,52 @@ var app = getApp();
 var util = require("../../utils/util.js");
 
 Page({
-	/**
-	 * 页面的初始数据
-	 */
-	data: {},
+    /**
+     * 页面的初始数据
+     */
+    data: {},
 
-	/**
-	 * 生命周期函数--监听页面加载
-	 */
-	onLoad: function (options) {
-		var page = this;
-		// 登录
-		wx.login({
-			success: res => {
-				// 发送 res.code 到后台换取 openId, sessionKey, unionId
-				app.globalData.code = res.code;
-				app.globalData.isWxLogin = true;
-				page.login();
-			},
-			fail: res => {
-				app.globalData.isWxLogin = false;
-				wx.showModal({
-					content: res.errMsg,
-					success: res => {
-						page.login();
-					}
-				});
-			}
-		});
-	},
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onLoad: function (options) {
+        wx.redirectTo({
+            url: '/pages/index/index',
+        });
+        return;
+        var page = this;
+        // 登录
+        wx.login({
+            success: res => {
+                // 发送 res.code 到后台换取 openId, sessionKey, unionId
+                app.globalData.code = res.code;
+                app.globalData.isWxLogin = true;
+                page.login();
+            },
+            fail: res => {
+                app.globalData.isWxLogin = false;
+                wx.showModal({
+                    content: res.errMsg,
+                    success: res => {
+                        page.login();
+                    }
+                });
+            }
+        });
+    },
 
-	login: function () {
-		app.Relogin({
-			success: function (res) {
-				wx.redirectTo({
-					url: '/pages/index/index',
-				});
-			},
-			fail: function (res) {
-				wx.redirectTo({
-					url: '/pages/account/index',
-				});
-			}
-		});
-	}
+    login: function () {
+        app.Relogin({
+            success: function (res) {
+                wx.redirectTo({
+                    url: '/pages/index/index',
+                });
+            },
+            fail: function (res) {
+                wx.redirectTo({
+                    url: '/pages/account/index',
+                });
+            }
+        });
+    }
 });

+ 6 - 1
src/pages/my/index/index.js

@@ -10,7 +10,8 @@ Page({
 		StatusBar: app.globalData.StatusBar,
 		CustomBar: app.globalData.CustomBar,
 		Custom: app.globalData.Custom,
-		data: {},
+        data: {},
+        isLogin: false,
 		isLoad: false,
 		loadType: "loading",
 		loadText: "加载中..."
@@ -20,6 +21,10 @@ Page({
 	 * 生命周期函数--监听页面加载
 	 */
 	onLoad: function (options) {
+        this.data.isLogin = app.globalData.isLogin;
+        if (!app.globalData.isLogin) {
+            return;
+        }
 		var page = this;
 		app.GetCurrentUser({
 			success: res => {

+ 3 - 2
src/pages/my/index/index.wxml

@@ -7,7 +7,7 @@
     </view>
 </view>
 <view class="cu-list menu shadow-lg solid-top">
-    <view class="cu-item arrow">
+    <view class="cu-item arrow" wx:if="{{isLogin}}">
         <navigator class="content" url="/pages/my/modifyPassword/index" hover-class="none">
             <text class="cuIcon-edit text-blue"></text>
             <text class="text-grey">修改登录密码</text>
@@ -15,5 +15,6 @@
     </view>
 </view>
 <view class="padding bg-white solid-top flex flex-direction" style="margin-bottom: 50px">
-    <view class="cu-btn bg-red lg round" bindtap="Exit">退出登录</view>
+    <view wx:if="{{isLogin}}" class="cu-btn bg-red lg round" bindtap="Exit">退出登录</view>
+    <navigator wx:else class="cu-btn bg-blue lg round" url="/pages/account/index" open-type="navigate">登  录</navigator>
 </view>

+ 45 - 61
src/project.config.json

@@ -1,64 +1,48 @@
 {
-    "description": "项目配置文件",
-    "packOptions": {
-        "ignore": []
+  "description": "项目配置文件",
+  "packOptions": {
+    "ignore": [],
+    "include": []
+  },
+  "setting": {
+    "urlCheck": false,
+    "es6": false,
+    "enhance": true,
+    "postcss": true,
+    "preloadBackgroundData": false,
+    "minified": true,
+    "newFeature": true,
+    "coverView": true,
+    "nodeModules": false,
+    "autoAudits": false,
+    "showShadowRootInWxmlPanel": true,
+    "scopeDataCheck": false,
+    "uglifyFileName": true,
+    "checkInvalidKey": true,
+    "checkSiteMap": true,
+    "uploadWithSourceMap": true,
+    "useMultiFrameRuntime": false,
+    "useApiHook": true,
+    "babelSetting": {
+      "ignore": [],
+      "disablePlugins": [],
+      "outputPath": ""
     },
-    "setting": {
-        "urlCheck": false,
-        "es6": false,
-        "enhance": true,
-        "postcss": true,
-        "preloadBackgroundData": false,
-        "minified": true,
-        "newFeature": true,
-        "coverView": true,
-        "nodeModules": false,
-        "autoAudits": false,
-        "showShadowRootInWxmlPanel": true,
-        "scopeDataCheck": false,
-        "uglifyFileName": true,
-        "checkInvalidKey": true,
-        "checkSiteMap": true,
-        "uploadWithSourceMap": true,
-        "useMultiFrameRuntime": false,
-        "useApiHook": true,
-        "babelSetting": {
-            "ignore": [],
-            "disablePlugins": [],
-            "outputPath": ""
-        },
-        "useIsolateContext": true,
-        "useCompilerModule": true,
-        "userConfirmedUseCompilerModuleSwitch": false,
-        "packNpmManually": false,
-        "packNpmRelationList": []
-    },
-    "compileType": "miniprogram",
-    "libVersion": "2.13.1",
-    "appid": "wx1ed929f19dd549a5",
-    "projectname": "双虎MES小程序",
-    "debugOptions": {
-        "hidedInDevtools": []
-    },
-    "isGameTourist": false,
-    "simulatorType": "wechat",
-    "simulatorPluginLibVersion": {},
-    "condition": {
-        "search": {
-            "current": -1,
-            "list": []
-        },
-        "conversation": {
-            "current": -1,
-            "list": []
-        },
-        "game": {
-            "currentL": -1,
-            "list": []
-        },
-        "miniprogram": {
-            "current": -1,
-            "list": []
-        }
-    }
+    "useIsolateContext": true,
+    "useCompilerModule": true,
+    "userConfirmedUseCompilerModuleSwitch": false,
+    "packNpmManually": false,
+    "packNpmRelationList": []
+  },
+  "compileType": "miniprogram",
+  "libVersion": "2.13.1",
+  "appid": "wxda962e6ee6a67d25",
+  "projectname": "双虎MES小程序",
+  "simulatorType": "wechat",
+  "simulatorPluginLibVersion": {},
+  "condition": {},
+  "editorSetting": {
+    "tabIndent": "insertSpaces",
+    "tabSize": 2
+  }
 }

+ 7 - 0
src/project.private.config.json

@@ -0,0 +1,7 @@
+{
+  "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
+  "projectname": "%E5%8F%8C%E8%99%8EMES%E5%B0%8F%E7%A8%8B%E5%BA%8F",
+  "setting": {
+    "compileHotReLoad": true
+  }
+}