|
|
@@ -1,189 +1,219 @@
|
|
|
+import store from '../store';
|
|
|
+
|
|
|
// 日期格式化
|
|
|
export function parseTime(time, pattern) {
|
|
|
- if(time!="null"){
|
|
|
+ if (time != 'null') {
|
|
|
if (arguments.length === 0 || !time) {
|
|
|
- return null
|
|
|
+ return null;
|
|
|
}
|
|
|
- const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
|
|
|
- let date
|
|
|
+ const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}';
|
|
|
+ let date;
|
|
|
if (typeof time === 'object') {
|
|
|
- date = time
|
|
|
+ date = time;
|
|
|
} else {
|
|
|
- if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
|
|
|
- time = parseInt(time)
|
|
|
- } else if (typeof time === 'string') {
|
|
|
- time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm), '');
|
|
|
- }
|
|
|
- if ((typeof time === 'number') && (time.toString().length === 10)) {
|
|
|
- time = time * 1000
|
|
|
- }
|
|
|
- date = new Date(time)
|
|
|
+ if (typeof time === 'string' && /^[0-9]+$/.test(time)) {
|
|
|
+ time = parseInt(time);
|
|
|
+ } else if (typeof time === 'string') {
|
|
|
+ time = time
|
|
|
+ .replace(new RegExp(/-/gm), '/')
|
|
|
+ .replace('T', ' ')
|
|
|
+ .replace(new RegExp(/\.[\d]{3}/gm), '');
|
|
|
+ }
|
|
|
+ if (typeof time === 'number' && time.toString().length === 10) {
|
|
|
+ time = time * 1000;
|
|
|
+ }
|
|
|
+ date = new Date(time);
|
|
|
}
|
|
|
const formatObj = {
|
|
|
- y: date.getFullYear(),
|
|
|
- m: date.getMonth() + 1,
|
|
|
- d: date.getDate(),
|
|
|
- h: date.getHours(),
|
|
|
- i: date.getMinutes(),
|
|
|
- s: date.getSeconds(),
|
|
|
- a: date.getDay()
|
|
|
- }
|
|
|
+ y: date.getFullYear(),
|
|
|
+ m: date.getMonth() + 1,
|
|
|
+ d: date.getDate(),
|
|
|
+ h: date.getHours(),
|
|
|
+ i: date.getMinutes(),
|
|
|
+ s: date.getSeconds(),
|
|
|
+ a: date.getDay(),
|
|
|
+ };
|
|
|
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
|
|
|
- let value = formatObj[key]
|
|
|
- // Note: getDay() returns 0 on Sunday
|
|
|
- if (key === 'a') {
|
|
|
- return ['日', '一', '二', '三', '四', '五', '六'][value]
|
|
|
- }
|
|
|
- if (result.length > 0 && value < 10) {
|
|
|
- value = '0' + value
|
|
|
- }
|
|
|
- return value || 0
|
|
|
- })
|
|
|
- return time_str
|
|
|
- }else{
|
|
|
- return ""
|
|
|
- }
|
|
|
+ let value = formatObj[key];
|
|
|
+ // Note: getDay() returns 0 on Sunday
|
|
|
+ if (key === 'a') {
|
|
|
+ return ['日', '一', '二', '三', '四', '五', '六'][value];
|
|
|
+ }
|
|
|
+ if (result.length > 0 && value < 10) {
|
|
|
+ value = '0' + value;
|
|
|
+ }
|
|
|
+ return value || 0;
|
|
|
+ });
|
|
|
+ return time_str;
|
|
|
+ } else {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
}
|
|
|
// 千分号
|
|
|
export function Micrometer(num) {
|
|
|
- if(num!=null){
|
|
|
- let numt = (num || 0).toString().split(".");
|
|
|
+ if (num != null) {
|
|
|
+ let numt = (num || 0).toString().split('.');
|
|
|
if (numt[1] == undefined) {
|
|
|
- return numt[0].replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
|
|
|
+ return numt[0].replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
|
|
|
} else {
|
|
|
- return numt[0].replace(/(\d)(?=(?:\d{3})+$)/g, "$1,") + "." + numt[1];
|
|
|
- }
|
|
|
- }else{
|
|
|
- return 0.00
|
|
|
+ return numt[0].replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') + '.' + numt[1];
|
|
|
}
|
|
|
+ } else {
|
|
|
+ return 0.0;
|
|
|
+ }
|
|
|
}
|
|
|
-export function weeklyTimeDivision(time,type){
|
|
|
- if(type==0){
|
|
|
- return time.split(" ")[0]+" "
|
|
|
- }else{
|
|
|
- return time.split(" ")[1]
|
|
|
- }
|
|
|
+export function weeklyTimeDivision(time, type) {
|
|
|
+ if (type == 0) {
|
|
|
+ return time.split(' ')[0] + ' ';
|
|
|
+ } else {
|
|
|
+ return time.split(' ')[1];
|
|
|
+ }
|
|
|
}
|
|
|
export function parseTimeParagraph(dayTime) {
|
|
|
- var currentDate = new Date(dayTime)
|
|
|
- var timesStamp = currentDate.getTime();
|
|
|
- var currenDay = currentDate.getDay();
|
|
|
- var dates = [];
|
|
|
- var tabTime=[]
|
|
|
- for (var i = 0; i < 14; i++) {
|
|
|
- var dataTime=new Date(timesStamp + 24 * 60 * 60 * 1000 * (i - (currenDay + 6) % 7)).toLocaleDateString().replace(/\//g, '-')
|
|
|
- var dataTimeArr=dataTime.split("-")
|
|
|
- if(dataTimeArr[1]<10){
|
|
|
- dataTimeArr[1]="0"+dataTimeArr[1]
|
|
|
- }
|
|
|
- if(dataTimeArr[2]<10){
|
|
|
- dataTimeArr[2]="0"+dataTimeArr[2]
|
|
|
- }
|
|
|
- dates.push(dataTimeArr.join("-")+" "+["周日","周一","周二","周三","周四","周五","周六"][new Date(dataTime.toString().replace(/-/g, '/')).getDay()]);
|
|
|
+ var currentDate = new Date(dayTime);
|
|
|
+ var timesStamp = currentDate.getTime();
|
|
|
+ var currenDay = currentDate.getDay();
|
|
|
+ var dates = [];
|
|
|
+ var tabTime = [];
|
|
|
+ for (var i = 0; i < 14; i++) {
|
|
|
+ var dataTime = new Date(timesStamp + 24 * 60 * 60 * 1000 * (i - ((currenDay + 6) % 7)))
|
|
|
+ .toLocaleDateString()
|
|
|
+ .replace(/\//g, '-');
|
|
|
+ var dataTimeArr = dataTime.split('-');
|
|
|
+ if (dataTimeArr[1] < 10) {
|
|
|
+ dataTimeArr[1] = '0' + dataTimeArr[1];
|
|
|
+ }
|
|
|
+ if (dataTimeArr[2] < 10) {
|
|
|
+ dataTimeArr[2] = '0' + dataTimeArr[2];
|
|
|
}
|
|
|
- tabTime.push(dates[0])
|
|
|
- tabTime.push(dates[4])
|
|
|
- return dates
|
|
|
+ dates.push(
|
|
|
+ dataTimeArr.join('-') +
|
|
|
+ ' ' +
|
|
|
+ ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][
|
|
|
+ new Date(dataTime.toString().replace(/-/g, '/')).getDay()
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ tabTime.push(dates[0]);
|
|
|
+ tabTime.push(dates[4]);
|
|
|
+ return dates;
|
|
|
}
|
|
|
export function weeklay(dataTime) {
|
|
|
- return ["周日","周一","周二","周三","周四","周五","周六"][new Date(dataTime).getDay()]
|
|
|
+ return ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][new Date(dataTime).getDay()];
|
|
|
}
|
|
|
|
|
|
// 回显数据字典
|
|
|
export function selectDictLabel(datas, value) {
|
|
|
- var actions = [];
|
|
|
- Object.keys(datas).some((key) => {
|
|
|
- if (datas[key].dictValue == ('' + value)) {
|
|
|
- actions.push(datas[key].dictLabel);
|
|
|
- return true;
|
|
|
- }
|
|
|
- })
|
|
|
- return actions.join('');
|
|
|
+ var actions = [];
|
|
|
+ Object.keys(datas).some((key) => {
|
|
|
+ if (datas[key].dictValue == '' + value) {
|
|
|
+ actions.push(datas[key].dictLabel);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return actions.join('');
|
|
|
}
|
|
|
|
|
|
export function selectDictLabelu(datas, value) {
|
|
|
- var actions = [];
|
|
|
- Object.keys(datas).some((key) => {
|
|
|
- if (datas[key].dictValue == ('' + value)) {
|
|
|
- actions.push(datas[key].text);
|
|
|
- return true;
|
|
|
- }
|
|
|
- })
|
|
|
- return actions.join('');
|
|
|
+ var actions = [];
|
|
|
+ Object.keys(datas).some((key) => {
|
|
|
+ if (datas[key].dictValue == '' + value) {
|
|
|
+ actions.push(datas[key].text);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return actions.join('');
|
|
|
}
|
|
|
|
|
|
// 回显数据字典(字符串数组)
|
|
|
export function selectDictLabels(datas, value, separator) {
|
|
|
- var actions = [];
|
|
|
- var currentSeparator = undefined === separator ? "," : separator;
|
|
|
- var temp = value.split(currentSeparator);
|
|
|
- Object.keys(value.split(currentSeparator)).some((val) => {
|
|
|
- Object.keys(datas).some((key) => {
|
|
|
- if (datas[key].dictValue == ('' + temp[val])) {
|
|
|
- actions.push(datas[key].dictLabel + currentSeparator);
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- return actions.join('').substring(0, actions.join('').length - 1);
|
|
|
+ var actions = [];
|
|
|
+ var currentSeparator = undefined === separator ? ',' : separator;
|
|
|
+ var temp = value.split(currentSeparator);
|
|
|
+ Object.keys(value.split(currentSeparator)).some((val) => {
|
|
|
+ Object.keys(datas).some((key) => {
|
|
|
+ if (datas[key].dictValue == '' + temp[val]) {
|
|
|
+ actions.push(datas[key].dictLabel + currentSeparator);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return actions.join('').substring(0, actions.join('').length - 1);
|
|
|
}
|
|
|
|
|
|
// 字符串格式化(%s )
|
|
|
export function sprintf(str) {
|
|
|
- var args = arguments, flag = true, i = 1;
|
|
|
- str = str.replace(/%s/g, function () {
|
|
|
- var arg = args[i++];
|
|
|
- if (typeof arg === 'undefined') {
|
|
|
- flag = false;
|
|
|
- return '';
|
|
|
- }
|
|
|
- return arg;
|
|
|
- });
|
|
|
- return flag ? str : '';
|
|
|
+ var args = arguments,
|
|
|
+ flag = true,
|
|
|
+ i = 1;
|
|
|
+ str = str.replace(/%s/g, function () {
|
|
|
+ var arg = args[i++];
|
|
|
+ if (typeof arg === 'undefined') {
|
|
|
+ flag = false;
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ return arg;
|
|
|
+ });
|
|
|
+ return flag ? str : '';
|
|
|
}
|
|
|
|
|
|
// 转换字符串,undefined,null等转化为""
|
|
|
export function praseStrEmpty(str) {
|
|
|
- if (!str || str == "undefined" || str == "null") {
|
|
|
- return "";
|
|
|
- }
|
|
|
- return str;
|
|
|
+ if (!str || str == 'undefined' || str == 'null') {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ return str;
|
|
|
}
|
|
|
|
|
|
//
|
|
|
export function twoPointSum(latA, lonA, latB, lonB) {
|
|
|
- var coordinate = 6371000.;
|
|
|
- var PI = 3.14159265358979324;
|
|
|
- var x = Math.cos(latA * PI / 180.) * Math.cos(latB * PI / 180.) * Math.cos((lonA - lonB) * PI / 180);
|
|
|
- var y = Math.sin(latA * PI / 180.) * Math.sin(latB * PI / 180.);
|
|
|
- var s = x + y;
|
|
|
- if (s > 1) s = 1;
|
|
|
- if (s < -1) s = -1;
|
|
|
- var alphabet = Math.acos(s);
|
|
|
- var PointSum = alphabet * coordinate;
|
|
|
- return PointSum;
|
|
|
+ var coordinate = 6371000;
|
|
|
+ var PI = 3.14159265358979324;
|
|
|
+ var x =
|
|
|
+ Math.cos((latA * PI) / 180) *
|
|
|
+ Math.cos((latB * PI) / 180) *
|
|
|
+ Math.cos(((lonA - lonB) * PI) / 180);
|
|
|
+ var y = Math.sin((latA * PI) / 180) * Math.sin((latB * PI) / 180);
|
|
|
+ var s = x + y;
|
|
|
+ if (s > 1) s = 1;
|
|
|
+ if (s < -1) s = -1;
|
|
|
+ var alphabet = Math.acos(s);
|
|
|
+ var PointSum = alphabet * coordinate;
|
|
|
+ return PointSum;
|
|
|
}
|
|
|
|
|
|
export function CJ02BD(gcjLat, gcjLon) {
|
|
|
- var x = gcjLon,
|
|
|
- y = gcjLat;
|
|
|
- var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
|
|
|
- var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
|
|
|
- var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
|
|
|
- var bdLon = z * Math.cos(theta) + 0.0065;
|
|
|
- var bdLat = z * Math.sin(theta) + 0.006;
|
|
|
+ var x = gcjLon,
|
|
|
+ y = gcjLat;
|
|
|
+ var x_pi = (3.14159265358979324 * 3000.0) / 180.0;
|
|
|
+ var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
|
|
|
+ var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
|
|
|
+ var bdLon = z * Math.cos(theta) + 0.0065;
|
|
|
+ var bdLat = z * Math.sin(theta) + 0.006;
|
|
|
|
|
|
- return {
|
|
|
- 'lat': bdLat,
|
|
|
- 'lon': bdLon
|
|
|
- };
|
|
|
+ return {
|
|
|
+ lat: bdLat,
|
|
|
+ lon: bdLon,
|
|
|
+ };
|
|
|
}
|
|
|
export function gcj02BD(gcjLat, gcjLon) {
|
|
|
- var x = gcjLon - 0.0065,
|
|
|
- y = gcjLat - 0.006;
|
|
|
- var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
|
|
|
- var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
|
|
|
- var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
|
|
|
- var bdLon = z * Math.cos(theta);
|
|
|
- var bdLat = z * Math.sin(theta);
|
|
|
- return { lat: bdLat, lon: bdLon };
|
|
|
+ var x = gcjLon - 0.0065,
|
|
|
+ y = gcjLat - 0.006;
|
|
|
+ var x_pi = (3.14159265358979324 * 3000.0) / 180.0;
|
|
|
+ var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
|
|
|
+ var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
|
|
|
+ var bdLon = z * Math.cos(theta);
|
|
|
+ var bdLat = z * Math.sin(theta);
|
|
|
+ return { lat: bdLat, lon: bdLon };
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ *门店类型集合,返回对应的类型
|
|
|
+ *@param {*String} dictValue //类型
|
|
|
+ * */
|
|
|
+export function verifyStoreType(dictValue) {
|
|
|
+ if (!dictValue) return null;
|
|
|
+ let storeData = null;
|
|
|
+ storeData = store.getters.storeType.find((val) => val.dictValue == dictValue);
|
|
|
+ let remarkType = JSON.parse(storeData.remark);
|
|
|
+ return remarkType;
|
|
|
}
|