|
@@ -1,151 +1,157 @@
|
|
|
+var that;
|
|
|
Component({
|
|
|
-
|
|
|
- * 组件的属性列表
|
|
|
- */
|
|
|
- properties: {
|
|
|
- previewImgList: {
|
|
|
- type: Array,
|
|
|
- value: [],
|
|
|
- observer: function(newVal) {
|
|
|
- this.initializeImgIndex();
|
|
|
- }
|
|
|
- },
|
|
|
- previewImg: {
|
|
|
- type: String,
|
|
|
- value: '',
|
|
|
- observer: function(newVal) {
|
|
|
- this.initializeImgIndex();
|
|
|
- }
|
|
|
- },
|
|
|
- previewHideStatus: {
|
|
|
- type: Boolean,
|
|
|
- value: false
|
|
|
- }
|
|
|
+
|
|
|
+ * 组件的属性列表
|
|
|
+ */
|
|
|
+ properties: {
|
|
|
+ previewImgList: {
|
|
|
+ type: Array,
|
|
|
+ value: false
|
|
|
},
|
|
|
-
|
|
|
-
|
|
|
- * 组件的初始数据
|
|
|
- */
|
|
|
- data: {
|
|
|
- index: 0,
|
|
|
- imgindex: 1,
|
|
|
- left: '0%',
|
|
|
- scaleObj: {
|
|
|
- scale: 1,
|
|
|
- x: 0,
|
|
|
- y: 0,
|
|
|
- yes: true
|
|
|
- },
|
|
|
- touchS: [],
|
|
|
- touchE: [],
|
|
|
- preview_box_top: '0%'
|
|
|
+ previewImg: {
|
|
|
+ type: null,
|
|
|
+ value: false
|
|
|
},
|
|
|
-
|
|
|
- lifetimes: {
|
|
|
- detached: function () {
|
|
|
-
|
|
|
- },
|
|
|
- attached: async function () {
|
|
|
-
|
|
|
- this.initializeImgIndex();
|
|
|
- },
|
|
|
+ },
|
|
|
+ attached: function () {
|
|
|
+ that = this;
|
|
|
+ },
|
|
|
+
|
|
|
+ * 组件的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ preview_box_top: 0,
|
|
|
+ left: '0px;',
|
|
|
+ touchS: [0, 0],
|
|
|
+ touchE: [0, 0],
|
|
|
+ index: 0,
|
|
|
+ imgindex:0,
|
|
|
+ previewHideStatus:false,
|
|
|
+ scale: 1,
|
|
|
+ scaleObj:{
|
|
|
+ scale:1,
|
|
|
+ x:0,
|
|
|
+ y:0,
|
|
|
+ yes:true
|
|
|
},
|
|
|
+ touchStartTime: 0,
|
|
|
+ touchEndTime: 0,
|
|
|
+ lastTapTime: 0,
|
|
|
+ lastTapTimeoutFunc: null,
|
|
|
+ },
|
|
|
+
|
|
|
+ * 组件的方法列表
|
|
|
+ */
|
|
|
+ methods: {
|
|
|
+ jingzhi(e) {
|
|
|
+ let diffTouch = this.data.touchEndTime - this.data.touchStartTime;
|
|
|
+ let curTime = e.timeStamp;
|
|
|
+ let lastTime = this.data.lastTapDiffTime;
|
|
|
+ this.data.lastTapDiffTime = curTime;
|
|
|
|
|
|
-
|
|
|
- * 组件的方法列表
|
|
|
- */
|
|
|
- methods: {
|
|
|
- initializeImgIndex: function () {
|
|
|
- const {
|
|
|
- previewImgList,
|
|
|
- previewImg
|
|
|
- } = this.properties;
|
|
|
- console.log(this.properties);
|
|
|
- if (previewImgList.length > 0 && previewImg) {
|
|
|
- const index = previewImgList.findIndex(img => img === previewImg);
|
|
|
- if (index !== -1) {
|
|
|
- this.setData({
|
|
|
- index: index,
|
|
|
- imgindex: index + 1,
|
|
|
- left: '-' + index + '00%;transition: all 0s;'
|
|
|
- });
|
|
|
- } else {
|
|
|
-
|
|
|
- this.setData({
|
|
|
- index: 0,
|
|
|
- imgindex: 1,
|
|
|
- left: '0%;transition: all .5s;'
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- touchStart: function (e) {
|
|
|
- this.data.touchStartTime = e.timeStamp;
|
|
|
- let sx = e.touches[0].pageX;
|
|
|
- let sy = e.touches[0].pageY;
|
|
|
- this.data.touchS = [sx, sy];
|
|
|
- },
|
|
|
-
|
|
|
- touchMove: function (e) {
|
|
|
- let start = this.data.touchS;
|
|
|
- let sx = e.touches[0].pageX;
|
|
|
- let sy = e.touches[0].pageY;
|
|
|
- this.data.touchE = [sx, sy];
|
|
|
- },
|
|
|
+ this.setData({previewHideStatus: false,preview_box_top: '100%' })
|
|
|
|
|
|
- touchEnd: function (e) {
|
|
|
- let start = this.data.touchS;
|
|
|
- let end = this.data.touchE;
|
|
|
- let scaleObj = this.data.scaleObj;
|
|
|
-
|
|
|
- if (scaleObj.yes) {
|
|
|
- if (end[0] === 0) {
|
|
|
- console.log('点击');
|
|
|
- this.jingzhi()
|
|
|
- } else if ((start[0] < end[0] - 50) && (scaleObj.scale === 1 && scaleObj.x === 0 && scaleObj.y === 0)) {
|
|
|
- if (this.data.index > 0) {
|
|
|
- this.data.index -= 1;
|
|
|
- this.data.imgindex -= 1;
|
|
|
- this.updateView();
|
|
|
- }
|
|
|
- } else if ((start[0] > end[0] + 50) && (scaleObj.scale === 1 && scaleObj.x === 0 && scaleObj.y === 0)) {
|
|
|
- if (this.data.index < this.data.previewImgList.length - 1) {
|
|
|
- this.data.index += 1;
|
|
|
- this.data.imgindex += 1;
|
|
|
- this.updateView();
|
|
|
- }
|
|
|
- } else {
|
|
|
- console.log('下滑/上滑');
|
|
|
-
|
|
|
- }
|
|
|
- this.data.touchE = [0, 0];
|
|
|
- }
|
|
|
-
|
|
|
- setTimeout(() => {
|
|
|
- if (this.data.scaleObj.x === 0 && this.data.scaleObj.y === 0 && this.data.scaleObj.scale === 1) {
|
|
|
- this.data.scaleObj.yes = true;
|
|
|
- }
|
|
|
- }, 500);
|
|
|
- },
|
|
|
-
|
|
|
- updateView: function () {
|
|
|
- this.setData({
|
|
|
- index: this.data.index,
|
|
|
- left: '-' + this.data.index + '00%;transition: all .5s;',
|
|
|
- imgindex: this.data.imgindex
|
|
|
- });
|
|
|
- },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+ configqxClick(e) { this.setData({ scopeWritePhotosAlbum: e.detail }) },
|
|
|
+ touchStart: function (e) {
|
|
|
+ this.data.touchStartTime = e.timeStamp
|
|
|
+ let sx = e.touches[0].pageX
|
|
|
+ let sy = e.touches[0].pageY
|
|
|
+ this.data.touchS = [sx, sy];
|
|
|
+ },
|
|
|
+ touchMove: function (e) {
|
|
|
+ let start = this.data.touchS;
|
|
|
+ let sx = e.touches[0].pageX;
|
|
|
+ let sy = e.touches[0].pageY;
|
|
|
+ this.data.touchE = [sx, sy];
|
|
|
+ },
|
|
|
+ touchEnd: function (e) {
|
|
|
+ this.data.touchEndTime = e.timeStamp
|
|
|
+ let start = this.data.touchS
|
|
|
+ let end = this.data.touchE
|
|
|
+ let scaleObj = this.data.scaleObj
|
|
|
+
|
|
|
+
|
|
|
+ if(scaleObj.yes){
|
|
|
+ if(end[0] == 0){
|
|
|
+ console.log('点击')
|
|
|
+ }else if((start[0] < end[0] - 50) && (scaleObj.scale==1&&scaleObj.x==0&&scaleObj.y==0)){
|
|
|
+ if (this.data.index !== 0) {
|
|
|
+ this.data.index -= 1;
|
|
|
+ this.data.imgindex -=1;
|
|
|
+ this.setData({ index: this.data.index, left: '-' + this.data.index + '00%;transition: all .5s;', imgindex: this.data.imgindex });
|
|
|
+ }
|
|
|
+ }else if((start[0] > end[0] + 50) && (scaleObj.scale==1&&scaleObj.x==0&&scaleObj.y==0)){
|
|
|
+ if (this.data.index !== this.data.previewImgList.length - 1) {
|
|
|
+ this.data.index += 1;
|
|
|
+ this.data.imgindex += 1;
|
|
|
+ this.setData({ index: this.data.index, left: '-' + this.data.index + '00%;transition: all .5s;', imgindex: this.data.imgindex });
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ console.log('下滑/上滑');
|
|
|
+ this.setData({ preview_box_top: '100%' })
|
|
|
+ }
|
|
|
+ this.data.touchE = [0, 0];
|
|
|
+ }
|
|
|
|
|
|
- jingzhi: function () {
|
|
|
-
|
|
|
- console.log('点击图片');
|
|
|
- this.setData({
|
|
|
- preview_box_top: '0%',
|
|
|
- previewHideStatus: false ,
|
|
|
- previewImgList:[],
|
|
|
- previewImg:''
|
|
|
- });
|
|
|
+ setTimeout(()=>{
|
|
|
+ if(this.data.scaleObj.x == 0 && this.data.scaleObj.y == 0 && this.data.scaleObj.scale == 1){
|
|
|
+ console.log('yes is true');
|
|
|
+ this.data.scaleObj.yes = true;
|
|
|
+ }
|
|
|
+ },500)
|
|
|
+ },
|
|
|
+ showPreview() {
|
|
|
+ this.setData({ previewHideStatus: true, preview_box_top: 0 })
|
|
|
+ },
|
|
|
+ hidePreview() {
|
|
|
+ this.setData({ previewHideStatus: false, preview_box_top: 0 })
|
|
|
+ },
|
|
|
+ onScale(e) {
|
|
|
+ this.data.scaleObj = {
|
|
|
+ scale:e.detail.scale,
|
|
|
+ x:e.detail.x,
|
|
|
+ y:e.detail.y,
|
|
|
+ yes:false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ stopPageScroll() { return },
|
|
|
+ },
|
|
|
+ observers: {
|
|
|
+ 'previewImgList': function (arr) {
|
|
|
+ console.log(arr)
|
|
|
+ },
|
|
|
+ 'previewImg':function(img){
|
|
|
+ this.data.previewImgList.map((item,index)=>{
|
|
|
+ if(item == img){
|
|
|
+ let imgindex = index;
|
|
|
+ imgindex+=1;
|
|
|
+ this.setData({ index: index, imgindex: imgindex, left: '-'+index+'00%;' })
|
|
|
}
|
|
|
+ })
|
|
|
}
|
|
|
-});
|
|
|
+ },
|
|
|
+})
|