project init

This commit is contained in:
limqhz
2022-11-11 21:51:57 +08:00
parent e9e20765f2
commit 82dbb842ba
68 changed files with 2771 additions and 43 deletions

2
components/behaviors/dom.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
declare const _default: string;
export default _default;

View File

@@ -0,0 +1,27 @@
export default Behavior({
methods: {
gettingBoundingClientRect(selector, all) {
return new Promise((resolve, reject) => {
try {
wx.createSelectorQuery()
.in(this)[all ? 'selectAll' : 'select'](selector)
.boundingClientRect((rect) => {
if (all && Array.isArray(rect) && rect.length) {
resolve(rect);
}
else if (!all && rect) {
resolve(rect);
}
else {
reject();
}
})
.exec();
}
catch (err) {
reject(err);
}
});
},
},
});

2
components/behaviors/touch.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
declare const _default: string;
export default _default;

View File

@@ -0,0 +1,35 @@
const MinDistance = 10;
const getDirection = (x, y) => {
if (x > y && x > MinDistance) {
return 'horizontal';
}
if (y > x && y > MinDistance) {
return 'vertical';
}
return '';
};
export default Behavior({
methods: {
resetTouchStatus() {
this.direction = '';
this.deltaX = 0;
this.deltaY = 0;
this.offsetX = 0;
this.offsetY = 0;
},
touchStart(event) {
this.resetTouchStatus();
const [touch] = event.touches;
this.startX = touch.clientX;
this.startY = touch.clientY;
},
touchMove(event) {
const [touch] = event.touches;
this.deltaX = touch.clientX - this.startX;
this.deltaY = touch.clientY - this.startY;
this.offsetX = Math.abs(this.deltaX);
this.offsetY = Math.abs(this.deltaY);
this.direction = getDirection(this.offsetX, this.offsetY);
},
},
});