vant
This commit is contained in:
1
utils/dist/mixins/basic.d.ts
vendored
Normal file
1
utils/dist/mixins/basic.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const basic: string;
|
||||
22
utils/dist/mixins/basic.js
vendored
Normal file
22
utils/dist/mixins/basic.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
export const basic = Behavior({
|
||||
methods: {
|
||||
$emit(...args) {
|
||||
this.triggerEvent(...args);
|
||||
},
|
||||
getRect(selector, all) {
|
||||
return new Promise(resolve => {
|
||||
wx.createSelectorQuery()
|
||||
.in(this)[all ? 'selectAll' : 'select'](selector)
|
||||
.boundingClientRect(rect => {
|
||||
if (all && Array.isArray(rect) && rect.length) {
|
||||
resolve(rect);
|
||||
}
|
||||
if (!all && rect) {
|
||||
resolve(rect);
|
||||
}
|
||||
})
|
||||
.exec();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
1
utils/dist/mixins/button.d.ts
vendored
Normal file
1
utils/dist/mixins/button.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const button: string;
|
||||
18
utils/dist/mixins/button.js
vendored
Normal file
18
utils/dist/mixins/button.js
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
export const button = Behavior({
|
||||
externalClasses: ['hover-class'],
|
||||
properties: {
|
||||
id: String,
|
||||
lang: {
|
||||
type: String,
|
||||
value: 'en'
|
||||
},
|
||||
businessId: Number,
|
||||
sessionFrom: String,
|
||||
sendMessageTitle: String,
|
||||
sendMessagePath: String,
|
||||
sendMessageImg: String,
|
||||
showMessageCard: Boolean,
|
||||
appParameter: String,
|
||||
ariaLabel: String
|
||||
}
|
||||
});
|
||||
1
utils/dist/mixins/link.d.ts
vendored
Normal file
1
utils/dist/mixins/link.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const link: string;
|
||||
17
utils/dist/mixins/link.js
vendored
Normal file
17
utils/dist/mixins/link.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
export const link = Behavior({
|
||||
properties: {
|
||||
url: String,
|
||||
linkType: {
|
||||
type: String,
|
||||
value: 'navigateTo'
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
jumpLink(urlKey = 'url') {
|
||||
const url = this.data[urlKey];
|
||||
if (url) {
|
||||
wx[this.data.linkType]({ url });
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
1
utils/dist/mixins/observer/behavior.d.ts
vendored
Normal file
1
utils/dist/mixins/observer/behavior.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const behavior: string;
|
||||
14
utils/dist/mixins/observer/behavior.js
vendored
Normal file
14
utils/dist/mixins/observer/behavior.js
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
export const behavior = Behavior({
|
||||
methods: {
|
||||
set(data, callback) {
|
||||
return new Promise(resolve => {
|
||||
this.setData(data, () => {
|
||||
if (callback && typeof callback === 'function') {
|
||||
callback.call(this);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
1
utils/dist/mixins/observer/index.d.ts
vendored
Normal file
1
utils/dist/mixins/observer/index.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare function observe(vantOptions: any, options: any): void;
|
||||
19
utils/dist/mixins/observer/index.js
vendored
Normal file
19
utils/dist/mixins/observer/index.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { behavior } from './behavior';
|
||||
export function observe(vantOptions, options) {
|
||||
const { watch } = vantOptions;
|
||||
options.behaviors.push(behavior);
|
||||
if (watch) {
|
||||
const props = options.properties || {};
|
||||
Object.keys(watch).forEach(key => {
|
||||
if (key in props) {
|
||||
let prop = props[key];
|
||||
if (prop === null || !('type' in prop)) {
|
||||
prop = { type: prop };
|
||||
}
|
||||
prop.observer = watch[key];
|
||||
props[key] = prop;
|
||||
}
|
||||
});
|
||||
options.properties = props;
|
||||
}
|
||||
}
|
||||
1
utils/dist/mixins/open-type.d.ts
vendored
Normal file
1
utils/dist/mixins/open-type.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const openType: string;
|
||||
25
utils/dist/mixins/open-type.js
vendored
Normal file
25
utils/dist/mixins/open-type.js
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
export const openType = Behavior({
|
||||
properties: {
|
||||
openType: String
|
||||
},
|
||||
methods: {
|
||||
bindGetUserInfo(event) {
|
||||
this.$emit('getuserinfo', event.detail);
|
||||
},
|
||||
bindContact(event) {
|
||||
this.$emit('contact', event.detail);
|
||||
},
|
||||
bindGetPhoneNumber(event) {
|
||||
this.$emit('getphonenumber', event.detail);
|
||||
},
|
||||
bindError(event) {
|
||||
this.$emit('error', event.detail);
|
||||
},
|
||||
bindLaunchApp(event) {
|
||||
this.$emit('launchapp', event.detail);
|
||||
},
|
||||
bindOpenSetting(event) {
|
||||
this.$emit('opensetting', event.detail);
|
||||
},
|
||||
}
|
||||
});
|
||||
1
utils/dist/mixins/touch.d.ts
vendored
Normal file
1
utils/dist/mixins/touch.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const touch: string;
|
||||
35
utils/dist/mixins/touch.js
vendored
Normal file
35
utils/dist/mixins/touch.js
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
const MIN_DISTANCE = 10;
|
||||
function getDirection(x, y) {
|
||||
if (x > y && x > MIN_DISTANCE) {
|
||||
return 'horizontal';
|
||||
}
|
||||
if (y > x && y > MIN_DISTANCE) {
|
||||
return 'vertical';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
export const touch = 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[0];
|
||||
this.startX = touch.clientX;
|
||||
this.startY = touch.clientY;
|
||||
},
|
||||
touchMove(event) {
|
||||
const touch = event.touches[0];
|
||||
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 = this.direction || getDirection(this.offsetX, this.offsetY);
|
||||
}
|
||||
}
|
||||
});
|
||||
1
utils/dist/mixins/transition.d.ts
vendored
Normal file
1
utils/dist/mixins/transition.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const transition: (showDefaultValue: boolean) => any;
|
||||
120
utils/dist/mixins/transition.js
vendored
Normal file
120
utils/dist/mixins/transition.js
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
import { isObj } from '../common/utils';
|
||||
const getClassNames = (name) => ({
|
||||
enter: `van-${name}-enter van-${name}-enter-active enter-class enter-active-class`,
|
||||
'enter-to': `van-${name}-enter-to van-${name}-enter-active enter-to-class enter-active-class`,
|
||||
leave: `van-${name}-leave van-${name}-leave-active leave-class leave-active-class`,
|
||||
'leave-to': `van-${name}-leave-to van-${name}-leave-active leave-to-class leave-active-class`
|
||||
});
|
||||
const nextTick = () => new Promise(resolve => setTimeout(resolve, 1000 / 30));
|
||||
export const transition = function (showDefaultValue) {
|
||||
return Behavior({
|
||||
properties: {
|
||||
customStyle: String,
|
||||
// @ts-ignore
|
||||
show: {
|
||||
type: Boolean,
|
||||
value: showDefaultValue,
|
||||
observer: 'observeShow'
|
||||
},
|
||||
// @ts-ignore
|
||||
duration: {
|
||||
type: null,
|
||||
value: 300,
|
||||
observer: 'observeDuration'
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
value: 'fade'
|
||||
}
|
||||
},
|
||||
data: {
|
||||
type: '',
|
||||
inited: false,
|
||||
display: false
|
||||
},
|
||||
attached() {
|
||||
if (this.data.show) {
|
||||
this.enter();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
observeShow(value) {
|
||||
value ? this.enter() : this.leave();
|
||||
},
|
||||
enter() {
|
||||
const { duration, name } = this.data;
|
||||
const classNames = getClassNames(name);
|
||||
const currentDuration = isObj(duration) ? duration.enter : duration;
|
||||
this.status = 'enter';
|
||||
this.$emit('before-enter');
|
||||
Promise.resolve()
|
||||
.then(nextTick)
|
||||
.then(() => {
|
||||
this.checkStatus('enter');
|
||||
this.$emit('enter');
|
||||
this.setData({
|
||||
inited: true,
|
||||
display: true,
|
||||
classes: classNames.enter,
|
||||
currentDuration
|
||||
});
|
||||
})
|
||||
.then(nextTick)
|
||||
.then(() => {
|
||||
this.checkStatus('enter');
|
||||
this.transitionEnded = false;
|
||||
this.setData({
|
||||
classes: classNames['enter-to']
|
||||
});
|
||||
})
|
||||
.catch(() => { });
|
||||
},
|
||||
leave() {
|
||||
if (!this.data.display) {
|
||||
return;
|
||||
}
|
||||
const { duration, name } = this.data;
|
||||
const classNames = getClassNames(name);
|
||||
const currentDuration = isObj(duration) ? duration.leave : duration;
|
||||
this.status = 'leave';
|
||||
this.$emit('before-leave');
|
||||
Promise.resolve()
|
||||
.then(nextTick)
|
||||
.then(() => {
|
||||
this.checkStatus('leave');
|
||||
this.$emit('leave');
|
||||
this.setData({
|
||||
classes: classNames.leave,
|
||||
currentDuration
|
||||
});
|
||||
})
|
||||
.then(nextTick)
|
||||
.then(() => {
|
||||
this.checkStatus('leave');
|
||||
this.transitionEnded = false;
|
||||
setTimeout(() => this.onTransitionEnd(), currentDuration);
|
||||
this.setData({
|
||||
classes: classNames['leave-to']
|
||||
});
|
||||
})
|
||||
.catch(() => { });
|
||||
},
|
||||
checkStatus(status) {
|
||||
if (status !== this.status) {
|
||||
throw new Error(`incongruent status: ${status}`);
|
||||
}
|
||||
},
|
||||
onTransitionEnd() {
|
||||
if (this.transitionEnded) {
|
||||
return;
|
||||
}
|
||||
this.transitionEnded = true;
|
||||
this.$emit(`after-${this.status}`);
|
||||
const { show, display } = this.data;
|
||||
if (!show && display) {
|
||||
this.setData({ display: false });
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user