(function() { var Permission = { hasPermission: function hasPermission(one_per) { var perms = new Array(); if (one_per) { perms.push(one_per); } else { var prs = document.getElementsByName("p_list"); for (var i = 0; i < prs.length; i++) { if (prs[i].checked) { perms.push(prs[i].value); } } } var rets = api.hasPermission({ list: perms }); if (!one_per) { console.log("判断结果:" + JSON.stringify(rets)); return; } return rets; }, reqPermission: function reqPermission(perm, callback) { var perms = new Array(); perms.push(perm); api.requestPermission( { list: perms, code: 1 }, function(ret, err) { if (ret && ret.list.length > 0) { callback(ret); } } ); }, reqPermissions: function reqPermissions(perms, callback) { api.requestPermissions( { list: perms, code: 1 }, function(ret, err) { if (ret && ret.list.length > 0) { callback(ret); console.log(JSON.stringify(ret)); } } ); } }; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function(sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function(key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) { Object.defineProperty( target, key, Object.getOwnPropertyDescriptor(source, key) ); }); } return target; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } var config = { // schema: 'http', // host: '192.168.0.107:8088', schema: "https", host: "tmr.nxcyx.com/api/", path: "app/tmr", secret: "776eca99-******-11e9-9897-*******" }; function req(options) { var baseUrl = config.schema + "://" + config.host + "/" + config.path + "/"; options.url = baseUrl + options.url; return new Promise(function(resolve, reject) { var data = options.data ? JSON.stringify(options.data.body) : ""; api.ajax(options, function(ret, err) { console.log( "[" + options.method + "] " + options.url + data + " [" + api.winName + "/" + api.frameName + "]" ); if (ret) { resolve(ret); api.hideProgress(); } else { reject(err); api.hideProgress(); } }); }); } /** * GET请求快捷方法 * @constructor * @param url {string} 地址 * @param options {Object} 附加参数 */ function GET(url, options) { if (options === void 0) { options = {}; } return req( _objectSpread2(_objectSpread2({}, options), {}, {url: url, method: "GET"}) ); } var DxxLoading = /*@__PURE__*/ (function(Component) { function DxxLoading(props) { Component.call(this, props); } if (Component) DxxLoading.__proto__ = Component; DxxLoading.prototype = Object.create(Component && Component.prototype); DxxLoading.prototype.constructor = DxxLoading; DxxLoading.prototype.closeview = function() { this.fire("closeview"); }; DxxLoading.prototype.render = function() { return apivm.h( "view", { class: "myloadingupview", style: {display: this.props.show ? "flex" : "none"}, onClick: this.closeview }, apivm.h( "view", {class: "myloadingview"}, apivm.h( "view", {class: "viewloading"}, apivm.h("image", { class: "loadingImage", src: "../components/loading.gif", mode: "widthFix" }), apivm.h( "view", null, apivm.h( "text", {class: "loadingtext"}, this.props.loadingtext ? this.props.loadingtext : "loading" ) ) ) ) ); }; return DxxLoading; })(Component); DxxLoading.css = { ".myloadingupview": { zIndex: "99999", position: "absolute", top: "0", left: "0", right: "0", bottom: "0", width: "100vw", height: "100vh", background: "rgba(0, 0, 0, 0.4)", flexDirection: "row-reverse", justifyContent: "center", alignItems: "center" }, ".viewloading": { width: "80px", height: "80px", textAlign: "center", background: "#ffffff", borderRadius: "6px", padding: "10px", justifyContent: "center", alignItems: "center" }, ".loadingImage": {height: "30px", width: "30px"}, ".loadingtext": {color: "#000000"} }; apivm.define("dxx-loading", DxxLoading); var Login = /*@__PURE__*/ (function(Component) { function Login(props) { Component.call(this, props); this.data = { //验证码文字 isCodeClick: false, msgNum: "获取验证码", phone: null, code: null, resCode: null, codeSwitch: false, isLoading: false, isLogin: true }; } if (Component) Login.__proto__ = Component; Login.prototype = Object.create(Component && Component.prototype); Login.prototype.constructor = Login; Login.prototype.apiready = function() { this.ifHasPhone(); this.ifHasBle(); this.ifHasBleCle(); this.ifHasLocation(); var token = api.getPrefs({sync: true, key: "token"}); var sourceCow = api.getPrefs({sync: true, key: "sourceCow"}); if ("" != token && "" != sourceCow) { api.openWin({ name: "index", reload: true, url: "../html/index1.html" }); } }; Login.prototype.ifHasLocation = function() { var statusJson = Permission.hasPermission("location"); // console.log(('location'+JSON.stringify(statusJson))); if (statusJson[0].granted == true); else { api.confirm( { title: "提醒", msg: "需要开启定位权限,去设置?", buttons: ["确认", "取消"] }, function(ret, err) { if (1 == ret.buttonIndex) { Permission.reqPermission("location", function(ret, err) { if (ret) { if (ret.never == true) { return; } else { if (ret.list[0].granted == true); else { return; } } } }); } } ); } }; Login.prototype.ifHasPhone = function() { var statusJson = Permission.hasPermission("phone"); // console.log(('phone'+JSON.stringify(statusJson))); if (statusJson[0].granted == true); else { api.confirm( { title: "提醒", msg: "需要开设备权限,去设置?", buttons: ["确认", "取消"] }, function(ret, err) { if (1 == ret.buttonIndex) { Permission.reqPermission("phone", function(ret, err) { if (ret) { if (ret.never == true) { return; } else { if (ret.list[0].granted == true); else { return; } } } }); } } ); } }; Login.prototype.ifHasBle = function() { var statusJson = Permission.hasPermission("ble-scan"); // console.log(('ble-scan'+JSON.stringify(statusJson))); if (statusJson[0].granted == true); else { api.confirm( { title: "提醒", msg: "需要开蓝牙权限,去设置?", buttons: ["确认", "取消"] }, function(ret, err) { if (1 == ret.buttonIndex) { Permission.reqPermission("ble-scan", function(ret, err) { if (ret) { if (ret.never == true) { return; } else { if (ret.list[0].granted == true); else { return; } } } }); } } ); } }; Login.prototype.ifHasBleCle = function() { var statusJson = Permission.hasPermission("ble-connect"); // console.log(('ble-connect'+JSON.stringify(statusJson))); if (statusJson[0].granted == true); else { api.confirm( { title: "提醒", msg: "需要开蓝牙权限,去设置?", buttons: ["确认", "取消"] }, function(ret, err) { if (1 == ret.buttonIndex) { Permission.reqPermission("ble-connect", function(ret, err) { if (ret) { if (ret.never == true) { return; } else { if (ret.list[0].granted == true); else { return; } } } }); } } ); } }; Login.prototype.handleGetCode = function() { var that = this; var _timeNum = 60; if (that.data.phone != null && "" != that.data.phone) { GET("sendSms?phone=" + that.data.phone) .then(function(ret) { if (ret.code == 200) { api.toast({ msg: "短信发送成功,请注意查收", location: "middle" }); that.data.resCode = ret.data.verificationCode; } else { api.toast({ msg: "短信发送成功,请稍后重试", location: "middle" }); } }) .catch(function(err) { api.toast({ msg: JSON.stringify(err) }); }); that.data.isCodeClick = true; var _timer = setInterval(function() { setTimeout(function() { if (_timeNum === 0) { that.data.msgNum = "获取验证码"; that.data.isCodeClick = false; clearInterval(_timer); return false; } _timeNum--; that.data.msgNum = _timeNum + "s"; }, 0); }, 1000); } else { api.toast({ msg: "手机号不能为空", location: "middle" }); } }; Login.prototype.handeLogin = function() { var _this = this; if (!this.data.phone) { api.toast({ msg: "手机号不能为空", location: "middle" }); } else if (!this.data.code && this.data.codeSwitch) { api.toast({ msg: "验证码不能为空", location: "middle" }); } else if (this.data.code != this.data.resCode && this.data.codeSwitch) { api.toast({ msg: "验证码错误,请重新发送", location: "middle" }); } else { _this.data.isLoading = true; GET("login?phonenumber=" + this.data.phone) .then(function(ret) { _this.data.isLoading = false; api.toast({ msg: ret.msg, location: "middle" }); if (ret.code == 200) { api.setPrefs({ key: "token", value: ret.token }); api.setPrefs({ key: "loginUser", value: ret.loginUser }); api.setPrefs({ key: "sourceCow", value: ret.loginUser.sourceCow }); api.openWin({ name: "index", reload: true, url: "../html/index1.html" }); // if (ret.loginUser.sourceCow !=2 ) { // api.openWin({ // name: 'index', // reload:true, // url:'../html/index.html' // }) // }else{ // api.openWin({ // name: 'index', // reload:true, // url:'./index.stml' // }) // } var token = api.getPrefs({sync: true, key: "token"}); var sourceCow = api.getPrefs({sync: true, key: "sourceCow"}); } }) .catch(function(err) { api.toast({ msg: JSON.stringify(err) }); }); } }; Login.prototype.render = function() { var this$1 = this; return apivm.h( "view", {class: "login_wrap"}, apivm.h("dxx-loading", { loadingtext: "正在登录...", show: this.data.isLoading }), apivm.h( "view", { class: "login_form", style: {display: this.data.isLogin ? "flex" : "none"} }, apivm.h( "view", {class: "login_form_title"}, apivm.h("text", {class: "login_title_text"}, "TMR饲喂管理") ), apivm.h( "view", {class: "login_form_content"}, apivm.h( "view", {class: "login_form_item"}, apivm.h("text", {class: "item_label"}, "手机号: "), apivm.h( "view", {class: "item_input_content"}, apivm.h("input", { type: "text", "keyboard-type": "tel", class: "input", name: "name", onInput: function(e) { if (typeof phone != "undefined") { phone = e.target.value; } else { this$1.data.phone = e.target.value; } }, placeholder: "请输入手机号", value: typeof phone == "undefined" ? this.data.phone : phone }) ) ), apivm.h( "view", {class: "login_form_item"}, apivm.h("text", {class: "item_label"}, "验证码: "), apivm.h( "view", {class: "item_input_content"}, apivm.h("input", { type: "text", "keyboard-type": "number", class: "input2", name: "psw", onInput: function(e) { if (typeof code != "undefined") { code = e.target.value; } else { this$1.data.code = e.target.value; } }, placeholder: "请输入验证码", value: typeof code == "undefined" ? this.data.code : code }), apivm.h( "button", { type: "button", class: this.data.isCodeClick ? "disabled_yam" : "login_yzm", disabled: this.data.isCodeClick, onClick: this.handleGetCode }, this.data.msgNum ) ) ), apivm.h( "button", {type: "button", class: "login_btn", onClick: this.handeLogin}, "立即登录" ) ) ) ); }; return Login; })(Component); Login.css = { ".login_wrap": { width: "100%", height: "100%", backgroundSize: "150%", backgroundRepeat: "no-repeat", backgroundPosition: "center", position: "relative", backgroundImage: 'url("../image/bg_img.jpg")' }, ".login_form": { position: "absolute", top: "45%", right: "10%", transform: "translateY(-45%)", boxSizing: "border-box", backgroundColor: "#ffffff", padding: "2%", borderRadius: "10px", width: "50%" }, ".login_form_title": {width: "100%", textAlign: "center", margin: "10px 0"}, ".login_title_text": {fontSize: "20px", color: "#000000"}, ".login_form_content": {marginTop: "20px", width: "100%"}, ".login_form_item": { display: "flex", flexDirection: "row", justifyContent: "center", alignItems: "center", margin: "10px 0", width: "100%" }, ".item_label": { fontSize: "16px", marginRight: "5px", width: "20%", textAlign: "right" }, ".item_input_content": { width: "80%", display: "flex", flexDirection: "row", alignItems: "center" }, ".input": { width: "100%", height: "40px", boxSizing: "border-box", padding: "5px 10px", borderRadius: "8px" }, ".input2": { height: "40px", boxSizing: "border-box", padding: "5px 10px", borderRadius: "8px" }, ".login_yzm": { backgroundColor: "#407ae6", color: "#ffffff", marginLeft: "5px", fontSize: "14px", opacity: "1" }, ".login_btn": { width: "80%", height: "48px", lineHeight: "24px", margin: "30px auto 20px", backgroundColor: "#407ae6", color: "#ffffff", fontSize: "16px" }, ".disabled_yam": { opacity: "0.7", backgroundColor: "#407ae6", color: "#ffffff", marginLeft: "5px", fontSize: "14px" } }; apivm.define("login", Login); apivm.render(apivm.h("login", null), "body"); })();