const formatTime = date => { // 确保date是Date对象 const dateObj = date instanceof Date ? date : new Date(date) const year = dateObj.getFullYear() const month = dateObj.getMonth() + 1 const day = dateObj.getDate() const hour = dateObj.getHours() const minute = dateObj.getMinutes() const second = dateObj.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}` } /** * 导航到webview页面 * @param {string} path - 页面路径 */ const navigateToWebview = (path) => { // 配置webview链接 const envConfig = { // 开发环境和测试环境 development: 'https://sit-kelamayi.4dage.com/mini/#', // 正式环境 production: 'https://kelamayi.4dage.com/mini/#' }; // 获取当前环境 const currentEnv = wx.getAccountInfoSync().miniProgram.envVersion || 'develop'; let baseUrl = envConfig.development; if (currentEnv === 'release') { baseUrl = envConfig.production; } // 检查path中是否已经包含isFrom参数,避免重复添加 let fullUrl; if (path.includes('isFrom=weixin')) { fullUrl = `${baseUrl}${path}`; } else { const separator = path.includes('?') ? '&' : '?'; fullUrl = `${baseUrl}${path}${separator}isFrom=weixin`; } wx.navigateTo({ url: `/pages/webview/index?url=${encodeURIComponent(fullUrl)}` }); }; module.exports = { formatTime, navigateToWebview }