ad_dianfei.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <!-- <web-view :src="url" :progress="false"></web-view> -->
  3. <view class="container" :style="{height: screenHeight}">
  4. <image :src="url" :show-menu-by-longpress="true" mode="aspectFit" class="ad_img" @tap="longClickImg"></image>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. data() {
  10. return {
  11. ceshi: 'code',
  12. screenHeight: '',
  13. url: ''
  14. }
  15. },
  16. onLoad() {
  17. this.get_img()
  18. },
  19. onShow() {
  20. // 从新计算高度
  21. setTimeout(() => {
  22. this.calc_screen_height()
  23. }, 1500)
  24. },
  25. methods: {
  26. async get_img() {
  27. let res = await this.$myRequest({
  28. host: this.ceshi,
  29. url: '/HotWaters/advertquery_h.action',
  30. method: 'POST',
  31. header: {
  32. 'content-type': 'application/x-www-form-urlencoded'
  33. },
  34. data: {
  35. 'url_name': '水电广告'
  36. }
  37. })
  38. // console.log(res.data)
  39. if (res.data.data.length == 0) {
  40. return
  41. }
  42. if (res.data.code == 200) {
  43. if (res.data.data.length > 0) {
  44. this.url = res.data.data[res.data.data.length - 1].url
  45. } else {
  46. uni.showToast({
  47. title: '未找到图片',
  48. duration: 2000
  49. })
  50. }
  51. } else {
  52. uni.showToast({
  53. title: '加载数据异常',
  54. duration: 1500
  55. })
  56. return
  57. }
  58. },
  59. longClickImg() {
  60. wx.previewImage({
  61. current: this.url,
  62. urls: [this.url]
  63. })
  64. },
  65. /**
  66. * 计算屏幕的高度
  67. */
  68. calc_screen_height() {
  69. uni.getSystemInfo({
  70. success: res => {
  71. let h = ((res.screenHeight * (750 / res.windowWidth)) - 160) //将px 转换rpx
  72. this.screenHeight = Math.floor(h) + 'rpx'
  73. }
  74. });
  75. }
  76. }
  77. }
  78. </script>
  79. <style scoped>
  80. page {
  81. background-color: #f5f5f5;
  82. }
  83. .container {
  84. display: flex;
  85. flex-direction: column;
  86. font-size: 29upx;
  87. font-family: "MicrosoftYaHei";
  88. padding: 10rpx;
  89. width: 730rpx;
  90. }
  91. .ad_img {
  92. width: 730rpx;
  93. height: 100%;
  94. }
  95. </style>