自主产品,供应链食堂系统。将两个端拆开了。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
6.2 KiB

  1. <template>
  2. <view>
  3. <swiper class="swiper" :animation="animationData"
  4. :style="{ 'opacity': animation ? '0' : '1',
  5. 'background-color': perspective ? 'rgba(0,0,0,0.5)' : '#000000'}"
  6. :current="swiper_current" :circular="circular"
  7. v-if="show_assembly" @click="hideAssembly"
  8. @touchmove.stop.prevent="touchmove"
  9. @change="e => switchItem(e.detail.current)">
  10. <swiper-item v-for="(item, index) in images" :key="index"
  11. class="swiper-item">
  12. <!-- 可移动缩放操作的容器 -->
  13. <movable-area class="movable-area" :scale-area="true">
  14. <movable-view class="movable-view" direction="all" :scale="true" :inertia="true" @scale="scale" :scale-value="scale_values[swiper_current]">
  15. <image :src="item" class="swiper-image" mode="aspectFit" @mousewheel.stop="mousewheel"></image>
  16. </movable-view>
  17. </movable-area>
  18. <!-- 控制器 -->
  19. <view class="controls" v-if="controls">
  20. <view>
  21. <view @click.stop="switchItem(swiper_current - 1)" v-if="swiper_current != 0">
  22. <uni-icons type="arrowleft" size="36" color="#fff"></uni-icons>
  23. </view>
  24. <view v-else></view>
  25. </view>
  26. <view>
  27. <view @click.stop="switchItem(swiper_current + 1)" v-if="swiper_current != images.length - 1">
  28. <uni-icons type="arrowright" size="36" color="#fff"></uni-icons>
  29. </view>
  30. <view v-else></view>
  31. </view>
  32. </view>
  33. <!-- 指示器 -->
  34. <view class="indicators" v-if="indicators && images.length > 1">
  35. <view class="number" v-if="indicatorType == 'number'">{{ swiper_current + 1 }} / {{ images.length }}</view>
  36. <view class="square" v-else-if="indicatorType == 'square'">
  37. <view v-for="(item, index) in images" :key="index" class="indicators-icon" :style="swiper_current == index ? 'background-color:'+ themeColor : ''"></view>
  38. </view>
  39. <view class="dot" v-else-if="indicatorType == 'dot'">
  40. <view v-for="(item, index) in images" :key="index" class="indicators-icon" :style="swiper_current == index ? 'background-color:'+ themeColor : ''"></view>
  41. </view>
  42. </view>
  43. </swiper-item>
  44. </swiper>
  45. </view>
  46. </template>
  47. <script>
  48. export default {
  49. props: {
  50. controls: {
  51. type: Boolean, // 是否显示左右箭头控制
  52. default: true
  53. },
  54. indicators: {
  55. type: Boolean,
  56. default: true // 是否显示指示器
  57. },
  58. indicatorType: {
  59. type: String, // 指示器类型,dot圆点,square方形,number数字
  60. default: 'number'
  61. },
  62. perspective: {
  63. type: Boolean, // 是否开启背景透视,遮罩透明可以看见底下其他元素
  64. default: true
  65. },
  66. circular: {
  67. type: Boolean, // 是否可以衔接滑动
  68. default: false
  69. },
  70. themeColor: {
  71. type: String, // 主题色
  72. default: '#1833F2'
  73. },
  74. animation: {
  75. type: Boolean, // 是否开启动画
  76. default: false
  77. }
  78. },
  79. data(){
  80. return {
  81. swiper_current: 0, // 当前显示的图片下标
  82. images: [],
  83. show_assembly: false, // 显示预览图片
  84. duration: 500, // 动画持续时间
  85. animationObj: {}, // 动画配置对象
  86. animationData: {}, // 动画导出执行对象
  87. scale_values: [], // 每张图的缩放比例
  88. clientY: 0
  89. }
  90. },
  91. created(){
  92. // TODO PC端屏蔽遮罩滚动穿透
  93. // TODO PC端滚轮放大缩小
  94. // TODO 放大缩小百分比显示
  95. // TODO 双击时会被关掉
  96. },
  97. methods: {
  98. // 初始化加载动画
  99. initAnimation(){
  100. let animationObj = uni.createAnimation({
  101. duration: this.duration
  102. });
  103. this.animationObj = animationObj;
  104. animationObj.opacity(0).step();
  105. animationObj.opacity(1).step();
  106. this.animationData = animationObj.export();
  107. },
  108. // swiper touchmove事件
  109. touchmove(){
  110. return false;
  111. },
  112. // swiper被改变
  113. switchItem(current){
  114. this.swiper_current = current;
  115. // this.clientY = 0; // 切换时需要复位
  116. },
  117. // movable 缩放事件
  118. scale(event){
  119. let scale = event.detail.scale;
  120. this.$msg(scale); // TODO 轻提示层级不够,没有被显示出来
  121. },
  122. // 鼠标滚动缩放事件,目前会触发浏览器页面滚动事件,暂时先不要这个功能
  123. mousewheel(event){
  124. return;
  125. let scale = this.scale_values[this.swiper_current];
  126. if(this.clientY > event.clientY){
  127. if(scale < 10){
  128. scale += 0.5;
  129. }
  130. }else{
  131. if(scale > 0.5){
  132. scale -= 0.5;
  133. }
  134. }
  135. this.clientY = event.clientY;
  136. this.scale_values.splice(this.swiper_current, 1, scale);
  137. },
  138. // 显示图片
  139. show(options){
  140. this.images = options.images || [];
  141. this.swiper_current = options.current || 0;
  142. this.scale_values = this.images.map(item => 1);
  143. this.show_assembly = true;
  144. if(this.$props.animation){
  145. this.initAnimation();
  146. }
  147. },
  148. // 关闭隐藏图片
  149. hideAssembly(){
  150. if(this.$props.animation){
  151. this.animationObj.opacity(0).step();
  152. this.animationData = this.animationObj.export();
  153. setTimeout(() => {
  154. this.show_assembly = false;
  155. }, this.duration);
  156. }else{
  157. this.show_assembly = false;
  158. }
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang="scss" scoped="scoped">
  164. .swiper{
  165. width: 100vw;
  166. height: 100vh;
  167. position: fixed;
  168. top: 0;
  169. left: 0;
  170. z-index: 1000;
  171. .swiper-item{
  172. position: relative;
  173. .movable-area, .movable-view, .swiper-image{
  174. width: 100%;
  175. height: 100%;
  176. }
  177. .controls{
  178. position: absolute;
  179. padding: 0 16rpx;
  180. box-sizing: border-box;
  181. display: flex;
  182. justify-content: space-between;
  183. top: 47vh;
  184. left: 0;
  185. font-size: 40rpx;
  186. width: 100%;
  187. z-index: 1002;
  188. }
  189. .indicators{
  190. width: 100%;
  191. position: absolute;
  192. left: 0;
  193. bottom: 10vh;
  194. z-index: 1002;
  195. display: flex;
  196. justify-content: center;
  197. .number, .square, .dot{
  198. width: max-content;
  199. height: max-content;
  200. background-color: #dfe4ea;
  201. }
  202. .number{
  203. padding: 4rpx 26rpx;
  204. border-radius: 40rpx;
  205. color: #555555;
  206. }
  207. .square{
  208. border-radius: 40rpx;
  209. display: flex;
  210. padding: 2rpx 4rpx;
  211. view{
  212. border-radius: 50%;
  213. }
  214. }
  215. .dot{
  216. display: flex;
  217. padding: 4rpx 4rpx;
  218. }
  219. .indicators-icon{
  220. width: 20rpx;
  221. height: 20rpx;
  222. background-color: #bdc5bd;
  223. margin: 2rpx;
  224. }
  225. }
  226. }
  227. }
  228. </style>