App.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <script>
  2. import {
  3. mapMutations
  4. } from 'vuex'
  5. import {
  6. version
  7. } from './package.json'
  8. import { initGlobalSafeArea } from '@/utils/safeArea'
  9. import { APP_ENV, CURRENT_ENV, IS_PRODUCTION, resolveApiBase, resolveWebOrigin } from '@/config/env'
  10. // #ifdef MP-WEIXIN
  11. import { checkMpUpdate } from '@/utils/mpUpdate'
  12. // #endif
  13. // #ifdef APP
  14. import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
  15. // #endif
  16. export default {
  17. onLaunch: function() {
  18. initGlobalSafeArea()
  19. // #ifdef MP-WEIXIN
  20. checkMpUpdate()
  21. // #endif
  22. console.log(
  23. `[ENV] APP_ENV=${APP_ENV} (${CURRENT_ENV.label}) api=${resolveApiBase()} web=${resolveWebOrigin()}`
  24. )
  25. if (!IS_PRODUCTION) {
  26. // 启动即弹窗,编译/预览时一眼能看见当前环境,降低误传生产风险
  27. uni.showModal({
  28. title: `⚠️ 非生产环境:${CURRENT_ENV.label}`,
  29. content: `APP_ENV=${APP_ENV}\nAPI:${resolveApiBase()}\nWeb:${resolveWebOrigin()}\n\n正式发版上传前请改为 production,并执行 npm run release:check-api`,
  30. showCancel: false,
  31. confirmText: '知道了'
  32. })
  33. }
  34. // #ifdef H5
  35. console.log(
  36. `%c hello uniapp %c v${version} `,
  37. 'background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff',
  38. 'background:#007aff ;padding: 1px; border-radius: 0 3px 3px 0; color: #fff; font-weight: bold;'
  39. )
  40. // #endif
  41. // 线上示例使用
  42. // console.log('%c uni-app官方团队诚邀优秀前 端工程师加盟,一起打造更卓越的uni-app & uniCloud,欢迎投递简历到 hr2013@dcloud.io', 'color: red');
  43. console.log('App Launch');
  44. // #ifdef APP-PLUS
  45. // App平台检测升级,服务端代码是通过uniCloud的云函数实现的,详情可参考:https://ext.dcloud.net.cn/plugin?id=4542
  46. if (plus.runtime.appid !== 'HBuilder') { // 真机运行不需要检查更新,真机运行时appid固定为'HBuilder',这是调试基座的appid
  47. checkUpdate()
  48. }
  49. // 一键登录预登陆,可以显著提高登录速度
  50. uni.preLogin({
  51. provider: 'univerify',
  52. success: (res) => {
  53. // 成功
  54. this.setUniverifyErrorMsg();
  55. console.log("preLogin success: ", res);
  56. },
  57. fail: (res) => {
  58. this.setUniverifyLogin(false);
  59. this.setUniverifyErrorMsg(res.errMsg);
  60. // 失败
  61. console.log("preLogin fail res: ", res);
  62. }
  63. })
  64. // #endif
  65. },
  66. onShow: function() {
  67. console.log('App Show')
  68. // #ifdef MP-WEIXIN
  69. checkMpUpdate()
  70. // #endif
  71. },
  72. onHide: function() {
  73. console.log('App Hide')
  74. },
  75. globalData: {
  76. test: '',
  77. safeArea: null
  78. },
  79. methods: {
  80. ...mapMutations(['setUniverifyErrorMsg', 'setUniverifyLogin'])
  81. }
  82. }
  83. </script>
  84. <style lang="scss">
  85. @import '@/uni_modules/uni-scss/index.scss';
  86. @import '@/styles/index.scss';
  87. /* #ifndef APP-PLUS-NVUE */
  88. /* uni.css - 通用组件、模板样式库,可以当作一套ui库应用 */
  89. @import './common/uni.css';
  90. uni-page-body {
  91. background-color: #ffffff;
  92. }
  93. /* 全局按钮兜底:避免微信/uni 默认 button-hover 覆盖导致点击发白 */
  94. button.button-hover:not([disabled]) {
  95. background-color: transparent;
  96. opacity: 1;
  97. }
  98. /* 保留原按钮边框策略,避免点击后出现系统默认描边 */
  99. button::after {
  100. border: none;
  101. }
  102. /* #ifdef H5 */
  103. html,
  104. body {
  105. height: 100%;
  106. margin: 0;
  107. }
  108. #app {
  109. height: 100%;
  110. }
  111. /* #endif */
  112. /* #endif*/
  113. </style>