init
This commit is contained in:
22
fuintUniapp/components/mixins/basic.js
Normal file
22
fuintUniapp/components/mixins/basic.js
Normal file
@@ -0,0 +1,22 @@
|
||||
export const basic = Behavior({
|
||||
methods: {
|
||||
$emit() {
|
||||
this.triggerEvent.apply(this, arguments);
|
||||
},
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
18
fuintUniapp/components/mixins/button.js
Normal file
18
fuintUniapp/components/mixins/button.js
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
|
||||
}
|
||||
});
|
||||
32
fuintUniapp/components/mixins/iphonex.js
Normal file
32
fuintUniapp/components/mixins/iphonex.js
Normal file
@@ -0,0 +1,32 @@
|
||||
let isIPhoneX = null;
|
||||
function getIsIPhoneX() {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (isIPhoneX !== null) {
|
||||
resolve(isIPhoneX);
|
||||
}
|
||||
else {
|
||||
wx.getSystemInfo({
|
||||
success: ({ model, screenHeight }) => {
|
||||
const iphoneX = /iphone x/i.test(model);
|
||||
const iphoneNew = /iPhone11/i.test(model) && screenHeight === 812;
|
||||
isIPhoneX = iphoneX || iphoneNew;
|
||||
resolve(isIPhoneX);
|
||||
},
|
||||
fail: reject
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
export const iphonex = Behavior({
|
||||
properties: {
|
||||
safeAreaInsetBottom: {
|
||||
type: Boolean,
|
||||
value: true
|
||||
}
|
||||
},
|
||||
created() {
|
||||
getIsIPhoneX().then(isIPhoneX => {
|
||||
this.set({ isIPhoneX });
|
||||
});
|
||||
}
|
||||
});
|
||||
17
fuintUniapp/components/mixins/link.js
Normal file
17
fuintUniapp/components/mixins/link.js
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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
47
fuintUniapp/components/mixins/observer/behavior.js
Normal file
47
fuintUniapp/components/mixins/observer/behavior.js
Normal file
@@ -0,0 +1,47 @@
|
||||
function setAsync(context, data) {
|
||||
return new Promise(resolve => {
|
||||
context.setData(data, resolve);
|
||||
});
|
||||
}
|
||||
;
|
||||
export const behavior = Behavior({
|
||||
created() {
|
||||
if (!this.$options) {
|
||||
return;
|
||||
}
|
||||
const cache = {};
|
||||
const { computed } = this.$options();
|
||||
const keys = Object.keys(computed);
|
||||
this.calcComputed = () => {
|
||||
const needUpdate = {};
|
||||
keys.forEach(key => {
|
||||
const value = computed[key].call(this);
|
||||
if (cache[key] !== value) {
|
||||
cache[key] = needUpdate[key] = value;
|
||||
}
|
||||
});
|
||||
return needUpdate;
|
||||
};
|
||||
},
|
||||
attached() {
|
||||
this.set();
|
||||
},
|
||||
methods: {
|
||||
// set data and set computed data
|
||||
set(data, callback) {
|
||||
const stack = [];
|
||||
if (data) {
|
||||
stack.push(setAsync(this, data));
|
||||
}
|
||||
if (this.calcComputed) {
|
||||
stack.push(setAsync(this, this.calcComputed()));
|
||||
}
|
||||
return Promise.all(stack).then(res => {
|
||||
if (callback && typeof callback === 'function') {
|
||||
callback.call(this);
|
||||
}
|
||||
return res;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
27
fuintUniapp/components/mixins/observer/index.js
Normal file
27
fuintUniapp/components/mixins/observer/index.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import { behavior } from './behavior';
|
||||
import { observeProps } from './props';
|
||||
export function observe(vantOptions, options) {
|
||||
const { watch, computed } = 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;
|
||||
}
|
||||
if (computed) {
|
||||
options.methods = options.methods || {};
|
||||
options.methods.$options = () => vantOptions;
|
||||
if (options.properties) {
|
||||
observeProps(options.properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
fuintUniapp/components/mixins/observer/props.js
Normal file
22
fuintUniapp/components/mixins/observer/props.js
Normal file
@@ -0,0 +1,22 @@
|
||||
export function observeProps(props) {
|
||||
if (!props) {
|
||||
return;
|
||||
}
|
||||
Object.keys(props).forEach(key => {
|
||||
let prop = props[key];
|
||||
if (prop === null || !('type' in prop)) {
|
||||
prop = { type: prop };
|
||||
}
|
||||
let { observer } = prop;
|
||||
prop.observer = function () {
|
||||
if (observer) {
|
||||
if (typeof observer === 'string') {
|
||||
observer = this[observer];
|
||||
}
|
||||
observer.apply(this, arguments);
|
||||
}
|
||||
this.set();
|
||||
};
|
||||
props[key] = prop;
|
||||
});
|
||||
}
|
||||
25
fuintUniapp/components/mixins/open-type.js
Normal file
25
fuintUniapp/components/mixins/open-type.js
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);
|
||||
},
|
||||
}
|
||||
});
|
||||
21
fuintUniapp/components/mixins/touch.js
Normal file
21
fuintUniapp/components/mixins/touch.js
Normal file
@@ -0,0 +1,21 @@
|
||||
export const touch = Behavior({
|
||||
methods: {
|
||||
touchStart(event) {
|
||||
this.direction = '';
|
||||
this.deltaX = 0;
|
||||
this.deltaY = 0;
|
||||
this.offsetX = 0;
|
||||
this.offsetY = 0;
|
||||
this.startX = event.touches[0].clientX;
|
||||
this.startY = event.touches[0].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.offsetX > this.offsetY ? 'horizontal' : this.offsetX < this.offsetY ? 'vertical' : '';
|
||||
}
|
||||
}
|
||||
});
|
||||
89
fuintUniapp/components/mixins/transition.js
Normal file
89
fuintUniapp/components/mixins/transition.js
Normal file
@@ -0,0 +1,89 @@
|
||||
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 requestAnimationFrame = (cb) => setTimeout(cb, 1000 / 60);
|
||||
export const transition = function (showDefaultValue) {
|
||||
return Behavior({
|
||||
properties: {
|
||||
customStyle: String,
|
||||
show: {
|
||||
type: Boolean,
|
||||
value: showDefaultValue,
|
||||
observer: 'observeShow'
|
||||
},
|
||||
duration: {
|
||||
type: [Number, Object],
|
||||
value: 300,
|
||||
observer: 'observeDuration'
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
value: 'fade',
|
||||
observer: 'updateClasses'
|
||||
}
|
||||
},
|
||||
data: {
|
||||
type: '',
|
||||
inited: false,
|
||||
display: false,
|
||||
classNames: getClassNames('fade')
|
||||
},
|
||||
attached() {
|
||||
if (this.data.show) {
|
||||
this.show();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
observeShow(value) {
|
||||
if (value) {
|
||||
this.show();
|
||||
}
|
||||
else {
|
||||
this.leave();
|
||||
}
|
||||
},
|
||||
updateClasses(name) {
|
||||
this.set({
|
||||
classNames: getClassNames(name)
|
||||
});
|
||||
},
|
||||
show() {
|
||||
const { classNames, duration } = this.data;
|
||||
this.set({
|
||||
inited: true,
|
||||
display: true,
|
||||
classes: classNames.enter,
|
||||
currentDuration: isObj(duration) ? duration.enter : duration
|
||||
}).then(() => {
|
||||
requestAnimationFrame(() => {
|
||||
this.set({
|
||||
classes: classNames['enter-to']
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
leave() {
|
||||
const { classNames, duration } = this.data;
|
||||
this.set({
|
||||
classes: classNames.leave,
|
||||
currentDuration: isObj(duration) ? duration.leave : duration
|
||||
}).then(() => {
|
||||
requestAnimationFrame(() => {
|
||||
this.set({
|
||||
classes: classNames['leave-to']
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
onTransitionEnd() {
|
||||
if (!this.data.show) {
|
||||
this.set({ display: false });
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user