/* eslint-disable */ function NoToChinese (num) { num = String(num) var chnNumChar = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十'] if (num == 0) { return chnNumChar[0] } let tmp = '' for (let i = 0; i < num.length; i++) { const ele = num.charAt(i) tmp += chnNumChar[ele] } return tmp } function randomWord (randomFlag, min, max) { let str = '' let range = min const arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] // 随机产生 if (randomFlag) { range = Math.round(Math.random() * (max - min)) + min } for (var i = 0; i < range; i++) { const pos = Math.round(Math.random() * (arr.length - 1)) str += arr[pos] } return str } module.exports = { formatDate: function (time) { var weekArr = ['日', '一', '二', '三', '四', '五', '六'] var date = new Date(time) var year = date.getFullYear() var month = date.getMonth() + 1 var day = date.getDate() var week = '星期' + weekArr[date.getDay()] if (window.innerWidth < 1700) { return ( year + '年' + (String(month).length > 1 ? month : '0' + month) + '月' + (String(day).length > 1 ? day : '0' + day) + '日' + '
' + week ) } return ( year + '年' + (String(month).length > 1 ? month : '0' + month) + '月' + (String(day).length > 1 ? day : '0' + day) + '日' + ' ' + week ) }, smoothscrollpos: function (domName) { if (domName == '/') { return window.scrollTo(0, 0) } const smoothscroll = () => { const dom = document.getElementById(domName) // window.scrollTo({ // top:dom.offsetTop - 100, // left:0, // behavior: "smooth" // }) dom && window.scrollTo(0, dom.offsetTop - 120) } smoothscroll() }, formatTime: function (time, fan = false) { let t1 = time.split(' ')[0].split('-') if (fan) { t1 = t1.map((item) => { const t = NoToChinese(item) return t }) } return t1 }, encodeStr: function (str, strv = '') { const NUM = 2 const front = randomWord(false, 8) const middle = randomWord(false, 8) const end = randomWord(false, 8) const str1 = str.substring(0, NUM) const str2 = str.substring(NUM) if (strv) { const strv1 = strv.substring(0, NUM) const strv2 = strv.substring(NUM) return [front + str2 + middle + str1 + end, front + strv2 + middle + strv1 + end] } return front + str2 + middle + str1 + end } }