Browse Source

预览图片API全部更换成自己封装的组件

master
邓平艺 5 years ago
parent
commit
264776c2e9
  1. 230
      canteen/components/lf-previewImage/lf-previewImage.vue
  2. 3
      canteen/main.js
  3. 1040
      canteen/pages/purchase/detail.vue
  4. 1067
      canteen/pages/purchase/receipt.vue
  5. 38
      supplier/components/lf-previewImage/lf-previewImage.vue

230
canteen/components/lf-previewImage/lf-previewImage.vue

@ -0,0 +1,230 @@
<template>
<view>
<swiper class="swiper" :animation="animationData"
:style="{ 'opacity': animation ? '0' : '1',
'background-color': perspective ? 'rgba(0,0,0,0.5)' : '#000000'}"
:current="swiper_current" :circular="circular"
v-if="show_assembly" @click="hideAssembly"
@touchmove.stop.prevent="touchmove"
@change="e => switchItem(e.detail.current)">
<swiper-item v-for="(item, index) in images" :key="index"
class="swiper-item">
<!-- 可移动缩放操作的容器 -->
<movable-area class="movable-area" :scale-area="true">
<movable-view class="movable-view" direction="all" :scale="true" :inertia="true" @scale="scale" :scale-value="scale_values[swiper_current]">
<image :src="item" class="swiper-image" mode="aspectFit" @mousewheel.stop="mousewheel"></image>
</movable-view>
</movable-area>
<!-- 控制器 -->
<view class="controls" v-if="controls">
<view>
<view @click.stop="switchItem(swiper_current - 1)" v-if="swiper_current != 0">
<uni-icons type="arrowleft" size="36" color="#fff"></uni-icons>
</view>
<view v-else></view>
</view>
<view>
<view @click.stop="switchItem(swiper_current + 1)" v-if="swiper_current != images.length - 1">
<uni-icons type="arrowright" size="36" color="#fff"></uni-icons>
</view>
<view v-else></view>
</view>
</view>
<!-- 指示器 -->
<view class="indicators" v-if="indicators && images.length > 1">
<view class="number" v-if="indicatorType == 'number'">{{ swiper_current + 1 }} / {{ images.length }}</view>
<view class="square" v-else-if="indicatorType == 'square'">
<view v-for="(item, index) in images" :key="index" class="indicators-icon" :style="swiper_current == index ? 'background-color:'+ themeColor : ''"></view>
</view>
<view class="dot" v-else-if="indicatorType == 'dot'">
<view v-for="(item, index) in images" :key="index" class="indicators-icon" :style="swiper_current == index ? 'background-color:'+ themeColor : ''"></view>
</view>
</view>
</swiper-item>
</swiper>
</view>
</template>
<script>
export default {
props: {
controls: {
type: Boolean, //
default: true
},
indicators: {
type: Boolean,
default: true //
},
indicatorType: {
type: String, // dotsquarenumber
default: 'number'
},
perspective: {
type: Boolean, //
default: true
},
circular: {
type: Boolean, //
default: false
},
themeColor: {
type: String, //
default: '#1833F2'
},
animation: {
type: Boolean, //
default: false
}
},
data(){
return {
swiper_current: 0, //
images: [],
show_assembly: false, //
duration: 500, //
animationObj: {}, //
animationData: {}, //
scale_values: [], //
clientY: 0
}
},
created(){
// TODO PC穿
// TODO PC
// TODO
// TODO
},
methods: {
//
initAnimation(){
let animationObj = uni.createAnimation({
duration: this.duration
});
this.animationObj = animationObj;
animationObj.opacity(0).step();
animationObj.opacity(1).step();
this.animationData = animationObj.export();
},
// swiper touchmove
touchmove(){
return false;
},
// swiper
switchItem(current){
this.swiper_current = current;
// this.clientY = 0; //
},
// movable
scale(event){
let scale = event.detail.scale;
this.$msg(scale); // TODO
},
//
mousewheel(event){
return;
let scale = this.scale_values[this.swiper_current];
if(this.clientY > event.clientY){
if(scale < 10){
scale += 0.5;
}
}else{
if(scale > 0.5){
scale -= 0.5;
}
}
this.clientY = event.clientY;
this.scale_values.splice(this.swiper_current, 1, scale);
},
//
show(options){
this.images = options.images || [];
this.swiper_current = options.current || 0;
this.scale_values = this.images.map(item => 1);
this.show_assembly = true;
if(this.$props.animation){
this.initAnimation();
}
},
//
hideAssembly(){
if(this.$props.animation){
this.animationObj.opacity(0).step();
this.animationData = this.animationObj.export();
setTimeout(() => {
this.show_assembly = false;
}, this.duration);
}else{
this.show_assembly = false;
}
}
}
}
</script>
<style lang="scss" scoped="scoped">
.swiper{
width: 100vw;
height: 100vh;
position: fixed;
top: 0;
left: 0;
z-index: 1000;
.swiper-item{
position: relative;
.movable-area, .movable-view, .swiper-image{
width: 100%;
height: 100%;
}
.controls{
position: absolute;
padding: 0 16rpx;
box-sizing: border-box;
display: flex;
justify-content: space-between;
top: 47vh;
left: 0;
font-size: 40rpx;
width: 100%;
z-index: 1002;
}
.indicators{
width: 100%;
position: absolute;
left: 0;
bottom: 10vh;
z-index: 1002;
display: flex;
justify-content: center;
.number, .square, .dot{
width: max-content;
height: max-content;
background-color: #dfe4ea;
}
.number{
padding: 4rpx 26rpx;
border-radius: 40rpx;
color: #555555;
}
.square{
border-radius: 40rpx;
display: flex;
padding: 2rpx 4rpx;
view{
border-radius: 50%;
}
}
.dot{
display: flex;
padding: 4rpx 4rpx;
}
.indicators-icon{
width: 20rpx;
height: 20rpx;
background-color: #bdc5bd;
margin: 2rpx;
}
}
}
}
</style>

