Skip to content

Commit

Permalink
Merge pull request #841 from wsd000/feat_license_plate_keyboard
Browse files Browse the repository at this point in the history
feat: 修复打包及组件默认值的问题ard
  • Loading branch information
qifeng0748 authored Nov 20, 2023
2 parents 87d8c22 + 8ea1fba commit f6d2da1
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 26 deletions.
12 changes: 6 additions & 6 deletions components/license-plate-keyboard/index.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<div class="md-license-plate-keyboard">
<div v-if="keyboardType === 1">
<shortcut-view
<md-shortcut-row
:shortcuts="shortcuts"
@enter="$_onEnter"
/>
</div>
<div v-else>
<keyboard-view
<md-mixed-key-board
:mixedKeyboard="mixedKeyboard"
@enter="$_onEnter"
@delete="$_onDelete"
Expand All @@ -17,15 +17,15 @@
</div>
</template>

<script>import keyboardView from './key-board-view.vue'
import shortcutView from './short-cut-view.vue'
<script>import MixedKeyBoard from './mixed-key-board'
import ShortcutRow from './short-cut-row'
export default {
name: 'md-license-plate-keyboard',
components: {
keyboardView,
shortcutView,
[MixedKeyBoard.name]: MixedKeyBoard,
[ShortcutRow.name]: ShortcutRow,
},
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
disabled: item.disabled
}"
>
<img v-if="item.type === 'delete'" src="./assets/close.png"/>
<div v-if="item.type === 'confirm' && item.text">{{ item.text }}</div>
</div>
</template>
Expand Down Expand Up @@ -85,10 +84,9 @@
font-weight: 400;
margin: 0px 0px 10px 10px;
&.delete{
img{
width: 40px;
height: 40px;
}
background: url(../_style/images/license-keyboard-del.png) center no-repeat;
background-color: #FFFFFF;
background-size: 40px 40px;
}
&.confirm{
width: 212px;
Expand Down
11 changes: 9 additions & 2 deletions components/license-plate/demo/cases/demo0.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<md-license-plate :stackViewBody="'#licensePlateContainer'"></md-license-plate>
<md-license-plate :defaultValue="defaultValue"></md-license-plate>
</div>
</template>

Expand All @@ -12,7 +12,14 @@ export default {
[LicensePlate.name]: LicensePlate,
},
data() {
return {}
return {
defaultValue: '',
}
},
mounted() {
// setTimeout(()=>{
// this.defaultValue = '23338888888'
// },10000)
},
methods: {},
}
Expand Down
58 changes: 45 additions & 13 deletions components/license-plate/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class="md-license-plate-input-container division"
:id="inputViewId"
>
<license-plate-input
<md-license-plate-input
:keyArray="keyArray"
:selectedIndex="dyCurrentIndex"
@keyMapping="keyMapping"
Expand All @@ -16,7 +16,7 @@
class="md-license-plate-keyboard-container division"
:id="keyboardViewId"
>
<license-plate-keyboard
<md-license-plate-keyboard
:keyboard="dyKeyboard"
@enter="$_onEnter"
@delete="$_onDelete"
Expand All @@ -41,14 +41,14 @@
></md-popup-title-bar>
<div class="md-popup-content">
<div class="md-license-plate-input-container popUp">
<license-plate-input
<md-license-plate-input
:keyArray="keyArray"
:selectedIndex="dyCurrentIndex"
@keyMapping="keyMapping"
/>
</div>
<div class="md-license-plate-keyboard-container popUp">
<license-plate-keyboard
<md-license-plate-keyboard
:keyboard="dyKeyboard"
@enter="$_onEnter"
@delete="$_onDelete"
Expand All @@ -61,8 +61,8 @@
</div>
</template>

<script>import licensePlateKeyboard from '../license-plate-keyboard'
import licensePlateInput from '../license-plate-input'
<script>import LicensePlateKeyboard from '../license-plate-keyboard'
import LicensePlateInput from '../license-plate-input'
import Popup from '../popup'
import PopupTitlebar from '../popup/title-bar'
import {directiveInit, queryCurParentNode, unique} from './util'
Expand All @@ -71,8 +71,8 @@ export default {
name: 'md-license-plate',
components: {
licensePlateKeyboard,
licensePlateInput,
[LicensePlateKeyboard.name]: LicensePlateKeyboard,
[LicensePlateInput.name]: LicensePlateInput,
[Popup.name]: Popup,
[PopupTitlebar.name]: PopupTitlebar,
},
Expand Down Expand Up @@ -302,7 +302,7 @@ export default {
},
],
// 用户输入的车牌数据
keyArray: (this.defaultValue && this.defaultValue.split('')) || ['', '', '', '', '', '', '', ''],
keyArray: ['', '', '', '', '', '', '', ''],
selectedIndex: 0, // 当前用户输入框已选中的序号
showDivisionKeyboard: false,
inputViewId: unique() + '_divisionInput',
Expand Down Expand Up @@ -367,6 +367,16 @@ export default {
keyboardType,
}
},
// 健值为null特殊处理
keyArrayCopy() {
return this.keyArray.map(item => {
if (item) {
return item
} else {
return ' '
}
})
},
},
created() {
Expand All @@ -380,10 +390,10 @@ export default {
if (!this.showDivisionKeyboard) {
this.showDivisionKeyboard = true
// 抛出展示分离键盘事件
this.$emit('sdKeyboard')
this.$emit('sdKeyboard', this.keyboardViewId)
}
// 顺序填写,不可无序点击
if (!this.keyArray[index + 1] && !this.keyArray[index - 1]) {
if (!this.keyArray[index + 1] && !this.keyArray[index - 1] && index > 0) {
return
}
this.selectedIndex = index
Expand Down Expand Up @@ -423,7 +433,7 @@ export default {
if (this.modeShow === 'division') {
this.hideDivisionKeyboard()
}
this.$emit('confirm', this.keyArray.join(''))
this.$emit('confirm', this.keyArrayCopy.join(''))
},
// 隐藏分离键盘
hideDivisionKeyboard(e) {
Expand All @@ -434,7 +444,7 @@ export default {
if (this.showDivisionKeyboard && !isKeyboard) {
this.showDivisionKeyboard = false
// 抛出隐藏分离键盘事件
this.$emit('hdKeyboard')
this.$emit('hdKeyboard', this.keyArrayCopy.join(''))
}
},
},
Expand All @@ -447,6 +457,28 @@ export default {
beforeDestroy() {
this.modeShow === 'division' && document.removeEventListener('click', this.hideDivisionKeyboard)
},
watch: {
defaultValue: {
handler(newVal) {
if (newVal !== '') {
const defaultValueArray = this.defaultValue.split('')
const keyArrayCopy = JSON.parse(JSON.stringify(this.keyArray))
keyArrayCopy.forEach((item, index) => {
if (defaultValueArray[index]) {
keyArrayCopy[index] = defaultValueArray[index]
} else {
keyArrayCopy[index] = ''
}
})
this.keyArray = keyArrayCopy
}
},
immediate: true,
},
},
}
</script>

Expand Down

0 comments on commit f6d2da1

Please sign in to comment.