single_list.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <image v-if="props.url" @load="loaded" :style="'width:'+ headImg.w +'px;height:'+ headImg.h +'px'" :src="props.url"
  3. mode="scaleToFill"></image>
  4. <image class="row_img" :style=" item.style ? 'width:'+ item.style.w +'px;height:' + item.style.h + 'px' : ''"
  5. @load="v=>loadIndex(v,i)" :src="item.cover" @click="()=>open(item)" v-for="(item,i) in list" :key="i"
  6. mode="scaleToFill"></image>
  7. </template>
  8. <script setup>
  9. import {
  10. ref,
  11. defineProps
  12. } from "vue";
  13. import {
  14. showPDF
  15. } from "../../unit/index.js";
  16. import config from "../../config/index.js";
  17. import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
  18. onShareAppMessage(()=>{})
  19. onShareTimeline(()=>{})
  20. const info = uni.getSystemInfoSync();
  21. const props = defineProps({
  22. title: String,
  23. url: String,
  24. page: String
  25. })
  26. uni.setNavigationBarTitle({
  27. title: props.title
  28. })
  29. const list = ref([]);
  30. uni.request({
  31. url: config.base + props.page + ".json?" + Date.now(),
  32. success: res => {
  33. if (res.statusCode !== 200) return
  34. list.value = res.data || [];
  35. }
  36. })
  37. const headImg = ref({
  38. w: 0,
  39. h: 0
  40. })
  41. function loaded(v) {
  42. const w = info.windowWidth;
  43. const h = v.detail.height / v.detail.width * w;
  44. headImg.value = {
  45. w,
  46. h
  47. }
  48. }
  49. function loadIndex(v, i) {
  50. const w = info.windowWidth - 8;
  51. const h = v.detail.height / v.detail.width * w;
  52. list.value[i].style = {
  53. w,
  54. h
  55. };
  56. }
  57. function open(item) {
  58. if (!item.pdfUrl) {
  59. uni.showToast({
  60. title: "暂无数据",
  61. icon: "none"
  62. });
  63. return
  64. }
  65. const file_type = item.pdfUrl.split(".").reverse()[0];
  66. if (file_type === 'mp4') {
  67. wx.previewMedia({
  68. sources: [
  69. {
  70. url: item.pdfUrl,
  71. type: 'video'
  72. }
  73. ]
  74. })
  75. return
  76. } else if (file_type === 'pdf') showPDF(item.pdfUrl);
  77. }
  78. </script>
  79. <style lang="scss">
  80. .row_img {
  81. display: block;
  82. margin: 4px 0 0 4px;
  83. border-radius: 7px;
  84. }
  85. </style>