index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view class="scan-v">
  3. <!-- #ifndef MP -->
  4. <mescroll-body ref="mescrollRef" @down="downCallback" :down="downOption" :sticky="true" @up="upCallback"
  5. :up="upOption" :bottombar="false" style="min-height: 100%" @init="mescrollInit">
  6. <view class="portal-v">
  7. <view v-if="formData.length">
  8. <view class="portal-box" v-for="(item,index) in formData" :key="index">
  9. <portalItem :item='item' ref="portalItem" :portalData="formData"></portalItem>
  10. </view>
  11. </view>
  12. <view v-else-if="!formData.length && portalConfig.linkType == 1 && portalConfig.customUrl">
  13. <web-view :src="portalConfig.customUrl" style="height: 100vh;"></web-view>
  14. </view>
  15. <view v-else class="portal-v portal-nodata">
  16. <view class="u-flex-col" style="align-items: center;">
  17. <u-image width="280rpx" height="280rpx" :src="emptyImg"></u-image>
  18. <text class="u-m-t-20" style="color: #909399;">{{$t('common.noData')}}</text>
  19. </view>
  20. </view>
  21. </view>
  22. </mescroll-body>
  23. <!-- #endif -->
  24. <!-- #ifdef MP -->
  25. <view>
  26. <web-view :src="mpPortalUrl"></web-view>
  27. </view>
  28. <!-- #endif -->
  29. </view>
  30. </template>
  31. <script>
  32. // #ifndef MP
  33. import portalItem from '@/pages/portal/components/index.vue'
  34. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js"
  35. // #endif
  36. import {
  37. getPreviewPortal,
  38. auth
  39. } from '@/api/portal/portal.js'
  40. import resources from '@/libs/resources.js'
  41. export default {
  42. // #ifndef MP
  43. mixins: [MescrollMixin],
  44. components: {
  45. portalItem
  46. },
  47. // #endif
  48. data() {
  49. return {
  50. mpPortalUrl: '',
  51. id: '',
  52. show: false,
  53. formData: [],
  54. dataList: [],
  55. emptyImg: resources.message.nodata,
  56. fullName: '',
  57. downOption: {
  58. use: true,
  59. auto: true
  60. },
  61. upOption: {
  62. page: {
  63. num: 0,
  64. size: 50,
  65. time: null
  66. },
  67. empty: {
  68. use: false,
  69. },
  70. textNoMore: this.$t('app.apply.noMoreData'),
  71. },
  72. portalType: 1,
  73. token: "",
  74. portalConfig: {}
  75. }
  76. },
  77. onLoad(e) {
  78. this.fullName = e.fullName
  79. uni.setNavigationBarTitle({
  80. title: this.fullName || '门户预览'
  81. })
  82. // #ifdef MP
  83. this.token = uni.getStorageSync('token')
  84. this.mpPortalUrl = this.define.baseURL + '/pages/portal/applyPortal/index?id=' + e.id + "&token=" + this.token
  85. // #endif
  86. // #ifndef MP
  87. this.id = e.id
  88. this.portalType = e.portalType
  89. uni.$on('refresh', () => {
  90. this.formData = [];
  91. this.mescroll.resetUpScroll();
  92. })
  93. // #endif
  94. },
  95. methods: {
  96. upCallback(keyword) {
  97. const method = this.portalType == 1 ? auth : getPreviewPortal
  98. if (this.portalType != 1) this.mescroll.lockDownScroll(true);
  99. method(this.id).then(res => {
  100. this.portalConfig = res.data || {}
  101. let data = res.data.formData ? JSON.parse(res.data.formData) : {};
  102. this.formData = data.layout ? JSON.parse(JSON.stringify(data.layout)) : [];
  103. this.mescroll.endSuccess(this.formData.length);
  104. if (!this.formData.length) return
  105. this.handelFormData(data)
  106. }).catch(() => {
  107. this.mescroll.endSuccess(0);
  108. this.mescroll.endErr();
  109. })
  110. },
  111. handelFormData(data) {
  112. const loop = (list) => {
  113. list.forEach(o => {
  114. o.allRefresh = data.refresh
  115. o.show = false
  116. if (o.visibility && o.visibility.length && o.visibility.includes('app')) o.show =
  117. true
  118. if (o.children && o.children.length) loop(o.children)
  119. })
  120. this.key = +new Date()
  121. }
  122. loop(this.formData)
  123. this.dataList = this.formData.filter(o => o.show)
  124. if (this.dataList.length < 1) {
  125. this.formData = this.dataList
  126. }
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss">
  132. page {
  133. background-color: #f0f2f6;
  134. }
  135. .portal-v {
  136. // width: 100%;
  137. // height: 100vh;
  138. }
  139. .portal-nodata {
  140. position: absolute;
  141. top: 450rpx;
  142. width: 100%;
  143. text-align: center;
  144. z-index: 100;
  145. background-color: #f0f2f6;
  146. }
  147. </style>