自主产品,供应链食堂系统。将两个端拆开了。
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.

237 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. },
  96. methods: {
  97. // 初始化加载动画
  98. initAnimation(){
  99. let animationObj = uni.createAnimation({
  100. duration: this.duration
  101. });
  102. this.animationObj = animationObj;
  103. animationObj.opacity(0).step();
  104. animationObj.opacity(1).step();
  105. this.animationData = animationObj.export();
  106. },
  107. // swiper touchmove事件
  108. touchmove(){
  109. return false;
  110. },
  111. // swiper被改变
  112. switchItem(current){
  113. this.swiper_current = current;
  114. // this.clientY = 0; // 切换时需要复位
  115. },
  116. // movable 缩放事件
  117. scale(event){
  118. let scale = parseInt(event.detail.scale * 100) +'%';
  119. uni.showToast({
  120. title: scale,
  121. icon: 'none',
  122. position: 'bottom'
  123. })
  124. },
  125. // 鼠标滚动缩放事件,目前会触发浏览器页面滚动事件,暂时先不要这个功能
  126. mousewheel(event){
  127. return;
  128. let scale = this.scale_values[this.swiper_current];
  129. if(this.clientY > event.clientY){
  130. if(scale < 10){
  131. scale += 0.5;
  132. }
  133. }else{
  134. if(scale > 0.5){
  135. scale -= 0.5;
  136. }
  137. }
  138. this.clientY = event.clientY;
  139. this.scale_values.splice(this.swiper_current, 1, scale);
  140. },
  141. // 显示图片
  142. show(options){
  143. this.images = options.images || [];
  144. this.swiper_current = options.current || 0;
  145. this.scale_values = this.images.map(item => 1);
  146. this.show_assembly = true;
  147. if(this.$props.animation){
  148. this.initAnimation();
  149. }
  150. },
  151. // 关闭隐藏图片
  152. hideAssembly(){
  153. if(this.$props.animation){
  154. this.animationObj.opacity(0).step();
  155. this.animationData = this.animationObj.export();
  156. setTimeout(() => {
  157. this.show_assembly = false;
  158. }, this.duration);
  159. }else{
  160. this.show_assembly = false;
  161. }
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="scss" scoped="scoped">
  167. .swiper{
  168. width: 100vw;
  169. height: 100vh;
  170. position: fixed;
  171. top: 0;
  172. left: 0;
  173. z-index: 1000;
  174. .swiper-item{
  175. position: relative;
  176. .movable-area, .movable-view, .swiper-image{
  177. width: 100%;
  178. height: 100%;
  179. }
  180. .controls{
  181. position: absolute;
  182. padding: 0 16rpx;
  183. box-sizing: border-box;
  184. display: flex;
  185. justify-content: space-between;
  186. top: 47vh;
  187. left: 0;
  188. font-size: 40rpx;
  189. width: 100%;
  190. z-index: 1002;
  191. }
  192. .indicators{
  193. width: 100%;
  194. position: absolute;
  195. left: 0;
  196. bottom: 10vh;
  197. z-index: 1002;
  198. display: flex;
  199. justify-content: center;
  200. .number, .square, .dot{
  201. width: max-content;
  202. height: max-content;
  203. background-color: #dfe4ea;
  204. }
  205. .number{
  206. padding: 4rpx 26rpx;
  207. border-radius: 40rpx;
  208. color: #555555;
  209. }
  210. .square{
  211. border-radius: 40rpx;
  212. display: flex;
  213. padding: 2rpx 4rpx;
  214. view{
  215. border-radius: 50%;
  216. }
  217. }
  218. .dot{
  219. display: flex;
  220. padding: 4rpx 4rpx;
  221. }
  222. .indicators-icon{
  223. width: 20rpx;
  224. height: 20rpx;
  225. background-color: #bdc5bd;
  226. margin: 2rpx;
  227. }
  228. }
  229. }
  230. }
  231. // 轻提示框样式
  232. /deep/.uni-sample-toast{
  233. z-index: 1002;
  234. }
  235. </style>