/* * @Author: 王文杰 * @Date: 2024-01-04 12:54:56 * @LastEditors: jevononlie 728254585@qq.com * @LastEditTime: 2024-04-07 09:36:33 * @FilePath: /app-nx-personal/src/utils/index.ts * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ /** * 日期格式化函数 * @param date 日期对象 * @param format 日期格式,默认为 YYYY-MM-DD HH:mm:ss */ export const formatDate = (datePramas: Date, format = 'YYYY-MM-DD HH:mm:ss') => { // 获取年月日时分秒,通过 padStart 补 0 const date = new Date(datePramas) const year = String(date.getFullYear()) const month = String(date.getMonth() + 1).padStart(2, '0') const day = String(date.getDate()).padStart(2, '0') const hours = String(date.getHours()).padStart(2, '0') const minutes = String(date.getMinutes()).padStart(2, '0') const seconds = String(date.getSeconds()).padStart(2, '0') // 返回格式化后的结果 return format .replace('YYYY', year) .replace('MM', month) .replace('DD', day) .replace('HH', hours) .replace('mm', minutes) .replace('ss', seconds) } /** * 微信小程序发布后提醒用户更新版本 * * @return {[type]} [return description] */ export const updateManager = () => { const updateManager = uni.getUpdateManager() // 小程序版本更新管理器 updateManager.onCheckForUpdate((res) => { // 检测新版本后的回调 if (res.hasUpdate) { // 如果有新版本提醒并进行强制升级 uni.showModal({ content: '新版本已经准备好,是否重启应用?', showCancel: false, confirmText: '确定', success: (res) => { if (res.confirm) { updateManager.onUpdateReady((res) => { // 新版本下载完成的回调 updateManager.applyUpdate() // 强制当前小程序应用上新版本并重启 }) updateManager.onUpdateFailed((res) => { // 新版本下载失败的回调 // 新版本下载失败,提示用户删除后通过冷启动重新打开 uni.showModal({ content: '下载失败,请删除当前小程序后重新打开', showCancel: false, confirmText: '知道了', }) }) } }, }) } }) }