refactor: add options

This commit is contained in:
Net 2024-07-25 17:25:05 +07:00
parent 51663b3fe6
commit 9656ede0cb
2 changed files with 85 additions and 23 deletions

View file

@ -16,13 +16,6 @@ const propertiesOption =
); );
const formServiceProperties = defineModel<Attributes>('formServiceProperties'); const formServiceProperties = defineModel<Attributes>('formServiceProperties');
// const abilitys = ref<Record<AdditionalType, Ability[AdditionalType]>>({
// string: { phoneNumber: { length: 10 } },
// number: { comma: true, decimal: { point: 2 } },
// date: '2024-07-25',
// array: ['item1', 'item2'],
// });
const telMax = ref(); const telMax = ref();
const pointNum = ref(); const pointNum = ref();
@ -80,13 +73,21 @@ function manageProperties(
continue; continue;
} }
if (ops.type === 'array' || ops.type === 'date') { if (ops.type === 'date') {
formServiceProperties.value?.additional.push({ formServiceProperties.value?.additional.push({
type: ops.type, type: ops.type,
fieldName: ops.value, fieldName: ops.value,
}); });
} }
if (ops.type === 'array') {
formServiceProperties.value?.additional.push({
type: ops.type,
fieldName: ops.value,
options: [''],
});
}
if (ops.type === 'string') { if (ops.type === 'string') {
formServiceProperties.value?.additional.push({ formServiceProperties.value?.additional.push({
type: ops.type, type: ops.type,
@ -101,6 +102,7 @@ function manageProperties(
type: ops.type, type: ops.type,
fieldName: ops.value, fieldName: ops.value,
comma: false, comma: false,
decimal: false,
decimalPlace: 2, decimalPlace: 2,
}); });
} }
@ -117,13 +119,21 @@ function manageProperties(
if (propertyIndex !== -1) { if (propertyIndex !== -1) {
formServiceProperties.value.additional.splice(propertyIndex, 1); formServiceProperties.value.additional.splice(propertyIndex, 1);
} else { } else {
if (propertyType === 'array' || propertyType === 'date') { if (propertyType === 'date') {
formServiceProperties.value?.additional.push({ formServiceProperties.value?.additional.push({
type: propertyType, type: propertyType,
fieldName: property, fieldName: property,
}); });
} }
if (propertyType === 'array') {
formServiceProperties.value?.additional.push({
type: propertyType,
fieldName: property,
options: [''],
});
}
if (propertyType === 'string') { if (propertyType === 'string') {
formServiceProperties.value?.additional.push({ formServiceProperties.value?.additional.push({
type: propertyType, type: propertyType,
@ -138,6 +148,7 @@ function manageProperties(
type: propertyType, type: propertyType,
fieldName: property, fieldName: property,
comma: false, comma: false,
decimal: false,
decimalPlace: 2, decimalPlace: 2,
}); });
} }
@ -169,13 +180,21 @@ function changeType(fieldName: string) {
if (!idx) return; if (!idx) return;
if (defaultPropType === 'array' || defaultPropType === 'date') { if (defaultPropType === 'date') {
formServiceProperties.value?.additional.push({ formServiceProperties.value?.additional.push({
type: defaultPropType, type: defaultPropType,
fieldName, fieldName,
}); });
} }
if (defaultPropType === 'array') {
formServiceProperties.value?.additional.push({
type: defaultPropType,
fieldName,
options: [''],
});
}
if (defaultPropType === 'string') { if (defaultPropType === 'string') {
formServiceProperties.value?.additional.push({ formServiceProperties.value?.additional.push({
type: defaultPropType, type: defaultPropType,
@ -190,6 +209,7 @@ function changeType(fieldName: string) {
type: defaultPropType, type: defaultPropType,
fieldName, fieldName,
comma: false, comma: false,
decimal: false,
decimalPlace: 2, decimalPlace: 2,
}); });
} }
@ -372,13 +392,21 @@ function confirmDelete(items: unknown[], index: number) {
@update:model-value=" @update:model-value="
(t: 'string' | 'number' | 'date' | 'array') => { (t: 'string' | 'number' | 'date' | 'array') => {
if (!formServiceProperties) return; if (!formServiceProperties) return;
if (t === 'array' || t === 'date') { if (t === 'date') {
formServiceProperties.additional[index] = { formServiceProperties.additional[index] = {
type: t, type: t,
fieldName: p.fieldName, fieldName: p.fieldName,
}; };
} }
if (t === 'array') {
formServiceProperties.additional[index] = {
type: t,
fieldName: p.fieldName,
options: [''],
};
}
if (t === 'string') { if (t === 'string') {
formServiceProperties.additional[index] = { formServiceProperties.additional[index] = {
type: t, type: t,
@ -393,6 +421,7 @@ function confirmDelete(items: unknown[], index: number) {
type: t, type: t,
fieldName: p.fieldName, fieldName: p.fieldName,
comma: false, comma: false,
decimal: false,
decimalPlace: 2, decimalPlace: 2,
}; };
} }
@ -473,17 +502,17 @@ function confirmDelete(items: unknown[], index: number) {
<div v-if="p.type === 'number'" class="q-gutter-y-sm"> <div v-if="p.type === 'number'" class="q-gutter-y-sm">
<div class="row items-center"> <div class="row items-center">
<div class="col surface-3 rounded q-py-xs"> <div class="col surface-3 rounded q-py-xs">
<q-checkbox v-model="comma" size="xs" /> <q-checkbox v-model="p.comma" size="xs" />
{{ $t('useComma') }} {{ $t('useComma') }}
</div> </div>
</div> </div>
<div class="row items-center"> <div class="row items-center">
<div class="col-7 surface-3 rounded q-mr-sm q-py-xs"> <div class="col-7 surface-3 rounded q-mr-sm q-py-xs">
<q-checkbox v-model="point" size="xs" /> <q-checkbox v-model="p.decimal" size="xs" />
{{ $t('decimal') }} {{ $t('decimal') }}
</div> </div>
<q-input <q-input
v-model="pointNum" v-model="p.decimalPlace"
class="col" class="col"
dense dense
outlined outlined
@ -492,20 +521,51 @@ function confirmDelete(items: unknown[], index: number) {
</div> </div>
</div> </div>
<div <div v-if="p.type === 'array'" class="q-gutter-y-sm">
v-if="p.type === 'array'" <div
class="row items-center justify-between" class="row items-center justify-between"
> v-for="(_, i) in p.options"
<div class="col surface-3 rounded q-mr-sm q-py-xs"> >
<q-checkbox v-model="selection" size="xs" /> <div class="col rounded">
{{ $t('addSelection') }} <q-input
v-model="p.options[i]"
class="col"
dense
outlined
:label="$t('selection')"
:rules="[
(val) => (!!val && i >= 1) || $t('pleaseInformation'),
]"
hide-bottom-space
/>
</div>
<div class="col-1 q-pl-sm">
<q-btn
@click="
() => {
p.options.splice(i, 1);
}
"
dense
flat
icon="mdi-trash-can-outline"
class="bordered"
text-color="negative"
style="border-radius: 6px"
/>
</div>
</div> </div>
<div class="col-1"> <div class="row">
<q-btn <q-btn
@click="
() => {
p.options.push('');
}
"
dense dense
flat flat
icon="mdi-plus" icon="mdi-plus"
class="bordered" class="bordered col-11"
text-color="grey" text-color="grey"
style="border-radius: 6px" style="border-radius: 6px"
/> />

View file

@ -80,6 +80,7 @@ type PropNumber = {
type: 'number'; type: 'number';
fieldName: string; fieldName: string;
comma: boolean; comma: boolean;
decimal: boolean;
decimalPlace: number; decimalPlace: number;
}; };
@ -91,6 +92,7 @@ type PropDate = {
type PropOptions = { type PropOptions = {
type: 'array'; type: 'array';
fieldName: string; fieldName: string;
options: string[];
}; };
// Product // Product