previewImage.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <view class="container">
  3. <network v-if="network.show" :num="network.num" :tips="network.tips" />
  4. <view
  5. v-if="ctrlItem"
  6. class="ctrl-but"
  7. :style="{ background: ctrlItem.background }"
  8. hover-class="navigator-hover"
  9. @click.stop="changeItem(ctrlItem)"
  10. >
  11. {{ ctrlItem.showValue }}
  12. </view>
  13. <swiper
  14. v-if="list.length"
  15. class="swiper"
  16. :indicator-dots="list.length > 1"
  17. :circular="true"
  18. indicator-color="#999"
  19. indicator-active-color="#fff"
  20. >
  21. <swiper-item
  22. v-for="(item, index) in list"
  23. @click="preview(index)"
  24. :key="item.url"
  25. >
  26. <image
  27. class="image"
  28. :src="item.url"
  29. mode="aspectFit"
  30. lazy-load="true"
  31. />
  32. </swiper-item>
  33. </swiper>
  34. <My_input ref="MyInput" />
  35. </view>
  36. </template>
  37. <script>
  38. import network from "./network.vue";
  39. export default {
  40. name: "previewImage",
  41. components: { network },
  42. props: {
  43. attinfos: Array,
  44. },
  45. data() {
  46. return {
  47. list: [],
  48. network: {
  49. show: false,
  50. num: 0,
  51. tips: "",
  52. },
  53. ctrlItem: null,
  54. };
  55. },
  56. watch: {
  57. attinfos: function (newVal) {
  58. this.list = newVal.filter((v) => v.usetype == "previewImage");
  59. },
  60. },
  61. methods: {
  62. preview(index) {
  63. uni.previewImage({
  64. current: index,
  65. urls: this.list.map((v) => v.url),
  66. indicator: "number",
  67. loop: true,
  68. longPressActions: {
  69. itemList: ["发送给朋友", "保存图片", "收藏"],
  70. success: function (data) {
  71. console.log(
  72. "选中了第" +
  73. (data.tapIndex + 1) +
  74. "个按钮,第" +
  75. (data.index + 1) +
  76. "张图片"
  77. );
  78. },
  79. fail: function (err) {
  80. console.log(err.errMsg);
  81. },
  82. },
  83. });
  84. },
  85. openNetwork(num = 0, tips = "信号强度:") {
  86. this.network = {
  87. show: true,
  88. num,
  89. tips,
  90. };
  91. },
  92. setData(params) {
  93. for (const key in params) {
  94. this[key] = params[key];
  95. }
  96. },
  97. changeItem(item) {
  98. this.$refs.MyInput.openInput(item);
  99. },
  100. },
  101. };
  102. </script>
  103. <style lang="scss" scoped>
  104. .container {
  105. position: relative;
  106. .swiper {
  107. width: 355px;
  108. height: 158px;
  109. margin: 15px auto 0;
  110. .image {
  111. width: 355px;
  112. height: 158px;
  113. }
  114. }
  115. .ctrl-but {
  116. position: absolute;
  117. top: 10px;
  118. right: 14px;
  119. font-size: 12px;
  120. color: #fff;
  121. padding: 4px 6px;
  122. border-radius: 4px;
  123. z-index: 1;
  124. }
  125. }
  126. </style>