|
@@ -1,59 +0,0 @@
|
|
|
-<template>
|
|
|
- <div>
|
|
|
- <el-form :model="form" :rules="rules" ref="formRef">
|
|
|
- <el-form-item prop="bid">
|
|
|
- <el-input
|
|
|
- v-model.number="form.bid"
|
|
|
- @input="handleInputChange"
|
|
|
- placeholder="请输入数字"
|
|
|
- style="width: 150px"
|
|
|
- clearable
|
|
|
- ></el-input>
|
|
|
- </el-form-item>
|
|
|
- <el-button type="primary" @click="submitForm">提交</el-button>
|
|
|
- </el-form>
|
|
|
- <p v-if="errorMessage" class="error-message">{{ errorMessage }}</p>
|
|
|
- </div>
|
|
|
-</template>
|
|
|
-
|
|
|
-<script setup>
|
|
|
-import { ref, computed } from 'vue';
|
|
|
-import { ElMessage } from 'element-plus'; // 确保已安装并导入Element Plus的消息组件
|
|
|
-
|
|
|
-const formRef = ref(null);
|
|
|
-const errorMessage = ref('');
|
|
|
-const rules = {
|
|
|
- bid: [
|
|
|
- { required: true, message: '此项为必填项', trigger: 'blur' },
|
|
|
- { type: 'number', message: '必须输入数字', trigger: 'blur' }
|
|
|
- ]
|
|
|
-};
|
|
|
-
|
|
|
-const form = reactive({
|
|
|
- bid: 1.00
|
|
|
-});
|
|
|
-
|
|
|
-const handleInputChange = (event) => {
|
|
|
- const value = event.target.value;
|
|
|
- event.target.value = value === '' ? '' : (value === '0' ? '0.00' : value.replace(/[^\d.]/g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^\./g, ''));
|
|
|
- form.bid = parseFloat(value); // 直接赋值,无需检查空字符串,因为验证规则会处理
|
|
|
-};
|
|
|
-
|
|
|
-const submitForm = () => {
|
|
|
- formRef.value.validate(async (valid) => {
|
|
|
- if (valid) {
|
|
|
- // 提交逻辑
|
|
|
- console.log("Form submitted!");
|
|
|
- } else {
|
|
|
- // 显示错误提示
|
|
|
- ElMessage.error('请确保所有必填项已正确填写');
|
|
|
- }
|
|
|
- });
|
|
|
-};
|
|
|
-</script>
|
|
|
-
|
|
|
-<style scoped>
|
|
|
-.error-message {
|
|
|
- color: red;
|
|
|
-}
|
|
|
-</style>
|