Merge pull request #841 from wsd000/feat_license_plate_keyboard

feat: 修复打包及组件默认值的问题ard
This commit is contained in:
MeloHG 2023-11-20 13:56:52 +08:00 committed by GitHub
commit f6d2da1665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 26 deletions

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -1,13 +1,13 @@
<template> <template>
<div class="md-license-plate-keyboard"> <div class="md-license-plate-keyboard">
<div v-if="keyboardType === 1"> <div v-if="keyboardType === 1">
<shortcut-view <md-shortcut-row
:shortcuts="shortcuts" :shortcuts="shortcuts"
@enter="$_onEnter" @enter="$_onEnter"
/> />
</div> </div>
<div v-else> <div v-else>
<keyboard-view <md-mixed-key-board
:mixedKeyboard="mixedKeyboard" :mixedKeyboard="mixedKeyboard"
@enter="$_onEnter" @enter="$_onEnter"
@delete="$_onDelete" @delete="$_onDelete"
@ -17,15 +17,15 @@
</div> </div>
</template> </template>
<script> import keyboardView from './key-board-view.vue' <script> import MixedKeyBoard from './mixed-key-board'
import shortcutView from './short-cut-view.vue' import ShortcutRow from './short-cut-row'
export default { export default {
name: 'md-license-plate-keyboard', name: 'md-license-plate-keyboard',
components: { components: {
keyboardView, [MixedKeyBoard.name]: MixedKeyBoard,
shortcutView, [ShortcutRow.name]: ShortcutRow,
}, },
props: { props: {

View File

@ -15,7 +15,6 @@
disabled: item.disabled 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 v-if="item.type === 'confirm' && item.text">{{ item.text }}</div>
</div> </div>
</template> </template>
@ -85,10 +84,9 @@
font-weight: 400; font-weight: 400;
margin: 0px 0px 10px 10px; margin: 0px 0px 10px 10px;
&.delete{ &.delete{
img{ background: url(../_style/images/license-keyboard-del.png) center no-repeat;
width: 40px; background-color: #FFFFFF;
height: 40px; background-size: 40px 40px;
}
} }
&.confirm{ &.confirm{
width: 212px; width: 212px;

View File

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<md-license-plate :stackViewBody="'#licensePlateContainer'"></md-license-plate> <md-license-plate :defaultValue="defaultValue"></md-license-plate>
</div> </div>
</template> </template>
@ -12,7 +12,14 @@ export default {
[LicensePlate.name]: LicensePlate, [LicensePlate.name]: LicensePlate,
}, },
data() { data() {
return {} return {
defaultValue: '',
}
},
mounted() {
// setTimeout(()=>{
// this.defaultValue = '23338888888'
// },10000)
}, },
methods: {}, methods: {},
} }

View File

@ -5,7 +5,7 @@
class="md-license-plate-input-container division" class="md-license-plate-input-container division"
:id="inputViewId" :id="inputViewId"
> >
<license-plate-input <md-license-plate-input
:keyArray="keyArray" :keyArray="keyArray"
:selectedIndex="dyCurrentIndex" :selectedIndex="dyCurrentIndex"
@keyMapping="keyMapping" @keyMapping="keyMapping"
@ -16,7 +16,7 @@
class="md-license-plate-keyboard-container division" class="md-license-plate-keyboard-container division"
:id="keyboardViewId" :id="keyboardViewId"
> >
<license-plate-keyboard <md-license-plate-keyboard
:keyboard="dyKeyboard" :keyboard="dyKeyboard"
@enter="$_onEnter" @enter="$_onEnter"
@delete="$_onDelete" @delete="$_onDelete"
@ -41,14 +41,14 @@
></md-popup-title-bar> ></md-popup-title-bar>
<div class="md-popup-content"> <div class="md-popup-content">
<div class="md-license-plate-input-container popUp"> <div class="md-license-plate-input-container popUp">
<license-plate-input <md-license-plate-input
:keyArray="keyArray" :keyArray="keyArray"
:selectedIndex="dyCurrentIndex" :selectedIndex="dyCurrentIndex"
@keyMapping="keyMapping" @keyMapping="keyMapping"
/> />
</div> </div>
<div class="md-license-plate-keyboard-container popUp"> <div class="md-license-plate-keyboard-container popUp">
<license-plate-keyboard <md-license-plate-keyboard
:keyboard="dyKeyboard" :keyboard="dyKeyboard"
@enter="$_onEnter" @enter="$_onEnter"
@delete="$_onDelete" @delete="$_onDelete"
@ -61,8 +61,8 @@
</div> </div>
</template> </template>
<script> import licensePlateKeyboard from '../license-plate-keyboard' <script> import LicensePlateKeyboard from '../license-plate-keyboard'
import licensePlateInput from '../license-plate-input' import LicensePlateInput from '../license-plate-input'
import Popup from '../popup' import Popup from '../popup'
import PopupTitlebar from '../popup/title-bar' import PopupTitlebar from '../popup/title-bar'
import {directiveInit, queryCurParentNode, unique} from './util' import {directiveInit, queryCurParentNode, unique} from './util'
@ -71,8 +71,8 @@ export default {
name: 'md-license-plate', name: 'md-license-plate',
components: { components: {
licensePlateKeyboard, [LicensePlateKeyboard.name]: LicensePlateKeyboard,
licensePlateInput, [LicensePlateInput.name]: LicensePlateInput,
[Popup.name]: Popup, [Popup.name]: Popup,
[PopupTitlebar.name]: PopupTitlebar, [PopupTitlebar.name]: PopupTitlebar,
}, },
@ -302,7 +302,7 @@ export default {
}, },
], ],
// //
keyArray: (this.defaultValue && this.defaultValue.split('')) || ['', '', '', '', '', '', '', ''], keyArray: ['', '', '', '', '', '', '', ''],
selectedIndex: 0, // selectedIndex: 0, //
showDivisionKeyboard: false, showDivisionKeyboard: false,
inputViewId: unique() + '_divisionInput', inputViewId: unique() + '_divisionInput',
@ -367,6 +367,16 @@ export default {
keyboardType, keyboardType,
} }
}, },
// null
keyArrayCopy() {
return this.keyArray.map(item => {
if (item) {
return item
} else {
return ' '
}
})
},
}, },
created() { created() {
@ -380,10 +390,10 @@ export default {
if (!this.showDivisionKeyboard) { if (!this.showDivisionKeyboard) {
this.showDivisionKeyboard = true 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 return
} }
this.selectedIndex = index this.selectedIndex = index
@ -423,7 +433,7 @@ export default {
if (this.modeShow === 'division') { if (this.modeShow === 'division') {
this.hideDivisionKeyboard() this.hideDivisionKeyboard()
} }
this.$emit('confirm', this.keyArray.join('')) this.$emit('confirm', this.keyArrayCopy.join(''))
}, },
// //
hideDivisionKeyboard(e) { hideDivisionKeyboard(e) {
@ -434,7 +444,7 @@ export default {
if (this.showDivisionKeyboard && !isKeyboard) { if (this.showDivisionKeyboard && !isKeyboard) {
this.showDivisionKeyboard = false this.showDivisionKeyboard = false
// //
this.$emit('hdKeyboard') this.$emit('hdKeyboard', this.keyArrayCopy.join(''))
} }
}, },
}, },
@ -447,6 +457,28 @@ export default {
beforeDestroy() { beforeDestroy() {
this.modeShow === 'division' && document.removeEventListener('click', this.hideDivisionKeyboard) 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> </script>