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

79 lines
2.0 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';
import { Input, Textarea } from 'ant-design-vue';
2025-05-26 18:46:06 +08:00
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
/** 处理文件内容返回 */
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
}
/** 计算输入框属性 */
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
};
});
/** 计算文本域属性 */
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
};
});
/** 计算文件上传属性 */
2025-05-26 18:46:06 +08:00
const fileUploadProps = computed(() => {
return {
...props.fileUploadProps,
};
});
</script>
<template>
<div class="w-full">
<Input v-if="inputType === 'input'" readonly v-bind="inputProps">
<template #suffix>
<FileUpload v-bind="fileUploadProps" @return-text="handleReturnText" />
</template>
</Input>
<div v-else class="relative w-full">
<Textarea readonly :rows="4" v-bind="textareaProps" />
<div class="absolute bottom-2 right-2">
<FileUpload v-bind="fileUploadProps" @return-text="handleReturnText" />
</div>
</div>
</div>
2025-05-26 18:46:06 +08:00
</template>