@tagplus/components 4.7.12 → 5.1.0
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/tp.common.js +2 -1
- package/dist/tp.common.js.LICENSE.txt +9 -0
- package/dist/tp.common.js.map +1 -1
- package/dist/tp.common.lang-tp-en-js.js +2 -0
- package/dist/tp.common.lang-tp-en-js.js.map +1 -0
- package/dist/tp.css +11 -167
- package/dist/tp.umd.js +2 -1
- package/dist/tp.umd.js.LICENSE.txt +9 -0
- package/dist/tp.umd.js.map +1 -1
- package/dist/tp.umd.lang-tp-en-js.js +2 -0
- package/dist/tp.umd.lang-tp-en-js.js.map +1 -0
- package/dist/tp.umd.min.js +2 -1
- package/dist/tp.umd.min.js.LICENSE.txt +9 -0
- package/dist/tp.umd.min.js.map +1 -1
- package/dist/tp.umd.min.lang-tp-en-js.js +2 -0
- package/dist/tp.umd.min.lang-tp-en-js.js.map +1 -0
- package/package.json +51 -50
- package/src/assets/scss/_fonts.scss +24 -23
- package/src/assets/scss/_helpers.scss +4 -0
- package/src/assets/scss/_mixins.scss +2 -2
- package/src/assets/scss/_overrides.scss +5 -52
- package/src/assets/scss/_resass.scss +21 -12
- package/src/assets/scss/_variables.scss +0 -1
- package/src/assets/scss/index.scss +1 -4
- package/src/components/Autosuggest/Autosuggest.vue +340 -767
- package/src/components/Autosuggest/Multisuggest.vue +22 -0
- package/src/components/Autosuggest/autosuggest-props.js +210 -0
- package/src/components/Autosuggest/autosuggest-style.scss +127 -0
- package/src/components/Autosuggest/core.js +63 -0
- package/src/components/Autosuggest/index.js +2 -0
- package/src/components/Autosuggest/multisuggest-props.js +9 -0
- package/src/components/Autosuggest/option.vue +136 -0
- package/src/components/Autosuggest/select-dropdown.vue +64 -0
- package/src/components/Autosuggest/useOption.js +120 -0
- package/src/components/Autosuggest/useSelect.js +1133 -0
- package/src/components/AutosuggestTest.vue +56 -0
- package/src/components/CardExemplo.vue +49 -0
- package/src/components/CodeSample.vue +78 -0
- package/src/components/Inline/Inline.vue +24 -32
- package/src/components/InputNumber/InputNumber.vue +329 -378
- package/src/components/InputNumber/input-number.js +135 -0
- package/src/components/Loader/Loader.vue +42 -53
- package/src/components/Loader/animations.scss +13 -0
- package/src/components/Money/Money.vue +11 -20
- package/src/components/Multisuggest/index.js +2 -3
- package/src/components/MultisuggestTest.vue +56 -0
- package/src/components/OptionsList/OptionsList.vue +7 -6
- package/src/components/OptionsListItem/OptionsListItem.vue +46 -42
- package/src/components/Percent/Percent.vue +8 -14
- package/src/components/Skeleton/Skeleton.vue +16 -11
- package/src/components/Step/Step.vue +42 -35
- package/src/components/Steps/Steps.vue +4 -7
- package/src/components/TesteToCurrency.vue +171 -0
- package/src/components/Tip/Tip.vue +45 -30
- package/src/components/ValueSelector.vue +60 -0
- package/src/components/autosuggestMixin.js +301 -0
- package/src/components/index.js +4 -1
- package/src/locale/i18n.js +162 -0
- package/src/locale/lang/en.js +3 -2
- package/src/locale/lang/pt-br.js +3 -2
- package/src/main.js +8 -14
- package/src/mixins/floatFormatter.js +12 -16
- package/src/plugins/currency.js +100 -0
- package/src/utils/browser.js +6 -0
- package/src/utils/constants.js +3 -0
- package/src/utils/error.js +22 -0
- package/src/utils/filters.js +1 -14
- package/src/utils/helpers.js +41 -0
- package/src/utils/i18n.js +2 -0
- package/src/utils/icon.js +35 -0
- package/src/utils/index.js +20 -0
- package/src/utils/objects.js +17 -0
- package/src/utils/runtime.js +86 -0
- package/src/utils/scroll.js +100 -0
- package/src/utils/strings.js +17 -0
- package/src/utils/style.js +80 -0
- package/src/utils/types.js +39 -0
- package/src/utils/use-derived-namespace.js +112 -0
- package/src/utils/use-form-common-props.js +41 -0
- package/src/utils/use-form-item.js +80 -0
- package/src/utils/use-id.js +40 -0
- package/src/utils/use-input.js +33 -0
- package/src/components/Dialog/Dialog.vue +0 -253
- package/src/components/Dialog/index.js +0 -3
- package/src/components/Multisuggest/Multisuggest.vue +0 -858
- package/src/locale/index.js +0 -78
- package/src/mixins/locale.js +0 -9
- package/src/utils/currency.js +0 -180
|
@@ -6,22 +6,24 @@
|
|
|
6
6
|
align="middle"
|
|
7
7
|
:class="tptipclasses"
|
|
8
8
|
>
|
|
9
|
-
<el-col
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
<el-col :sm="24" :lg="3">
|
|
10
|
+
<div
|
|
11
|
+
style="
|
|
12
|
+
display: flex;
|
|
13
|
+
min-width: 25px;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
margin: 15px;
|
|
16
|
+
padding: auto;
|
|
17
|
+
"
|
|
18
|
+
>
|
|
14
19
|
<em class="far fa-lightbulb-on" />
|
|
15
20
|
</div>
|
|
16
21
|
</el-col>
|
|
17
22
|
|
|
18
|
-
<el-col
|
|
19
|
-
:sm="24"
|
|
20
|
-
:lg="21"
|
|
21
|
-
>
|
|
23
|
+
<el-col :sm="24" :lg="21">
|
|
22
24
|
<div
|
|
23
25
|
:id="`${_id}-text`"
|
|
24
|
-
style="margin:15px; margin-left:
|
|
26
|
+
style="margin: 15px; margin-left: 0"
|
|
25
27
|
v-html="text"
|
|
26
28
|
/>
|
|
27
29
|
</el-col>
|
|
@@ -32,11 +34,14 @@
|
|
|
32
34
|
type="flex"
|
|
33
35
|
align="middle"
|
|
34
36
|
justify="space-between"
|
|
35
|
-
:class="tptipclasses"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
:class="tptipclasses"
|
|
38
|
+
>
|
|
39
|
+
<el-col :span="17">
|
|
40
|
+
<el-row
|
|
41
|
+
align="middle"
|
|
42
|
+
type="flex"
|
|
43
|
+
style="min-width: 25px; margin: 15px; padding: auto"
|
|
44
|
+
>
|
|
40
45
|
<em class="far fa-lightbulb-on" />
|
|
41
46
|
<b class="tp-title">{{ title }}</b>
|
|
42
47
|
</el-row>
|
|
@@ -45,10 +50,10 @@
|
|
|
45
50
|
<em class="fa fa-ellipsis-h tp-close-button" @click="closed = !closed" />
|
|
46
51
|
</el-col>
|
|
47
52
|
|
|
48
|
-
<el-col :class="'tp-text ' + (closed ? 'tp-vanish' : ''
|
|
53
|
+
<el-col :class="'tp-text ' + (closed ? 'tp-vanish' : '')" :span="24">
|
|
49
54
|
<div
|
|
50
55
|
:id="`${_id}-text`"
|
|
51
|
-
style="margin:15px; margin-left:
|
|
56
|
+
style="margin: 15px; margin-left: 0"
|
|
52
57
|
v-html="text"
|
|
53
58
|
/>
|
|
54
59
|
</el-col>
|
|
@@ -56,7 +61,9 @@
|
|
|
56
61
|
</template>
|
|
57
62
|
|
|
58
63
|
<script>
|
|
59
|
-
|
|
64
|
+
import { defineComponent } from 'vue'
|
|
65
|
+
|
|
66
|
+
export default defineComponent({
|
|
60
67
|
name: 'TpTip',
|
|
61
68
|
props: {
|
|
62
69
|
id: {
|
|
@@ -111,7 +118,7 @@ export default {
|
|
|
111
118
|
return classes
|
|
112
119
|
}
|
|
113
120
|
}
|
|
114
|
-
}
|
|
121
|
+
})
|
|
115
122
|
</script>
|
|
116
123
|
|
|
117
124
|
<style lang="scss" scoped>
|
|
@@ -121,10 +128,9 @@ export default {
|
|
|
121
128
|
|
|
122
129
|
.grid-content {
|
|
123
130
|
flex-wrap: wrap;
|
|
131
|
+
background-color: rgb(76 135 251 / 10%);
|
|
124
132
|
border-radius: 4px;
|
|
125
|
-
|
|
126
|
-
border-radius: 4px;
|
|
127
|
-
border: solid 1px rgba(76, 135, 251, 0.2);
|
|
133
|
+
border: solid 1px rgb(76 135 251 / 20%);
|
|
128
134
|
padding: 1rem;
|
|
129
135
|
font-size: 14px;
|
|
130
136
|
line-height: 24px;
|
|
@@ -143,8 +149,11 @@ export default {
|
|
|
143
149
|
.tp-tip-error {
|
|
144
150
|
background: #f56c6c1a 0% 0% no-repeat padding-box;
|
|
145
151
|
border: 1px solid #ff6077;
|
|
146
|
-
|
|
147
|
-
|
|
152
|
+
|
|
153
|
+
:deep() {
|
|
154
|
+
strong,
|
|
155
|
+
b,
|
|
156
|
+
em {
|
|
148
157
|
color: #ff425f;
|
|
149
158
|
}
|
|
150
159
|
}
|
|
@@ -153,8 +162,11 @@ export default {
|
|
|
153
162
|
.tp-tip-warning {
|
|
154
163
|
background: #fff9ea 0% 0% no-repeat padding-box;
|
|
155
164
|
border: 1px solid #ffc437;
|
|
156
|
-
|
|
157
|
-
|
|
165
|
+
|
|
166
|
+
:deep() {
|
|
167
|
+
strong,
|
|
168
|
+
b,
|
|
169
|
+
em {
|
|
158
170
|
color: #ffc437;
|
|
159
171
|
}
|
|
160
172
|
}
|
|
@@ -163,8 +175,11 @@ export default {
|
|
|
163
175
|
.tp-tip-success {
|
|
164
176
|
background: #f3fcfc 0% 0% no-repeat padding-box;
|
|
165
177
|
border: 1px solid #08a19e;
|
|
166
|
-
|
|
167
|
-
|
|
178
|
+
|
|
179
|
+
:deep() {
|
|
180
|
+
strong,
|
|
181
|
+
b,
|
|
182
|
+
em {
|
|
168
183
|
color: #08a19e;
|
|
169
184
|
}
|
|
170
185
|
}
|
|
@@ -187,9 +202,9 @@ export default {
|
|
|
187
202
|
|
|
188
203
|
.tp-vanish {
|
|
189
204
|
position: absolute;
|
|
190
|
-
max-height:0;
|
|
205
|
+
max-height: 0;
|
|
191
206
|
transform: scale(0);
|
|
192
|
-
opacity:0;
|
|
207
|
+
opacity: 0;
|
|
193
208
|
transition: 0s opacity linear;
|
|
194
209
|
}
|
|
195
210
|
</style>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-row justify="center" align="middle" class="value-selector-row">
|
|
3
|
+
<el-button
|
|
4
|
+
v-for="item in formattedValues"
|
|
5
|
+
:key="item.value"
|
|
6
|
+
:type="type"
|
|
7
|
+
class="value-selector-btn"
|
|
8
|
+
@click="$emit('input', item.value)">
|
|
9
|
+
{{item.label}}
|
|
10
|
+
</el-button>
|
|
11
|
+
</el-row>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script>
|
|
15
|
+
export default {
|
|
16
|
+
name: 'ValueSelector',
|
|
17
|
+
|
|
18
|
+
props: {
|
|
19
|
+
modelValue: {
|
|
20
|
+
type: Array,
|
|
21
|
+
default: () => []
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
type: {
|
|
25
|
+
type: String,
|
|
26
|
+
default: 'primary'
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
emits: ['input'],
|
|
31
|
+
|
|
32
|
+
computed: {
|
|
33
|
+
formattedValues () {
|
|
34
|
+
return this.modelValue.map(item => {
|
|
35
|
+
let label = item
|
|
36
|
+
if (typeof item === 'string'){
|
|
37
|
+
label = `'${item}'`
|
|
38
|
+
} else if (item === null){
|
|
39
|
+
label = 'null'
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
label,
|
|
43
|
+
value: item
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<style lang="scss" scoped>
|
|
52
|
+
.value-selector-row {
|
|
53
|
+
flex-wrap: nowrap;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.value-selector-btn {
|
|
57
|
+
flex-shrink: 0;
|
|
58
|
+
min-width: 50px;
|
|
59
|
+
}
|
|
60
|
+
</style>
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mixin contendo metodos para autosuggests
|
|
3
|
+
*/
|
|
4
|
+
export default {
|
|
5
|
+
props: {
|
|
6
|
+
/**
|
|
7
|
+
* @vuese
|
|
8
|
+
* id do css para teste unitário
|
|
9
|
+
*/
|
|
10
|
+
id: {
|
|
11
|
+
type: String
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
modelValue: {
|
|
15
|
+
type: [Number, String, Object, Boolean, Array],
|
|
16
|
+
default: ''
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
// Desativa o loader global ao carregar lista
|
|
20
|
+
disableLoader: {
|
|
21
|
+
type: Boolean,
|
|
22
|
+
default: false
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
// Indica se primeiro item da lista deve ser retornado por padrão
|
|
26
|
+
noDefault: {
|
|
27
|
+
type: Boolean,
|
|
28
|
+
default: false
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Se a lista vai ser carregada no create ou o labelKey não venha por padrão na requisição loadOnCreate = true,
|
|
33
|
+
* caso deva ser carregada quando o usuário clica deixar vazio ou false.
|
|
34
|
+
*/
|
|
35
|
+
loadOnCreate: {
|
|
36
|
+
type: Boolean,
|
|
37
|
+
default: null
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
// Indicia se o campo deve ser desabilitado
|
|
41
|
+
disabled: {
|
|
42
|
+
type: Boolean,
|
|
43
|
+
default: false
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
// Se o valor desse autosuggest for obrigatório se o value for vazio o after get vai selecionar a primeira opção
|
|
47
|
+
isRequired: {
|
|
48
|
+
type: Boolean,
|
|
49
|
+
default: false
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
allowCreate: {
|
|
53
|
+
type: Boolean,
|
|
54
|
+
default: true
|
|
55
|
+
},
|
|
56
|
+
valueKey: {
|
|
57
|
+
type: String,
|
|
58
|
+
default: 'id'
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
disableForm: {
|
|
62
|
+
type: Boolean,
|
|
63
|
+
default: false
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
data () {
|
|
68
|
+
return {
|
|
69
|
+
config: {
|
|
70
|
+
params: {}
|
|
71
|
+
},
|
|
72
|
+
doEmptyRequest: false,
|
|
73
|
+
list: [],
|
|
74
|
+
loading: true,
|
|
75
|
+
isLoadOnCreate: true,
|
|
76
|
+
modal: false,
|
|
77
|
+
autosuggest: false, // endpoint /autosuggest/*
|
|
78
|
+
customEndpoint: false // buscar em qualquer endpoint
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
computed: {
|
|
83
|
+
_id () {
|
|
84
|
+
return this.id || this.$options.name
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
/** desabilita o componente quando recebe disable true ou não tem permissão no form de incluir ou alterar */
|
|
88
|
+
_disabled () {
|
|
89
|
+
if (this.disabled) {
|
|
90
|
+
return true
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (this.disableForm) {
|
|
94
|
+
return true
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return false
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
/** @vuese
|
|
101
|
+
* Action para buscar em stores customizadas/dinâmicas, por padrão pega do $options.listAction
|
|
102
|
+
*/
|
|
103
|
+
listAction () {
|
|
104
|
+
return this.customAction ? this.customAction : this.$options.listAction
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
/** @vuese
|
|
108
|
+
* Retorna a URL a ser usada para buscar a lista caso não esteja definida no $options
|
|
109
|
+
* Passam aqui as urls customizadas, do /autosuggests, /entidade/categorias etc
|
|
110
|
+
*/
|
|
111
|
+
customUrl () {
|
|
112
|
+
if (this.customEndpoint) {
|
|
113
|
+
return this.customEndpoint
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (this.autosuggest) {
|
|
117
|
+
return `/autosuggests/${this.$options.autosuggest}`
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return false
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
_valueKey () {
|
|
124
|
+
return this.$options.valueKey || 'id'
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
_labelKey () {
|
|
128
|
+
return this.$options.labelKey || 'descricao'
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Ao montar componente, inicia o loading
|
|
134
|
+
*/
|
|
135
|
+
mounted () {
|
|
136
|
+
if (!this.disableLoader && this.isLoadOnCreate) {
|
|
137
|
+
this.startLoading(this.$options.name)
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
created () {
|
|
142
|
+
if (this.$parent.$options.name.substring(0, 6) === 'Filtro') {
|
|
143
|
+
this.isLoadOnCreate = false
|
|
144
|
+
} else if (this.loadOnCreate !== null) { // Se recebeu loadOnCreate via prop leva precedência
|
|
145
|
+
// Se for campo obrigatório e não vier o value inicial força a busca na api
|
|
146
|
+
if (this.isRequired && typeof this.value === 'undefined') {
|
|
147
|
+
this.isLoadOnCreate = true
|
|
148
|
+
} else {
|
|
149
|
+
this.isLoadOnCreate = this.loadOnCreate
|
|
150
|
+
}
|
|
151
|
+
} else if (this.$route && !isNaN(this.$route.params.id)) {
|
|
152
|
+
// Se está num form com ID só carrega lista quando clica
|
|
153
|
+
this.isLoadOnCreate = false
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Caso tenha value no created a primeira busca quando clica é vazia
|
|
157
|
+
this.doEmptyRequest = (typeof this.value !== 'undefined')
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
methods: {
|
|
161
|
+
/**
|
|
162
|
+
* HOOK executado quando getList é chamado
|
|
163
|
+
*/
|
|
164
|
+
autosuggestMixin_beforeGet () { },
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* HOOK executado quando getList é chamado
|
|
168
|
+
*/
|
|
169
|
+
autosuggestMixin_afterGet () { },
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* HOOK executado quando handleClose é chamado
|
|
173
|
+
*/
|
|
174
|
+
autosuggestMixin_beforeHandleClose () { },
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Realiza chamada da action no endpoint
|
|
178
|
+
* @param {*} busca valor recebido no autosuggest
|
|
179
|
+
*/
|
|
180
|
+
async autosuggestMixin_getList (busca) {
|
|
181
|
+
busca ||= ''
|
|
182
|
+
|
|
183
|
+
if (!Array.isArray(busca) && (busca !== '' || this.config.params.q !== busca)) {
|
|
184
|
+
this.config.params.q = busca
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Tratamento caso clique no primeiro autosuggest daquele tipo com loadOnCreate false e tenha um valor padrão
|
|
188
|
+
if (this.doEmptyRequest) {
|
|
189
|
+
this.config.params.q = ''
|
|
190
|
+
this.doEmptyRequest = false
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Hook executado antes de recuperar a lista
|
|
194
|
+
this.autosuggestMixin_beforeGet()
|
|
195
|
+
|
|
196
|
+
this.loading = true
|
|
197
|
+
|
|
198
|
+
// Se buscar em /autosuggest ou url dinâmica/customizada pega a url aqui
|
|
199
|
+
this.config.customUrl = this.customUrl
|
|
200
|
+
|
|
201
|
+
/* try {
|
|
202
|
+
await this.axios
|
|
203
|
+
.get(`${this.params.uri}?q=${busca}`)
|
|
204
|
+
.then(res => {
|
|
205
|
+
this.list = res.data
|
|
206
|
+
})
|
|
207
|
+
// eslint-disable-next-line no-unused-vars
|
|
208
|
+
.catch(_err => {
|
|
209
|
+
this.list = []
|
|
210
|
+
}).finally(() => {
|
|
211
|
+
this.loading = false
|
|
212
|
+
})
|
|
213
|
+
} catch (err) {
|
|
214
|
+
// this.$TpError(err)
|
|
215
|
+
} finally {
|
|
216
|
+
// this.finishLoading(this.$options.name)
|
|
217
|
+
} */
|
|
218
|
+
},
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Metodo para lidar com a criação de um novo registro
|
|
222
|
+
* Exibe o modal por padrão
|
|
223
|
+
* @param {*} evt Evento de criação
|
|
224
|
+
*/
|
|
225
|
+
autosuggestMixin_handleCreate (evt) {
|
|
226
|
+
if (evt.created) {
|
|
227
|
+
this.modal = true
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Método para lidar com o fechamento do modal
|
|
233
|
+
* Por padrão recarrega a lista e recupera o valor criado no modal, caso haja
|
|
234
|
+
* @param {*} val Valor recebido do modal
|
|
235
|
+
*/
|
|
236
|
+
async autosuggestMixin_handleClose (val) {
|
|
237
|
+
// Fecha o modal primeiro para diminuir tempo de transição
|
|
238
|
+
this.modal = false
|
|
239
|
+
|
|
240
|
+
if (val.id !== 0) {
|
|
241
|
+
const id = val.id?.id !== undefined ? val.id.id : val.id
|
|
242
|
+
|
|
243
|
+
await this.autosuggestMixin_getList('')
|
|
244
|
+
|
|
245
|
+
this.$emit('update:model-value', val.id)
|
|
246
|
+
|
|
247
|
+
const item = this.list.filter((value) => {
|
|
248
|
+
return id === value.id
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
this.$emit('change', item[0])
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Evento para tratamento do valor
|
|
257
|
+
* Devolve o valor recebido para o v-model no componente pai
|
|
258
|
+
* @param {*} evt
|
|
259
|
+
*/
|
|
260
|
+
autosuggestMixin_input (evt) {
|
|
261
|
+
this.$emit('update:model-value', evt)
|
|
262
|
+
this.autosuggestMixin_inputFullItem(evt)
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Evento Input com os dados completos do item selecionado
|
|
267
|
+
* @param {*} evt
|
|
268
|
+
*/
|
|
269
|
+
autosuggestMixin_inputFullItem (evt) {
|
|
270
|
+
let res = []
|
|
271
|
+
|
|
272
|
+
if (Array.isArray(evt)) {
|
|
273
|
+
evt.map((idValue) => {
|
|
274
|
+
this.list.map((item2) => {
|
|
275
|
+
if (idValue === item2[this._valueKey]) {
|
|
276
|
+
res.push(item2)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return item2
|
|
280
|
+
})
|
|
281
|
+
})
|
|
282
|
+
} else {
|
|
283
|
+
res = evt
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
this.$emit('inputFullItem', res)
|
|
287
|
+
},
|
|
288
|
+
|
|
289
|
+
autosuggestMixin_handleChange (val) {
|
|
290
|
+
if (val !== null && val !== undefined) {
|
|
291
|
+
const item = this.list.filter((value) => {
|
|
292
|
+
return val === value.id
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
this.$emit('change', item[0])
|
|
296
|
+
} else {
|
|
297
|
+
this.$emit('change', val)
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
package/src/components/index.js
CHANGED
|
@@ -11,7 +11,10 @@ import Multisuggest from './Multisuggest'
|
|
|
11
11
|
import Step from './Step'
|
|
12
12
|
import Steps from './Steps'
|
|
13
13
|
import InputNumber from './InputNumber'
|
|
14
|
-
import
|
|
14
|
+
import { ElDialog } from 'element-plus'
|
|
15
|
+
// hack para não ter que substituir todos tp-dialog de uma vez no nuxt
|
|
16
|
+
ElDialog.name = 'TpDialog'
|
|
17
|
+
const Dialog = ElDialog
|
|
15
18
|
|
|
16
19
|
export {
|
|
17
20
|
Autosuggest,
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { createI18n } from 'vue-i18n'
|
|
2
|
+
import { reactive } from 'vue'
|
|
3
|
+
|
|
4
|
+
let i18n
|
|
5
|
+
|
|
6
|
+
const loadedLanguages = []
|
|
7
|
+
|
|
8
|
+
let importLangFile = false
|
|
9
|
+
const i18nHelper = {
|
|
10
|
+
/**
|
|
11
|
+
* Eventos que podem ser observados com watch
|
|
12
|
+
*/
|
|
13
|
+
hooks: reactive({
|
|
14
|
+
onLanguageChanged: ''
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Assincronamente importa e mescla arquivos de lang do vue components e do projeto em que essa lib é importada
|
|
20
|
+
* na lingaguem escolhida
|
|
21
|
+
* caminho padrão src/locale/lang/*.js
|
|
22
|
+
* @param {String} filename - The name of the language file to import.
|
|
23
|
+
* @returns {Promise} - A promise that resolves to an object containing merged custom and local language messages.
|
|
24
|
+
*/
|
|
25
|
+
const importLangFiles = async function (filename) {
|
|
26
|
+
let langsCustom = {}
|
|
27
|
+
const langsLocais = await import(/* webpackChunkName: "lang-tp-[request]" */ `@src/locale/lang/${filename}.js`)
|
|
28
|
+
if (importLangFile && typeof importLangFile === 'function') {
|
|
29
|
+
langsCustom = await importLangFile(filename)
|
|
30
|
+
}
|
|
31
|
+
return { ...langsCustom, ...langsLocais }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Essa função deve ser impementada no i18nHelper para executar ações após trocar a linguagem,
|
|
36
|
+
* como salvar nos cookies ou session a linguagem atual
|
|
37
|
+
*
|
|
38
|
+
* @param {String} locale - The locale string representing the language to be set.
|
|
39
|
+
* @throws {Error} Throws an error if the onLanguageSet function is not implemented.
|
|
40
|
+
* @returns {void}
|
|
41
|
+
*/
|
|
42
|
+
i18nHelper.onLanguageSet = function (locale) {
|
|
43
|
+
throw new Error('Implemente a função onLanguageSet na definição do plugin i18n')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Sets the current language and updates the i18n instance accordingly.
|
|
48
|
+
* Triggers the onLanguageChanged hook and calls the onLanguageSet function.
|
|
49
|
+
* @param {String} locale - The locale string representing the language to be set. EX: 'pt-br', 'en'
|
|
50
|
+
* @returns {String} - The updated locale string.
|
|
51
|
+
*/
|
|
52
|
+
i18nHelper.setI18nLanguage = function (locale) {
|
|
53
|
+
if (i18n.mode === 'legacy') {
|
|
54
|
+
i18n.global.locale = locale
|
|
55
|
+
} else {
|
|
56
|
+
i18n.global.locale.value = locale
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
i18nHelper.hooks.onLanguageChanged = locale
|
|
60
|
+
document.querySelector('html').setAttribute('lang', locale)
|
|
61
|
+
i18nHelper.onLanguageSet(locale)
|
|
62
|
+
return locale
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Asynchronously loads and sets the current language for the i18n instance.
|
|
67
|
+
* If the language is already loaded, it returns immediately.
|
|
68
|
+
* @param {String} locale - The locale string representing the language to be set. EX: 'pt-br', 'en'
|
|
69
|
+
* @returns {Promise}
|
|
70
|
+
*/
|
|
71
|
+
i18nHelper.loadLanguageAsync = async function (locale) {
|
|
72
|
+
if (i18n.global.locale === locale) {
|
|
73
|
+
return locale
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// If the language was already loaded
|
|
77
|
+
if (loadedLanguages.includes(locale)) {
|
|
78
|
+
return locale
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// load locale messages with dynamic import
|
|
82
|
+
const messages = await importLangFiles(locale)
|
|
83
|
+
// set locale and locale message
|
|
84
|
+
i18n.global.setLocaleMessage(locale, messages.default)
|
|
85
|
+
loadedLanguages.push(locale)
|
|
86
|
+
return locale
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Asynchronously sets up and initializes the i18n instance with the provided options.
|
|
91
|
+
* If the i18n instance is already created, it returns the existing instance.
|
|
92
|
+
*
|
|
93
|
+
* @param {Object} [options={}] - An optional object containing configuration options for the i18n instance.
|
|
94
|
+
* @param {String} [options.locale='pt-br'] - The default locale for the i18n instance.
|
|
95
|
+
* @param {Object} [options.i18nOptions] - Additional options to be passed to the createI18n function.
|
|
96
|
+
*
|
|
97
|
+
* @returns {Promise<I18n>} - A promise that resolves to the initialized i18n instance.
|
|
98
|
+
*/
|
|
99
|
+
async function setupI18n (options = {}) {
|
|
100
|
+
if (!i18n) {
|
|
101
|
+
const locale = options.locale || 'pt-br'
|
|
102
|
+
|
|
103
|
+
i18n = createI18n({
|
|
104
|
+
legacy: false,
|
|
105
|
+
locale,
|
|
106
|
+
missing: (locale, key) => {
|
|
107
|
+
console.warn(`translation missing: locale=${locale}, key=${key}`)
|
|
108
|
+
},
|
|
109
|
+
...options
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
await i18nHelper.loadLanguageAsync(locale)
|
|
113
|
+
i18nHelper.setI18nLanguage(locale)
|
|
114
|
+
}
|
|
115
|
+
return i18n
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A plugin for Vue.js that initializes and configures the i18n instance with customizable options.
|
|
120
|
+
* It also provides a helper object for managing language settings and loading language files asynchronously.
|
|
121
|
+
*
|
|
122
|
+
* @param {Object} options - An object containing configuration options for the plugin.
|
|
123
|
+
* @param {Object} options.i18nHelper - An object containing custom functions for managing language settings.
|
|
124
|
+
* @param {Function} [options.i18nHelper.importLangFile] - A function for asynchronously importing custom language files.
|
|
125
|
+
* @param {Function} [options.i18nHelper.onLanguageSet] - A function to be called after setting the language.
|
|
126
|
+
* @param {Object} [options.i18nOptions] - Additional options to be passed to the createI18n function.
|
|
127
|
+
*
|
|
128
|
+
* @returns {Object} - An object with an install function for Vue.js plugins.
|
|
129
|
+
*/
|
|
130
|
+
export default async (options) => {
|
|
131
|
+
// Override the importLangFile function if provided in options
|
|
132
|
+
if (typeof options.i18nHelper.importLangFile === 'function') {
|
|
133
|
+
i18nHelper.importLangFile = options.i18nHelper.importLangFile
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Override the onLanguageSet function if provided in options
|
|
137
|
+
if (typeof options.i18nHelper.onLanguageSet === 'function') {
|
|
138
|
+
i18nHelper.onLanguageSet = options.i18nHelper.onLanguageSet
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
let i18nOptions = {}
|
|
142
|
+
// Use provided i18nOptions if available
|
|
143
|
+
if (options.i18nOptions && typeof options.i18nOptions === 'object') {
|
|
144
|
+
i18nOptions = options.i18nOptions
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Initialize the i18n instance with the provided options
|
|
148
|
+
i18n = await setupI18n(i18nOptions)
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
install: (app, opts) => {
|
|
152
|
+
// Install the original i18n instance
|
|
153
|
+
i18n.install(app, i18nOptions)
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Override project-specific functions and provide the $i18nHelper
|
|
157
|
+
* in the Vue.js app's global properties.
|
|
158
|
+
**/
|
|
159
|
+
app.config.globalProperties.$i18nHelper = i18nHelper
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
package/src/locale/lang/en.js
CHANGED