pic.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template name="pic">
  2. <view class="cover cover-height">
  3. <block v-if="item.text.length > 0">
  4. <image v-show="loaded" @click="Dever.viewPic([item.pic], item.pic)" :src="item.pic" @error="onError" @load="onSuccess" mode="aspectFill" :class="['default', 'slide-image', 'slide-image-'+item.type]" style="height:100%;scroll-snap-align: start;"></image>
  5. <ourLoading v-show="!loaded" active text="加载中..." />
  6. <dever-position :item="item.text" :down="item.pic" :button="item.is_button"></dever-position>
  7. </block>
  8. <block v-if="item.text.length <= 0">
  9. <image v-show="loaded" @click="Dever.viewPic([item.pic], item.pic)" :src="item.pic" @error="onError" @load="onSuccess" mode="aspectFill" :class="['default', 'slide-image', 'slide-image-'+item.type]" style="height:100%;scroll-snap-align: start;"></image>
  10. <ourLoading v-show="!loaded" active text="加载中..." />
  11. </block>
  12. </view>
  13. </template>
  14. <script>
  15. import deverPosition from "@/lib/dever/components/position.vue";
  16. export default {
  17. name: "pic",
  18. props: {
  19. control : {
  20. type : Object,
  21. defalut : {}
  22. },
  23. item : {
  24. type : Object,
  25. defalut : {}
  26. },
  27. index : {
  28. type : Number,
  29. default : 0
  30. },
  31. pic_index : {
  32. type : Number,
  33. default : 0
  34. },
  35. },
  36. data() {
  37. return {
  38. loaded : false
  39. };
  40. },
  41. mounted : function() {
  42. this.loaded = false;
  43. //this.loadImage();
  44. },
  45. methods:{
  46. async loadImage() {
  47. // 由于方法是异步的,渲染时高度会不生效,所以要加await
  48. let info = await uni.getImageInfo({src: this.item.pic})
  49. // 取到图片的宽高
  50. let {width, height} = info[1]
  51. this.loaded = true;
  52. },
  53. onSuccess : function(e) {
  54. this.loaded = true;
  55. },
  56. onError : function(e) {
  57. this.loaded = false;
  58. },
  59. onImg : function(width, height) {
  60. //var height = e.detail.height / (e.detail.width / this.Dever.config.system.windowWidth);
  61. /*
  62. if (this.pic_index == 0) {
  63. this.$emit('show', this.pic_index);
  64. }*/
  65. }
  66. },
  67. components:{
  68. deverPosition
  69. }
  70. }
  71. </script>
  72. <style>
  73. .cover{
  74. position: relative;
  75. /*width: 100%;*/
  76. height: 100%;
  77. }
  78. .cover-height{
  79. overflow: auto;
  80. position: absolute;
  81. top:0;
  82. left:0;
  83. /*width: 100%;*/
  84. height:100%;
  85. }
  86. .slide-image {
  87. }
  88. .slide-image-1 {
  89. width: 750rpx;
  90. height: 1386rpx;
  91. display: block;
  92. }
  93. .slide-image-2 {
  94. width: 2000rpx;
  95. height: 100%;
  96. display: block;
  97. }
  98. .long-wrapper {
  99. position: relative;
  100. }
  101. </style>