Files
sweekar-app/App.vue
T
2026-01-04 17:53:40 +08:00

178 lines
3.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup>
import {
ref
} from 'vue';
import {
onShow,
onLaunch,
onHide
} from '@dcloudio/uni-app';
import {
useI18n
} from 'vue-i18n';
import i18n from '@/lang';
import pinia from '@/store/store.js';
import {
useUserStore
} from '@/store/user';
import {
isEmpty,
platformMap
} from '@/common/common.js';
import {
getConfigInfo
} from '@/common/subscribePayment.js'
const {
t,
locale
} = useI18n();
// 初始化platform
function initApplication() {
const user = useUserStore(pinia);
// platform
let uniPlatform = uni.getSystemInfoSync().uniPlatform;
let hasPlatform = platformMap.filter((h) => h.map.match(uniPlatform))[0];
if (hasPlatform) {
// 非app,mp-weixin,mp-alipay,web都会进入这里
user.platform = hasPlatform.key;
} else {
// app
let port = uni.getSystemInfoSync().platform;
let platform = platformMap.filter((h) => h.map.match(port))[0];
user.platform = platform.key;
}
// 获取本机语种
let appLanguage = uni.getSystemInfoSync().appLanguage;
let languageMap = ['zh-CN', 'zh-TW'];
if (isEmpty(user.lang)) {
if (languageMap.indexOf(appLanguage) === -1) {
user.lang = 'zh-CN';
} else {
user.lang = appLanguage;
}
}
user.lang = user.lang.replace(/\"/g, '');
locale.value = user.lang;
i18n.global.locale.value = user.lang;
}
// 检查小程序更新
function checkUpDateMini() {
if (uni.canIUse('getUpdateManager')) {
const updateManager = uni.getUpdateManager();
updateManager.onCheckForUpdate(function(res) {
if (res.hasUpdate) {
updateManager.onUpdateReady(function(ready) {
uni.showModal({
title: t('modal.upDate'),
content: t('modal.finishUpdate'),
showCancel: false,
success: function(res) {
if (res.confirm) {
updateManager.applyUpdate();
}
},
});
});
updateManager.onUpdateFailed(function(err) {
uni.showModal({
title: t('modal.hasUpdate'),
content: t('modal.hasntUsed'),
showCancel: false,
});
});
}
});
} else {
uni.showModal({
title: t('modal.title'),
content: t('modal.upgradeCarrier'),
showCancel: false,
});
}
}
onLaunch(() => {
initApplication();
// getConfigInfo();
});
onShow(() => {
// #ifdef APP-PLUS
uni.onNetworkStatusChange(function(res) {
if (res.isConnected) {
setTimeout(() => {
uni.reLaunch({
url: '/pages/index/index',
});
}, 0);
} else {
uni.showModal({
cancelText: t('modal.reStart'),
confirmText: t('modal.reLoad'),
content: t('modal.offNet'),
title: t('modal.title'),
success(res) {
if (res.confirm) {
uni.reLaunch({
url: '/pages/index/index',
});
} else {
plus.runtime.restart();
}
},
});
}
});
// #endif
// #ifdef MP
checkUpDateMini();
// #endif
});
onHide(() => {});
</script>
<style lang="scss">
@import 'tailwindcss/base';
@import 'tailwindcss/utilities';
@import 'tailwindcss/components';
html,
head,
body {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: SourceHanSansCN, SourceHanSansCN;
}
page {
background: #fbfbfd;
box-sizing: border-box;
}
.shadow {
box-shadow: 0px 5rpx 10rpx 0px rgba(207, 207, 207, 0.5);
}
.border-bottom {
@apply border-0 border-b border-solid border-[#F2F2F2];
}
.border-bottom-theme {
@apply border-0 border-b border-solid border-theme;
}
.border-round-theme {
@apply border border-solid border-theme;
}
.submit-btn {
@apply bg-theme text-white h-[100rpx] text-[30rpx];
}
:root {
--theme-color: #274c40;
}
</style>