uni-documentPreview.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view class="imgview">
  3. <view class="imgregion">
  4. <movable-area>
  5. <movable-view direction="all" out-of-bounds :scale="true" :damping="30" :friction="10">
  6. <image :src="images[currentIndex].img" mode="widthFix"
  7. :style="{transform:`rotate(-${images[currentIndex].deg}deg)`}">
  8. </image>
  9. </movable-view>
  10. </movable-area>
  11. <!-- 操作按钮 -->
  12. <view class="blur-background ">
  13. <view class="item dis a-c j-c" @tap="leftTurn">
  14. <image src="/static/icon/left.png" mode=""></image>
  15. <text>左转</text>
  16. </view>
  17. <view class="item dis a-c j-c " @tap="reUpload(Type)">
  18. <image src="/static/icon/upload.png" mode=""></image>
  19. <text>上传</text>
  20. </view>
  21. <view class="item dis a-c j-c " @tap="rightTurn">
  22. <image src="/static/icon/right.png" mode=""></image>
  23. <text>右转</text>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="pageTurn dis a-c j-s mt-3 mb-3" v-if="images.length>1">
  28. <view class="btn dis a-c j-c" @tap="prevImage">
  29. 上一张
  30. </view>
  31. <view class="btn dis a-c j-c" @tap="nextImage">
  32. 下一张
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. name: 'uni-documentPreview', //插件名称
  40. props: {
  41. images: {
  42. type: Array,
  43. default: () => []
  44. },
  45. Type: {
  46. type: String,
  47. default: 'carInfo'
  48. }
  49. },
  50. computed: {},
  51. data() {
  52. return {
  53. deg: 0, //旋转角度
  54. currentIndex: 0, // 当前显示图片的索引
  55. checkType: this.Type,
  56. };
  57. },
  58. watch: {
  59. Type(newVal) {
  60. this.checkType = newVal;
  61. }
  62. },
  63. methods: {
  64. // 上一张(到达第一张时停止)
  65. prevImage() {
  66. if (this.currentIndex > 0) {
  67. this.currentIndex = this.currentIndex - 1
  68. this.deg = 0;
  69. }
  70. },
  71. // 下一张(到达最后一张时停止)
  72. nextImage() {
  73. if (this.currentIndex < this.images.length - 1) {
  74. this.currentIndex = this.currentIndex + 1;
  75. this.deg = 0;
  76. }
  77. },
  78. leftTurn() {
  79. this.images[this.currentIndex].deg = this.images[this.currentIndex].deg == 270 ? 0 : this.images[this
  80. .currentIndex].deg + 90;
  81. },
  82. rightTurn() {
  83. this.images[this.currentIndex].deg = this.images[this.currentIndex].deg == 0 ? 270 : this.images[this
  84. .currentIndex].deg - 90;
  85. },
  86. reUpload(name) {
  87. this.$emit('reupload', name)
  88. },
  89. }
  90. };
  91. </script>
  92. <!--使用scss,只在本组件生效-->
  93. <style lang="scss" scoped>
  94. /* 新增禁用样式 */
  95. .disabled {
  96. background-color: #cccccc !important;
  97. opacity: 0.6;
  98. pointer-events: none;
  99. }
  100. .imgview {
  101. width: 100%;
  102. border-radius: 0rpx 0rpx 0rpx 0rpx;
  103. .imgregion {
  104. position: relative;
  105. width: 100%;
  106. height: 393rpx;
  107. border-radius: 10rpx 10rpx 10rpx 10rpx;
  108. image {
  109. width: 100%;
  110. height: 100%;
  111. border-radius: 10rpx;
  112. }
  113. }
  114. }
  115. .blur-background {
  116. position: absolute;
  117. bottom: 0;
  118. width: 100%;
  119. background-color: rgba(255, 255, 255, 10%);
  120. backdrop-filter: blur(20rpx);
  121. padding: 16rpx;
  122. box-sizing: border-box;
  123. border-radius: 0 0 10rpx 10rpx;
  124. display: grid;
  125. grid-template-columns: repeat(3, 1fr);
  126. grid-template-rows: auto;
  127. .item {
  128. font-size: 26rpx;
  129. color: #fff;
  130. image {
  131. width: 26rpx;
  132. height: 26rpx;
  133. margin-right: 8rpx;
  134. }
  135. }
  136. .item:nth-child(2) {
  137. border-left: 1rpx solid #fff;
  138. border-right: 1rpx solid #fff;
  139. }
  140. }
  141. .pageTurn {
  142. border: 2px solid #FDE935;
  143. border-radius: 40rpx;
  144. .btn {
  145. width: 50%;
  146. font-size: 28rpx;
  147. color: #333;
  148. }
  149. :first-child {
  150. padding: 16rpx;
  151. border-right: 1px solid #FDE935;
  152. }
  153. :last-child {
  154. padding: 16rpx;
  155. }
  156. }
  157. movable-area {
  158. height: 100%;
  159. width: 100%;
  160. border-radius: 10rpx;
  161. background-color: #D8D8D8;
  162. overflow: hidden;
  163. }
  164. movable-view {
  165. display: flex;
  166. align-items: center;
  167. justify-content: center;
  168. height: 100%;
  169. width: 100%;
  170. }
  171. </style>