import { defineStore } from "pinia"; const commonStore = defineStore("common", { state: () => ({ mapBool: 1, //1.高德 2.测绘院 streetTownList: [ { value: "", label: "全区" }, { value: "华漕镇", label: "华漕镇" }, { value: "虹桥镇", label: "虹桥镇" }, { value: "梅陇镇", label: "梅陇镇" }, { value: "七宝镇", label: "七宝镇" }, { value: "颛桥镇", label: "颛桥镇" }, { value: "马桥镇", label: "马桥镇" }, { value: "吴泾镇", label: "吴泾镇" }, { value: "浦江镇", label: "浦江镇" }, { value: "新虹街道", label: "新虹街道" }, { value: "古美路街道", label: "古美路街道" }, { value: "江川路街道", label: "江川路街道" }, { value: "浦锦街道", label: "浦锦街道" }, { value: "莘庄镇", label: "莘庄镇" }, ], timeList: [ new Date().getFullYear() + "-" + (new Date().getMonth() + 1 < 10 ? "0" + (new Date().getMonth() + 1) : "" + (new Date().getMonth() + 1)) + "-" + (new Date().getDate() < 10 ? "0" + new Date().getDate() : new Date().getDate()) + " 00:00:00", new Date().getFullYear() + "-" + (new Date().getMonth() + 1 < 10 ? "0" + (new Date().getMonth() + 1) : "" + (new Date().getMonth() + 1)) + "-" + (new Date().getDate() < 10 ? "0" + new Date().getDate() : new Date().getDate()) + " 23:59:59", ], mhjz: [ { streetTown: "全区", id: 12, x: 121.4175597, y: 31.119248 }, { streetTown: "江川路街道", id: 1201, x: 121.399126538181, y: 31.0099719391863, }, { streetTown: "新虹街道", id: 1217, x: 121.319329296294, y: 31.1983901916889, }, { streetTown: "古美路街道", id: 1206, x: 121.388451866936, y: 31.1478233480159, }, { streetTown: "浦锦街道", id: 1218, x: 121.483929120352, y: 31.089967318558, }, { streetTown: "浦江镇", id: 1215, x: 121.524058543447, y: 31.0540039472667, }, { streetTown: "吴泾镇", id: 1213, x: 121.454076463728, y: 31.04860402113, }, { streetTown: "马桥镇", id: 1214, x: 121.352680027718, y: 31.0213512298508, }, { streetTown: "颛桥镇", id: 1209, x: 121.40607138504, y: 31.0612972443508, }, { streetTown: "莘庄镇", id: 1207, x: 121.37064864047, y: 31.1154549548722, }, { streetTown: "梅陇镇", id: 1212, x: 121.421346814491, y: 31.1069718313722, }, { streetTown: "七宝镇", id: 1208, x: 121.350366186317, y: 31.1553292680362, }, { streetTown: "虹桥镇", id: 1211, x: 121.37956256207, y: 31.1806219953212, }, { streetTown: "华漕镇", id: 1210, x: 121.277541517147, y: 31.2289121171624, }, { streetTown: "莘庄工业区", id: 1216, x: 121.376508452784, y: 31.0678185611843, }, ], deviceDetailsArray: {},//设备详情页面-数据存储 facilitiesGatherType: "",//设施采集类型-数据存储 facilitiesGatherArray: { department: "", //所属部门 facilityType: "", //设施类型 facilityTypeName: "", //设施类型名称 facilityName: "", //设施名称 status: "0", //设施状态 address: "", //设施地址 longitude: "", //经度 latitude: "", //纬度 province: "", //省 city: "", //市 area: "", //区(县) facilityAddress: "", //详细地址 streetTown: null, //所属街镇 gpsAreas: [], //经纬度集合 contact: "", //联系人 contactPhone: "", //联系方式 imagesUrl: "", //图⽚地址URL facilityDesc: "", //备注 extendData: [], //扩展属性 recordPictureList: [], typeGuise: "", //点线面类型 },//设施采集页面-数据存储 }), persist: { storage: window ? window.localStorage : uni.setStorageSync(), // 指定换成地址 beforeRestore: (context) => { // console.log("Before" + context); }, afterRestore: (context) => { // console.log("After" + context); }, }, actions: { getDate() { var date = new Date(); var year = date.getFullYear(); // 返回的是年份 var month = date.getMonth() + 1; // 返回的月份上个月的月份,记得+1才是当月 if (month < 10) { month = "0" + month; } var dates = date.getDate(); // 返回的是几号 if (dates < 10) { dates = "0" + dates; } var day = date.getDay(); // 周一返回的是1,周六是6,但是周日是0 var arr = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; return { year, month, dates, day, arr, }; }, /** * @处理公共日期格式 */ formatterDate(date, fmt) { let nowDate = { yyyy: date.getFullYear(), // 年 MM: date.getMonth() + 1, // 月份 dd: date.getDate(), //日 hh: date.getHours(), mm: date.getMinutes(), ss: date.getSeconds(), }; if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); } for (var k in nowDate) { if (new RegExp("(" + k + ")").test(fmt)) { fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? nowDate[k] : ("00" + nowDate[k]).substr(("" + nowDate[k]).length)); } } return fmt; }, /** * @获取当前日期前一年的日期 */ getYearLast(dateStr) { // 假设要获取的日期为dateStr,格式为"YYYY-MM-DD" let date = new Date(dateStr); let Y = date.getFullYear() - 1; // 获取前一年的年份 let M = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; // 月 let D; // 日 var h = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":"; var m = (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) + ":"; var s = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); // 判断原日期的月份是否为2月份 if (date.getMonth() === 1) { // 2月份 // 判断前一年是否为闰年 if (Y % 4 === 0 && Y % 100 !== 0 || Y % 400 === 0) { // 闰年 D = Math.min(date.getDate(), 29); // 新日期的日期最大为29 } else { // 平年 D = Math.min(date.getDate(), 28); // 新日期的日期最大为28 } } else { // 非2月份 D = date.getDate(); // 新日期的日期为原日期的日期 } let newDateStr = Y + "-" + M + "-" + (D < 10 ? "0" + D : D) + " " + h + m + s; // 格式化日期字符串 return newDateStr }, /** * @获取年月日时分秒 * @returns */ formatterDateTime(time3) { var date = new Date(time3); var Y = date.getFullYear() + "-"; var M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-"; var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " "; var h = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":"; var m = (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) + ":"; var s = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); var strDate = Y + M + D + h + m + s; return strDate; }, /** * @统计两个日期之间的月份 */ getMonths(date1, date2) { //用-分成数组 date1 = date1.split("-"); date2 = date2.split("-"); //获取年,月数 var year1 = parseInt(date1[0]), month1 = parseInt(date1[1]), year2 = parseInt(date2[0]), month2 = parseInt(date2[1]), //通过年,月差计算月份差 months = (year2 - year1) * 12 + (month2 - month1) + 1; return months; }, /** * @计算当前坐标和G点坐标的偏差值 * @returns */ caculateLL(lat1, lng1, lat2, lng2) { var radLat1 = (lat1 * Math.PI) / 180.0; var radLat2 = (lat2 * Math.PI) / 180.0; var a = radLat1 - radLat2; var b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0; var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); s = s * 6378.137; s = Math.round(s * 10000) / 10; console.log(s); return s; }, /** * @数组对象排序 * @return * @param {数据} data * @param {0 从小到大 1 从大到小} sort */ sortEvent(data, sort) { let arr = []; // 将需要排序的 key, 进行排列 let sortKeys = Object.keys(JSON.parse(JSON.stringify(data))).sort((a, b) => { return sort == 0 ? JSON.parse(JSON.stringify(data))[a].sort - JSON.parse(JSON.stringify(data))[b].sort : JSON.parse(JSON.stringify(data))[b].sort - JSON.parse(JSON.stringify(data))[a].sort; }); // 循环排列好的 key, 重新组成一个新的数组 for (var sortIndex in sortKeys) { arr.push(JSON.parse(JSON.stringify(data))[sortKeys[sortIndex]]); } return arr; }, /** * @公共添加服务器列表 */ setServeList(linkUrl, content) { let serveList = uni.getStorageSync("serveList"); if (serveList.length <= 0) { uni.setStorageSync("serveList", [ { radiolist: [ { id: 1, linkUrl: linkUrl, content: content, }, ], radiovalue: 1, }, ]); } else { serveList[0].radiolist.push({ id: serveList[0].radiolist[serveList[0].radiolist.length - 1].id + 1, linkUrl: linkUrl, content: content, }); uni.setStorageSync("serveList", serveList); } } }, }); export default commonStore;