@tagplus/components 5.2.8 → 5.2.9
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 +1 -1
- package/dist/tp.common.js.map +1 -1
- package/dist/{tp.common.lang-tp-en-js.js → tp.common.lang-en-js.js} +2 -2
- package/dist/tp.common.lang-en-js.js.map +1 -0
- package/dist/tp.umd.js +1 -1
- package/dist/tp.umd.js.map +1 -1
- package/dist/{tp.umd.lang-tp-en-js.js → tp.umd.lang-en-js.js} +2 -2
- package/dist/tp.umd.lang-en-js.js.map +1 -0
- package/dist/tp.umd.min.js +1 -1
- package/dist/tp.umd.min.js.map +1 -1
- package/dist/{tp.umd.min.lang-tp-en-js.js → tp.umd.min.lang-en-js.js} +2 -2
- package/dist/tp.umd.min.lang-en-js.js.map +1 -0
- package/package.json +2 -7
- package/dist/tp.common.lang-tp-en-js.js.map +0 -1
- package/dist/tp.umd.lang-tp-en-js.js.map +0 -1
- package/dist/tp.umd.min.lang-tp-en-js.js.map +0 -1
- package/src/assets/scss/_fonts.scss +0 -28
- package/src/assets/scss/_functions.scss +0 -22
- package/src/assets/scss/_helpers.scss +0 -116
- package/src/assets/scss/_mixins.scss +0 -69
- package/src/assets/scss/_overrides.scss +0 -22
- package/src/assets/scss/_resass.scss +0 -92
- package/src/assets/scss/_variables.scss +0 -26
- package/src/assets/scss/index.scss +0 -8
- package/src/components/Autosuggest/Autosuggest.vue +0 -362
- package/src/components/Autosuggest/Multisuggest.vue +0 -22
- package/src/components/Autosuggest/autosuggest-props.js +0 -210
- package/src/components/Autosuggest/autosuggest-style.scss +0 -127
- package/src/components/Autosuggest/core.js +0 -63
- package/src/components/Autosuggest/index.js +0 -5
- package/src/components/Autosuggest/multisuggest-props.js +0 -9
- package/src/components/Autosuggest/option.vue +0 -136
- package/src/components/Autosuggest/select-dropdown.vue +0 -64
- package/src/components/Autosuggest/useOption.js +0 -120
- package/src/components/Autosuggest/useSelect.js +0 -1133
- package/src/components/AutosuggestTest.vue +0 -56
- package/src/components/CardExemplo.vue +0 -49
- package/src/components/CodeSample.vue +0 -78
- package/src/components/Inline/Inline.vue +0 -141
- package/src/components/Inline/index.js +0 -3
- package/src/components/InputNumber/InputNumber.vue +0 -381
- package/src/components/InputNumber/index.js +0 -3
- package/src/components/InputNumber/input-number.js +0 -135
- package/src/components/Loader/Loader.vue +0 -306
- package/src/components/Loader/animations.scss +0 -81
- package/src/components/Loader/index.js +0 -3
- package/src/components/Money/Money.vue +0 -73
- package/src/components/Money/index.js +0 -3
- package/src/components/Multisuggest/index.js +0 -2
- package/src/components/MultisuggestTest.vue +0 -56
- package/src/components/OptionsList/OptionsList.vue +0 -62
- package/src/components/OptionsList/index.js +0 -3
- package/src/components/OptionsListItem/OptionsListItem.vue +0 -195
- package/src/components/OptionsListItem/index.js +0 -3
- package/src/components/Percent/Percent.vue +0 -75
- package/src/components/Percent/index.js +0 -3
- package/src/components/Skeleton/Skeleton.vue +0 -142
- package/src/components/Skeleton/index.js +0 -3
- package/src/components/Step/Step.vue +0 -237
- package/src/components/Step/index.js +0 -3
- package/src/components/Steps/Steps.vue +0 -15
- package/src/components/Steps/index.js +0 -3
- package/src/components/TesteToCurrency.vue +0 -171
- package/src/components/Tip/Tip.vue +0 -210
- package/src/components/Tip/index.js +0 -3
- package/src/components/ValueSelector.vue +0 -60
- package/src/components/autosuggestMixin.js +0 -301
- package/src/components/index.js +0 -34
- package/src/locale/i18nCreator.js +0 -166
- package/src/locale/lang/en.js +0 -35
- package/src/locale/lang/pt-br.js +0 -35
- package/src/main.js +0 -21
- package/src/mixins/floatFormatter.js +0 -49
- package/src/plugins/currency.js +0 -100
- package/src/utils/browser.js +0 -6
- package/src/utils/constants.js +0 -3
- package/src/utils/error.js +0 -22
- package/src/utils/filters.js +0 -71
- package/src/utils/helpers.js +0 -41
- package/src/utils/i18n.js +0 -2
- package/src/utils/icon.js +0 -35
- package/src/utils/index.js +0 -20
- package/src/utils/objects.js +0 -17
- package/src/utils/runtime.js +0 -86
- package/src/utils/scroll.js +0 -100
- package/src/utils/strings.js +0 -17
- package/src/utils/style.js +0 -80
- package/src/utils/types.js +0 -39
- package/src/utils/use-derived-namespace.js +0 -112
- package/src/utils/use-form-common-props.js +0 -41
- package/src/utils/use-form-item.js +0 -80
- package/src/utils/use-id.js +0 -40
- package/src/utils/use-input.js +0 -33
|
@@ -1,301 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import Autosuggest from './Autosuggest'
|
|
2
|
-
import Inline from './Inline'
|
|
3
|
-
import Money from './Money'
|
|
4
|
-
import Percent from './Percent'
|
|
5
|
-
import OptionsList from './OptionsList'
|
|
6
|
-
import OptionsListItem from './OptionsListItem'
|
|
7
|
-
import Loader from './Loader'
|
|
8
|
-
import Skeleton from './Skeleton'
|
|
9
|
-
import Tip from './Tip'
|
|
10
|
-
import Multisuggest from './Multisuggest'
|
|
11
|
-
import Step from './Step'
|
|
12
|
-
import Steps from './Steps'
|
|
13
|
-
import InputNumber from './InputNumber'
|
|
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
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
-
Autosuggest,
|
|
21
|
-
Inline,
|
|
22
|
-
Money,
|
|
23
|
-
Percent,
|
|
24
|
-
OptionsList,
|
|
25
|
-
OptionsListItem,
|
|
26
|
-
Loader,
|
|
27
|
-
Skeleton,
|
|
28
|
-
Tip,
|
|
29
|
-
Multisuggest,
|
|
30
|
-
Step,
|
|
31
|
-
Steps,
|
|
32
|
-
InputNumber,
|
|
33
|
-
Dialog
|
|
34
|
-
}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { createI18n } from 'vue-i18n'
|
|
2
|
-
import { reactive } from 'vue'
|
|
3
|
-
|
|
4
|
-
let i18n
|
|
5
|
-
|
|
6
|
-
const loadedLanguages = []
|
|
7
|
-
|
|
8
|
-
const i18nHelper = {
|
|
9
|
-
importLangFile: false,
|
|
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 (i18nHelper.importLangFile && typeof i18nHelper.importLangFile === 'function') {
|
|
29
|
-
langsCustom = await i18nHelper.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
|
-
* @param {Function} [postInstall] - A function to be called after the plugin is installed.
|
|
128
|
-
*
|
|
129
|
-
* @returns {Object} - An object with an install function for Vue.js plugins.
|
|
130
|
-
*/
|
|
131
|
-
export default async (options = {}, postInstall = (app, options, i18nHelper) => {}) => {
|
|
132
|
-
// Validating the options
|
|
133
|
-
const keys = Object.keys(options).filter(key => !['i18nHelper', 'i18nOptions'].includes(key))
|
|
134
|
-
if (keys.length) {
|
|
135
|
-
throw new Error(`Invalid options: ${keys.join(', ')}, expected { i18nOptions, i18nHelper }`)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Overriding the importLangFile function if provided in options
|
|
139
|
-
if (options.i18nHelper && typeof options.i18nHelper.importLangFile === 'function') {
|
|
140
|
-
i18nHelper.importLangFile = options.i18nHelper.importLangFile
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Overriding the onLanguageSet function if provided in options
|
|
144
|
-
if (options.i18nHelper && typeof options.i18nHelper.onLanguageSet === 'function') {
|
|
145
|
-
i18nHelper.onLanguageSet = options.i18nHelper.onLanguageSet
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
let i18nOptions = {}
|
|
149
|
-
// Using provided i18nOptions if available
|
|
150
|
-
if (options.i18nOptions && typeof options.i18nOptions === 'object') {
|
|
151
|
-
i18nOptions = options.i18nOptions
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Initializing the i18n instance with the provided options
|
|
155
|
-
i18n = await setupI18n(i18nOptions)
|
|
156
|
-
|
|
157
|
-
return {
|
|
158
|
-
install: (app, opts) => {
|
|
159
|
-
// Installing the original i18n instance
|
|
160
|
-
i18n.install(app, i18nOptions)
|
|
161
|
-
if (typeof postInstall === 'function') {
|
|
162
|
-
postInstall(app, options, i18nHelper)
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
package/src/locale/lang/en.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import enLocale from 'element-plus/es/locale/lang/en'
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
...enLocale,
|
|
5
|
-
lingua: 'English',
|
|
6
|
-
|
|
7
|
-
tp: {
|
|
8
|
-
money: {
|
|
9
|
-
currency: '$'
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
locale: {
|
|
14
|
-
// locale name equals filename reference
|
|
15
|
-
name: 'en',
|
|
16
|
-
|
|
17
|
-
// IANA.ORG convetions according to W3C
|
|
18
|
-
prefix: 'en-US',
|
|
19
|
-
|
|
20
|
-
number: {
|
|
21
|
-
decimal: '.',
|
|
22
|
-
thousands: '',
|
|
23
|
-
prefix: '',
|
|
24
|
-
suffix: '',
|
|
25
|
-
precision: 2
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
date: {
|
|
29
|
-
format: 'YYYY-MM-DD'
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
common: {
|
|
33
|
-
placeholder: 'placeholder'
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/locale/lang/pt-br.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import ptbrLocale from 'element-plus/es/locale/lang/pt-br'
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
...ptbrLocale,
|
|
5
|
-
lingua: 'Português',
|
|
6
|
-
|
|
7
|
-
tp: {
|
|
8
|
-
money: {
|
|
9
|
-
currency: 'R$'
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
locale: {
|
|
14
|
-
// locale name equals filename reference
|
|
15
|
-
name: 'pt-br',
|
|
16
|
-
|
|
17
|
-
// IANA.ORG convetions according to W3C
|
|
18
|
-
prefix: 'pt-BR',
|
|
19
|
-
|
|
20
|
-
number: {
|
|
21
|
-
decimal: ',',
|
|
22
|
-
thousands: '.',
|
|
23
|
-
prefix: '',
|
|
24
|
-
suffix: '',
|
|
25
|
-
precision: 2
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
date: {
|
|
29
|
-
format: 'DD/MM/YYYY'
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
common: {
|
|
33
|
-
placeholder: 'placeholder'
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/main.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// import 'element-plus/dist/index.css'
|
|
2
|
-
import * as components from '@src/components'
|
|
3
|
-
import Currency from '@src/plugins/currency.js'
|
|
4
|
-
import i18nCreator from '@src/locale/i18nCreator.js'
|
|
5
|
-
|
|
6
|
-
const install = function (app) {
|
|
7
|
-
app.use(Currency)
|
|
8
|
-
|
|
9
|
-
// components
|
|
10
|
-
for (const componentName in components) {
|
|
11
|
-
const component = components[componentName]
|
|
12
|
-
app.component(component.name, component)
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (typeof window !== 'undefined' && window.Vue) {
|
|
17
|
-
install(window.Vue)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default { ...components, install }
|
|
21
|
-
export { i18nCreator }
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Eventos para componentes tp-money e tp-percent mostratem o número formatado com a precisão correta e devolver float sem arredondar
|
|
3
|
-
*/
|
|
4
|
-
export default {
|
|
5
|
-
inject: ['formatMoney'],
|
|
6
|
-
|
|
7
|
-
data () {
|
|
8
|
-
return {
|
|
9
|
-
formattedValue: this.modelValue
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
props: {
|
|
14
|
-
allowEmpty: {
|
|
15
|
-
type: Boolean,
|
|
16
|
-
default: false
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
customPrecision: {
|
|
20
|
-
default: false
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
watch: {
|
|
25
|
-
modelValue: {
|
|
26
|
-
immediate: true,
|
|
27
|
-
handler (newValue, oldValue) {
|
|
28
|
-
if (newValue === '' && this.allowEmpty) {
|
|
29
|
-
this.formattedValue = ''
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
this.formattedValue = this.formatMoney(newValue, true, this.locale, this.customPrecision)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
methods: {
|
|
38
|
-
input (evt) {
|
|
39
|
-
this.formattedValue = this.formatMoney(evt, true, this.locale, this.customPrecision)
|
|
40
|
-
const moneyFormatado = this.formatMoney(evt, false, this.locale, this.customPrecision)
|
|
41
|
-
|
|
42
|
-
this.$emit('input', moneyFormatado)
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
handleChange (evt) {
|
|
46
|
-
this.$emit('change', this.formatMoney(evt, false, this.locale, this.customPrecision))
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|