7 changed files with 184 additions and 193 deletions
-
86src/components/AddPreSetting.vue
-
12src/components/LiquidHandle.vue
-
89src/components/MyInput.vue
-
92src/components/Setting/components/Device.vue
-
12src/components/Test.vue
-
84src/components/UpdatePreSetting.vue
-
2src/main.js
@ -0,0 +1,89 @@ |
|||
<template> |
|||
<van-field |
|||
ref="input" |
|||
v-model="value" |
|||
readonly |
|||
:formatter="props.formatter" |
|||
:class="props.class" |
|||
:type="props.type" |
|||
@click.stop="actionInputClick" |
|||
></van-field> |
|||
|
|||
<template v-if="keyboardVisible"> |
|||
<van-number-keyboard v-if="'number' === props.type" |
|||
v-model="value" |
|||
:show="true" |
|||
:title="value" |
|||
:theme="props.theme" |
|||
:close-button-text="props.closeText" |
|||
@input="actionKeyBoardInput" |
|||
@blur="actionKeyBoardBlur" |
|||
@close="actionKeyBoardClose" |
|||
></van-number-keyboard> |
|||
</template> |
|||
</template> |
|||
<script setup> |
|||
import { nextTick, ref, watch } from 'vue'; |
|||
/** @var {Function} */ |
|||
const emits = defineEmits(['update:value','done']); |
|||
/** @var {Object} */ |
|||
const props = defineProps({ |
|||
// 格式化函数 |
|||
formatter : { type: Function, default: value => value}, |
|||
// 类名 |
|||
class : { type: String, default: ''}, |
|||
// 类型 |
|||
type : { type: String, default: 'text'}, |
|||
// 取值 |
|||
value : { type: String, default: ''}, |
|||
// 主题 |
|||
theme : { type: String, default: ''}, |
|||
// 关闭按钮文本 |
|||
closeText : { type: String, default: ''}, |
|||
}); |
|||
/** @var {String} */ |
|||
const value = ref(props.value); |
|||
/** @var {Boolean} */ |
|||
const keyboardVisible = ref(false); |
|||
/** @var {Boolean} */ |
|||
const isFirstClick = ref(true); |
|||
/** @var {Component} */ |
|||
const input = ref(null); |
|||
/** @var {String} */ |
|||
let originValue = null; |
|||
// 监听外部值变化 |
|||
watch(() => props.value, (val) => value.value = val); |
|||
|
|||
// 输入框点击 |
|||
async function actionInputClick() { |
|||
originValue = props.value; |
|||
isFirstClick.value = true; |
|||
keyboardVisible.value = true; |
|||
await nextTick(); |
|||
input.value.$el.querySelector('input').select(); |
|||
input.value.$el.querySelector('input').focus(); |
|||
} |
|||
|
|||
// 键盘输入 |
|||
function actionKeyBoardInput(val) { |
|||
if (isFirstClick.value) { |
|||
setTimeout(() => value.value = val + ''); |
|||
isFirstClick.value = false |
|||
} |
|||
} |
|||
|
|||
// 键盘失焦 |
|||
function actionKeyBoardBlur() { |
|||
actionKeyBoardClose(); |
|||
} |
|||
|
|||
// 键盘关闭 |
|||
function actionKeyBoardClose() { |
|||
keyboardVisible.value = false; |
|||
window.getSelection().removeAllRanges(); |
|||
emits('update:value', value.value); |
|||
if (`${originValue}` !== value.value) { |
|||
emits('done'); |
|||
} |
|||
} |
|||
</script> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue