mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
optimize code (#529)
This commit is contained in:
parent
92d09aba86
commit
172f97cdd5
5
dist/mixins/basic.js
vendored
5
dist/mixins/basic.js
vendored
@ -1,9 +1,4 @@
|
||||
export const basic = Behavior({
|
||||
options: {
|
||||
multipleSlots: true,
|
||||
addGlobalClass: true
|
||||
},
|
||||
|
||||
methods: {
|
||||
$emit() {
|
||||
this.triggerEvent.apply(this, arguments);
|
||||
|
27
dist/mixins/button.js
vendored
27
dist/mixins/button.js
vendored
@ -1,15 +1,12 @@
|
||||
export const button = Behavior({
|
||||
properties: {
|
||||
loading: Boolean,
|
||||
// 在自定义组件中,无法与外界的 form 组件联动,暂时不开放
|
||||
// formType: String,
|
||||
openType: String,
|
||||
appParameter: String,
|
||||
// 暂时不开放,直接传入无法设置样式
|
||||
// hoverClass: {
|
||||
// type: String,
|
||||
// value: 'button-hover'
|
||||
// },
|
||||
sendMessageTitle: String,
|
||||
sendMessagePath: String,
|
||||
sendMessageImg: String,
|
||||
showMessageCard: String,
|
||||
hoverStopPropagation: Boolean,
|
||||
hoverStartTime: {
|
||||
type: Number,
|
||||
@ -26,32 +23,28 @@ export const button = Behavior({
|
||||
sessionFrom: {
|
||||
type: String,
|
||||
value: ''
|
||||
},
|
||||
sendMessageTitle: String,
|
||||
sendMessagePath: String,
|
||||
sendMessageImg: String,
|
||||
showMessageCard: String
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
bindgetuserinfo(event = {}) {
|
||||
this.$emit('getuserinfo', event.detail || {});
|
||||
this.$emit('getuserinfo', event.detail);
|
||||
},
|
||||
|
||||
bindcontact(event = {}) {
|
||||
this.$emit('contact', event.detail || {});
|
||||
this.$emit('contact', event.detail);
|
||||
},
|
||||
|
||||
bindgetphonenumber(event = {}) {
|
||||
this.$emit('getphonenumber', event.detail || {});
|
||||
this.$emit('getphonenumber', event.detail);
|
||||
},
|
||||
|
||||
bindopensetting(event = {}) {
|
||||
this.$emit('opensetting', event.detail || {});
|
||||
this.$emit('opensetting', event.detail);
|
||||
},
|
||||
|
||||
binderror(event = {}) {
|
||||
this.$emit('error', event.detail || {});
|
||||
this.$emit('error', event.detail);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
16
dist/notify/notify.js
vendored
16
dist/notify/notify.js
vendored
@ -1,25 +1,25 @@
|
||||
import { isObj } from '../common/utils';
|
||||
|
||||
const defaultOptions = {
|
||||
selector: '#van-notify',
|
||||
duration: 3000
|
||||
};
|
||||
|
||||
function parseOptions(message) {
|
||||
return isObj(message) ? message : { message };
|
||||
}
|
||||
|
||||
export default function Notify(options = {}) {
|
||||
const pages = getCurrentPages();
|
||||
const ctx = pages[pages.length - 1];
|
||||
|
||||
options = Object.assign({}, defaultOptions, parseParam(options));
|
||||
options = Object.assign({}, defaultOptions, parseOptions(options));
|
||||
|
||||
const el = ctx.selectComponent(options.selector);
|
||||
delete options.selector;
|
||||
|
||||
if (el) {
|
||||
el.setData({
|
||||
...options
|
||||
});
|
||||
el.setData(options);
|
||||
el.show();
|
||||
}
|
||||
}
|
||||
|
||||
function parseParam(params = '') {
|
||||
return typeof params === 'object' ? params : { text: params };
|
||||
}
|
||||
|
12
dist/steps/index.js
vendored
12
dist/steps/index.js
vendored
@ -28,16 +28,10 @@ create({
|
||||
methods: {
|
||||
formatSteps() {
|
||||
const { steps } = this.data;
|
||||
const formattedSteps = steps.map((step, index) => {
|
||||
return {
|
||||
...step,
|
||||
status: this.getStatus(index)
|
||||
};
|
||||
});
|
||||
|
||||
this.setData({
|
||||
formattedSteps
|
||||
steps.forEach((step, index) => {
|
||||
step.status = this.getStatus(index);
|
||||
});
|
||||
this.setData({ steps });
|
||||
},
|
||||
|
||||
getStatus(index) {
|
||||
|
2
dist/steps/index.wxml
vendored
2
dist/steps/index.wxml
vendored
@ -1,6 +1,6 @@
|
||||
<view class="custom-class van-steps van-steps--{{ direction }}">
|
||||
<view
|
||||
wx:for="{{ formattedSteps }}"
|
||||
wx:for="{{ steps }}"
|
||||
wx:key="index"
|
||||
class="van-step van-hairline van-step--{{ direction }} {{ item.status ? 'van-step--' + item.status : '' }}"
|
||||
style="{{ width ? 'width:' + width + 'px' : '' }}"
|
||||
|
5
dist/toast/toast.js
vendored
5
dist/toast/toast.js
vendored
@ -11,11 +11,14 @@ const defaultOptions = {
|
||||
loadingType: 'circular',
|
||||
selector: '#van-toast'
|
||||
};
|
||||
const parseOptions = message => isObj(message) ? message : { message };
|
||||
|
||||
let queue = [];
|
||||
let currentOptions = { ...defaultOptions };
|
||||
|
||||
function parseOptions(message) {
|
||||
return isObj(message) ? message : { message };
|
||||
}
|
||||
|
||||
function Toast(options = {}) {
|
||||
options = {
|
||||
...currentOptions,
|
||||
|
10
dist/tree-select/index.js
vendored
10
dist/tree-select/index.js
vendored
@ -39,18 +39,12 @@ create({
|
||||
methods: {
|
||||
// 当一个子项被选择时
|
||||
onSelectItem(event) {
|
||||
const {
|
||||
dataset = {}
|
||||
} = event.currentTarget || {};
|
||||
this.$emit('click-item', { ...(dataset.item || {}) });
|
||||
this.$emit('click-item', event.currentTarget.dataset.item);
|
||||
},
|
||||
|
||||
// 当一个导航被点击时
|
||||
onClickNav(event) {
|
||||
const {
|
||||
dataset = {}
|
||||
} = event.currentTarget || {};
|
||||
this.$emit('click-nav', { index: dataset.index });
|
||||
this.$emit('click-nav', event.currentTarget.dataset.index);
|
||||
},
|
||||
|
||||
// 更新子项列表
|
||||
|
2
dist/tree-select/index.wxml
vendored
2
dist/tree-select/index.wxml
vendored
@ -19,7 +19,7 @@
|
||||
>
|
||||
<view
|
||||
wx:for="{{ subItems }}"
|
||||
wx:key="id"
|
||||
wx:key="item.id"
|
||||
class="tree-select__item van-ellipsis {{ activeId === item.id ? 'tree-select__item--active' : '' }}"
|
||||
data-item="{{ item }}"
|
||||
bind:tap="onSelectItem"
|
||||
|
@ -1,9 +1,4 @@
|
||||
export const basic = Behavior({
|
||||
options: {
|
||||
multipleSlots: true,
|
||||
addGlobalClass: true
|
||||
},
|
||||
|
||||
methods: {
|
||||
$emit() {
|
||||
this.triggerEvent.apply(this, arguments);
|
||||
|
@ -1,15 +1,12 @@
|
||||
export const button = Behavior({
|
||||
properties: {
|
||||
loading: Boolean,
|
||||
// 在自定义组件中,无法与外界的 form 组件联动,暂时不开放
|
||||
// formType: String,
|
||||
openType: String,
|
||||
appParameter: String,
|
||||
// 暂时不开放,直接传入无法设置样式
|
||||
// hoverClass: {
|
||||
// type: String,
|
||||
// value: 'button-hover'
|
||||
// },
|
||||
sendMessageTitle: String,
|
||||
sendMessagePath: String,
|
||||
sendMessageImg: String,
|
||||
showMessageCard: String,
|
||||
hoverStopPropagation: Boolean,
|
||||
hoverStartTime: {
|
||||
type: Number,
|
||||
@ -26,32 +23,28 @@ export const button = Behavior({
|
||||
sessionFrom: {
|
||||
type: String,
|
||||
value: ''
|
||||
},
|
||||
sendMessageTitle: String,
|
||||
sendMessagePath: String,
|
||||
sendMessageImg: String,
|
||||
showMessageCard: String
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
bindgetuserinfo(event = {}) {
|
||||
this.$emit('getuserinfo', event.detail || {});
|
||||
this.$emit('getuserinfo', event.detail);
|
||||
},
|
||||
|
||||
bindcontact(event = {}) {
|
||||
this.$emit('contact', event.detail || {});
|
||||
this.$emit('contact', event.detail);
|
||||
},
|
||||
|
||||
bindgetphonenumber(event = {}) {
|
||||
this.$emit('getphonenumber', event.detail || {});
|
||||
this.$emit('getphonenumber', event.detail);
|
||||
},
|
||||
|
||||
bindopensetting(event = {}) {
|
||||
this.$emit('opensetting', event.detail || {});
|
||||
this.$emit('opensetting', event.detail);
|
||||
},
|
||||
|
||||
binderror(event = {}) {
|
||||
this.$emit('error', event.detail || {});
|
||||
this.$emit('error', event.detail);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1,25 +1,25 @@
|
||||
import { isObj } from '../common/utils';
|
||||
|
||||
const defaultOptions = {
|
||||
selector: '#van-notify',
|
||||
duration: 3000
|
||||
};
|
||||
|
||||
function parseOptions(message) {
|
||||
return isObj(message) ? message : { message };
|
||||
}
|
||||
|
||||
export default function Notify(options = {}) {
|
||||
const pages = getCurrentPages();
|
||||
const ctx = pages[pages.length - 1];
|
||||
|
||||
options = Object.assign({}, defaultOptions, parseParam(options));
|
||||
options = Object.assign({}, defaultOptions, parseOptions(options));
|
||||
|
||||
const el = ctx.selectComponent(options.selector);
|
||||
delete options.selector;
|
||||
|
||||
if (el) {
|
||||
el.setData({
|
||||
...options
|
||||
});
|
||||
el.setData(options);
|
||||
el.show();
|
||||
}
|
||||
}
|
||||
|
||||
function parseParam(params = '') {
|
||||
return typeof params === 'object' ? params : { text: params };
|
||||
}
|
||||
|
@ -28,16 +28,10 @@ create({
|
||||
methods: {
|
||||
formatSteps() {
|
||||
const { steps } = this.data;
|
||||
const formattedSteps = steps.map((step, index) => {
|
||||
return {
|
||||
...step,
|
||||
status: this.getStatus(index)
|
||||
};
|
||||
});
|
||||
|
||||
this.setData({
|
||||
formattedSteps
|
||||
steps.forEach((step, index) => {
|
||||
step.status = this.getStatus(index);
|
||||
});
|
||||
this.setData({ steps });
|
||||
},
|
||||
|
||||
getStatus(index) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
<view class="custom-class van-steps van-steps--{{ direction }}">
|
||||
<view
|
||||
wx:for="{{ formattedSteps }}"
|
||||
wx:for="{{ steps }}"
|
||||
wx:key="index"
|
||||
class="van-step van-hairline van-step--{{ direction }} {{ item.status ? 'van-step--' + item.status : '' }}"
|
||||
style="{{ width ? 'width:' + width + 'px' : '' }}"
|
||||
|
@ -11,11 +11,14 @@ const defaultOptions = {
|
||||
loadingType: 'circular',
|
||||
selector: '#van-toast'
|
||||
};
|
||||
const parseOptions = message => isObj(message) ? message : { message };
|
||||
|
||||
let queue = [];
|
||||
let currentOptions = { ...defaultOptions };
|
||||
|
||||
function parseOptions(message) {
|
||||
return isObj(message) ? message : { message };
|
||||
}
|
||||
|
||||
function Toast(options = {}) {
|
||||
options = {
|
||||
...currentOptions,
|
||||
|
@ -39,18 +39,12 @@ create({
|
||||
methods: {
|
||||
// 当一个子项被选择时
|
||||
onSelectItem(event) {
|
||||
const {
|
||||
dataset = {}
|
||||
} = event.currentTarget || {};
|
||||
this.$emit('click-item', { ...(dataset.item || {}) });
|
||||
this.$emit('click-item', event.currentTarget.dataset.item);
|
||||
},
|
||||
|
||||
// 当一个导航被点击时
|
||||
onClickNav(event) {
|
||||
const {
|
||||
dataset = {}
|
||||
} = event.currentTarget || {};
|
||||
this.$emit('click-nav', { index: dataset.index });
|
||||
this.$emit('click-nav', event.currentTarget.dataset.index);
|
||||
},
|
||||
|
||||
// 更新子项列表
|
||||
|
@ -19,7 +19,7 @@
|
||||
>
|
||||
<view
|
||||
wx:for="{{ subItems }}"
|
||||
wx:key="id"
|
||||
wx:key="item.id"
|
||||
class="tree-select__item van-ellipsis {{ activeId === item.id ? 'tree-select__item--active' : '' }}"
|
||||
data-item="{{ item }}"
|
||||
bind:tap="onSelectItem"
|
||||
|
Loading…
x
Reference in New Issue
Block a user