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({
options: {
multipleSlots: true,
addGlobalClass: true
},
methods: {
$emit() {
this.triggerEvent.apply(this, arguments);

27
dist/mixins/button.js vendored
View File

@ -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
View File

@ -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
View File

@ -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) {

View File

@ -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
View File

@ -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,

View File

@ -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);
},
// 更新子项列表

View File

@ -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"

View File

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

View File

@ -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);
}
}
});

View File

@ -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 };
}

View File

@ -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) {

View File

@ -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' : '' }}"

View File

@ -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,

View File

@ -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);
},
// 更新子项列表

View File

@ -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"