Files
shanxia2.0/miniprogram/App.vue
2026-09-26 11:59:39 +08:00

123 lines
3.5 KiB
Vue
Raw Permalink 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>
import {
mapMutations
} from 'vuex'
import {
version
} from './package.json'
import { initGlobalSafeArea } from '@/utils/safeArea'
import { APP_ENV, CURRENT_ENV, IS_PRODUCTION, resolveApiBase, resolveWebOrigin } from '@/config/env'
// #ifdef MP-WEIXIN
import { checkMpUpdate } from '@/utils/mpUpdate'
// #endif
// #ifdef APP
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
// #endif
export default {
onLaunch: function() {
initGlobalSafeArea()
// #ifdef MP-WEIXIN
checkMpUpdate()
// #endif
console.log(
`[ENV] APP_ENV=${APP_ENV} (${CURRENT_ENV.label}) api=${resolveApiBase()} web=${resolveWebOrigin()}`
)
if (!IS_PRODUCTION) {
// 启动即弹窗,编译/预览时一眼能看见当前环境,降低误传生产风险
uni.showModal({
title: `⚠️ 非生产环境:${CURRENT_ENV.label}`,
content: `APP_ENV=${APP_ENV}\nAPI:${resolveApiBase()}\nWeb:${resolveWebOrigin()}\n\n正式发版上传前请改为 production,并执行 npm run release:check-api`,
showCancel: false,
confirmText: '知道了'
})
}
// #ifdef H5
console.log(
`%c hello uniapp %c v${version} `,
'background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff',
'background:#007aff ;padding: 1px; border-radius: 0 3px 3px 0; color: #fff; font-weight: bold;'
)
// #endif
// 线上示例使用
// console.log('%c uni-app官方团队诚邀优秀前 端工程师加盟,一起打造更卓越的uni-app & uniCloud,欢迎投递简历到 hr2013@dcloud.io', 'color: red');
console.log('App Launch');
// #ifdef APP-PLUS
// App平台检测升级,服务端代码是通过uniCloud的云函数实现的,详情可参考:https://ext.dcloud.net.cn/plugin?id=4542
if (plus.runtime.appid !== 'HBuilder') { // 真机运行不需要检查更新,真机运行时appid固定为'HBuilder',这是调试基座的appid
checkUpdate()
}
// 一键登录预登陆,可以显著提高登录速度
uni.preLogin({
provider: 'univerify',
success: (res) => {
// 成功
this.setUniverifyErrorMsg();
console.log("preLogin success: ", res);
},
fail: (res) => {
this.setUniverifyLogin(false);
this.setUniverifyErrorMsg(res.errMsg);
// 失败
console.log("preLogin fail res: ", res);
}
})
// #endif
},
onShow: function() {
console.log('App Show')
// #ifdef MP-WEIXIN
checkMpUpdate()
// #endif
},
onHide: function() {
console.log('App Hide')
},
globalData: {
test: '',
safeArea: null
},
methods: {
...mapMutations(['setUniverifyErrorMsg', 'setUniverifyLogin'])
}
}
</script>
<style lang="scss">
@import '@/uni_modules/uni-scss/index.scss';
@import '@/styles/index.scss';
/* #ifndef APP-PLUS-NVUE */
/* uni.css - 通用组件、模板样式库,可以当作一套ui库应用 */
@import './common/uni.css';
uni-page-body {
background-color: #ffffff;
}
/* 全局按钮兜底:避免微信/uni 默认 button-hover 覆盖导致点击发白 */
button.button-hover:not([disabled]) {
background-color: transparent;
opacity: 1;
}
/* 保留原按钮边框策略,避免点击后出现系统默认描边 */
button::after {
border: none;
}
/* #ifdef H5 */
html,
body {
height: 100%;
margin: 0;
}
#app {
height: 100%;
}
/* #endif */
/* #endif*/
</style>