feat: 添加应用版本检查功能,优化用户体验
This commit is contained in:
259
App.vue
259
App.vue
@@ -1,136 +1,159 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
import { setSdkLanguageFromSystem } from '@/uni_modules/tuikit-atomic-x/utils/setSdkLanguageFromSystem'
|
import { setSdkLanguageFromSystem } from '@/uni_modules/tuikit-atomic-x/utils/setSdkLanguageFromSystem'
|
||||||
// import * as call from "@/uni_modules/RongCloud-CallWrapper/lib/index"
|
// import * as call from "@/uni_modules/RongCloud-CallWrapper/lib/index"
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
import * as RongIMLib from '@rongcloud/imlib-next';
|
import * as RongIMLib from '@rongcloud/imlib-next'
|
||||||
import { installer as rtcInstaller } from '@rongcloud/plugin-rtc';
|
import { installer as rtcInstaller } from '@rongcloud/plugin-rtc'
|
||||||
import { installer as callPlusInstaller } from '@rongcloud/plugin-call-plus';
|
import { installer as callPlusInstaller } from '@rongcloud/plugin-call-plus'
|
||||||
// #endif
|
// #endif
|
||||||
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
|
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
|
||||||
import { reLaunch } from './utils/router'
|
import { reLaunch } from './utils/router'
|
||||||
import { useAuthUser } from './composables/useAuthUser'
|
import { useAuthUser } from './composables/useAuthUser'
|
||||||
import { useUserStore } from './stores/user'
|
import { useUserStore } from './stores/user'
|
||||||
import { TUIChatKit } from './TUIKit'
|
import { TUIChatKit } from './TUIKit'
|
||||||
import { getIpBlack } from './api'
|
import { getIpBlack, getAppVersion } from './api'
|
||||||
import {reasonDeal,errorDeal,imCode} from '@/utils/code.js'
|
import { reasonDeal, errorDeal, imCode } from '@/utils/code.js'
|
||||||
import { navigateTo } from '@/utils/router'
|
import { compareVersion } from '@/utils/util.js'
|
||||||
|
import { navigateTo } from '@/utils/router'
|
||||||
|
|
||||||
TUIChatKit.init()
|
TUIChatKit.init()
|
||||||
|
|
||||||
const { token, tencentUserSig } = useAuthUser()
|
const { token, tencentUserSig } = useAuthUser()
|
||||||
const { loginTencentIM } = useUserStore()
|
const { loginTencentIM } = useUserStore()
|
||||||
/** 静默登录逻辑 */
|
/** 静默登录逻辑 */
|
||||||
const silentLogin = async (e) => {
|
const silentLogin = async e => {
|
||||||
if (token.value) {
|
if (token.value) {
|
||||||
loginTencentIM()
|
loginTencentIM()
|
||||||
// reLaunch('/TUIKit/components/TUIConversation/index')
|
// reLaunch('/TUIKit/components/TUIConversation/index')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(tencentUserSig, '=====222==')
|
console.log(tencentUserSig, '=====222==')
|
||||||
if (e?.query?.invitationCode) {
|
if (e?.query?.invitationCode) {
|
||||||
reLaunch('/pages/login/phone-register/phone-register', {
|
reLaunch('/pages/login/phone-register/phone-register', {
|
||||||
invitationCode: e.query.invitationCode
|
invitationCode: e.query.invitationCode
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// 没有token去登录页
|
// 没有token去登录页
|
||||||
reLaunch('/pages/login/login')
|
reLaunch('/pages/login/login')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 初始化 H5 音视频通话 */
|
/** 初始化 H5 音视频通话 */
|
||||||
const iniCall = () => {
|
const iniCall = () => {
|
||||||
// IM 初始化
|
// IM 初始化
|
||||||
RongIMLib.init({
|
RongIMLib.init({
|
||||||
appkey: '<Your-Appkey>',
|
appkey: '<Your-Appkey>'
|
||||||
});
|
})
|
||||||
|
|
||||||
// RTC 初始化
|
// RTC 初始化
|
||||||
const rtcClient = RongIMLib.installPlugin(rtcInstaller, {});
|
const rtcClient = RongIMLib.installPlugin(rtcInstaller, {})
|
||||||
|
|
||||||
// CallPlus 初始化
|
// CallPlus 初始化
|
||||||
const callPlusClient = RongIMLib.installPlugin(callPlusInstaller, {
|
const callPlusClient = RongIMLib.installPlugin(callPlusInstaller, {
|
||||||
rtcClient
|
rtcClient
|
||||||
});
|
})
|
||||||
|
|
||||||
|
console.log('====1111111111=====', callPlusClient)
|
||||||
|
}
|
||||||
|
|
||||||
console.log('====1111111111=====', callPlusClient)
|
onLaunch(e => {
|
||||||
}
|
// #ifdef APP-PLUS
|
||||||
|
plus.runtime.getProperty(plus.runtime.appid, function (widgetInfo) {
|
||||||
|
getAppVersion().then(res => {
|
||||||
|
console.log('应用版本信息', res.data)
|
||||||
|
const lastVersion = res.data.version
|
||||||
|
const currentVersion = widgetInfo.version
|
||||||
|
if (compareVersion(currentVersion, lastVersion) < 0) {
|
||||||
|
// 当前版本低于最新版本,提示用户更新
|
||||||
|
console.log('当前版本低于最新版本,请更新应用')
|
||||||
|
const isForceUpdate = res.data.forceUpdate
|
||||||
|
const url = res.data.updateUrl
|
||||||
|
uni.showModal({
|
||||||
|
title: '更新提示',
|
||||||
|
content: res.data.updateMessage,
|
||||||
|
confirmText: '立即更新',
|
||||||
|
cancelText: '稍后再说',
|
||||||
|
showCancel: !isForceUpdate,
|
||||||
|
success: res => {
|
||||||
|
if (res.confirm) {
|
||||||
|
plus.runtime.openURL(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.log('当前版本为最新版本')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
// #endif
|
||||||
|
// return
|
||||||
|
console.log('App Launch111')
|
||||||
|
silentLogin(e)
|
||||||
|
|
||||||
onLaunch((e) => {
|
// #ifdef APP-PLUS
|
||||||
// return
|
setSdkLanguageFromSystem()
|
||||||
console.log('App Launch111')
|
// onAllListeners()
|
||||||
silentLogin(e)
|
// #endif
|
||||||
|
|
||||||
// #ifdef APP-PLUS
|
// #ifdef H5
|
||||||
setSdkLanguageFromSystem()
|
iniCall()
|
||||||
// onAllListeners()
|
// #endif
|
||||||
// #endif
|
})
|
||||||
|
|
||||||
// #ifdef H5
|
onShow(() => {
|
||||||
iniCall()
|
console.log('App Show222')
|
||||||
// #endif
|
})
|
||||||
|
|
||||||
})
|
onHide(async () => {
|
||||||
|
if (token.value) {
|
||||||
|
const show = await getIpBlack(false)
|
||||||
|
console.log(show.data.data, '======')
|
||||||
|
}
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
removeAllListeners()
|
||||||
|
// #endif
|
||||||
|
console.log('App Hide333')
|
||||||
|
})
|
||||||
|
|
||||||
onShow(() => {
|
function removeAllListeners() {
|
||||||
console.log('App Show222')
|
call.unInit()
|
||||||
})
|
//移除监听-接收到通话呼入
|
||||||
|
call.removeCallReceivedListener()
|
||||||
onHide(async () => {
|
// 移除监听-开始呼叫通话的回调
|
||||||
if (token.value) {
|
call.removeCallOutgoingListener()
|
||||||
const show = await getIpBlack(false)
|
// 移除监听-通话已接通
|
||||||
console.log(show.data.data, '======')
|
call.removeCallReceivedListener()
|
||||||
}
|
// 移除监听-通话已结束
|
||||||
// #ifdef APP-PLUS
|
call.removeCallDisconnectedListener()
|
||||||
removeAllListeners()
|
// 移除监听-对端用户正在振铃
|
||||||
// #endif
|
call.removeRemoteUserRingingListener()
|
||||||
console.log('App Hide333')
|
// 移除监听-对端用户加入了通话
|
||||||
})
|
call.removeRemoteUserJoinedListener()
|
||||||
|
// 移除监听-有用户被邀请加入通话
|
||||||
|
call.removeRemoteUserInvited()
|
||||||
|
// 移除监听-对端用户挂断
|
||||||
function removeAllListeners(){
|
call.removeRemoteUserLeftListener()
|
||||||
call.unInit();
|
// 移除监听-对端用户切换了媒体类型
|
||||||
//移除监听-接收到通话呼入
|
call.removeRemoteUserMediaTypeChangedListener()
|
||||||
call.removeCallReceivedListener();
|
// 移除监听-通话出现错误的回调
|
||||||
// 移除监听-开始呼叫通话的回调
|
call.removeErrorListener()
|
||||||
call.removeCallOutgoingListener();
|
}
|
||||||
// 移除监听-通话已接通
|
|
||||||
call.removeCallReceivedListener();
|
|
||||||
// 移除监听-通话已结束
|
|
||||||
call.removeCallDisconnectedListener();
|
|
||||||
// 移除监听-对端用户正在振铃
|
|
||||||
call.removeRemoteUserRingingListener();
|
|
||||||
// 移除监听-对端用户加入了通话
|
|
||||||
call.removeRemoteUserJoinedListener();
|
|
||||||
// 移除监听-有用户被邀请加入通话
|
|
||||||
call.removeRemoteUserInvited();
|
|
||||||
// 移除监听-对端用户挂断
|
|
||||||
call.removeRemoteUserLeftListener();
|
|
||||||
// 移除监听-对端用户切换了媒体类型
|
|
||||||
call.removeRemoteUserMediaTypeChangedListener();
|
|
||||||
// 移除监听-通话出现错误的回调
|
|
||||||
call.removeErrorListener();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
/*每个页面公共css */
|
/*每个页面公共css */
|
||||||
@import './styles/global.scss';
|
@import './styles/global.scss';
|
||||||
|
|
||||||
/* common css for page */
|
/* common css for page */
|
||||||
// uni-page-body,
|
// uni-page-body,
|
||||||
// html,
|
// html,
|
||||||
// body,
|
// body,
|
||||||
// page {
|
// page {
|
||||||
// width: 100% !important;
|
// width: 100% !important;
|
||||||
// height: 100% !important;
|
// height: 100% !important;
|
||||||
// overflow: hidden;
|
// overflow: hidden;
|
||||||
// }
|
// }
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -194,4 +194,12 @@ export const getGroupBanList = id => {
|
|||||||
url: `/api/service/imGroup/muted/account/${id}`,
|
url: `/api/service/imGroup/muted/account/${id}`,
|
||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取应用版本信息 */
|
||||||
|
export const getAppVersion = () => {
|
||||||
|
return uni.request({
|
||||||
|
url: 'https://s3.yxdim.com/app-version.json',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
7
app-version.json
Normal file
7
app-version.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"version": "1.1.8",
|
||||||
|
"forceUpdate": true,
|
||||||
|
"updateMessage": "修复了一些问题并优化了性能",
|
||||||
|
"updateUrl": "https://store.yxdim.com/app/yxdIM",
|
||||||
|
"minSupportVersion": "0.0.1"
|
||||||
|
}
|
||||||
@@ -350,7 +350,7 @@
|
|||||||
<view class="right-box">
|
<view class="right-box">
|
||||||
<text>{{ friendInfo.nick || '未知名称' }}</text>
|
<text>{{ friendInfo.nick || '未知名称' }}</text>
|
||||||
<text v-if="friendInfo?.cbType !== 'group'">
|
<text v-if="friendInfo?.cbType !== 'group'">
|
||||||
手机号: {{ friendInfo.userID }}
|
ID: {{ friendInfo.userID }}
|
||||||
</text>
|
</text>
|
||||||
<text v-if="friendInfo?.cbType !== 'group'">
|
<text v-if="friendInfo?.cbType !== 'group'">
|
||||||
个性签名: {{ friendInfo.selfSignature || '暂无个性签名' }}
|
个性签名: {{ friendInfo.selfSignature || '暂无个性签名' }}
|
||||||
@@ -513,7 +513,9 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
.title {
|
.title {
|
||||||
font-family: PingFang SC, PingFang SC;
|
font-family:
|
||||||
|
PingFang SC,
|
||||||
|
PingFang SC;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
color: #333333;
|
color: #333333;
|
||||||
|
|||||||
@@ -97,7 +97,9 @@
|
|||||||
<uni-icons v-else type="contact-filled" size="70"></uni-icons>
|
<uni-icons v-else type="contact-filled" size="70"></uni-icons>
|
||||||
<view class="nickname">
|
<view class="nickname">
|
||||||
<text class="name">{{ userInfo?.userName || '' }}</text>
|
<text class="name">{{ userInfo?.userName || '' }}</text>
|
||||||
<text class="name">ID:{{ userInfo?.invitationCode || '' }}</text>
|
<text class="name">
|
||||||
|
ID: {{ userInfo?.invitationCode || '' }}
|
||||||
|
</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<image
|
<image
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<uni-icons v-else type="contact-filled" size="60"></uni-icons>
|
<uni-icons v-else type="contact-filled" size="60"></uni-icons>
|
||||||
<view class="right-box">
|
<view class="right-box">
|
||||||
<text>{{ userInfo.userName }}</text>
|
<text>{{ userInfo.userName }}</text>
|
||||||
<text>ID: {{ userInfo.userId }}</text>
|
<text>ID: {{ userInfo.invitationCode }}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="code-img">
|
<view class="code-img">
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
import { useUserStore } from '@/stores/user'
|
import { useUserStore } from '@/stores/user'
|
||||||
import { navigateTo } from '../../../utils/router'
|
import { navigateTo } from '../../../utils/router'
|
||||||
import { useUI } from '../../../utils/use-ui'
|
import { useUI } from '../../../utils/use-ui'
|
||||||
|
import { getAppVersion } from '@/api'
|
||||||
|
import { compareVersion } from '@/utils/util.js'
|
||||||
|
|
||||||
const { showDialog, showToast } = useUI()
|
const { showDialog, showToast } = useUI()
|
||||||
|
|
||||||
@@ -14,7 +16,11 @@
|
|||||||
},
|
},
|
||||||
// { name: '聊天背景', value: '', url: '' },
|
// { name: '聊天背景', value: '', url: '' },
|
||||||
// { name: '朋友圈设置', value: '', url: '' },
|
// { name: '朋友圈设置', value: '', url: '' },
|
||||||
{ name: '消息通知', value: '', url: '/pages/my-index/set-up/message/index' }
|
{
|
||||||
|
name: '消息通知',
|
||||||
|
value: '',
|
||||||
|
url: '/pages/my-index/set-up/message/index'
|
||||||
|
}
|
||||||
// { name: '安全设置', value: '', url: '' },
|
// { name: '安全设置', value: '', url: '' },
|
||||||
// { name: '群发消息', value: '', url: '' },
|
// { name: '群发消息', value: '', url: '' },
|
||||||
// { name: '登录设备', value: '', url: '' }
|
// { name: '登录设备', value: '', url: '' }
|
||||||
@@ -29,6 +35,9 @@
|
|||||||
value: '',
|
value: '',
|
||||||
url: '/pages/my-index/set-up/feedback'
|
url: '/pages/my-index/set-up/feedback'
|
||||||
},
|
},
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
{ name: '检查更新', value: '3', url: '' },
|
||||||
|
// #endif
|
||||||
{ name: '关于我们', value: '', url: '/pages/discover/company' }
|
{ name: '关于我们', value: '', url: '/pages/discover/company' }
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -45,6 +54,35 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
} else if (item.value === '3') {
|
||||||
|
plus.runtime.getProperty(plus.runtime.appid, function (widgetInfo) {
|
||||||
|
getAppVersion().then(res => {
|
||||||
|
console.log('应用版本信息', res.data)
|
||||||
|
const lastVersion = res.data.version
|
||||||
|
const currentVersion = widgetInfo.version
|
||||||
|
if (compareVersion(currentVersion, lastVersion) < 0) {
|
||||||
|
// 当前版本低于最新版本,提示用户更新
|
||||||
|
console.log('当前版本低于最新版本,请更新应用')
|
||||||
|
const url = res.data.updateUrl
|
||||||
|
const isForceUpdate = res.data.forceUpdate
|
||||||
|
uni.showModal({
|
||||||
|
title: '更新提示',
|
||||||
|
content: res.data.updateMessage,
|
||||||
|
confirmText: '立即更新',
|
||||||
|
cancelText: '稍后再说',
|
||||||
|
showCancel: !isForceUpdate,
|
||||||
|
success: res => {
|
||||||
|
if (res.confirm) {
|
||||||
|
plus.runtime.openURL(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
showToast('当前已是最新版本', 'info')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
item.url && navigateTo(item.url)
|
item.url && navigateTo(item.url)
|
||||||
}
|
}
|
||||||
@@ -104,7 +142,9 @@
|
|||||||
padding: 0 32rpx;
|
padding: 0 32rpx;
|
||||||
.item {
|
.item {
|
||||||
padding: 20rpx 0;
|
padding: 20rpx 0;
|
||||||
font-family: PingFang SC, PingFang SC;
|
font-family:
|
||||||
|
PingFang SC,
|
||||||
|
PingFang SC;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
text-transform: none;
|
text-transform: none;
|
||||||
@@ -135,7 +175,9 @@
|
|||||||
height: 80rpx;
|
height: 80rpx;
|
||||||
line-height: 80rpx;
|
line-height: 80rpx;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
font-family: PingFang SC, PingFang SC;
|
font-family:
|
||||||
|
PingFang SC,
|
||||||
|
PingFang SC;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
color: #eb1c26;
|
color: #eb1c26;
|
||||||
|
|||||||
@@ -1,3 +1,21 @@
|
|||||||
export const formate = function(arr){
|
export const formate = function (arr) {
|
||||||
return JSON.parse('['+ arr.join(',') + ']');
|
return JSON.parse('[' + arr.join(',') + ']');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function compareVersion(version1, version2) {
|
||||||
|
const v1Parts = version1.split(".").map(Number);
|
||||||
|
const v2Parts = version2.split(".").map(Number);
|
||||||
|
const maxLength = Math.max(v1Parts.length, v2Parts.length);
|
||||||
|
|
||||||
|
for (let i = 0; i < maxLength; i++) {
|
||||||
|
const v1Part = v1Parts[i] || 0;
|
||||||
|
const v2Part = v2Parts[i] || 0;
|
||||||
|
|
||||||
|
if (v1Part < v2Part)
|
||||||
|
return -1;
|
||||||
|
if (v1Part > v2Part)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user