调试完成中英文切换;完成自动更新功能

This commit is contained in:
hejin 2025-08-26 00:42:42 +08:00
parent 327da6f04c
commit 6c63f59aad
12 changed files with 150 additions and 17 deletions

View File

@ -126,4 +126,11 @@ export const fullTextSearchApi = (params) => {
**/
export const appInfoApi = () => {
return request.get('/web/footerInfo')
}
/**
* @function 获取最新的app版本
**/
export const newAppApi = () => {
return request.get('/web/getNewApp')
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -13,8 +13,8 @@
</view>
<slot name="footer">
<view class="footer">
<view v-if="processLoad.showCancel" class="confirm-btn1 cancel" @click="close" type="primary">取消</view>
<button :loading="confirmLoading" class="confirm-btn1" @click="confirm" type="primary">{{processLoad.confirmMsg}}</button>
<view v-if="processLoad.showCancel" class="confirm-btn1 cancel" @click="close" type="primary"></view>
<button v-if="processLoad.showConfirm" :loading="confirmLoading" class="confirm-btn1" @click="confirm" type="primary">{{processLoad.confirmMsg}}</button>
</view>
</slot>
</view>
@ -24,7 +24,10 @@
<script setup>
import { ref,computed } from 'vue';
import { useI18n } from 'vue-i18n';
const { t } = useI18n()
const popup = ref()
const confirmLoading = ref(false)
const params = ref({})
@ -33,9 +36,11 @@
const {
isHtml=false, // html
showCancel=true, //
showConfirm=true, //
isMaskClick=false, //
isLoading=false, // loading
confirmMsg='确定', //
cancelMsg=t('common.cancel'),
confirmMsg=t('common.confirm'), //
close=()=>{}, //
confirm=()=>{}, //
contentStyle // content
@ -44,9 +49,11 @@
return {
isHtml,
showCancel,
showConfirm,
isMaskClick,
isLoading,
confirmMsg,
cancelMsg,
close,
confirm,
contentStyle

View File

@ -1,15 +1,17 @@
import { ref, nextTick } from 'vue';
import { useI18n } from 'vue-i18n';
// 公共弹窗hooks
export const useComfirmPopup = () => {
const popupShow = ref(false)
const comfirmPopupRef = ref()
const { t } = useI18n()
const openPopup = (row = {}) => {
popupShow.value = true
nextTick(() => {
comfirmPopupRef.value.setParams({
title: row.title || '温馨提示',
title: row.title || t('common.KindReminder'),
content: row.content || '',
load: row.load || {}
})

View File

@ -6,13 +6,19 @@
<SuspensionBtn @ClickTop="ClickTop" @clickMsg="onlineModalShow=true"/>
<OnlineModal v-if="onlineModalShow" @close="onlineModalShow=false" />
</template>
<ConfirmPopup ref="comfirmPopupRef" v-if="popupShow" />
</view>
</template>
<script setup>
import { onShow } from "@dcloudio/uni-app";
import { onLoad } from '@dcloudio/uni-app';
import { ref, watch, computed } from 'vue';
import { useScroll } from '@/stores/index.js';
import { useI18n } from 'vue-i18n';
import { useScroll, useAppUpdate } from '@/stores/index.js';
import { useComfirmPopup } from '@/hooks/utils.js';
const { t } = useI18n()
const { comfirmPopupRef, popupShow, openPopup } = useComfirmPopup()
const currentPage = computed(() => {
let arr = getCurrentPages()
@ -35,10 +41,29 @@
useScroll().sendCallback()
}
onShow(() => {
let locale = uni.getLocale()
console.log(locale)
uni.setLocale(locale === 'zh-Hans' ? 'zh-Hans' : 'en')
const updateText = computed(() => {
let progress = useAppUpdate().progress
return `${t('common.appUpdate')}:${progress}%`
})
const updateModal = () => {
openPopup({
content: updateText,
load: {
showCancel: false,
showConfirm: false
}
})
}
watch(() => useAppUpdate().progress, (val) => {
if (Number(val) >= 100) {
popupShow.value = false
}
}, {deep: true})
onLoad(() => {
useAppUpdate().callback = updateModal
useAppUpdate().getAppInfo()
})
</script>

View File

@ -52,7 +52,11 @@
"Reset": "Reset",
"Sure": "Sure",
"Newdetail": "Newdetail",
"Allloaded": "All loaded"
"Allloaded": "All loaded",
"appUpdate": "Updating",
"confirm": "confirm",
"cancel": "cancel",
"KindReminder": "KindReminder"
},
"menu": {
"Home": "Home",

View File

@ -52,7 +52,11 @@
"Reset": "重置",
"Sure": "确认",
"Newdetail": "文章详情",
"Allloaded": "已全部加载"
"Allloaded": "已全部加载",
"appUpdate": "更新中",
"confirm": "确认",
"cancel": "取消",
"KindReminder": "温馨提示"
},
"menu": {
"Home": "首页",

View File

@ -30,7 +30,6 @@ const messages = {
en,
'zh-Hans': zh,
}
uni.setLocale('en')
let i18nConfig = {
locale: uni.getLocale(),// 获取已设置的语言
messages

View File

@ -41,7 +41,9 @@
]
},
/* ios */
"ios" : {},
"ios" : {
"dSYMs" : false
},
/* SDK */
"sdkConfigs" : {},
"icons" : {

View File

@ -31,6 +31,12 @@
</image>
</template>
</uni-easyinput>
<image
class="language"
src="@/assets/images/icon/language.png"
@click="language"
>
</image>
</view>
<view class="panel">
@ -144,6 +150,7 @@
import { ref } from 'vue';
import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app';
import dayJs from 'dayjs';
import { useI18n } from 'vue-i18n';
import {
homeBannberApi,
hotProductApi,
@ -151,6 +158,8 @@
hotNewsApi
} from '@/api/index.js';
const { locale } = useI18n()
const bannerList = ref([])
const getBannerList = () => {
return homeBannberApi().then(({data:res}) => {
@ -201,6 +210,16 @@
}
}
const language = () => {
let language = uni.getLocale()
let setLanguage = language === 'zh-Hans' ? 'en' : 'zh-Hans'
locale.value = setLanguage
uni.setLocale(setLanguage)
uni.reLaunch({
url: '/pages/index/index'
})
}
onPullDownRefresh(async() => {
try {
await getBannerList()
@ -241,6 +260,8 @@
position: relative;
top: -40rpx;
.search-box {
display: flex;
align-items: center;
::v-deep .uni-easyinput {
border-radius: 32rpx;
overflow: hidden;
@ -253,6 +274,11 @@
height: 24rpx;
margin-right: 16rpx;
}
.language {
width: 40rpx;
height: 40rpx;
margin-left: 20rpx;
}
}
.panel {
width: 100%;

View File

@ -4,8 +4,8 @@
<view class="company-information">
<view class="main-box">
<image class="logo" src="@/assets/images/company-logo.png"></image>
<image class="badge" src="@/assets/images/company-badge.png"></image>
<image class="logo" :src="useIndex().appInfo.mobileLogo"></image>
<!-- <image class="badge" src="@/assets/images/company-badge.png"></image> -->
<view class="desc">
<view>
<label>{{$t('contactUs.contact')}}: </label>

View File

@ -1,7 +1,13 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { menuCategoryApi, msgListApi, saveMsg, appInfoApi } from '@/api/index.js';
import {
menuCategoryApi,
msgListApi,
saveMsg,
appInfoApi,
newAppApi
} from '@/api/index.js';
import { getUuid } from '@/utils/tool.js';
export const useIndex = defineStore('index',()=>{
@ -161,4 +167,55 @@ export const useScoketMsg = defineStore('scoketMsg', () => {
send,
msgCallback
}
})
export const useAppUpdate = defineStore('appUpdate', () => {
const { t } = useI18n()
const loading = ref(false)
const progress = ref(0)
const callback = ref(null)
const getAppInfo = () => {
if (loading.value) {
return
}
return newAppApi().then(({data:res}) => {
let appConfig = uni.getSystemInfoSync()
if (String(res.data.version) !== appConfig.appVersion) {
callback.value && callback.value()
loading.value = true
const downloadTask = uni.downloadFile({
url: res.data.apkUrl,
// url: 'https://114.132.197.85:26035/down/0JjTqTl4atsE.apk',
success: res1 => {
loading.value = false
if (res1.statusCode===200) {
plus.runtime.install(res1.tempFilePath, false, (installSuccess) => {
console.log(installSuccess,'installSuccess');
}, (installErrorCB) => {
console.log(installErrorCB);
});
}
},
complete: () => {
loading.value = false
}
})
downloadTask.onProgressUpdate((res1) => {
progress.value = res1.progress
if (res1.progress===100) {
loading.value = false
}
})
}
})
}
return {
getAppInfo,
progress,
callback
}
})