master
王文杰 8 months ago
parent 5954bb9bae
commit 065296f0bc

@ -1,8 +1,18 @@
<!--
* @Author: 王文杰
* @Date: 2024-01-04 12:54:56
* @LastEditors: 王文杰
* @LastEditTime: 2024-03-08 12:02:37
* @FilePath: /app-nx-recycle/src/App.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup lang="ts"> <script setup lang="ts">
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app' import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
import { updateManager } from '@/utils/index'
onLaunch(() => { onLaunch(() => {
console.log('App Launch') console.log('App Launch')
updateManager()
}) })
onShow(() => { onShow(() => {
console.log('App Show') console.log('App Show')

@ -92,16 +92,6 @@ const handleNewsList = () => {
<uni-icons type="settings" color="#3775F6" size="20"></uni-icons> <uni-icons type="settings" color="#3775F6" size="20"></uni-icons>
<view class="label"> 设置 </view> <view class="label"> 设置 </view>
</navigator> </navigator>
<!-- <button hover-class="none" class="item arrow" open-type="contact">
<image
class="img"
src="/static/images/seting_my.png"
mode="scaleToFill"
/>
<view class="text">
检查更新
</view>
</button> -->
<!-- <button hover-class="none" class="item arrow" @click="handleNewsList"> <!-- <button hover-class="none" class="item arrow" @click="handleNewsList">
<image class="img" src="/static/images/detail_concat.png" mode="scaleToFill" /> <image class="img" src="/static/images/detail_concat.png" mode="scaleToFill" />
<view class="text"> 消息列表 </view> <view class="text"> 消息列表 </view>

@ -2,7 +2,7 @@
* @Author: * @Author:
* @Date: 2024-01-04 12:54:56 * @Date: 2024-01-04 12:54:56
* @LastEditors: * @LastEditors:
* @LastEditTime: 2024-03-07 17:18:09 * @LastEditTime: 2024-03-08 12:04:46
* @FilePath: /app-nx-recycle/src/utils/http.ts * @FilePath: /app-nx-recycle/src/utils/http.ts
* @Description: ,`customMade`, koroFileHeader : https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: ,`customMade`, koroFileHeader : https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
@ -66,7 +66,7 @@ type Data<T> = {
result: T result: T
} }
function ajaxError(data) { function ajaxError(data: AnyObject) {
uni.showToast({ uni.showToast({
title: data.msg || '请求出错,请重试', title: data.msg || '请求出错,请重试',
icon: 'none', icon: 'none',
@ -75,10 +75,10 @@ function ajaxError(data) {
const memberStore = useMemberStore() const memberStore = useMemberStore()
memberStore.clearProfile() memberStore.clearProfile()
uni.reLaunch({ uni.reLaunch({
url: '/pages/login/login' url: '/pages/login/login',
}) })
} }
} },
}) })
} }
// 2.2 添加类型,支持泛型 // 2.2 添加类型,支持泛型
@ -88,7 +88,7 @@ export const http = <T>(options: UniApp.RequestOptions) => {
uni.request({ uni.request({
...options, ...options,
// 响应成功 // 响应成功
success(res) { success(res: AnyObject) {
// 状态码 2xx axios 就是这样设计的 // 状态码 2xx axios 就是这样设计的
if (res.statusCode >= 200 && res.statusCode < 300) { if (res.statusCode >= 200 && res.statusCode < 300) {
if (res.data?.code == 200) { if (res.data?.code == 200) {

@ -1,3 +1,11 @@
/*
* @Author:
* @Date: 2024-01-04 12:54:56
* @LastEditors:
* @LastEditTime: 2024-03-08 12:05:02
* @FilePath: /app-nx-recycle/src/utils/index.ts
* @Description: ,`customMade`, koroFileHeader : https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
/** /**
* *
* @param date * @param date
@ -21,3 +29,40 @@ export const formatDate = (date: Date, format = 'YYYY-MM-DD HH:mm:ss') => {
.replace('mm', minutes) .replace('mm', minutes)
.replace('ss', seconds) .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: '知道了',
})
})
}
},
})
}
})
}

Loading…
Cancel
Save