optimize code (#529)

This commit is contained in:
neverland 2018-09-07 13:32:00 +08:00 committed by GitHub
parent 92d09aba86
commit 172f97cdd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 58 additions and 100 deletions

View File

@ -1,9 +1,4 @@
export const basic = Behavior({ export const basic = Behavior({
options: {
multipleSlots: true,
addGlobalClass: true
},
methods: { methods: {
$emit() { $emit() {
this.triggerEvent.apply(this, arguments); this.triggerEvent.apply(this, arguments);

27
dist/mixins/button.js vendored
View File

@ -1,15 +1,12 @@
export const button = Behavior({ export const button = Behavior({
properties: { properties: {
loading: Boolean, loading: Boolean,
// 在自定义组件中,无法与外界的 form 组件联动,暂时不开放
// formType: String,
openType: String, openType: String,
appParameter: String, appParameter: String,
// 暂时不开放,直接传入无法设置样式 sendMessageTitle: String,
// hoverClass: { sendMessagePath: String,
// type: String, sendMessageImg: String,
// value: 'button-hover' showMessageCard: String,
// },
hoverStopPropagation: Boolean, hoverStopPropagation: Boolean,
hoverStartTime: { hoverStartTime: {
type: Number, type: Number,
@ -26,32 +23,28 @@ export const button = Behavior({
sessionFrom: { sessionFrom: {
type: String, type: String,
value: '' value: ''
}, }
sendMessageTitle: String,
sendMessagePath: String,
sendMessageImg: String,
showMessageCard: String
}, },
methods: { methods: {
bindgetuserinfo(event = {}) { bindgetuserinfo(event = {}) {
this.$emit('getuserinfo', event.detail || {}); this.$emit('getuserinfo', event.detail);
}, },
bindcontact(event = {}) { bindcontact(event = {}) {
this.$emit('contact', event.detail || {}); this.$emit('contact', event.detail);
}, },
bindgetphonenumber(event = {}) { bindgetphonenumber(event = {}) {
this.$emit('getphonenumber', event.detail || {}); this.$emit('getphonenumber', event.detail);
}, },
bindopensetting(event = {}) { bindopensetting(event = {}) {
this.$emit('opensetting', event.detail || {}); this.$emit('opensetting', event.detail);
}, },
binderror(event = {}) { binderror(event = {}) {
this.$emit('error', event.detail || {}); this.$emit('error', event.detail);
} }
} }
}); });

16
dist/notify/notify.js vendored
View File

@ -1,25 +1,25 @@
import { isObj } from '../common/utils';
const defaultOptions = { const defaultOptions = {
selector: '#van-notify', selector: '#van-notify',
duration: 3000 duration: 3000
}; };
function parseOptions(message) {
return isObj(message) ? message : { message };
}
export default function Notify(options = {}) { export default function Notify(options = {}) {
const pages = getCurrentPages(); const pages = getCurrentPages();
const ctx = pages[pages.length - 1]; const ctx = pages[pages.length - 1];
options = Object.assign({}, defaultOptions, parseParam(options)); options = Object.assign({}, defaultOptions, parseOptions(options));
const el = ctx.selectComponent(options.selector); const el = ctx.selectComponent(options.selector);
delete options.selector; delete options.selector;
if (el) { if (el) {
el.setData({ el.setData(options);
...options
});
el.show(); el.show();
} }
} }
function parseParam(params = '') {
return typeof params === 'object' ? params : { text: params };
}

12
dist/steps/index.js vendored
View File

@ -28,16 +28,10 @@ create({
methods: { methods: {
formatSteps() { formatSteps() {
const { steps } = this.data; const { steps } = this.data;
const formattedSteps = steps.map((step, index) => { steps.forEach((step, index) => {
return { step.status = this.getStatus(index);
...step,
status: this.getStatus(index)
};
});
this.setData({
formattedSteps
}); });
this.setData({ steps });
}, },
getStatus(index) { getStatus(index) {

View File

@ -1,6 +1,6 @@
<view class="custom-class van-steps van-steps--{{ direction }}"> <view class="custom-class van-steps van-steps--{{ direction }}">
<view <view
wx:for="{{ formattedSteps }}" wx:for="{{ steps }}"
wx:key="index" wx:key="index"
class="van-step van-hairline van-step--{{ direction }} {{ item.status ? 'van-step--' + item.status : '' }}" class="van-step van-hairline van-step--{{ direction }} {{ item.status ? 'van-step--' + item.status : '' }}"
style="{{ width ? 'width:' + width + 'px' : '' }}" style="{{ width ? 'width:' + width + 'px' : '' }}"

5
dist/toast/toast.js vendored
View File

@ -11,11 +11,14 @@ const defaultOptions = {
loadingType: 'circular', loadingType: 'circular',
selector: '#van-toast' selector: '#van-toast'
}; };
const parseOptions = message => isObj(message) ? message : { message };
let queue = []; let queue = [];
let currentOptions = { ...defaultOptions }; let currentOptions = { ...defaultOptions };
function parseOptions(message) {
return isObj(message) ? message : { message };
}
function Toast(options = {}) { function Toast(options = {}) {
options = { options = {
...currentOptions, ...currentOptions,

View File

@ -39,18 +39,12 @@ create({
methods: { methods: {
// 当一个子项被选择时 // 当一个子项被选择时
onSelectItem(event) { onSelectItem(event) {
const { this.$emit('click-item', event.currentTarget.dataset.item);
dataset = {}
} = event.currentTarget || {};
this.$emit('click-item', { ...(dataset.item || {}) });
}, },
// 当一个导航被点击时 // 当一个导航被点击时
onClickNav(event) { onClickNav(event) {
const { this.$emit('click-nav', event.currentTarget.dataset.index);
dataset = {}
} = event.currentTarget || {};
this.$emit('click-nav', { index: dataset.index });
}, },
// 更新子项列表 // 更新子项列表

View File

@ -19,7 +19,7 @@
> >
<view <view
wx:for="{{ subItems }}" wx:for="{{ subItems }}"
wx:key="id" wx:key="item.id"
class="tree-select__item van-ellipsis {{ activeId === item.id ? 'tree-select__item--active' : '' }}" class="tree-select__item van-ellipsis {{ activeId === item.id ? 'tree-select__item--active' : '' }}"
data-item="{{ item }}" data-item="{{ item }}"
bind:tap="onSelectItem" bind:tap="onSelectItem"

View File

@ -1,9 +1,4 @@
export const basic = Behavior({ export const basic = Behavior({
options: {
multipleSlots: true,
addGlobalClass: true
},
methods: { methods: {
$emit() { $emit() {
this.triggerEvent.apply(this, arguments); this.triggerEvent.apply(this, arguments);

View File

@ -1,15 +1,12 @@
export const button = Behavior({ export const button = Behavior({
properties: { properties: {
loading: Boolean, loading: Boolean,
// 在自定义组件中,无法与外界的 form 组件联动,暂时不开放
// formType: String,
openType: String, openType: String,
appParameter: String, appParameter: String,
// 暂时不开放,直接传入无法设置样式 sendMessageTitle: String,
// hoverClass: { sendMessagePath: String,
// type: String, sendMessageImg: String,
// value: 'button-hover' showMessageCard: String,
// },
hoverStopPropagation: Boolean, hoverStopPropagation: Boolean,
hoverStartTime: { hoverStartTime: {
type: Number, type: Number,
@ -26,32 +23,28 @@ export const button = Behavior({
sessionFrom: { sessionFrom: {
type: String, type: String,
value: '' value: ''
}, }
sendMessageTitle: String,
sendMessagePath: String,
sendMessageImg: String,
showMessageCard: String
}, },
methods: { methods: {
bindgetuserinfo(event = {}) { bindgetuserinfo(event = {}) {
this.$emit('getuserinfo', event.detail || {}); this.$emit('getuserinfo', event.detail);
}, },
bindcontact(event = {}) { bindcontact(event = {}) {
this.$emit('contact', event.detail || {}); this.$emit('contact', event.detail);
}, },
bindgetphonenumber(event = {}) { bindgetphonenumber(event = {}) {
this.$emit('getphonenumber', event.detail || {}); this.$emit('getphonenumber', event.detail);
}, },
bindopensetting(event = {}) { bindopensetting(event = {}) {
this.$emit('opensetting', event.detail || {}); this.$emit('opensetting', event.detail);
}, },
binderror(event = {}) { binderror(event = {}) {
this.$emit('error', event.detail || {}); this.$emit('error', event.detail);
} }
} }
}); });

View File

@ -1,25 +1,25 @@
import { isObj } from '../common/utils';
const defaultOptions = { const defaultOptions = {
selector: '#van-notify', selector: '#van-notify',
duration: 3000 duration: 3000
}; };
function parseOptions(message) {
return isObj(message) ? message : { message };
}
export default function Notify(options = {}) { export default function Notify(options = {}) {
const pages = getCurrentPages(); const pages = getCurrentPages();
const ctx = pages[pages.length - 1]; const ctx = pages[pages.length - 1];
options = Object.assign({}, defaultOptions, parseParam(options)); options = Object.assign({}, defaultOptions, parseOptions(options));
const el = ctx.selectComponent(options.selector); const el = ctx.selectComponent(options.selector);
delete options.selector; delete options.selector;
if (el) { if (el) {
el.setData({ el.setData(options);
...options
});
el.show(); el.show();
} }
} }
function parseParam(params = '') {
return typeof params === 'object' ? params : { text: params };
}

View File

@ -28,16 +28,10 @@ create({
methods: { methods: {
formatSteps() { formatSteps() {
const { steps } = this.data; const { steps } = this.data;
const formattedSteps = steps.map((step, index) => { steps.forEach((step, index) => {
return { step.status = this.getStatus(index);
...step,
status: this.getStatus(index)
};
});
this.setData({
formattedSteps
}); });
this.setData({ steps });
}, },
getStatus(index) { getStatus(index) {

View File

@ -1,6 +1,6 @@
<view class="custom-class van-steps van-steps--{{ direction }}"> <view class="custom-class van-steps van-steps--{{ direction }}">
<view <view
wx:for="{{ formattedSteps }}" wx:for="{{ steps }}"
wx:key="index" wx:key="index"
class="van-step van-hairline van-step--{{ direction }} {{ item.status ? 'van-step--' + item.status : '' }}" class="van-step van-hairline van-step--{{ direction }} {{ item.status ? 'van-step--' + item.status : '' }}"
style="{{ width ? 'width:' + width + 'px' : '' }}" style="{{ width ? 'width:' + width + 'px' : '' }}"

View File

@ -11,11 +11,14 @@ const defaultOptions = {
loadingType: 'circular', loadingType: 'circular',
selector: '#van-toast' selector: '#van-toast'
}; };
const parseOptions = message => isObj(message) ? message : { message };
let queue = []; let queue = [];
let currentOptions = { ...defaultOptions }; let currentOptions = { ...defaultOptions };
function parseOptions(message) {
return isObj(message) ? message : { message };
}
function Toast(options = {}) { function Toast(options = {}) {
options = { options = {
...currentOptions, ...currentOptions,

View File

@ -39,18 +39,12 @@ create({
methods: { methods: {
// 当一个子项被选择时 // 当一个子项被选择时
onSelectItem(event) { onSelectItem(event) {
const { this.$emit('click-item', event.currentTarget.dataset.item);
dataset = {}
} = event.currentTarget || {};
this.$emit('click-item', { ...(dataset.item || {}) });
}, },
// 当一个导航被点击时 // 当一个导航被点击时
onClickNav(event) { onClickNav(event) {
const { this.$emit('click-nav', event.currentTarget.dataset.index);
dataset = {}
} = event.currentTarget || {};
this.$emit('click-nav', { index: dataset.index });
}, },
// 更新子项列表 // 更新子项列表

View File

@ -19,7 +19,7 @@
> >
<view <view
wx:for="{{ subItems }}" wx:for="{{ subItems }}"
wx:key="id" wx:key="item.id"
class="tree-select__item van-ellipsis {{ activeId === item.id ? 'tree-select__item--active' : '' }}" class="tree-select__item van-ellipsis {{ activeId === item.id ? 'tree-select__item--active' : '' }}"
data-item="{{ item }}" data-item="{{ item }}"
bind:tap="onSelectItem" bind:tap="onSelectItem"