ad_dianfei.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. let tf = false;
  44. let tmpData = res.data.data;
  45. for (var i = 0; i < tmpData.length; i++) {
  46. if (tmpData[i].state == 1 && tmpData[i].remark.indexOf('二维码') != -1) {
  47. this.url = tmpData[i].url;
  48. tf = true;
  49. }
  50. }
  51. if (tf == false) {
  52. uni.showToast({
  53. icon: 'none',
  54. title: '没有启用的二维码图',
  55. duration: 2000
  56. });
  57. }
  58. } else {
  59. uni.showToast({
  60. title: '加载数据异常',
  61. duration: 1500
  62. })
  63. return
  64. }
  65. },
  66. longClickImg() {
  67. wx.previewImage({
  68. current: this.url,
  69. urls: [this.url]
  70. })
  71. },
  72. /**
  73. * 计算屏幕的高度
  74. */
  75. calc_screen_height() {
  76. uni.getSystemInfo({
  77. success: res => {
  78. let h = ((res.screenHeight * (750 / res.windowWidth)) - 160) //将px 转换rpx
  79. this.screenHeight = Math.floor(h) + 'rpx'
  80. }
  81. });
  82. }
  83. }
  84. }
  85. </script>
  86. <style scoped>
  87. page {
  88. background-color: #f5f5f5;
  89. }
  90. .container {
  91. display: flex;
  92. flex-direction: column;
  93. font-size: 29upx;
  94. font-family: "MicrosoftYaHei";
  95. padding: 10rpx;
  96. width: 730rpx;
  97. }
  98. .ad_img {
  99. width: 730rpx;
  100. height: 100%;
  101. }
  102. </style>