/** * 登录 **/ (function($, owner) { /** * 用户登录 **/ owner.login = function(loginInfo, callback) { callback = callback || $.noop; loginInfo = loginInfo || {}; loginInfo.account = loginInfo.account || ''; loginInfo.password = loginInfo.password || ''; if (loginInfo.account.length < 3) { return callback('账号最短为 3 个字符'); } if (loginInfo.password.length < 4) { return callback('密码最短为 4 个字符'); } $.ajax('http://v2.xinnongbaohe.com/web/application/passport/?login.action?json=1', { data: { username:loginInfo.account, password:loginInfo.password, project:'front' }, dataType:'text',//服务器返回json格式数据 timeout:10000,//超时时间设置为10秒; type:'post',//HTTP请求类型 success:function(r) { var t = JSON.parse(r); if(t.status == 1) { return owner.createState(t.account, callback); } else { return callback('用户名或密码错误'); } }, error:function(xhr,type,errorThrown) { alert(type); } }); }; owner.createState = function(name, callback) { var state = owner.getState(); state.account = name; state.token = "tokenv2123456789"; owner.setState(state); return callback(); }; /** * 新用户注册 **/ owner.reg = function(regInfo, callback) { callback = callback || $.noop; regInfo = regInfo || {}; regInfo.account = regInfo.account || ''; regInfo.password = regInfo.password || ''; if (regInfo.account.length < 5) { return callback('用户名最短需要 5 个字符'); } if (regInfo.password.length < 6) { return callback('密码最短需要 6 个字符'); } if (!checkEmail(regInfo.email)) { return callback('邮箱地址不合法'); } var users = JSON.parse(localStorage.getItem('$usersv2') || '[]'); users.push(regInfo); localStorage.setItem('$usersv2', JSON.stringify(users)); return callback(); }; /** * 获取当前状态 **/ owner.getState = function() { var stateText = localStorage.getItem('$statev5') || "{}"; return JSON.parse(stateText); }; /** * 设置当前状态 **/ owner.setState = function(state) { state = state || {}; localStorage.setItem('$statev5', JSON.stringify(state)); //var settings = owner.getSettings(); //settings.gestures = ''; //owner.setSettings(settings); }; var checkEmail = function(email) { email = email || ''; return (email.length > 3 && email.indexOf('@') > -1); }; /** * 找回密码 **/ owner.forgetPassword = function(email, callback) { callback = callback || $.noop; if (!checkEmail(email)) { return callback('邮箱地址不合法'); } return callback(null, '新的随机密码已经发送到您的邮箱,请查收邮件。'); }; /** * 获取应用本地配置 **/ owner.setSettings = function(settings) { settings = settings || {}; localStorage.setItem('$settings', JSON.stringify(settings)); } /** * 设置应用本地配置 **/ owner.getSettings = function() { var settingsText = localStorage.getItem('$settings') || "{}"; return JSON.parse(settingsText); } /** * 获取本地是否安装客户端 **/ owner.isInstalled = function(id) { if (id === 'qihoo' && mui.os.plus) { return true; } if (mui.os.android) { var main = plus.android.runtimeMainActivity(); var packageManager = main.getPackageManager(); var PackageManager = plus.android.importClass(packageManager) var packageName = { "qq": "com.tencent.mobileqq", "weixin": "com.tencent.mm", "sinaweibo": "com.sina.weibo" } try { return packageManager.getPackageInfo(packageName[id], PackageManager.GET_ACTIVITIES); } catch (e) {} } else { switch (id) { case "qq": var TencentOAuth = plus.ios.import("TencentOAuth"); return TencentOAuth.iphoneQQInstalled(); case "weixin": var WXApi = plus.ios.import("WXApi"); return WXApi.isWXAppInstalled() case "sinaweibo": var SinaAPI = plus.ios.import("WeiboSDK"); return SinaAPI.isWeiboAppInstalled() default: break; } } } }(mui, window.app = {}));