UNPKG

mini-check

Version:

73 lines 2.43 kB
import Taro, { setStorageSync as _setStorageSync, removeStorage as _removeStorage, getStorageSync as _getStorageSync } from "@tarojs/taro-h5"; import padEnd from 'lodash/padEnd'; export function formatArea(areaInfo) { // 获取省节点 const proviceArr = areaInfo.filter(item => item.administrativeDivisionType === 1).map(item => { // 获取市节点 const cityArr = areaInfo.filter(i => i.parentAreaId === item.areaId).map(i => { // 获取区县节点 const country = areaInfo.filter(j => j.parentAreaId === i.areaId).map(j => { return { label: j.name, value: j.areaId, children: null, isLeaf: false }; }); const md = i.administrativeDivisionType === 3 ? { isLeaf: false } : {}; return { label: i.name, value: i.areaId, children: country.length === 0 ? undefined : country, ...md }; }); return { label: item.name, value: item.areaId, children: cityArr }; }); return [{ label: '全国', value: '10', children: [] }].concat(proviceArr); } export function fullZero(areaId) { let result = areaId; if (areaId.length < 6) { // result = padEnd(areaId, 6, 0); result = padEnd(areaId, 6, '0'); } return result; } export function setItem({ key, data }) { _setStorageSync(key, data); } export function removeItem(key) { _removeStorage({ key }); } export function getItem(key) { return _getStorageSync(key); } export function getValue(value) { if (value === undefined || value === null) { return ''; } return value; } export function isEmpty(value) { if (value === undefined || value === null || value === '' || value.length === 0) { return true; } return false; } export function uuid() { let s = []; let hexDigits = "0123456789abcdef"; for (let i = 0; i < 36; i++) { s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); } s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010 s[19] = hexDigits.substr(s[19] & 0x3 | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01 s[8] = s[13] = s[18] = s[23] = "-"; const uuid = s.join(""); return uuid; } export function getTimestamp(date) { return new Date(date).getTime(); } export function getTime(timestamp) { const time = new Date(timestamp).toLocaleDateString().replace(/\//g, "-") + " " + new Date(timestamp).toTimeString().substr(0, 8); return time.substring(0, time.length - 3); }