1)
+ },
+ },
+
watch: {
value(val) {
this.isCashierShow = val
@@ -224,6 +244,11 @@ export default {
created() {
this.$_initialCashier()
+
+ if (this.channels.length < 3) {
+ this.isChannelShow = true
+ this.isChannelActive = true
+ }
},
methods: {
diff --git a/components/cashier/rolling.vue b/components/cashier/rolling.vue
index a3c7f6fe3..7206385d8 100644
--- a/components/cashier/rolling.vue
+++ b/components/cashier/rolling.vue
@@ -79,7 +79,7 @@
doSuccess() {
const st = this.startTmp
const et = Date.now()
- const delay = Math.ceil((et - st) / 2000) * 2000 - (et - st)
+ const delay = Math.ceil((et - st) / 1500) * 1500 - (et - st)
setTimeout(() => {
this.successFlag = true
}, delay)
diff --git a/components/cashier/test/index.spec.js b/components/cashier/test/index.spec.js
index 77a17d323..42a0b04d3 100644
--- a/components/cashier/test/index.spec.js
+++ b/components/cashier/test/index.spec.js
@@ -45,10 +45,10 @@ describe('Cashier', () => {
wrapper.vm.channels = channels
wrapper.vm.defaultIndex = 1
wrapper.vm.value = true
- wrapper.vm.$nextTick(() => {
+ setTimeout(() => {
expect(
wrapper
- .find('.choose-channel-item')[0]
+ .find('.choose-channel-item.default')[0]
.text()
.trim(),
).to.equal(channels[1].text)
@@ -71,7 +71,7 @@ describe('Cashier', () => {
wrapper.vm.value = false
done()
})
- })
+ }, 500)
})
it('cashier captcha', done => {
diff --git a/components/date-picker/README.md b/components/date-picker/README.md
index 9cc00a597..c113f27d6 100644
--- a/components/date-picker/README.md
+++ b/components/date-picker/README.md
@@ -36,6 +36,7 @@ Vue.component(DatePicker.name, DatePicker)
|title|选择器标题|String|-|-|
|ok-text|选择器确认文案|String|`确认`|-|
|cancel-text|选择器取消文案|String|`取消`|-|
+|mask-closable|点击蒙层是否可关闭弹出层|Boolean|`true`|-|
#### DatePicker Methods
diff --git a/components/date-picker/index.vue b/components/date-picker/index.vue
index 5bf0be111..40cf4846d 100644
--- a/components/date-picker/index.vue
+++ b/components/date-picker/index.vue
@@ -10,9 +10,11 @@
:ok-text="okText"
:cancel-text="cancelText"
:is-view="isView"
+ :mask-closable="maskClosable"
@initialed="$emit('initialed')"
@change="$_onPickerChange"
@confirm="$_onPickerConfirm"
+ @cancel="$_onPickerCancel"
@show="$_onPickerShow"
@hide="$_onPickerHide"
>
@@ -133,6 +135,10 @@ export default {
isView: {
type: Boolean,
default: false
+ },
+ maskClosable: {
+ type: Boolean,
+ default: true,
}
},
@@ -141,6 +147,7 @@ export default {
isPickerShow: false,
currentDateIns: new Date(),
columnData: [],
+ oldColumnData: null,
columnDataDefault: [],
columnDataGenerator: [],
disabledCascadeComlumnIndex: [] // columns do not need cascading
@@ -235,7 +242,7 @@ export default {
isSetColumn && this.picker.refresh(null, columnIndex)
},
$_initColumnDataGenerator () {
- const defaultDate = this.defaultDate
+ const defaultDate = this.$_getDefaultDate()
switch (this.type) {
case 'date':
this.$_initColumnDataGeneratorForDate(defaultDate)
@@ -319,6 +326,25 @@ export default {
this.columnDataDefault.push(hourInfo.ap)
}
},
+ $_getDefaultDate () {
+ const defaultDate = this.defaultDate
+ const minDate = this.minDate
+ const maxDate = this.maxDate
+
+ if (!defaultDate) {
+ return defaultDate
+ }
+
+ if (minDate && defaultDate.getTime() < minDate.getTime()) {
+ return minDate
+ }
+
+ if (maxDate && defaultDate.getTime() > maxDate.getTime()) {
+ return maxDate
+ }
+
+ return defaultDate
+ },
$_generateYearData () {
const start = this.minDate ? this.minDate.getFullYear() : this.currentYear - 20
const end = this.maxDate ? this.maxDate.getFullYear() : this.currentYear + 20
@@ -469,6 +495,7 @@ export default {
// MARK: events handler
$_onPickerShow () {
+ this.oldColumnData = [...this.columnData]
this.$emit('show')
},
$_onPickerHide () {
@@ -489,6 +516,10 @@ export default {
$_onPickerConfirm (columnsValue) {
this.$emit('confirm', columnsValue)
},
+ $_onPickerCancel () {
+ this.$emit('cancel')
+ this.columnData = [...this.oldColumnData]
+ },
getFormatDate (format = 'yyyy-MM-dd hh:mm') {
const columnValues = this.picker.getColumnValues()
diff --git a/components/picker/README.md b/components/picker/README.md
index e7243eff3..8463b4cd5 100644
--- a/components/picker/README.md
+++ b/components/picker/README.md
@@ -31,6 +31,7 @@ Vue.component(Picker.name, Picker)
|title|选择器标题|String|-|-|
|ok-text|选择器确认文案|String|`确认`|-|
|cancel-text|选择器取消文案|String|`取消`|-|
+|mask-closable|点击蒙层是否可关闭弹出层|Boolean|`true`|-|
#### Picker Methods
diff --git a/components/picker/demo/cases/demo2.vue b/components/picker/demo/cases/demo2.vue
index 8d33a38b2..68324fed3 100644
--- a/components/picker/demo/cases/demo2.vue
+++ b/components/picker/demo/cases/demo2.vue
@@ -2,26 +2,42 @@
+ :value="pickerValue0"
+ @click.native="isPickerShow0 = true">
+
+
+
@@ -197,6 +225,7 @@ export default {
background-color color-bg-base
.md-selector-container
background color-bg-base
+ overflow auto
.md-selector-item
position relative
height selector-height
diff --git a/components/tab-picker/README.md b/components/tab-picker/README.md
index 0441ff490..75db73bcd 100644
--- a/components/tab-picker/README.md
+++ b/components/tab-picker/README.md
@@ -52,6 +52,7 @@ tab切换的title支持自定义渲染(通过slot-scope)
|title|弹窗标题|Boolean|-|-|
|ok-text|确认按钮文案|String|`确认`|-|
|cancel-text|取消按钮文案|String|`取消`|-|
+|mask-closable|点击蒙层是否可关闭弹出层|Boolean|`true`|-|
#### TabPicker Methods
diff --git a/components/tab-picker/demo/index.vue b/components/tab-picker/demo/index.vue
index caa1b6e9c..eee2844db 100644
--- a/components/tab-picker/demo/index.vue
+++ b/components/tab-picker/demo/index.vue
@@ -49,6 +49,7 @@
cancel-text="取消"
data-struct= "cascade"
:option-render="[()=>{}, ()=>{}, $_optionRender]"
+ :default-index="[0,0,0]"
@confirm="$_confirm"
@cancel="$_cancel"
@change="$_change"
diff --git a/components/tab-picker/index.vue b/components/tab-picker/index.vue
index 8bfa7d534..ce79015d7 100644
--- a/components/tab-picker/index.vue
+++ b/components/tab-picker/index.vue
@@ -3,9 +3,10 @@
0) {
- let i = 0
- const func = array => {
- if (i < this.defaultIndex.length) {
- const temp = this.defaultIndex[i]
- array.forEach((item, eq) => {
- if (eq === temp) {
- this.subTitles.push(item.label)
- this.renderData.push({index: i, clickedKey: temp, data: array})
- if (item && item.children && Array.isArray(item.children)) {
- i++
- func(item.children)
- }
- }
- })
- } else {
- this.defaultTabIndex = i
- return false
- }
- }
- func(this.data)
- } else {
- this.subTitles.push('请选择')
- this.renderData.push({index: 0, clickedKey: -1, data: this.data})
- }
- },
$_initNoCascadeData() {
if (this.data.length === 0) {
return
}
this.isLoading = false
+
+ const initialIndex = this.lastSelectIndex || this.defaultIndex
+ this.$_initTabContent()
+
this.data.forEach((item, index) => {
const temp = {
index: index,
- clickedKey: this.defaultIndex.length > 0 && ~this.defaultIndex[index] ? this.defaultIndex[index] : -1,
+ clickedKey: initialIndex.length > 0 && ~initialIndex[index] ? initialIndex[index] : -1,
data: item.children,
}
this.renderData.push(temp)
const currentColumn = this.renderData[index]
- if (this.defaultIndex && this.defaultIndex.length > 0) {
+ if (initialIndex && initialIndex.length > 0) {
this.subTitles.push(currentColumn.data[currentColumn.clickedKey].label)
} else {
this.subTitles.push(item.label)
}
})
},
+ $_initCascadeData() {
+ if (this.data.length === 0) {
+ return
+ }
+ const initialIndex = this.lastSelectIndex || this.defaultIndex
+ this.$_walk(initialIndex, this.data)
+ },
$_initAsyncCascadeData() {
- this.asyncFunc(null, this.$_renderNextTabContent)
+ this.asyncFunc(null, this.$_renderInitalAsync)
},
- $_renderNextTabContent(err, data) {
- this.isLoading = false
+ $_renderInitalAsync(err, data) {
if (err) {
this.isDataError = err
return
}
- try {
- this.subTitles.splice(this.currentIndex + 1, this.subTitles.length - 1, '请选择')
- this.renderData.splice(this.currentIndex + 1, this.renderData.length - 1, {
- index: this.currentIndex,
- clickedKey: -1,
- data: data.options,
- asyncFunc: data.asyncFunc,
- })
- if (this.renderData.length > 1) {
- this.$nextTick(() => {
- this.$refs.tabs.selectTab(++this.currentIndex)
+ const initialIndex = this.lastSelectIndex || this.defaultIndex
+ this.$_walk(initialIndex, data, true)
+ },
+ $_walk(initialIndex, data, isAsync) {
+ // recursion cascade or async data with initialIndex
+ const func = () => {
+ if (initialIndex && initialIndex.length > 0) {
+ const walk = (err, data) => {
+ if (err) {
+ this.isLoading = false
+ this.isDataError = err
+ return
+ }
+ if (this.walkTimes < initialIndex.length) {
+ const temp = initialIndex[this.walkTimes]
+ let rawData = isAsync ? data.options : data
+ rawData.forEach((item, eq, array) => {
+ if (eq === temp) {
+ this.currentIndex = this.walkTimes
+ this.subTitles.splice(this.currentIndex, this.subTitles.length - 1, item.label)
+ let renderContent = {
+ index: this.walkTimes,
+ clickedKey: temp,
+ data: array,
+ }
+ if (isAsync) {
+ renderContent = {
+ ...renderContent,
+ asyncFunc: data.asyncFunc,
+ }
+ }
+ this.renderData.splice(this.currentIndex, this.renderData.length - 1, renderContent)
+ this.$refs.tabs && this.$refs.tabs.selectTab(this.currentIndex)
+ this.walkTimes++
+ if (item && item.children && Array.isArray(item.children)) {
+ walk(null, item.children)
+ } else if (isAsync && data && data.asyncFunc && typeof data.asyncFunc === 'function') {
+ data.asyncFunc(
+ {
+ index: this.walkTimes,
+ item,
+ eq,
+ },
+ walk,
+ )
+ } else {
+ walk()
+ }
+ }
+ })
+ } else {
+ this.isLoading = false
+ this.defaultTabIndex = this.walkTimes - 1
+ this.walkTimes = 0
+ return false
+ }
+ }
+ walk(null, data)
+ } else {
+ this.$_initTabContent()
+ this.subTitles.push('请选择')
+ if (isAsync) {
+ this.renderData.push({
+ index: 0,
+ clickedKey: -1,
+ data: data.options,
+ asyncFunc: data.asyncFunc,
+ })
+ } else {
+ this.renderData.push({
+ index: 0,
+ clickedKey: -1,
+ data: data,
+ })
+ }
+ this.isLoading = false
+ }
+ }
+ func()
+ },
+ $_initTabContent() {
+ this.subTitles = []
+ this.renderData = []
+ this.currentIndex = 0
+ },
+ $_renderNextTabContent(orignData) {
+ return (err, asyncData) => {
+ this.isLoading = false
+ if (err) {
+ this.isDataError = err
+ return
+ }
+ try {
+ let data,
+ asyncFunc = null
+ if (orignData) {
+ data = orignData
+ } else if (asyncData && asyncData.options) {
+ data = asyncData.options
+ if (asyncData.asyncFunc) {
+ asyncFunc = asyncData.asyncFunc
+ }
+ } else {
+ data = []
+ }
+ this.subTitles.splice(this.currentIndex + 1, this.subTitles.length - 1, '请选择')
+ this.renderData.splice(this.currentIndex + 1, this.renderData.length - 1, {
+ index: this.currentIndex,
+ clickedKey: -1,
+ data,
+ asyncFunc,
})
+ if (this.renderData.length > 1) {
+ this.$nextTick(() => {
+ this.$refs.tabs.selectTab(++this.currentIndex)
+ setTimeout(() => {
+ this.currentColumnLock = false
+ }, 500)
+ })
+ }
+ } catch (error) {
+ this.isDataError = true
}
- } catch (error) {
- this.isDataError = true
}
},
+ $_refreshTabPicker() {
+ // revoke this opration
+ this.isTabPickerShow = false
+ this.isLoading = true
+ this.isDataError = false
+ this.currentColumnLock = false
+ this.refreshTabPicker = Math.random()
+ this.$nextTick(() => {
+ this.$_initTabPicker()
+ })
+ },
// MARK: events handler, 如 $_onButtonClick
$_onShow() {
@@ -283,11 +390,22 @@ export default {
$_onConfirm() {
this.isTabPickerShow = false
const selectedItem = this.getSelectedItem()
+ const isSelectPart = selectedItem.some(option => {
+ return !option
+ })
+ if (!isSelectPart) {
+ this.lastSelectIndex = selectedItem.map(option => {
+ return option.item.eq
+ })
+ }
this.$emit('confirm', selectedItem)
},
$_onCancel() {
- this.isTabPickerShow = false
this.$emit('cancel')
+ this.$_refreshTabPicker()
+ },
+ $_onMaskClose() {
+ this.$_refreshTabPicker()
},
$_onRadioChange(value, index) {
if (this.dataStruct === 'cascade' && this.currentColumnLock) {
@@ -304,18 +422,7 @@ export default {
})
if (this.dataStruct === 'cascade') {
if (value && value.children && Array.isArray(value.children) && value.children.length > 0) {
- this.subTitles.splice(this.currentIndex + 1, this.subTitles.length - 1, '请选择')
- this.renderData.splice(this.currentIndex + 1, this.renderData.length - 1, {
- index: ++this.currentIndex,
- clickedKey: -1,
- data: value.children,
- })
- this.$nextTick(() => {
- this.$refs.tabs.selectTab(this.currentIndex)
- setTimeout(() => {
- this.currentColumnLock = false
- }, 500)
- })
+ this.$_renderNextTabContent(value.children)()
return
}
this.currentColumnLock = false
@@ -327,7 +434,7 @@ export default {
}
// Object.assign(value, {index})
this.isLoading = true
- typeof currentColumn.asyncFunc === 'function' && currentColumn.asyncFunc(value, this.$_renderNextTabContent)
+ typeof currentColumn.asyncFunc === 'function' && currentColumn.asyncFunc(value, this.$_renderNextTabContent())
}
},
$_onIndexChange(index) {
@@ -344,6 +451,7 @@ export default {
item: {
label: selected.label,
value: selected.value,
+ eq: item.clickedKey,
},
}
} else {
diff --git a/components/tab-picker/test/index.spec.js b/components/tab-picker/test/index.spec.js
index 52b650b72..792cd78a5 100644
--- a/components/tab-picker/test/index.spec.js
+++ b/components/tab-picker/test/index.spec.js
@@ -56,8 +56,10 @@ describe('TabPicker', () => {
expect(wrapper.vm.renderData.length).to.equal(2)
expect(wrapper.find('.md-tab-title').length).to.equal(2)
wrapper.find('.md-popup-confirm')[0].trigger('click')
- expect(eventStub.calledWith('confirm')).to.be.true
- done()
+ setTimeout(() => {
+ expect(eventStub.calledWith('confirm')).to.be.true
+ done()
+ }, 200)
}, 500)
})
})
@@ -152,8 +154,10 @@ describe('TabPicker', () => {
expect(wrapper.find('.md-tab-title').length).to.equal(3)
const confirmBtn = wrapper.find('.md-popup-confirm')[0]
confirmBtn.trigger('click')
- expect(eventStub.calledWith('confirm')).to.be.true
- done()
+ setTimeout(() => {
+ expect(eventStub.calledWith('confirm')).to.be.true
+ done()
+ }, 200)
})
})
})