feat: 添加应用版本检查功能,优化用户体验
This commit is contained in:
259
App.vue
259
App.vue
@@ -1,136 +1,159 @@
|
||||
<script setup>
|
||||
// #ifdef APP-PLUS
|
||||
import { setSdkLanguageFromSystem } from '@/uni_modules/tuikit-atomic-x/utils/setSdkLanguageFromSystem'
|
||||
// import * as call from "@/uni_modules/RongCloud-CallWrapper/lib/index"
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
import * as RongIMLib from '@rongcloud/imlib-next';
|
||||
import { installer as rtcInstaller } from '@rongcloud/plugin-rtc';
|
||||
import { installer as callPlusInstaller } from '@rongcloud/plugin-call-plus';
|
||||
// #endif
|
||||
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
|
||||
import { reLaunch } from './utils/router'
|
||||
import { useAuthUser } from './composables/useAuthUser'
|
||||
import { useUserStore } from './stores/user'
|
||||
import { TUIChatKit } from './TUIKit'
|
||||
import { getIpBlack } from './api'
|
||||
import {reasonDeal,errorDeal,imCode} from '@/utils/code.js'
|
||||
import { navigateTo } from '@/utils/router'
|
||||
// #ifdef APP-PLUS
|
||||
import { setSdkLanguageFromSystem } from '@/uni_modules/tuikit-atomic-x/utils/setSdkLanguageFromSystem'
|
||||
// import * as call from "@/uni_modules/RongCloud-CallWrapper/lib/index"
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
import * as RongIMLib from '@rongcloud/imlib-next'
|
||||
import { installer as rtcInstaller } from '@rongcloud/plugin-rtc'
|
||||
import { installer as callPlusInstaller } from '@rongcloud/plugin-call-plus'
|
||||
// #endif
|
||||
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
|
||||
import { reLaunch } from './utils/router'
|
||||
import { useAuthUser } from './composables/useAuthUser'
|
||||
import { useUserStore } from './stores/user'
|
||||
import { TUIChatKit } from './TUIKit'
|
||||
import { getIpBlack, getAppVersion } from './api'
|
||||
import { reasonDeal, errorDeal, imCode } from '@/utils/code.js'
|
||||
import { compareVersion } from '@/utils/util.js'
|
||||
import { navigateTo } from '@/utils/router'
|
||||
|
||||
TUIChatKit.init()
|
||||
TUIChatKit.init()
|
||||
|
||||
const { token, tencentUserSig } = useAuthUser()
|
||||
const { loginTencentIM } = useUserStore()
|
||||
/** 静默登录逻辑 */
|
||||
const silentLogin = async (e) => {
|
||||
if (token.value) {
|
||||
loginTencentIM()
|
||||
// reLaunch('/TUIKit/components/TUIConversation/index')
|
||||
return
|
||||
}
|
||||
const { token, tencentUserSig } = useAuthUser()
|
||||
const { loginTencentIM } = useUserStore()
|
||||
/** 静默登录逻辑 */
|
||||
const silentLogin = async e => {
|
||||
if (token.value) {
|
||||
loginTencentIM()
|
||||
// reLaunch('/TUIKit/components/TUIConversation/index')
|
||||
return
|
||||
}
|
||||
|
||||
console.log(tencentUserSig, '=====222==')
|
||||
if (e?.query?.invitationCode) {
|
||||
reLaunch('/pages/login/phone-register/phone-register', {
|
||||
invitationCode: e.query.invitationCode
|
||||
})
|
||||
} else {
|
||||
// 没有token去登录页
|
||||
reLaunch('/pages/login/login')
|
||||
}
|
||||
}
|
||||
console.log(tencentUserSig, '=====222==')
|
||||
if (e?.query?.invitationCode) {
|
||||
reLaunch('/pages/login/phone-register/phone-register', {
|
||||
invitationCode: e.query.invitationCode
|
||||
})
|
||||
} else {
|
||||
// 没有token去登录页
|
||||
reLaunch('/pages/login/login')
|
||||
}
|
||||
}
|
||||
|
||||
/** 初始化 H5 音视频通话 */
|
||||
const iniCall = () => {
|
||||
// IM 初始化
|
||||
RongIMLib.init({
|
||||
appkey: '<Your-Appkey>',
|
||||
});
|
||||
/** 初始化 H5 音视频通话 */
|
||||
const iniCall = () => {
|
||||
// IM 初始化
|
||||
RongIMLib.init({
|
||||
appkey: '<Your-Appkey>'
|
||||
})
|
||||
|
||||
// RTC 初始化
|
||||
const rtcClient = RongIMLib.installPlugin(rtcInstaller, {});
|
||||
// RTC 初始化
|
||||
const rtcClient = RongIMLib.installPlugin(rtcInstaller, {})
|
||||
|
||||
// CallPlus 初始化
|
||||
const callPlusClient = RongIMLib.installPlugin(callPlusInstaller, {
|
||||
rtcClient
|
||||
});
|
||||
// CallPlus 初始化
|
||||
const callPlusClient = RongIMLib.installPlugin(callPlusInstaller, {
|
||||
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) => {
|
||||
// return
|
||||
console.log('App Launch111')
|
||||
silentLogin(e)
|
||||
// #ifdef APP-PLUS
|
||||
setSdkLanguageFromSystem()
|
||||
// onAllListeners()
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
setSdkLanguageFromSystem()
|
||||
// onAllListeners()
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
iniCall()
|
||||
// #endif
|
||||
})
|
||||
|
||||
// #ifdef H5
|
||||
iniCall()
|
||||
// #endif
|
||||
onShow(() => {
|
||||
console.log('App Show222')
|
||||
})
|
||||
|
||||
})
|
||||
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(() => {
|
||||
console.log('App Show222')
|
||||
})
|
||||
|
||||
onHide(async () => {
|
||||
if (token.value) {
|
||||
const show = await getIpBlack(false)
|
||||
console.log(show.data.data, '======')
|
||||
}
|
||||
// #ifdef APP-PLUS
|
||||
removeAllListeners()
|
||||
// #endif
|
||||
console.log('App Hide333')
|
||||
})
|
||||
|
||||
|
||||
|
||||
function removeAllListeners(){
|
||||
call.unInit();
|
||||
//移除监听-接收到通话呼入
|
||||
call.removeCallReceivedListener();
|
||||
// 移除监听-开始呼叫通话的回调
|
||||
call.removeCallOutgoingListener();
|
||||
// 移除监听-通话已接通
|
||||
call.removeCallReceivedListener();
|
||||
// 移除监听-通话已结束
|
||||
call.removeCallDisconnectedListener();
|
||||
// 移除监听-对端用户正在振铃
|
||||
call.removeRemoteUserRingingListener();
|
||||
// 移除监听-对端用户加入了通话
|
||||
call.removeRemoteUserJoinedListener();
|
||||
// 移除监听-有用户被邀请加入通话
|
||||
call.removeRemoteUserInvited();
|
||||
// 移除监听-对端用户挂断
|
||||
call.removeRemoteUserLeftListener();
|
||||
// 移除监听-对端用户切换了媒体类型
|
||||
call.removeRemoteUserMediaTypeChangedListener();
|
||||
// 移除监听-通话出现错误的回调
|
||||
call.removeErrorListener();
|
||||
|
||||
}
|
||||
|
||||
function removeAllListeners() {
|
||||
call.unInit()
|
||||
//移除监听-接收到通话呼入
|
||||
call.removeCallReceivedListener()
|
||||
// 移除监听-开始呼叫通话的回调
|
||||
call.removeCallOutgoingListener()
|
||||
// 移除监听-通话已接通
|
||||
call.removeCallReceivedListener()
|
||||
// 移除监听-通话已结束
|
||||
call.removeCallDisconnectedListener()
|
||||
// 移除监听-对端用户正在振铃
|
||||
call.removeRemoteUserRingingListener()
|
||||
// 移除监听-对端用户加入了通话
|
||||
call.removeRemoteUserJoinedListener()
|
||||
// 移除监听-有用户被邀请加入通话
|
||||
call.removeRemoteUserInvited()
|
||||
// 移除监听-对端用户挂断
|
||||
call.removeRemoteUserLeftListener()
|
||||
// 移除监听-对端用户切换了媒体类型
|
||||
call.removeRemoteUserMediaTypeChangedListener()
|
||||
// 移除监听-通话出现错误的回调
|
||||
call.removeErrorListener()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
/*每个页面公共css */
|
||||
@import './styles/global.scss';
|
||||
/*每个页面公共css */
|
||||
@import './styles/global.scss';
|
||||
|
||||
/* common css for page */
|
||||
// uni-page-body,
|
||||
// html,
|
||||
// body,
|
||||
// page {
|
||||
// width: 100% !important;
|
||||
// height: 100% !important;
|
||||
// overflow: hidden;
|
||||
// }
|
||||
</style>
|
||||
/* common css for page */
|
||||
// uni-page-body,
|
||||
// html,
|
||||
// body,
|
||||
// page {
|
||||
// width: 100% !important;
|
||||
// height: 100% !important;
|
||||
// overflow: hidden;
|
||||
// }
|
||||
</style>
|
||||
|
||||
@@ -194,4 +194,12 @@ export const getGroupBanList = id => {
|
||||
url: `/api/service/imGroup/muted/account/${id}`,
|
||||
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">
|
||||
<text>{{ friendInfo.nick || '未知名称' }}</text>
|
||||
<text v-if="friendInfo?.cbType !== 'group'">
|
||||
手机号: {{ friendInfo.userID }}
|
||||
ID: {{ friendInfo.userID }}
|
||||
</text>
|
||||
<text v-if="friendInfo?.cbType !== 'group'">
|
||||
个性签名: {{ friendInfo.selfSignature || '暂无个性签名' }}
|
||||
@@ -513,7 +513,9 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
.title {
|
||||
font-family: PingFang SC, PingFang SC;
|
||||
font-family:
|
||||
PingFang SC,
|
||||
PingFang SC;
|
||||
font-weight: 500;
|
||||
font-size: 28rpx;
|
||||
color: #333333;
|
||||
|
||||
@@ -97,7 +97,9 @@
|
||||
<uni-icons v-else type="contact-filled" size="70"></uni-icons>
|
||||
<view class="nickname">
|
||||
<text class="name">{{ userInfo?.userName || '' }}</text>
|
||||
<text class="name">ID:{{ userInfo?.invitationCode || '' }}</text>
|
||||
<text class="name">
|
||||
ID: {{ userInfo?.invitationCode || '' }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
<image
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<uni-icons v-else type="contact-filled" size="60"></uni-icons>
|
||||
<view class="right-box">
|
||||
<text>{{ userInfo.userName }}</text>
|
||||
<text>ID: {{ userInfo.userId }}</text>
|
||||
<text>ID: {{ userInfo.invitationCode }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="code-img">
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { navigateTo } from '../../../utils/router'
|
||||
import { useUI } from '../../../utils/use-ui'
|
||||
import { getAppVersion } from '@/api'
|
||||
import { compareVersion } from '@/utils/util.js'
|
||||
|
||||
const { showDialog, showToast } = useUI()
|
||||
|
||||
@@ -14,7 +16,11 @@
|
||||
},
|
||||
// { 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: '' }
|
||||
@@ -29,6 +35,9 @@
|
||||
value: '',
|
||||
url: '/pages/my-index/set-up/feedback'
|
||||
},
|
||||
// #ifdef APP-PLUS
|
||||
{ name: '检查更新', value: '3', url: '' },
|
||||
// #endif
|
||||
{ name: '关于我们', value: '', url: '/pages/discover/company' }
|
||||
]
|
||||
|
||||
@@ -45,6 +54,35 @@
|
||||
}
|
||||
})
|
||||
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)
|
||||
}
|
||||
@@ -104,7 +142,9 @@
|
||||
padding: 0 32rpx;
|
||||
.item {
|
||||
padding: 20rpx 0;
|
||||
font-family: PingFang SC, PingFang SC;
|
||||
font-family:
|
||||
PingFang SC,
|
||||
PingFang SC;
|
||||
text-align: left;
|
||||
font-style: normal;
|
||||
text-transform: none;
|
||||
@@ -135,7 +175,9 @@
|
||||
height: 80rpx;
|
||||
line-height: 80rpx;
|
||||
background: #fff;
|
||||
font-family: PingFang SC, PingFang SC;
|
||||
font-family:
|
||||
PingFang SC,
|
||||
PingFang SC;
|
||||
font-weight: 500;
|
||||
font-size: 28rpx;
|
||||
color: #eb1c26;
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
export const formate = function(arr){
|
||||
return JSON.parse('['+ arr.join(',') + ']');
|
||||
export const formate = function (arr) {
|
||||
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