This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function padNum(num, len = 2) { | |
return num.toString().padStart(len, '0') | |
} | |
/** | |
* 获取日期和时间戳(如:202009271518) | |
*/ | |
function getDateTimeString(d = new Date()) { | |
return `${d.getFullYear()}${padNum(d.getMonth() + 1)}${padNum(d.getDate())}${padNum(d.getHours())}${padNum(d.getMinutes())}` | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 安全地获取嵌套对象的值 | |
* @param obj 对象 | |
* @param path 键值数组 | |
* @param fallback 获取失败的返回值 | |
*/ | |
function getVal(obj, path, fallback) { | |
try { | |
let i | |
const len = path.length |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// parseFileName('aaa_aa_xx.mp3') | |
const parseFileName = (n) => { | |
let dotIndex = n.lastIndexOf('.') | |
if (dotIndex < 0) { | |
dotIndex = n.length | |
} | |
const prefix = n.substr(0, dotIndex) | |
const suffix = n.substr(dotIndex, n.length) | |
return { | |
// dotIndex, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const guid = () => { | |
function S4() { | |
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1) | |
} | |
return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4()) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function copyToClip(content) { | |
var aux = document.createElement("input"); | |
aux.setAttribute("value", content); | |
document.body.appendChild(aux); | |
aux.select(); | |
document.execCommand("copy"); | |
document.body.removeChild(aux); | |
} | |
function getLanhuSelectedText(splitter = ' ') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns a random number between min (inclusive) and max (exclusive) | |
*/ | |
function getRandomArbitrary(min, max) { | |
return Math.random() * (max - min) + min; | |
} | |
/** | |
* Returns a random integer between min (inclusive) and max (inclusive). | |
* The value is no lower than min (or the next integer greater than min |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs-extra') | |
const Path = require('path') | |
// https://stackoverflow.com/a/65403443 | |
const writeFileIncrement = async (filename, data, increment = 0) => { | |
const incrementText = increment ? `_${increment}` : '' | |
const name = `${Path.basename(filename, Path.extname(filename))}${incrementText}${Path.extname(filename)}` | |
return await fs.writeFileIncrement(name, data, {encoding: 'utf8', flag: 'wx'}).catch(async ex => { | |
if (ex.code === 'EEXIST') return await writeFileIncrement(filename, data, increment += 1) | |
throw ex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
methods: { | |
async initMap() { | |
import('leaflet/dist/leaflet.css') | |
import('leaflet').then((L) => { | |
const itemList = this.originalList || [{}] | |
const map = L.map('myMap').setView(itemList[0].latlng || [-25.363, 131.044], commonZoom) | |
const icon = L.icon({ | |
iconUrl: require('~/assets/images/utils/map-icons/marker-icon.png'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 扁平文件夹数组生成文件夹树状结构 | |
* @param files | |
* @returns {*} | |
*/ | |
function genFolderTree(files) { | |
const tree = [] | |
const buildTree = (hierarchy, file) => { | |
let curTree = tree | |
const maxDepth = hierarchy.length - 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class EventEmitter { | |
constructor() { | |
this.events = [] | |
} | |
on(name, fn) { | |
if (this.events[name]) { | |
this.events[name].push(fn) | |
} else { | |
this.events[name] = [fn] |
OlderNewer