2025-07-15 15:16:03 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="form-container">
|
2025-09-05 16:41:50 +08:00
|
|
|
<Form :model="formData" ref="formRef" layout="vertical">
|
|
|
|
|
<FormItem
|
2025-07-15 15:16:03 +08:00
|
|
|
v-for="(field, index) in formFields"
|
|
|
|
|
:key="index"
|
2025-07-24 19:07:46 +08:00
|
|
|
:label="field.props.label"
|
2025-09-05 16:41:50 +08:00
|
|
|
:name="field.props.name"
|
2025-07-24 19:07:46 +08:00
|
|
|
:rules="field.props.rules"
|
2025-07-28 17:07:49 +08:00
|
|
|
:tooltip="field.props.tip"
|
2025-07-15 15:16:03 +08:00
|
|
|
>
|
2025-09-04 11:07:21 +08:00
|
|
|
<Input
|
2025-07-24 19:07:46 +08:00
|
|
|
allowClear
|
|
|
|
|
v-if="field.type === 'input'"
|
2025-09-04 11:07:21 +08:00
|
|
|
v-model:value="formData[field.props.name]"
|
2025-07-24 19:07:46 +08:00
|
|
|
:placeholder="field?.props?.placeholder"
|
|
|
|
|
/>
|
2025-09-04 11:07:21 +08:00
|
|
|
<TextArea
|
2025-07-24 19:07:46 +08:00
|
|
|
v-if="field.type === 'textarea'"
|
2025-07-28 19:59:54 +08:00
|
|
|
style="width: 500px; height: 200px"
|
2025-09-04 11:07:21 +08:00
|
|
|
v-model:value="formData[field.props.name]"
|
2025-07-24 19:07:46 +08:00
|
|
|
:placeholder="field?.props?.placeholder"
|
|
|
|
|
/>
|
2025-07-28 19:59:54 +08:00
|
|
|
<ImageUpload
|
|
|
|
|
v-if="field.type == 'upload_image'"
|
|
|
|
|
v-model="formData[field.props.name]"
|
|
|
|
|
:limit="field.props.limit"
|
|
|
|
|
></ImageUpload>
|
|
|
|
|
<FileUpload
|
|
|
|
|
v-if="field.type == 'upload_file'"
|
|
|
|
|
v-model="formData[field.props.name]"
|
|
|
|
|
:limit="field.props.limit"
|
|
|
|
|
></FileUpload>
|
2025-09-04 12:07:18 +08:00
|
|
|
<Select
|
2025-07-24 19:07:46 +08:00
|
|
|
v-else-if="field.type === 'select'"
|
2025-09-04 12:07:18 +08:00
|
|
|
v-model:value="formData[field.props.name]"
|
2025-07-24 19:07:46 +08:00
|
|
|
:placeholder="field.placeholder"
|
|
|
|
|
>
|
2025-09-04 12:07:18 +08:00
|
|
|
<Option v-for="(option, optIndex) in field.props.options" :key="optIndex" :value="option.value">
|
2025-07-15 15:16:03 +08:00
|
|
|
{{ option.label }}
|
2025-09-04 12:07:18 +08:00
|
|
|
</Option>
|
|
|
|
|
</Select>
|
2025-09-05 16:41:50 +08:00
|
|
|
</FormItem>
|
|
|
|
|
</Form>
|
2025-09-03 11:15:37 +08:00
|
|
|
<Button class="submit-btn" type="primary" :disabled="loading" @click="handleSubmit">提交执行</Button>
|
2025-07-15 15:16:03 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<script setup>
|
|
|
|
|
import { defineProps, defineEmits } from 'vue';
|
|
|
|
|
import ImageUpload from '@/components/upload/ImageUpload.vue';
|
2025-07-24 19:07:46 +08:00
|
|
|
import FileUpload from '@/components/upload/FileUpload.vue';
|
2025-09-05 16:41:50 +08:00
|
|
|
import { Button, Input, Select, Row, Col, Form } from 'ant-design-vue';
|
2025-09-04 11:07:21 +08:00
|
|
|
const { TextArea } = Input;
|
2025-09-04 12:07:18 +08:00
|
|
|
const { Option } = Select;
|
2025-09-05 16:41:50 +08:00
|
|
|
const { Item: FormItem } = Form;
|
2025-07-15 15:16:03 +08:00
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
formFields: {
|
|
|
|
|
type: Array,
|
|
|
|
|
required: true,
|
|
|
|
|
},
|
|
|
|
|
formData: {
|
|
|
|
|
type: Object,
|
|
|
|
|
required: true,
|
|
|
|
|
},
|
2025-07-16 18:49:28 +08:00
|
|
|
loading: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false,
|
|
|
|
|
},
|
2025-07-15 15:16:03 +08:00
|
|
|
});
|
|
|
|
|
const emit = defineEmits(['submit']);
|
|
|
|
|
const formRef = ref(null);
|
|
|
|
|
const handleSubmit = async () => {
|
|
|
|
|
const errors = await formRef.value.validate();
|
|
|
|
|
if (errors) return;
|
2025-07-24 19:07:46 +08:00
|
|
|
console.log(props.formFields, 'props.formFields');
|
2025-07-15 15:16:03 +08:00
|
|
|
emit('submit', props.formData);
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
.form-container {
|
2025-09-04 11:07:21 +08:00
|
|
|
:deep(.ant-input),
|
|
|
|
|
:deep(.ant-input:focus),
|
|
|
|
|
:deep(.ant-input-focused) {
|
2025-07-15 15:16:03 +08:00
|
|
|
border-radius: 4px;
|
|
|
|
|
border-color: #d7d7d9;
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
height: 35px;
|
2025-07-29 17:46:10 +08:00
|
|
|
width: 300px;
|
2025-07-15 15:16:03 +08:00
|
|
|
|
2025-09-04 11:07:21 +08:00
|
|
|
&:focus,
|
|
|
|
|
&:focus-within {
|
2025-07-15 15:16:03 +08:00
|
|
|
background-color: var(--color-bg-2);
|
|
|
|
|
border-color: rgb(var(--primary-6));
|
|
|
|
|
box-shadow: 0 0 0 0 var(--color-primary-light-2);
|
|
|
|
|
}
|
2025-09-04 11:07:21 +08:00
|
|
|
}
|
2025-07-15 15:16:03 +08:00
|
|
|
|
2025-09-04 11:07:21 +08:00
|
|
|
&.ant-textarea-wrapper {
|
|
|
|
|
height: 60px;
|
2025-07-15 15:16:03 +08:00
|
|
|
}
|
2025-07-28 19:59:54 +08:00
|
|
|
|
|
|
|
|
.submit-btn {
|
|
|
|
|
display: block;
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
}
|
2025-07-15 15:16:03 +08:00
|
|
|
}
|
|
|
|
|
</style>
|