page.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div class="page" :class="{ isPCWeb: !isMobile }" :style="style">
  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. backMain:false,
  27. page: undefined,
  28. isMain: false,
  29. background:"",
  30. interval: 3000,
  31. logo: "",
  32. uuid:'',
  33. style:'',
  34. nodeList: [],
  35. itemList: [],
  36. paperId: 1,
  37. nodeId: 0,
  38. slider: [],
  39. title: "",
  40. isMobile: /mobile/i.test(navigator.userAgent),
  41. error: false,
  42. }
  43. },
  44. computed: {
  45. loaded(){
  46. return this.$store.state.pages.loaded;
  47. }
  48. },
  49. watch: {
  50. loading(val) {
  51. EventBus.$emit('loading', val);
  52. },
  53. $route(){
  54. this.getPageInfo();
  55. setTimeout(() => window.scrollTo(0, 0), 0);
  56. }
  57. },
  58. created(){
  59. if(!this.loaded) {
  60. this.init();
  61. } else {
  62. this.getPageInfo();
  63. }
  64. },
  65. mounted(){
  66. if(!this.isMobile) {
  67. QR.ecclevel = 3;
  68. QR.size = 500;
  69. document.querySelector('#qr').append(QR.makeImage(location.href))
  70. }
  71. },
  72. methods: {
  73. getPageInfo() {
  74. const { data } = this.$store.state.pages;
  75. const { pages, main } = data;
  76. const { id = 'main'} = this.$route.params;
  77. let page = pages[id]||{};
  78. this.isMain = (id == 'main');
  79. this.page = { ...main, ...page };
  80. const { title } = this.page;
  81. title && (document.title = title);
  82. },
  83. init(){
  84. let {uuid, id} = this.$route.params;
  85. const { data } = this.$store.state.pages;
  86. if(data) {
  87. return this.getPageInfo();
  88. }
  89. this.backMain = (id != 'main');
  90. if(this.loading) return;
  91. this.loading = true;
  92. fetch("paper.getpaper", {uuid}).then((res) => {
  93. this.loading = false;
  94. this.$store.dispatch('setPage', res);
  95. res.title && (document.title = res.title);
  96. this.getPageInfo();
  97. }).catch((err) => {
  98. console.log("err", err)
  99. this.loading = false;
  100. this.error = true;
  101. })
  102. },
  103. back(){
  104. // 分享二级页面,回到主页
  105. if(this.backMain){
  106. this.$router.push({
  107. name: 'page',
  108. params: {
  109. id: 'main'
  110. }
  111. });
  112. this.backMain = false;
  113. }else{
  114. this.$router.back();
  115. }
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="less">
  121. .back {
  122. position: fixed;
  123. right: 1rem;
  124. top: 1rem;
  125. z-index: 100;
  126. border-radius: 1rem;
  127. padding: 0.5rem 1rem;
  128. line-height: 1;
  129. color: rgba(255, 255, 255, 0.75);
  130. background: rgba(0, 0, 0, 0.2);
  131. }
  132. .isPCWeb {
  133. background: #4c4c4c;
  134. height: 100vh;
  135. #qr {
  136. background: #fff;
  137. img {
  138. width: 100%;
  139. }
  140. }
  141. }
  142. </style>