page.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div class="page" :class="{ isPCWeb: !isMobile }">
  3. <template v-if="isMobile">
  4. <template v-if="!error">
  5. <v-view v-if="page" :options="page"></v-view>
  6. <div class="back" v-if="!isMain" @click="back">返回</div>
  7. </template>
  8. <div v-else class="notFound">
  9. <div class="mx-auto h-96 flex justify-center items-center text-white">您访问的资源不存在!</div>
  10. </div>
  11. </template>
  12. <div v-else class="flex items-center justify-center flex-col h-full">
  13. <div id="qr" class="w-52 h-52 mx-auto -mt-48 rounded-lg overflow-hidden" style="font-size: 0"></div>
  14. <p class="mt-2 text-sm text-white">请使用手机扫码进入</p>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. import EventBus from '@/utils/eventBus.js';
  20. import QR from '../plugins/qr';
  21. import {fetch} from '@/api/page.js'
  22. export default {
  23. data(){
  24. return {
  25. loading: false,
  26. page: undefined,
  27. isMain: false,
  28. background:"",
  29. interval: 3000,
  30. logo: "",
  31. uuid:'',
  32. nodeList: [],
  33. itemList: [],
  34. paperId: 1,
  35. nodeId: 0,
  36. slider: [],
  37. title: "",
  38. isMobile: /mobile/i.test(navigator.userAgent),
  39. error: false,
  40. }
  41. },
  42. computed: {
  43. loaded(){
  44. return this.$store.state.pages.loaded;
  45. }
  46. },
  47. watch: {
  48. loading(val) {
  49. EventBus.$emit('loading', val);
  50. },
  51. $route(){
  52. this.getPageInfo();
  53. }
  54. },
  55. created(){
  56. if(!this.loaded) {
  57. this.init();
  58. } else {
  59. this.getPageInfo();
  60. }
  61. },
  62. mounted(){
  63. if(!this.isMobile) {
  64. QR.ecclevel = 3;
  65. QR.size = 500;
  66. document.querySelector('#qr').append(QR.makeImage(location.href))
  67. }
  68. },
  69. methods: {
  70. getPageInfo() {
  71. const { data } = this.$store.state.pages;
  72. console.log("getinfo", data)
  73. const { pages, main } = data;
  74. const { id = 'main'} = this.$route.params;
  75. let page = pages[id]||{};
  76. this.isMain = (id == 'main');
  77. this.page = { ...main, ...page };
  78. const { title } = this.page;
  79. title && (document.title = title);
  80. },
  81. init(){
  82. let {uuid} = this.$route.params;
  83. console.log("loadData", uuid);
  84. if(this.loading) return;
  85. this.loading = true;
  86. fetch("paper.getpaper", {uuid}).then((res) => {
  87. this.loading = false;
  88. this.$store.dispatch('setPage', res);
  89. res.title && (document.title = res.title);
  90. this.getPageInfo()
  91. }).catch((err) => {
  92. console.log("err", err)
  93. this.loading = false;
  94. this.error = true;
  95. })
  96. },
  97. back(){
  98. this.$router.back();
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="less">
  104. .back {
  105. position: fixed;
  106. right: 1rem;
  107. top: 1rem;
  108. z-index: 100000;
  109. border-radius: 1rem;
  110. padding: 0.5rem 1rem;
  111. line-height: 1;
  112. color: rgba(255, 255, 255, 0.75);
  113. background: rgba(0, 0, 0, 0.2);
  114. }
  115. .isPCWeb {
  116. background: #4c4c4c;
  117. height: 100vh;
  118. #qr {
  119. background: #fff;
  120. img {
  121. width: 100%;
  122. }
  123. }
  124. }
  125. </style>