3
canteen/main.js

@ -30,6 +30,9 @@ Vue.component('self-line', selfLine);
// 将步骤条组件注入全局
import lfStepbar from '@/components/lf-stepbar/lf-stepbar';
Vue.component('lf-stepbar', lfStepbar);
// 预览图片组件
import lfPreviewImage from '@/components/lf-previewImage/lf-previewImage';
Vue.component('lf-previewimage', lfPreviewImage);
const app = new Vue({
...App

1040
canteen/pages/purchase/detail.vue
File diff suppressed because it is too large
View File

1067
canteen/pages/purchase/receipt.vue
File diff suppressed because it is too large
View File

38
supplier/components/lf-previewImage/lf-previewImage.vue

@ -1,7 +1,8 @@
<template>
<view>
<swiper class="swiper" :animation="animationData"
:style="{'background-color': perspective ? 'rgba(0,0,0,0.5)' : '#000000'}"
:style="{ 'opacity': animation ? '0' : '1',
'background-color': perspective ? 'rgba(0,0,0,0.5)' : '#000000'}"
:current="swiper_current" :circular="circular"
v-if="show_assembly" @click="hideAssembly"
@touchmove.stop.prevent="touchmove"
@ -70,6 +71,10 @@
themeColor: {
type: String, //
default: '#1833F2'
},
animation: {
type: Boolean, //
default: false
}
},
data(){
@ -78,7 +83,7 @@
images: [],
show_assembly: false, //
duration: 500, //
animation: {}, //
animationObj: {}, //
animationData: {}, //
scale_values: [], //
clientY: 0
@ -93,13 +98,13 @@
methods: {
//
initAnimation(){
let animation = uni.createAnimation({
let animationObj = uni.createAnimation({
duration: this.duration
});
this.animation = animation;
animation.opacity(0).step();
animation.opacity(1).step();
this.animationData = animation.export();
this.animationObj = animationObj;
animationObj.opacity(0).step();
animationObj.opacity(1).step();
this.animationData = animationObj.export();
},
// swiper touchmove
touchmove(){
@ -137,15 +142,21 @@
this.swiper_current = options.current || 0;
this.scale_values = this.images.map(item => 1);
this.show_assembly = true;
this.initAnimation();
if(this.$props.animation){
this.initAnimation();
}
},
//
hideAssembly(){
this.animation.opacity(0).step();
this.animationData = this.animation.export();
setTimeout(() => {
if(this.$props.animation){
this.animationObj.opacity(0).step();
this.animationData = this.animationObj.export();
setTimeout(() => {
this.show_assembly = false;
}, this.duration);
}else{
this.show_assembly = false;
}, this.duration);
}
}
}
}
@ -159,7 +170,6 @@
top: 0;
left: 0;
z-index: 1000;
opacity: 0;
.swiper-item{
position: relative;
.movable-area, .movable-view, .swiper-image{
@ -172,7 +182,7 @@
box-sizing: border-box;
display: flex;
justify-content: space-between;
top: 42vh;
top: 47vh;
left: 0;
font-size: 40rpx;
width: 100%;

Loading…
Cancel
Save