index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view class="app-page"></view>
  3. </template>
  4. <script>
  5. const homePagePath = '/pages/tabbar/home/home'
  6. const startPagePath = '/pagesA/start/start'
  7. const articleDetailPath = '/pagesA/article-detail/article-detail';
  8. export default {
  9. computed: {
  10. configs() {
  11. return this.$tm.vx.getters().getConfigs;
  12. }
  13. },
  14. onLoad: function (options) {
  15. uni.$tm.vx.actions('config/fetchConfigs').then(async (res) => {
  16. if (options.scene) {
  17. if ('' !== options.scene) {
  18. const postId = await this.getPostIdByQRCode(options.scene);
  19. if (postId) {
  20. uni.redirectTo({
  21. url: articleDetailPath + `?name=${postId}`,
  22. animationType: 'slide-in-right'
  23. });
  24. }
  25. }
  26. }
  27. // #ifdef MP-WEIXIN
  28. // uni.$tm.vx.commit('setWxShare', res.shareConfig);
  29. // #endif
  30. // 获取mockjson
  31. if (res.auditConfig.auditModeEnabled) {
  32. if (res.auditConfig.auditModeData.jsonUrl) {
  33. await uni.$tm.vx.actions('config/fetchMockJson')
  34. } else {
  35. const mockJson = uni.$utils.checkJsonAndParse(res.auditConfig.auditModeData.jsonData)
  36. if (mockJson.ok) {
  37. uni.$tm.vx.commit('config/setMockJson', mockJson.jsonData)
  38. }
  39. }
  40. }
  41. // 进入检查
  42. this.fnCheckShowStarted();
  43. }).catch((err) => {
  44. uni.switchTab({
  45. url: homePagePath
  46. });
  47. })
  48. },
  49. methods: {
  50. fnCheckShowStarted() {
  51. if (!this.configs.appConfig.startConfig.enabled) {
  52. uni.switchTab({
  53. url: homePagePath
  54. });
  55. return;
  56. }
  57. // 是否每次都显示启动页
  58. if (this.configs.appConfig.startConfig.alwaysShow) {
  59. uni.removeStorageSync('APP_HAS_STARTED')
  60. uni.redirectTo({
  61. url: startPagePath
  62. });
  63. return;
  64. }
  65. // 只显示一次启动页
  66. if (uni.getStorageSync('APP_HAS_STARTED')) {
  67. uni.switchTab({
  68. url: homePagePath
  69. });
  70. } else {
  71. uni.redirectTo({
  72. url: startPagePath
  73. });
  74. }
  75. },
  76. async getPostIdByQRCode(key) {
  77. const response = await this.$httpApi.v2.getQRCodeInfo(key);
  78. if (response) {
  79. if (response && response.postId) {
  80. return response.postId;
  81. }
  82. }
  83. return null;
  84. }
  85. }
  86. };
  87. </script>