1
0

index.vue 3.3 KB

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