@metano/quasar_rest_auth 1.0.9 → 1.0.11

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/boot/app.js CHANGED
@@ -49,20 +49,6 @@ export const pegaDominio = function () {
49
49
  return dominiourl // retorna a parte www.endereco.com.brs@
50
50
  }
51
51
 
52
- export const MeIsAuthorized = function (permissions, permission) {
53
- // const store = useStore()
54
- let result = false
55
- if (Array.isArray(permissions)) {
56
- permissions.forEach(element => {
57
- if (element.nome === permission) {
58
- result = true
59
- } else {
60
- // store?.commit('auth/SET_PAGEPERMISSOES', permission)
61
- }
62
- })
63
- }
64
- return result
65
- }
66
52
 
67
53
  export const tdc = traducao
68
54
  export const ds = dateSplit
package/boot/base.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { LanguageStore } from '../stores/AuthStore'
2
+
1
3
 
2
4
  let result = false
3
5
  export const localStorageSetItem = (key, value) => {
@@ -10,22 +12,6 @@ export const localStorageSetItem = (key, value) => {
10
12
  }
11
13
 
12
14
 
13
- export const IsAuthorized = {
14
- bind (el, binding, vnode) {
15
- const store = vnode.context.$store
16
- const permissions = store.getters['auth/getPermissions']
17
-
18
- permissions.forEach(element => {
19
- if (element.nome === binding.value) {
20
- result = true
21
- }
22
- })
23
-
24
- if (!result) {
25
- el.style.display = 'none'
26
- }
27
- }
28
- }
29
15
 
30
16
  export const pegaDominio = function () {
31
17
  let pagelocalurl = location.href // pega endereço que esta no navegador
@@ -34,65 +20,46 @@ export const pegaDominio = function () {
34
20
  return dominiourl // retorna a parte www.endereco.com.brs@
35
21
  }
36
22
 
37
- export const MeIsAuthorized = function (permissions, permission) {
38
- let result = false
39
- // permissions.forEach(element => {
40
- // if (element.nome === permission) {
41
- // result = true
42
- // }
43
- // })
44
- result = true
45
- return result
46
- }
47
23
 
48
- export const traducao = function (texto = '') {
49
- let returne = ''
50
- try {
51
- if (this.$store?.state?.lingua?.Traducao !== '') {
52
- for (const txt in this.$store?.state?.lingua?.Traducao) {
53
- for (const key in this.$store?.state?.lingua?.Traducao[txt]) {
54
- if (remocao(key) === remocao(texto)) {
55
- const traducao = this.$store?.state?.lingua?.Traducao[txt][key]
56
- returne = replaceTraducao(texto, traducao)
57
- }
58
- }
59
- }
60
- }
61
- } catch (error) {
62
24
 
25
+
26
+ export const traducao = (texto = '') => {
27
+ const linguaStore = LanguageStore()
28
+ const chave = texto.toLowerCase().trim()
29
+
30
+ const traducaoDireta = linguaStore.TraducaoMap[chave]
31
+
32
+ if (!traducaoDireta) {
33
+ return texto
63
34
  }
64
- if (returne === '') {
65
- returne = texto
66
- }
67
- return returne
68
- }
69
35
 
70
- function remocao (texto) {
71
- const re = /(\s*%-\s*[a-zA-Z-0-9\s*]+\s*-%\s*)/g
72
- const newstr = texto?.replace(re, ' ')
73
- return newstr
36
+ return replaceTraducao
37
+ ? replaceTraducao(texto, traducaoDireta)
38
+ : traducaoDireta
74
39
  }
75
40
 
76
- function captura (texto) {
77
- const re = /(\s*%-\s*[a-zA-Z-0-9\s*]+\s*-%\s*)/g
78
- const newstr = texto.match(re)
79
- return newstr
41
+ function captura (texto = '') {
42
+ return texto.match(/\s*%-\s*[\w\s-]+\s*-%\s*/g) || []
80
43
  }
81
44
 
82
- function replaceTraducao (texto, textDeTraducao) {
83
- const array = captura(texto)
84
- if (array != null) {
85
- array.forEach(element => {
86
- element = element.replace('%-', '')
87
- element = element.replace('-%', '')
88
- const text = element.trim()
89
- const re = /(\s*%-\s*[a-zA-Z-0-9\s*]+\s*-%\s*)/
90
- textDeTraducao = textDeTraducao.replace(re, ' ' + text + ' ')
91
- })
92
- }
93
- return textDeTraducao
45
+ function replaceTraducao (texto = '', textDeTraducao = '') {
46
+ const valores = captura(texto)
47
+ if (!valores.length) return textDeTraducao
48
+
49
+ let i = 0
50
+
51
+ return textDeTraducao.replace(
52
+ /\s*%-\s*[\w\s-]+\s*-%\s*/g,
53
+ () => {
54
+ const v = valores[i++]
55
+ return v
56
+ ? ' ' + v.replace('%-', '').replace('-%', '').trim() + ' '
57
+ : ''
58
+ }
59
+ )
94
60
  }
95
61
 
62
+
96
63
  export const MeIsTipoEntidade = function (entidade, permission) {
97
64
  let result = false
98
65
  // console.log(entidade.nome, permission)
@@ -0,0 +1,34 @@
1
+ <template>
2
+ <div class="q-pa-md q-gutter-sm">
3
+ <h2>{{ tdc('Page permissoes') }}</h2>
4
+ </div>
5
+ </template>
6
+ <script >
7
+
8
+ import { defineComponent } from 'vue'
9
+ import { tdc } from '../boot/app'
10
+
11
+
12
+ export default defineComponent({
13
+ components: {
14
+
15
+ },
16
+ setup () {
17
+ },
18
+ data () {
19
+ return {
20
+ tdc: tdc,
21
+ }
22
+ },
23
+ methods: {
24
+
25
+ },
26
+ created () {
27
+ },
28
+ computed: {
29
+ },
30
+ mounted () {
31
+
32
+ }
33
+ })
34
+ </script>
@@ -0,0 +1,34 @@
1
+ <template>
2
+ <div class="q-pa-md q-gutter-sm">
3
+ <h2>{{ tdc('User permissoes') }}</h2>
4
+ </div>
5
+ </template>
6
+ <script >
7
+
8
+ import { defineComponent } from 'vue'
9
+ import { tdc } from '../boot/app'
10
+
11
+
12
+ export default defineComponent({
13
+ components: {
14
+
15
+ },
16
+ setup () {
17
+ },
18
+ data () {
19
+ return {
20
+ tdc: tdc,
21
+ }
22
+ },
23
+ methods: {
24
+
25
+ },
26
+ created () {
27
+ },
28
+ computed: {
29
+ },
30
+ mounted () {
31
+
32
+ }
33
+ })
34
+ </script>
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.0.9",
6
+ "version": "1.0.11",
7
7
  "description": "Rest em quasar para autenticacao",
8
8
  "keywords": [
9
9
  "rest",
@@ -82,13 +82,31 @@ export const LanguageStore = defineStore("lang", {
82
82
  state: () => ({
83
83
  current: {} ,
84
84
  list: [],
85
+ TraducaoMap: {}
85
86
  }),
86
87
 
87
88
  actions: {
88
89
  change(lang) {
89
90
  this.current = lang
91
+ this.setTraducao()
90
92
  },
91
93
 
94
+ async setTraducao() {
95
+ this.TraducaoMap = {}
96
+
97
+ await HTTPClient.get(url({type: "u", url: "auth/traducaos", params: {}}) )
98
+ .then(res => {
99
+ const payload = res.data
100
+ for (const bloco in payload) {
101
+ for (const key in payload[bloco]) {
102
+ const normalizada = key.trim()
103
+ this.TraducaoMap[normalizada] = payload[bloco][key]
104
+ }
105
+ }
106
+ }).catch(err => {
107
+ })
108
+ },
109
+
92
110
  async get() {
93
111
  await HTTPClient.get(url({type: "u", url: "auth/idiomas", params: {}}) )
94
112
  .then(res => {