uni-documentPreview.vue 3.8 KB

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