123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- /* eslint-disable */
- // @ts-nocheck
- const STORAGE_USER_KEY = 'STORAGE_USER_KEY'
- // const STORAGE_CARTLIST_KEY = 'STORAGE_CARTLIST_KEY'
- // const STORAGE_QUERYMYLIST_KEY = 'STORAGE_QUERYMYLIST_KEY'
- // import { Toast } from 'mint-ui';
- import axios from 'axios'
- const prefix = 'http://testapi.gu-dao.cn';
- // import authService from '@/api/authService.js'
- //定义一些常量
- var x_PI = 3.14159265358979324 * 3000.0 / 180.0;
- var PI = 3.1415926535897932384626;
- var a = 6378245.0;
- var ee = 0.00669342162296594323;
- export default {
- // 获取
- getLocal(key = STORAGE_USER_KEY) {
- // console.log('get local operation')
- return JSON.parse(window.localStorage.getItem(key))
- },
- // 设置用
- /**
- * @param {any} res
- */
- setLocal(res, key = STORAGE_USER_KEY, isSaveOldData = false) {
- //第三个参数是true的话,会增加数据而不是重新设置,res必须是数组
- if (isSaveOldData) {
- if (this.getLocal(key)) {
- let oldData = this.getLocal(key);
- return window.localStorage.setItem(key, JSON.stringify(oldData.concat(res)))
- }
- }
- return window.localStorage.setItem(key, JSON.stringify(res))
- },
- /**
- * @param {any[]} obj
- */
- deepClone(obj) {
- var o;
- if (typeof obj == "object") {
- if (obj === null) {
- o = null;
- } else {
- if (obj instanceof Array) {
- o = [];
- for (var i = 0, len = obj.length; i < len; i++) {
- o.push(this.deepClone(obj[i]));
- }
- } else {
- o = {};
- for (var j in obj) {
- o[j] = this.deepClone(obj[j]);
- }
- }
- }
- } else {
- o = obj;
- }
- return o;
- },
- getGuid() {
- function S4() {
- return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
- }
- return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
- },
- /**
- * @param {string} value
- */
- isEmpty(value) {
- let result = false;
- if (value == null || value == undefined) {
- result = true;
- }
- if (typeof value == 'string' && (value.replace(/\s+/g, "") == "" || value == "")) {
- result = true;
- }
- if (typeof value == "object" && value instanceof Array && value.length === 0) {
- result = true;
- }
- return result;
- },
- /**
- * @param {any} time
- */
- formatTime(time) {
- // 格式:yyyy-MM-dd hh:mm:ss
- let date = new Date(Number(time));
- let Y = date.getFullYear() + '-';
- let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
- let D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
- let h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
- let m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
- let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
- return Y + M + D + h + m + s;
- },
- /**
- * @param {any} time
- */
- formatDate(time) {
- // 格式:yyyy-MM-dd
- let date = new Date(Number(time));
- let Y = date.getFullYear() + '-';
- let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
- let D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
- return Y + M + D;
- },
- /**
- * 字符串转数组
- * @param {*} value
- * @returns
- */
- stringToArray(value) {
- if (this.isEmpty(value)) return []
- if (typeof value !== 'string') return []
- if (value.indexOf(",") < 0) return [value]
- let array = value.split(",");
- return array
- },
- /**
- * 数组转字符串
- * @param {*} value
- * @returns
- */
- arrayToString(value) {
- if (typeof value == "object" && value instanceof Array) {
- if (value.length == 0) return ""
- let str = '';
- value.forEach(element => {
- str += element + ',';
- })
- return str.substr(0, str.length - 1);
- } else {
- return ""
- }
- },
- /**
- * 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
- * 即谷歌、高德 转 百度
- * @param {number} lng
- * @param {number} lat
- * @returns {*[]}
- */
- gcj02tobd09(lng, lat) {
- var z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
- var theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
- var bd_lng = z * Math.cos(theta) + 0.0065;
- var bd_lat = z * Math.sin(theta) + 0.006;
- return [bd_lng, bd_lat]
- },
- /**
- * @param {string} value
- */
- isPhone(value) {
- var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
- if (!myreg.test(value)) {
- return false;
- } else {
- return true;
- }
- },
- /**
- * 身份证号验证
- * @param {string} value
- */
- isIDCardNo(value) {
- var myreg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
- if (!myreg.test(value)) {
- return false;
- } else {
- return true;
- }
- },
- /**
- * 从身份证号中获取出生日期、性别、年龄
- * @param idCard
- * @returns {{sex: string, birth: null, age: number}}
- */
- decomposeIdCard(idCard) {
- let sex = null
- let birth = null
- let myDate = new Date()
- let month = myDate.getMonth() + 1
- let day = myDate.getDate()
- let age = 0
- if (idCard.length === 18) {
- age = myDate.getFullYear() - idCard.substring(6, 10) - 1
- sex = idCard.substring(16, 17)
- birth = idCard.substring(6, 10) + '-' + idCard.substring(10, 12) + '-' + idCard.substring(12, 14)
- // eslint-disable-next-line no-mixed-operators
- if (idCard.substring(10, 12) < month || idCard.substring(10, 12) === month && idCard.substring(12, 14) <= day) age++
- }
- if (idCard.length === 15) {
- age = myDate.getFullYear() - idCard.substring(6, 8) - 1901
- sex = idCard.substring(13, 14)
- birth = '19' + idCard.substring(6, 8) + '-' + idCard.substring(8, 10) + '-' + idCard.substring(10, 12)
- // eslint-disable-next-line no-mixed-operators
- if (idCard.substring(8, 10) < month || idCard.substring(8, 10) === month && idCard.substring(10, 12) <= day) age++
- }
- if (sex % 2 === 0) {
- sex = '2' // 性别代码 1代表男,2代表女,暂时不涉及其他类型性别
- } else {
- sex = '1'
- }
- return {age, sex, birth}
- }
- }
|