|
@@ -1,74 +1,74 @@
|
|
|
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()
|
|
|
+ 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(':')
|
|
|
+ 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
|
|
|
+ n = n.toString()
|
|
|
+ return n[1] ? n : '0' + n
|
|
|
}
|
|
|
|
|
|
// 格式化时间// 20180101101010 => 2018-01-01 10:10:10
|
|
|
function formatDate(time) {
|
|
|
- return `${time.substring(8,10)}:${time.substring(10,12)}`
|
|
|
+ return `${time.substring(8, 10)}:${time.substring(10, 12)}`
|
|
|
}
|
|
|
/** 检测是否有定位权限BY 小程序 **/
|
|
|
function checkHasLocationPermissionByMP() {
|
|
|
- return new Promise(function (resolve, reject) {
|
|
|
- wx.getSetting({
|
|
|
- success(sd) {
|
|
|
- if (!sd.authSetting['scope.userLocation']) {
|
|
|
- wx.authorize({
|
|
|
- scope: 'scope.userLocation',
|
|
|
- success(e) {
|
|
|
- resolve(e)
|
|
|
- },
|
|
|
- fail(e) {
|
|
|
- reject()
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- resolve(sd)
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
+ return new Promise(function (resolve, reject) {
|
|
|
+ wx.getSetting({
|
|
|
+ success(sd) {
|
|
|
+ if (!sd.authSetting['scope.userLocation']) {
|
|
|
+ wx.authorize({
|
|
|
+ scope: 'scope.userLocation',
|
|
|
+ success(e) {
|
|
|
+ resolve(e)
|
|
|
+ },
|
|
|
+ fail(e) {
|
|
|
+ reject()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ resolve(sd)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
}
|
|
|
-function picInit(value){
|
|
|
- let baseUrl="../../static/images/"
|
|
|
+function picInit(value) {
|
|
|
+ let baseUrl = "../../static/images/"
|
|
|
value = value || '';
|
|
|
return baseUrl + "room.png"
|
|
|
- if(value.startsWith("300")||value.startsWith("310")||value.startsWith("311")){
|
|
|
+ if (value.startsWith("300") || value.startsWith("310") || value.startsWith("311")) {
|
|
|
return baseUrl + "ic311.png"
|
|
|
- }else if(value.startsWith("312")){
|
|
|
+ } else if (value.startsWith("312")) {
|
|
|
return baseUrl + "ic312.png"
|
|
|
- }else if(value.startsWith("313")){
|
|
|
+ } else if (value.startsWith("313")) {
|
|
|
return baseUrl + "ic313.png"
|
|
|
- }else if(value.startsWith("314")){
|
|
|
+ } else if (value.startsWith("314")) {
|
|
|
return baseUrl + "ic314.png"
|
|
|
- }else if(value.startsWith("315")){
|
|
|
+ } else if (value.startsWith("315")) {
|
|
|
return baseUrl + "ic315.png"
|
|
|
- }else if(value.startsWith("320")||value.startsWith("321")){
|
|
|
+ } else if (value.startsWith("320") || value.startsWith("321")) {
|
|
|
return baseUrl + "ic321.png"
|
|
|
- }else if(value.startsWith("322")){
|
|
|
+ } else if (value.startsWith("322")) {
|
|
|
return baseUrl + "ic322.png"
|
|
|
- }else if(value.startsWith("323")){
|
|
|
+ } else if (value.startsWith("323")) {
|
|
|
return baseUrl + "ic323.png"
|
|
|
- }else if(value.startsWith("33")){
|
|
|
+ } else if (value.startsWith("33")) {
|
|
|
return baseUrl + "ic331.png"
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return baseUrl + "ic313.png"
|
|
|
}
|
|
|
}
|
|
|
// 前面补零
|
|
|
function PrefixZero(num, n = 2) {
|
|
|
- return (Array(n).join(0) + num).slice(-n);
|
|
|
+ return (Array(n).join(0) + num).slice(-n);
|
|
|
}
|
|
|
function formatMsgTime(dateStr) {
|
|
|
// let dateObj = dateStr.replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '').replace(/(-)/g, '/')
|
|
@@ -97,7 +97,7 @@ function formatMsgTime(dateStr) {
|
|
|
timeSpanStr = Math.round(milliseconds / (1000 * 60 * 60 * 24)) + '天前';
|
|
|
}
|
|
|
else if (milliseconds > 1000 * 60 * 60 * 24 * 15 && year == nowDate.getFullYear()) {
|
|
|
- timeSpanStr = month + '.' + day + ' ' + (hour<10?`0${hour}`:hour) + ':' +(minute<10?`0${minute}`:minute) ;
|
|
|
+ timeSpanStr = month + '.' + day + ' ' + (hour < 10 ? `0${hour}` : hour) + ':' + (minute < 10 ? `0${minute}` : minute);
|
|
|
} else {
|
|
|
timeSpanStr = year + '-' + month + '-' + day;
|
|
|
}
|
|
@@ -106,51 +106,51 @@ function formatMsgTime(dateStr) {
|
|
|
|
|
|
|
|
|
function buildTree(value) {
|
|
|
- let list = JSON.parse(JSON.stringify(value));
|
|
|
- // let temp = {};
|
|
|
- let tree = [];
|
|
|
- list.forEach(item => {
|
|
|
- let temp = {};
|
|
|
- let children = {};
|
|
|
- temp.projectId = item.projectId;
|
|
|
- temp.projectName = item.projectName;
|
|
|
- temp.children = [];
|
|
|
- tree.push(temp)
|
|
|
- });
|
|
|
- let hash = {};
|
|
|
- tree = tree.reduce((item, next) => {
|
|
|
- hash[next.projectId] ? '' : hash[next.projectId] = true && item.push(next);
|
|
|
- return item;
|
|
|
- }, []);
|
|
|
- value.forEach((item) => {
|
|
|
- tree.forEach(items => {
|
|
|
- if (item.projectId === items.projectId) {
|
|
|
- // items.children=[];
|
|
|
- let children = {};
|
|
|
- children.tenantId = item.tenantId;
|
|
|
- children.projectId = item.projectId;
|
|
|
- children.tenantName = item.tenantName;
|
|
|
- children.remote = item.remote;
|
|
|
- items.children.push(children);
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- return tree;
|
|
|
+ let list = JSON.parse(JSON.stringify(value));
|
|
|
+ // let temp = {};
|
|
|
+ let tree = [];
|
|
|
+ list.forEach(item => {
|
|
|
+ let temp = {};
|
|
|
+ let children = {};
|
|
|
+ temp.projectId = item.projectId;
|
|
|
+ temp.projectName = item.projectName;
|
|
|
+ temp.children = [];
|
|
|
+ tree.push(temp)
|
|
|
+ });
|
|
|
+ let hash = {};
|
|
|
+ tree = tree.reduce((item, next) => {
|
|
|
+ hash[next.projectId] ? '' : hash[next.projectId] = true && item.push(next);
|
|
|
+ return item;
|
|
|
+ }, []);
|
|
|
+ value.forEach((item) => {
|
|
|
+ tree.forEach(items => {
|
|
|
+ if (item.projectId === items.projectId) {
|
|
|
+ // items.children=[];
|
|
|
+ let children = {};
|
|
|
+ children.tenantId = item.tenantId;
|
|
|
+ children.projectId = item.projectId;
|
|
|
+ children.tenantName = item.tenantName;
|
|
|
+ children.remote = item.remote;
|
|
|
+ items.children.push(children);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ return tree;
|
|
|
}
|
|
|
// base64解码
|
|
|
var Base64 = {
|
|
|
- // 转码表
|
|
|
- tables: [
|
|
|
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
|
|
- 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
|
|
- 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
|
|
- 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
|
|
- 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
|
|
- 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
|
|
- 'w', 'x', 'y', 'z', '0', '1', '2', '3',
|
|
|
- '4', '5', '6', '7', '8', '9', '+', '/'
|
|
|
- ],
|
|
|
- UTF16ToUTF8 : function (str) {
|
|
|
+ // 转码表
|
|
|
+ tables: [
|
|
|
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
|
|
+ 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
|
|
+ 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
|
|
+ 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
|
|
+ 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
|
|
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
|
|
+ 'w', 'x', 'y', 'z', '0', '1', '2', '3',
|
|
|
+ '4', '5', '6', '7', '8', '9', '+', '/'
|
|
|
+ ],
|
|
|
+ UTF16ToUTF8: function (str) {
|
|
|
let results = [], len = str.length;
|
|
|
for (let i = 0; i < len; i++) {
|
|
|
let code = str.charCodeAt(i);
|
|
@@ -200,7 +200,7 @@ var Base64 = {
|
|
|
|
|
|
return results.join('');
|
|
|
},
|
|
|
- UTF8ToUTF16 : function (str) {
|
|
|
+ UTF8ToUTF16: function (str) {
|
|
|
let results = [], len = str.length;
|
|
|
let i = 0;
|
|
|
for (let i = 0; i < len; i++) {
|
|
@@ -241,11 +241,11 @@ var Base64 = {
|
|
|
|
|
|
return results.join('');
|
|
|
},
|
|
|
- encode : function (str) {
|
|
|
+ encode: function (str) {
|
|
|
if (!str) {
|
|
|
return '';
|
|
|
}
|
|
|
- let utf8 = this.UTF16ToUTF8(str); // 转成UTF-8
|
|
|
+ let utf8 = this.UTF16ToUTF8(str); // 转成UTF-8
|
|
|
let i = 0; // 遍历索引
|
|
|
let len = utf8.length;
|
|
|
let results = [];
|
|
@@ -274,47 +274,65 @@ var Base64 = {
|
|
|
|
|
|
return results.join('');
|
|
|
},
|
|
|
- decode: function (str) {
|
|
|
- //判断是否为空
|
|
|
- if (!str) {
|
|
|
- return '';
|
|
|
- }
|
|
|
+ decode: function (str) {
|
|
|
+ //判断是否为空
|
|
|
+ if (!str) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
|
|
|
- let len = str.length;
|
|
|
- let i = 0;
|
|
|
- let results = [];
|
|
|
- //循环解出字符数组
|
|
|
- while (i < len) {
|
|
|
- let code1 = this.tables.indexOf(str.charAt(i++));
|
|
|
- let code2 = this.tables.indexOf(str.charAt(i++));
|
|
|
- let code3 = this.tables.indexOf(str.charAt(i++));
|
|
|
- let code4 = this.tables.indexOf(str.charAt(i++));
|
|
|
+ let len = str.length;
|
|
|
+ let i = 0;
|
|
|
+ let results = [];
|
|
|
+ //循环解出字符数组
|
|
|
+ while (i < len) {
|
|
|
+ let code1 = this.tables.indexOf(str.charAt(i++));
|
|
|
+ let code2 = this.tables.indexOf(str.charAt(i++));
|
|
|
+ let code3 = this.tables.indexOf(str.charAt(i++));
|
|
|
+ let code4 = this.tables.indexOf(str.charAt(i++));
|
|
|
|
|
|
- let c1 = (code1 << 2) | (code2 >> 4);
|
|
|
- results.push(String.fromCharCode(c1));
|
|
|
+ let c1 = (code1 << 2) | (code2 >> 4);
|
|
|
+ results.push(String.fromCharCode(c1));
|
|
|
|
|
|
- if (code3 != -1) {
|
|
|
- let c2 = ((code2 & 0xF) << 4) | (code3 >> 2);
|
|
|
- results.push(String.fromCharCode(c2));
|
|
|
- }
|
|
|
- if (code4 != -1) {
|
|
|
- let c3 = ((code3 & 0x3) << 6) | code4;
|
|
|
- results.push(String.fromCharCode(c3));
|
|
|
- }
|
|
|
+ if (code3 != -1) {
|
|
|
+ let c2 = ((code2 & 0xF) << 4) | (code3 >> 2);
|
|
|
+ results.push(String.fromCharCode(c2));
|
|
|
+ }
|
|
|
+ if (code4 != -1) {
|
|
|
+ let c3 = ((code3 & 0x3) << 6) | code4;
|
|
|
+ results.push(String.fromCharCode(c3));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ return this.UTF8ToUTF16(results.join(''));
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- return this.UTF8ToUTF16(results.join(''));
|
|
|
- }
|
|
|
+// 解析参数
|
|
|
+function getUrlParams(url, key) {
|
|
|
+ // debugger
|
|
|
+ // let url = url //获取url中"?"符后的字串
|
|
|
+ let theRequest = {}
|
|
|
+ url = "?" + url
|
|
|
+ if (url.indexOf('?') != -1) {
|
|
|
+ let str = url.substr(1)
|
|
|
+ let strs = str.split('&')
|
|
|
+ for (var i = 0; i < strs.length; i++) {
|
|
|
+ theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let value = theRequest[key] || ''
|
|
|
+ return value
|
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
|
- formatTime: formatTime,
|
|
|
- formatDate: formatDate,
|
|
|
- checkHasLocationPermissionByMP: checkHasLocationPermissionByMP,
|
|
|
- PrefixZero: PrefixZero,
|
|
|
- buildTree: buildTree,
|
|
|
- Base64:Base64,
|
|
|
- picInit:picInit,
|
|
|
- formatMsgTime:formatMsgTime,
|
|
|
+ formatTime: formatTime,
|
|
|
+ formatDate: formatDate,
|
|
|
+ checkHasLocationPermissionByMP: checkHasLocationPermissionByMP,
|
|
|
+ PrefixZero: PrefixZero,
|
|
|
+ buildTree: buildTree,
|
|
|
+ Base64: Base64,
|
|
|
+ getUrlParams,
|
|
|
+ picInit: picInit,
|
|
|
+ formatMsgTime: formatMsgTime,
|
|
|
}
|