Files
iot-device-management-frontend/apps/web-antd/src/components/upload/input-upload.vue

75 lines
1.7 KiB
Vue
Raw Normal View History

2025-05-26 18:46:06 +08:00
<script setup lang="ts">
import type { InputProps, TextAreaProps } from 'ant-design-vue';
import type { FileUploadProps } from './typing';
2025-05-27 22:14:49 +08:00
import { computed } from 'vue';
2025-05-26 18:46:06 +08:00
2025-05-27 22:14:49 +08:00
import { useVModel } from '@vueuse/core';
2025-05-26 18:46:06 +08:00
import { Col, Input, Row, Textarea } from 'ant-design-vue';
import FileUpload from './file-upload.vue';
const props = defineProps<{
2025-05-27 22:14:49 +08:00
defaultValue?: number | string;
2025-05-26 18:46:06 +08:00
fileUploadProps?: FileUploadProps;
inputProps?: InputProps;
inputType?: 'input' | 'textarea';
2025-05-27 22:14:49 +08:00
modelValue?: number | string;
2025-05-26 18:46:06 +08:00
textareaProps?: TextAreaProps;
}>();
2025-05-27 22:14:49 +08:00
const emits = defineEmits<{
(e: 'change', payload: number | string): void;
(e: 'update:value', payload: number | string): void;
(e: 'update:modelValue', payload: number | string): void;
}>();
2025-05-26 18:46:06 +08:00
2025-05-27 22:14:49 +08:00
const modelValue = useVModel(props, 'modelValue', emits, {
defaultValue: props.defaultValue,
passive: true,
});
2025-05-26 18:46:06 +08:00
function handleReturnText(text: string) {
2025-05-27 22:14:49 +08:00
modelValue.value = text;
emits('change', modelValue.value);
emits('update:value', modelValue.value);
emits('update:modelValue', modelValue.value);
2025-05-26 18:46:06 +08:00
}
const inputProps = computed(() => {
return {
...props.inputProps,
2025-05-27 22:14:49 +08:00
value: modelValue.value,
2025-05-26 18:46:06 +08:00
};
});
const textareaProps = computed(() => {
return {
...props.textareaProps,
2025-05-27 22:14:49 +08:00
value: modelValue.value,
2025-05-26 18:46:06 +08:00
};
});
const fileUploadProps = computed(() => {
return {
...props.fileUploadProps,
};
});
</script>
<template>
<Row>
<Col :span="18">
<Input readonly v-if="inputType === 'input'" v-bind="inputProps" />
<Textarea readonly v-else :row="4" v-bind="textareaProps" />
2025-05-26 18:46:06 +08:00
</Col>
<Col :span="6">
<FileUpload
class="ml-4"
v-bind="fileUploadProps"
@return-text="handleReturnText"
/>
</Col>
</Row>
</template>