single-input.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <el-dialog
  3. :model-value="visible"
  4. @update:model-value="(val) => emit('update:visible', val)"
  5. :title="title"
  6. width="500"
  7. >
  8. <el-input
  9. v-model.trim="ivalue"
  10. :maxlength="100"
  11. show-word-limit
  12. type="textarea"
  13. placeholder="请输入"
  14. />
  15. <template #footer>
  16. <div class="dialog-footer">
  17. <el-button @click="emit('update:visible', false)">取消</el-button>
  18. <el-button type="primary" @click="submit"> 确定 </el-button>
  19. </div>
  20. </template>
  21. </el-dialog>
  22. </template>
  23. <script setup lang="ts">
  24. import { ElMessage } from "element-plus";
  25. import { ref, watchEffect } from "vue";
  26. const props = defineProps<{
  27. visible: boolean;
  28. value: string;
  29. title: string;
  30. updateValue: (value: string) => void;
  31. }>();
  32. const emit = defineEmits<{
  33. (e: "update:visible", visible: boolean): void;
  34. }>();
  35. const ivalue = ref(props.value);
  36. watchEffect(() => {
  37. ivalue.value = props.value;
  38. });
  39. const submit = async () => {
  40. if (ivalue.value.length === 0) {
  41. return ElMessage.error("点位名称不能为空!");
  42. }
  43. await props.updateValue(ivalue.value);
  44. emit("update:visible", false);
  45. };
  46. </script>