index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <view class="app-page flex flex-center">
  3. <PluginUnavailable v-if="!uniHaloPluginAvailable" :pluginId="uniHaloPluginId"
  4. :error-text="uniHaloPluginAvailableError" />
  5. </view>
  6. </template>
  7. <script>
  8. import pluginAvailable from "@/common/mixins/pluginAvailable.js"
  9. const homePagePath = '/pages/tabbar/home/home'
  10. const startPagePath = '/pagesA/start/start'
  11. const articleDetailPath = '/pagesA/article-detail/article-detail';
  12. const _DEV_ = false
  13. const _DEV_TO_TYPE_ = "page"
  14. const _DEV_TO_PATH_ = "/pagesA/votes/votes"
  15. export default {
  16. mixins: [pluginAvailable],
  17. computed: {
  18. configs() {
  19. return this.$tm.vx.getters().getConfigs;
  20. }
  21. },
  22. async onLoad(options) {
  23. // 检查插件
  24. this.setPluginId(this.NeedPluginIds.PluginUniHalo)
  25. this.setPluginError("阿偶,检测到当前插件没有安装或者启用,无法启动 uni-halo 哦,请联系管理员")
  26. if (!await this.checkPluginAvailable()) return
  27. // 获取配置
  28. uni.$tm.vx.actions('config/fetchConfigs').then(async (res) => {
  29. if (options.scene) {
  30. if ('' !== options.scene) {
  31. const postId = await this.getPostIdByQRCode(options.scene);
  32. if (postId) {
  33. uni.redirectTo({
  34. url: articleDetailPath + `?name=${postId}`,
  35. animationType: 'slide-in-right'
  36. });
  37. }
  38. }
  39. }
  40. // #ifdef MP-WEIXIN
  41. // uni.$tm.vx.commit('setWxShare', res.shareConfig);
  42. // #endif
  43. // 获取mockjson
  44. if (res.auditConfig.auditModeEnabled) {
  45. if (res.auditConfig.auditModeData.jsonUrl) {
  46. await uni.$tm.vx.actions('config/fetchMockJson')
  47. } else {
  48. const mockJson = uni.$utils.checkJsonAndParse(res.auditConfig.auditModeData
  49. .jsonData)
  50. if (mockJson.ok) {
  51. uni.$tm.vx.commit('config/setMockJson', mockJson.jsonData)
  52. }
  53. }
  54. }
  55. // 进入检查
  56. this.fnCheckShowStarted();
  57. }).catch((err) => {
  58. uni.switchTab({
  59. url: homePagePath
  60. });
  61. })
  62. },
  63. methods: {
  64. fnCheckShowStarted() {
  65. // 本地开发,快速跳转页面,发布请设置 _DEV_ = false
  66. if (_DEV_) {
  67. if (_DEV_TO_TYPE_ == 'tabbar') {
  68. uni.switchTab({
  69. url: _DEV_TO_PATH_
  70. });
  71. } else if (_DEV_TO_TYPE_ == 'page') {
  72. uni.navigateTo({
  73. url: _DEV_TO_PATH_
  74. });
  75. }
  76. return
  77. }
  78. if (!this.configs.appConfig.startConfig.enabled) {
  79. uni.switchTab({
  80. url: homePagePath
  81. });
  82. return;
  83. }
  84. // 是否每次都显示启动页
  85. if (this.configs.appConfig.startConfig.alwaysShow) {
  86. uni.removeStorageSync('APP_HAS_STARTED')
  87. uni.redirectTo({
  88. url: startPagePath
  89. });
  90. return;
  91. }
  92. // 只显示一次启动页
  93. if (uni.getStorageSync('APP_HAS_STARTED')) {
  94. uni.switchTab({
  95. url: homePagePath
  96. });
  97. } else {
  98. uni.redirectTo({
  99. url: startPagePath
  100. });
  101. }
  102. },
  103. async getPostIdByQRCode(key) {
  104. const response = await this.$httpApi.v2.getQRCodeInfo(key);
  105. if (response) {
  106. if (response && response.postId) {
  107. return response.postId;
  108. }
  109. }
  110. return null;
  111. }
  112. }
  113. };
  114. </script>
  115. <style lang="scss" scoped>
  116. .app-page {
  117. width: 100vw;
  118. height: 100vh;
  119. }
  120. </style>