diff --git a/src/area/index.js b/src/area/index.js index ef999d8a4..446482564 100644 --- a/src/area/index.js +++ b/src/area/index.js @@ -112,12 +112,12 @@ export default createComponent({ if (this.placeholderMap[type] && result.length) { // set columns placeholder - const codeFill = - type === 'province' - ? '' - : type === 'city' - ? PLACEHOLDER_CODE.slice(2, 4) - : PLACEHOLDER_CODE.slice(4, 6); + let codeFill = ''; + if (type === 'city') { + codeFill = PLACEHOLDER_CODE.slice(2, 4); + } else if (type === 'county') { + codeFill = PLACEHOLDER_CODE.slice(4, 6); + } result.unshift({ code: `${code}${codeFill}`, diff --git a/src/checkbox/index.js b/src/checkbox/index.js index e89f49245..507f6f9c9 100644 --- a/src/checkbox/index.js +++ b/src/checkbox/index.js @@ -4,16 +4,21 @@ import { CheckboxMixin } from '../mixins/checkbox'; const [createComponent, bem] = createNamespace('checkbox'); export default createComponent({ - mixins: [CheckboxMixin({ - bem, - role: 'checkbox', - parent: 'vanCheckbox', - })], + mixins: [ + CheckboxMixin({ + bem, + role: 'checkbox', + parent: 'vanCheckbox', + }), + ], computed: { checked: { get() { - return this.parent ? this.parent.value.indexOf(this.name) !== -1 : this.value; + if (this.parent) { + return this.parent.value.indexOf(this.name) !== -1; + } + return this.value; }, set(val) { diff --git a/src/collapse-item/index.js b/src/collapse-item/index.js index bce427033..6a16a4a6b 100644 --- a/src/collapse-item/index.js +++ b/src/collapse-item/index.js @@ -106,9 +106,10 @@ export default createComponent({ } const { parent, currentName } = this; - const name = parent.accordion && currentName === parent.value ? '' : currentName; + const close = parent.accordion && currentName === parent.value; + const name = close ? '' : currentName; - this.parent.switch(name, !this.expanded); + parent.switch(name, !this.expanded); }, onTransitionEnd() { diff --git a/src/coupon-list/index.js b/src/coupon-list/index.js index 24354dc83..e28e3a50e 100644 --- a/src/coupon-list/index.js +++ b/src/coupon-list/index.js @@ -182,7 +182,10 @@ export default createComponent({ const CouponTab = ( -
+
{coupons.map((coupon, index) => ( -
+
{disabledCoupons.map(coupon => ( ${this.currency} ${formatAmount(this.coupon.denominations)}`; + const denominations = formatAmount(this.coupon.denominations); + return `${this.currency} ${denominations}`; } if (coupon.discount) { @@ -70,13 +73,20 @@ export default createComponent({

-

{this.coupon.condition || this.conditionMessage}

+

+ {this.coupon.condition || this.conditionMessage} +

{coupon.name}

{this.validPeriod}

{!this.disabled && ( - + )}
diff --git a/src/datetime-picker/DatePicker.js b/src/datetime-picker/DatePicker.js index 9b3d6b78b..b8aa80058 100644 --- a/src/datetime-picker/DatePicker.js +++ b/src/datetime-picker/DatePicker.js @@ -44,15 +44,21 @@ export default createComponent({ computed: { ranges() { - const { maxYear, maxDate, maxMonth, maxHour, maxMinute } = this.getBoundary( - 'max', - this.innerValue - ); + const { + maxYear, + maxDate, + maxMonth, + maxHour, + maxMinute, + } = this.getBoundary('max', this.innerValue); - const { minYear, minDate, minMonth, minHour, minMinute } = this.getBoundary( - 'min', - this.innerValue - ); + const { + minYear, + minDate, + minMonth, + minHour, + minMinute, + } = this.getBoundary('min', this.innerValue); const result = [ { @@ -134,7 +140,11 @@ export default createComponent({ updateInnerValue() { const indexes = this.getPicker().getIndexes(); - const getValue = index => getTrueValue(this.originColumns[index].values[indexes[index]]); + + const getValue = index => { + const { values } = this.originColumns[index]; + return getTrueValue(values[indexes[index]]); + }; const year = getValue(0); const month = getValue(1); diff --git a/src/datetime-picker/TimePicker.js b/src/datetime-picker/TimePicker.js index cc4e13eed..12e781fc6 100644 --- a/src/datetime-picker/TimePicker.js +++ b/src/datetime-picker/TimePicker.js @@ -75,11 +75,12 @@ export default createComponent({ updateInnerValue() { const [hourIndex, minuteIndex] = this.getPicker().getIndexes(); - const hour = this.originColumns[0].values[hourIndex] || this.originColumns[0].values[0]; - const minute = this.originColumns[1].values[minuteIndex] || this.originColumns[1].values[0]; - const value = `${hour}:${minute}`; + const [hourColumn, minuteColumn] = this.originColumns; - this.innerValue = this.formatValue(value); + const hour = hourColumn.values[hourIndex] || hourColumn.values[0]; + const minute = minuteColumn.values[minuteIndex] || minuteColumn.values[0]; + + this.innerValue = this.formatValue(`${hour}:${minute}`); }, onChange(picker) { diff --git a/src/dialog/Dialog.js b/src/dialog/Dialog.js index 7b19cbc9a..621e38c6d 100644 --- a/src/dialog/Dialog.js +++ b/src/dialog/Dialog.js @@ -103,7 +103,9 @@ export default createComponent({ const title = this.slots('title') || this.title; const Title = title && ( -
{title}
+
+ {title} +
); const Content = (messageSlot || message) && ( @@ -111,7 +113,10 @@ export default createComponent({ {messageSlot || (
)}
diff --git a/src/dialog/index.js b/src/dialog/index.js index f803c01e8..c66fcfcd6 100644 --- a/src/dialog/index.js +++ b/src/dialog/index.js @@ -73,10 +73,11 @@ Dialog.defaultOptions = { Dialog.alert = Dialog; -Dialog.confirm = options => Dialog({ - showCancelButton: true, - ...options, -}); +Dialog.confirm = options => + Dialog({ + showCancelButton: true, + ...options, + }); Dialog.close = () => { if (instance) { diff --git a/src/dropdown-menu/index.js b/src/dropdown-menu/index.js index c65c78762..d898413cb 100644 --- a/src/dropdown-menu/index.js +++ b/src/dropdown-menu/index.js @@ -102,7 +102,9 @@ export default createComponent({ ]} style={{ color: item.showPopup ? this.activeColor : '' }} > -
{item.slots('title') || item.displayTitle}
+
+ {item.slots('title') || item.displayTitle} +
)); diff --git a/src/grid-item/index.js b/src/grid-item/index.js index 88ce87579..8d9f2b680 100644 --- a/src/grid-item/index.js +++ b/src/grid-item/index.js @@ -87,6 +87,18 @@ export default createComponent({ } }, + getText() { + const textSlot = this.slots('text'); + + if (textSlot) { + return textSlot; + } + + if (this.text) { + return {this.text}; + } + }, + genContent() { const slot = this.slots(); @@ -94,10 +106,7 @@ export default createComponent({ return slot; } - return [ - this.genIcon(), - this.slots('text') || (this.text && {this.text}), - ]; + return [this.genIcon(), this.getText()]; }, }, diff --git a/src/notice-bar/index.js b/src/notice-bar/index.js index ea8329577..e5fed29b4 100644 --- a/src/notice-bar/index.js +++ b/src/notice-bar/index.js @@ -109,9 +109,21 @@ export default createComponent({ return slot; } - const iconName = mode === 'closeable' ? 'cross' : mode === 'link' ? 'arrow' : ''; + let iconName; + if (mode === 'closeable') { + iconName = 'cross'; + } else if (mode === 'link') { + iconName = 'arrow'; + } + if (iconName) { - return ; + return ( + + ); } } diff --git a/src/number-keyboard/index.js b/src/number-keyboard/index.js index f8ef9c573..b46494545 100644 --- a/src/number-keyboard/index.js +++ b/src/number-keyboard/index.js @@ -145,10 +145,17 @@ export default createComponent({ const Title = showTitle && (
- {titleLeftSlot && {titleLeftSlot}} + {titleLeftSlot && ( + {titleLeftSlot} + )} {title && {title}} {showTitleClose && ( - + {closeButtonText} )} @@ -192,7 +199,10 @@ export default createComponent({
))} {simple && ( -
  • {this.slots('pageDesc') || `${value}/${this.count}`}
  • +
  • + {this.slots('pageDesc') || `${value}/${this.count}`} +
  • )}
  • {this.nextText || t('next')} diff --git a/src/picker/index.js b/src/picker/index.js index 2391cae58..c6d2b1e9f 100644 --- a/src/picker/index.js +++ b/src/picker/index.js @@ -180,11 +180,7 @@ export default createComponent({ return (
    {this.slots() || [ - , this.genTitle(), diff --git a/src/radio/index.js b/src/radio/index.js index e69d2c32f..3b9584a97 100644 --- a/src/radio/index.js +++ b/src/radio/index.js @@ -4,11 +4,13 @@ import { CheckboxMixin } from '../mixins/checkbox'; const [createComponent, bem] = createNamespace('radio'); export default createComponent({ - mixins: [CheckboxMixin({ - bem, - role: 'radio', - parent: 'vanRadio', - })], + mixins: [ + CheckboxMixin({ + bem, + role: 'radio', + parent: 'vanRadio', + }), + ], computed: { currentValue: { diff --git a/src/row/index.js b/src/row/index.js index a27f2a08b..1e233bdfb 100644 --- a/src/row/index.js +++ b/src/row/index.js @@ -27,7 +27,9 @@ export default createComponent({ const { align, justify } = this; const flex = this.type === 'flex'; const margin = `-${Number(this.gutter) / 2}px`; - const style = this.gutter ? { marginLeft: margin, marginRight: margin } : {}; + const style = this.gutter + ? { marginLeft: margin, marginRight: margin } + : {}; return ( (this.selectedProp[it.k_id] || []).length < 1)) { + if ( + this.propList.some(it => (this.selectedProp[it.k_id] || []).length < 1) + ) { return false; } return true; @@ -193,8 +195,14 @@ export default createComponent({ }; } if (skuComb) { - skuComb.properties = getSelectedProperties(this.propList, this.selectedProp); - skuComb.property_price = this.selectedPropValues.reduce((acc, cur) => acc + (cur.price || 0), 0); + skuComb.properties = getSelectedProperties( + this.propList, + this.selectedProp + ); + skuComb.property_price = this.selectedPropValues.reduce( + (acc, cur) => acc + (cur.price || 0), + 0 + ); } } return skuComb; @@ -210,7 +218,10 @@ export default createComponent({ price() { if (this.selectedSkuComb) { - return ((this.selectedSkuComb.price + this.selectedSkuComb.property_price) / 100).toFixed(2); + return ( + (this.selectedSkuComb.price + this.selectedSkuComb.property_price) / + 100 + ).toFixed(2); } // sku.price是一个格式化好的价格区间 return this.sku.price; @@ -218,7 +229,11 @@ export default createComponent({ originPrice() { if (this.selectedSkuComb && this.selectedSkuComb.origin_price) { - return ((this.selectedSkuComb.origin_price + this.selectedSkuComb.property_price) / 100).toFixed(2); + return ( + (this.selectedSkuComb.origin_price + + this.selectedSkuComb.property_price) / + 100 + ).toFixed(2); } return this.sku.origin_price; }, @@ -269,7 +284,11 @@ export default createComponent({ return [ `${t('stock')} `, - + {this.stock} , ` ${t('stockUnit')}`, @@ -289,7 +308,9 @@ export default createComponent({ .filter(item => (this.selectedProp[item.k_id] || []).length < 1) .map(item => item.k); - return `${t('select')} ${unselectedSku.concat(unselectedProp).join(';')}`; + return `${t('select')} ${unselectedSku + .concat(unselectedProp) + .join(';')}`; }, }, @@ -335,7 +356,8 @@ export default createComponent({ // 重置 selectedSku this.skuTree.forEach(item => { - this.selectedSku[item.k_s] = this.initialSku[item.k_s] || UNSELECTED_SKU_VALUE_ID; + this.selectedSku[item.k_s] = + this.initialSku[item.k_s] || UNSELECTED_SKU_VALUE_ID; }); // 只有一个 sku 规格值时默认选中 @@ -389,11 +411,15 @@ export default createComponent({ }, getSkuCartMessages() { - return this.$refs.skuMessages ? this.$refs.skuMessages.getCartMessages() : {}; + return this.$refs.skuMessages + ? this.$refs.skuMessages.getCartMessages() + : {}; }, validateSkuMessages() { - return this.$refs.skuMessages ? this.$refs.skuMessages.validateMessages() : ''; + return this.$refs.skuMessages + ? this.$refs.skuMessages.validateMessages() + : ''; }, validateSku() { @@ -418,7 +444,10 @@ export default createComponent({ // 点击已选中的sku时则取消选中 this.selectedSku = this.selectedSku[skuValue.skuKeyStr] === skuValue.id - ? { ...this.selectedSku, [skuValue.skuKeyStr]: UNSELECTED_SKU_VALUE_ID } + ? { + ...this.selectedSku, + [skuValue.skuKeyStr]: UNSELECTED_SKU_VALUE_ID, + } : { ...this.selectedSku, [skuValue.skuKeyStr]: skuValue.id }; this.$emit('sku-selected', { @@ -575,19 +604,27 @@ export default createComponent({ const slots = name => this.slots(name, slotsProps); const Header = slots('sku-header') || ( - + {slots('sku-header-price') || (
    {price} - {this.priceTag && {this.priceTag}} + {this.priceTag && ( + {this.priceTag} + )}
    )} - {slots('sku-header-origin-price') || ( - originPrice && ( - {t('originPrice')} ¥{originPrice} - ) - )} + {slots('sku-header-origin-price') || + (originPrice && ( + + {t('originPrice')} ¥{originPrice} + + ))} {!this.hideStock && ( {this.stockText} diff --git a/src/sku/components/SkuImgUploader.js b/src/sku/components/SkuImgUploader.js index df49ed637..baf0a702d 100644 --- a/src/sku/components/SkuImgUploader.js +++ b/src/sku/components/SkuImgUploader.js @@ -53,9 +53,7 @@ export default createComponent({ maxSize={this.maxSize * 1024 * 1024} onOversize={this.onOversize} > -
    - {content} -
    +
    {content}
    ); }, @@ -63,15 +61,14 @@ export default createComponent({ genMask() { return (
    - {this.uploadFail - ? ( - [ - , -
    , - ] - ) : ( - - )} + {this.uploadFail ? ( + [ + , +
    , + ] + ) : ( + + )}
    ); }, @@ -80,33 +77,34 @@ export default createComponent({ render() { return (
    - {this.value && this.genUploader( - [ - , - { - this.$emit('input', ''); - }} - />, - ], - true - )} + {this.value && + this.genUploader( + [ + , + { + this.$emit('input', ''); + }} + />, + ], + true + )} - {this.paddingImg && this.genUploader( - [ - , - this.genMask(), - ], - !this.uploadFail - )} + {this.paddingImg && + this.genUploader( + [, this.genMask()], + !this.uploadFail + )} - {!this.value && !this.paddingImg && this.genUploader( -
    - -
    - )} + {!this.value && + !this.paddingImg && + this.genUploader( +
    + +
    + )}
    ); }, diff --git a/src/sku/components/SkuMessages.js b/src/sku/components/SkuMessages.js index 5f9edb884..b68d86ee7 100644 --- a/src/sku/components/SkuMessages.js +++ b/src/sku/components/SkuMessages.js @@ -103,43 +103,54 @@ export default createComponent({ if (message.type === 'email' && !isEmail(value)) { return t('invalid.email'); } - if (message.type === 'id_no' && (value.length < 15 || value.length > 18)) { + if ( + message.type === 'id_no' && + (value.length < 15 || value.length > 18) + ) { return t('invalid.id_no'); } } } }, + + genMessage(message, index) { + if (message.type === 'image') { + return ( + + + + ); + } + + return ( + + ); + }, }, render() { return ( 0}> - {this.messages.map((message, index) => (message.type === 'image' ? ( - - - - ) : ( - - )))} + {this.messages.map(this.genMessage)} ); }, diff --git a/src/sku/components/SkuRowPropItem.js b/src/sku/components/SkuRowPropItem.js index 1c59b66a6..4336f2640 100644 --- a/src/sku/components/SkuRowPropItem.js +++ b/src/sku/components/SkuRowPropItem.js @@ -11,6 +11,18 @@ export default createComponent({ multiple: Boolean, }, + computed: { + choosed() { + const { selectedProp, skuKeyStr, skuValue } = this; + + if (selectedProp && selectedProp[skuKeyStr]) { + return selectedProp[skuKeyStr].indexOf(skuValue.id) > -1; + } + + return false; + }, + }, + methods: { onSelect() { this.skuEventBus.$emit('sku:propSelect', { @@ -22,14 +34,11 @@ export default createComponent({ }, render() { - const choosed = this.selectedProp && (this.selectedProp[this.skuKeyStr] || []).indexOf(this.skuValue.id) > -1; return ( diff --git a/src/sku/components/SkuStepper.js b/src/sku/components/SkuStepper.js index 9a8bb9095..f1e1266f8 100644 --- a/src/sku/components/SkuStepper.js +++ b/src/sku/components/SkuStepper.js @@ -157,7 +157,9 @@ export default createComponent({ return (
    -
    {this.stepperTitle || t('num')}
    +
    + {this.stepperTitle || t('num')} +
    - {!this.hideQuotaText && this.quotaText && ({this.quotaText})} + {!this.hideQuotaText && this.quotaText && ( + ({this.quotaText}) + )}
    ); diff --git a/src/sku/utils/skuHelper.js b/src/sku/utils/skuHelper.js index ca2973be7..4312512d1 100644 --- a/src/sku/utils/skuHelper.js +++ b/src/sku/utils/skuHelper.js @@ -65,11 +65,11 @@ export const isAllSelected = (skuTree, selectedSku) => { // 根据已选择的 sku 获取 skuComb export const getSkuComb = (skuList, selectedSku) => { - const skuComb = skuList.filter(item => ( + const skuComb = skuList.filter(item => Object.keys(selectedSku).every( skuKeyStr => String(item[skuKeyStr]) === String(selectedSku[skuKeyStr]) ) - )); + ); return skuComb[0]; }; @@ -103,11 +103,11 @@ export const isSkuChoosable = (skuList, selectedSku, skuToChoose) => { skuKey => matchedSku[skuKey] !== UNSELECTED_SKU_VALUE_ID ); - const filteredSku = skuList.filter(sku => ( + const filteredSku = skuList.filter(sku => skusToCheck.every( skuKey => String(matchedSku[skuKey]) === String(sku[skuKey]) ) - )); + ); const stock = filteredSku.reduce((total, sku) => { total += sku.stock_num; diff --git a/src/slider/index.js b/src/slider/index.js index 24a3207a9..57e8e5f15 100644 --- a/src/slider/index.js +++ b/src/slider/index.js @@ -107,7 +107,9 @@ export default createComponent({ if (this.disabled) return; const rect = this.$el.getBoundingClientRect(); - const delta = this.vertical ? event.clientY - rect.top : event.clientX - rect.left; + const delta = this.vertical + ? event.clientY - rect.top + : event.clientX - rect.left; const total = this.vertical ? rect.height : rect.width; const value = (delta / total) * this.range + this.min; @@ -129,7 +131,8 @@ export default createComponent({ format(value) { return ( - Math.round(Math.max(this.min, Math.min(value, this.max)) / this.step) * this.step + Math.round(Math.max(this.min, Math.min(value, this.max)) / this.step) * + this.step ); }, }, diff --git a/src/step/index.js b/src/step/index.js index ed952c29e..98bda55d3 100644 --- a/src/step/index.js +++ b/src/step/index.js @@ -34,7 +34,9 @@ export default createComponent({ const inactiveIconSlot = this.slots('inactive-icon'); if (inactiveIcon || inactiveIconSlot) { - return inactiveIconSlot || ; + return ( + inactiveIconSlot || + ); } return ; diff --git a/src/stepper/index.js b/src/stepper/index.js index d32df6dc0..a716e3fd2 100644 --- a/src/stepper/index.js +++ b/src/stepper/index.js @@ -78,7 +78,9 @@ export default createComponent({ computed: { minusDisabled() { - return this.disabled || this.disableMinus || this.currentValue <= this.min; + return ( + this.disabled || this.disableMinus || this.currentValue <= this.min + ); }, plusDisabled() { diff --git a/src/toast/Toast.js b/src/toast/Toast.js index bf7f12263..3b16fcf8a 100644 --- a/src/toast/Toast.js +++ b/src/toast/Toast.js @@ -85,10 +85,16 @@ export default createComponent({ genIcon() { const { icon, type, iconPrefix, loadingType } = this; - const hasIcon = icon || (type === 'success' || type === 'fail'); + const hasIcon = icon || type === 'success' || type === 'fail'; if (hasIcon) { - return ; + return ( + + ); } if (type === 'loading') { @@ -120,7 +126,10 @@ export default createComponent({ >
    {this.genIcon()} diff --git a/src/uploader/index.js b/src/uploader/index.js index 384463367..c73d84e44 100644 --- a/src/uploader/index.js +++ b/src/uploader/index.js @@ -117,19 +117,21 @@ export default createComponent({ files = files.slice(0, maxCount); } - Promise.all(files.map(file => readFile(file, this.resultType))).then(contents => { - const fileList = files.map((file, index) => { - const result = { file }; + Promise.all(files.map(file => readFile(file, this.resultType))).then( + contents => { + const fileList = files.map((file, index) => { + const result = { file }; - if (contents[index]) { - result.content = contents[index]; - } + if (contents[index]) { + result.content = contents[index]; + } - return result; - }); + return result; + }); - this.onAfterRead(fileList, oversize); - }); + this.onAfterRead(fileList, oversize); + } + ); } else { readFile(files, this.resultType).then(content => { const result = { file: files }; @@ -317,7 +319,9 @@ export default createComponent({ return (
    - {this.uploadText && {this.uploadText}} + {this.uploadText && ( + {this.uploadText} + )} {Input}
    );