TMRAppBle/script/util.js

128 lines
4.1 KiB
JavaScript

var Util = {
appOpen:function(){
var phoneInfoMore = api.require('phoneInfoMore');
var data1 = {
appDeviceid: api.deviceId,
appId: api.appId,
appName: api.appName,
appVersion: api.appVersion,
systemType: api.systemType,
systemVersion: api.systemVersion,
version: api.version,
deviceModel: api.deviceModel,
devicename: api.deviceName,
uimode: api.uimode,
platform: api.platform,
operator: api.operator,
connectiontype: api.connectionType,
screenwidth: api.screenWidth,
screenheight: api.screenHeight,
sourceCow: api.getPrefs({ sync: true, key: 'sourceCow' }),
}
if(api.systemVersion<=10){
phoneInfoMore.getBaseInfo(function(ret, err) {
if(ret){
api.setGlobalData({ key: 'imei', value: ret.imei });
data1.imei = ret.imei
POST('appOpen', data1, {}).then(ret => {
// console.log(JSON.stringify(ret));
}).catch(err => {
api.toast({
msg: JSON.stringify(err)
})
})
}
});
}else{
data1.imei = api.deviceId
POST('appOpen', data1, {}).then(ret => {
// console.log(JSON.stringify(ret));
}).catch(err => {
api.toast({
msg: JSON.stringify(err)
})
})
}
},
getDateStr:function(date){
var seperator1 = "-";
var seperator2 = ":";
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = date.getFullYear() +seperator1+ month+seperator1 + strDate;
return currentdate
},
//得到当前时间
currTimeFn:function(_date) {
let _year = _date.getFullYear();
let _month = _date.getMonth() + 1 < 10 ? '0' + (_date.getMonth() + 1) : _date.getMonth() + 1;
let _day = _date.getDate() < 10 ? '0' + _date.getDate() : _date.getDate();
let _hour = _date.getHours() < 10 ? '0' + _date.getHours() : _date.getHours();
let _minutes = _date.getMinutes() < 10 ? '0' + _date.getMinutes() : _date.getMinutes();
let _seconds = _date.getSeconds() < 10 ? '0' + _date.getSeconds() : _date.getSeconds();
return _year + "-" + _month + "-" + _day + " " + _hour + ":" + _minutes + ":" + _seconds;
},
};
const 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) {
const baseUrl = `${config.schema}://${config.host}/${config.path}/`;
options.url = baseUrl + options.url;
return new Promise((resolve, reject) => {
api.ajax(options, (ret, err) => {
console.log('[' + options.method + '] ' + options.url + ' [' + 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 = {}) {
return req({
...options, url, method: 'GET'
});
}
/**
* POST 请求快捷方法
* @param url
* @param data
* @param options {Object} 附加参数
* @returns {Promise<Object>}
* @constructor
*/
function POST(url, data, options = {}) {
options.headers= {'Content-Type': 'application/json;charset=utf-8'};
return req({
...options, url, method: 'POST', data: {body:data}
});
}
export {
Util
}