contactstudiocstools 1.0.255 → 1.0.256
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<OrganismForm
|
|
3
|
+
v-slot="{ models, getRef }"
|
|
4
|
+
ref="form"
|
|
5
|
+
:submit="submit"
|
|
6
|
+
:deny="deny"
|
|
7
|
+
:defaults="defaults"
|
|
8
|
+
class="form"
|
|
9
|
+
>
|
|
10
|
+
<div
|
|
11
|
+
v-for="(field, i) in mailing"
|
|
12
|
+
:key="i"
|
|
13
|
+
class="flex items-center space-between"
|
|
14
|
+
:disabled="field.disabled"
|
|
15
|
+
>
|
|
16
|
+
<span class="flex-grow max-w-32 text-right pr-2 text-[11px] font-medium">
|
|
17
|
+
{{field.label}}
|
|
18
|
+
</span>
|
|
19
|
+
<MoleculeFieldGroup
|
|
20
|
+
:ref="getRef"
|
|
21
|
+
:rules="[getRulesByField(models[field.name], field)]"
|
|
22
|
+
class="flex-grow"
|
|
23
|
+
>
|
|
24
|
+
<AtomField
|
|
25
|
+
v-model="models[field.name]"
|
|
26
|
+
:type="field.type"
|
|
27
|
+
:field="field"
|
|
28
|
+
@blur.capture="
|
|
29
|
+
persist(field.name, models[field.name]);
|
|
30
|
+
routine({ models, field });
|
|
31
|
+
"
|
|
32
|
+
/>
|
|
33
|
+
</MoleculeFieldGroup>
|
|
34
|
+
</div>
|
|
35
|
+
</OrganismForm>
|
|
36
|
+
</template>
|
|
37
|
+
|
|
38
|
+
<script setup lang="ts">
|
|
39
|
+
import { ref, computed } from "vue";
|
|
40
|
+
import { IMailing, IField, IRule, EFieldTypes } from "./types";
|
|
41
|
+
import OrganismForm from "./Organism.Form.vue";
|
|
42
|
+
|
|
43
|
+
interface IProps {
|
|
44
|
+
mailing: IMailing;
|
|
45
|
+
submit: Function;
|
|
46
|
+
deny?: Function;
|
|
47
|
+
persist?: Function;
|
|
48
|
+
routine?: Function;
|
|
49
|
+
|
|
50
|
+
defaults?: { [name: string]: string };
|
|
51
|
+
}
|
|
52
|
+
const props = defineProps<IProps>();
|
|
53
|
+
|
|
54
|
+
// computed
|
|
55
|
+
const getRulesByField = computed<Function>(
|
|
56
|
+
() =>
|
|
57
|
+
(value: string, { regex, required, messages, type }: IField): IRule => {
|
|
58
|
+
const isPhoneField = type === EFieldTypes.phone;
|
|
59
|
+
const isBrazilianPhone = /^\+55[0-9]/.test(value);
|
|
60
|
+
const errorMessage = messages?.error || "";
|
|
61
|
+
|
|
62
|
+
if (isPhoneField && isBrazilianPhone) {
|
|
63
|
+
regex = /^\+55[0-9]{10,11}$/;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return buildRule({ value, regex, required, errorMessage });
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// data
|
|
71
|
+
const form = ref<InstanceType<typeof OrganismForm> | null>(null);
|
|
72
|
+
|
|
73
|
+
// methods
|
|
74
|
+
function buildRule({ value, regex, required, errorMessage }: any): IRule {
|
|
75
|
+
return () => {
|
|
76
|
+
if (value) return regex.test(value) || errorMessage;
|
|
77
|
+
if (required) return "Campo obrigatório!";
|
|
78
|
+
|
|
79
|
+
return true;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function persist(label: string, value: any) {
|
|
84
|
+
if (!props.persist) return;
|
|
85
|
+
|
|
86
|
+
props.persist({ [label]: value });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function routine({ models, field }: any) {
|
|
90
|
+
if (!props.routine) return;
|
|
91
|
+
|
|
92
|
+
props.routine({ models, field });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// expose
|
|
96
|
+
defineExpose({ form });
|
|
97
|
+
</script>
|
|
98
|
+
|
|
99
|
+
<style scoped>
|
|
100
|
+
.field-group {
|
|
101
|
+
position: relative;
|
|
102
|
+
}
|
|
103
|
+
</style>
|