const formatTime = date => { const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const hour = date.getHours() const minute = date.getMinutes() const second = date.getSeconds() return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}` } const formatNumber = n => { n = n.toString() return n[1] ? n : `0${n}` } // 跳转到书籍详情页 export const goToBookDetail = (options) => { // 检查必要参数 if (!options || (!options.bookId || !options.wxBookId)) { console.warn('书籍ID不能为空'); return; } let url = ''; // 根据不同参数构建不同的URL if (options.wxBookId) { // 微信书籍ID跳转 url = `plugin-private://wx293c4b6097a8a4d0/pages/novel/index?bookId=${options.wxBookId}`; // 如果有章节ID,添加到URL if (options.chapterId) { url += `&chapterId=${options.chapterId}`; } if (options.bookId) { url += `&innerBookId=${options.bookId}`; } } wx.navigateTo({ url, fail: (err) => { console.error('跳转书籍详情页失败:', err); console.log('url',url); wx.showToast({ title: '跳转失败,请重试', icon: 'none' }); } }); }; // 随机整数方法 export const rnd = (min = 0, max = 1) => { const random = Math.floor(Math.random() * (max - min + 1) + min) return random }; // 随机整数方法 export const rndone = (self = []) => { return self.length > 0 ? self[rnd(0, self.length - 1)] : '' }; /** * 拷贝 */ export function deepCopy(data) { let t = typeof data if (data instanceof Array) { t = 'array' } let o if (t === 'array') { o = [] for (let i = 0; i < data.length; i++) { o.push(deepCopy(data[i])) } } else if (t === 'object') { o = {} for (let i in data) { o[i] = deepCopy(data[i]) } } else { return data } return o } module.exports = { formatTime, goToBookDetail, rnd, rndone, deepCopy }