air-vue-components-2 3.2.165 → 3.2.167

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "message": "\"Mensagem Automatica\"",
6
6
  "version_increment": "patch"
7
7
  },
8
- "version": "3.2.165",
8
+ "version": "3.2.167",
9
9
  "author": "ti.acessos@alloha.com",
10
10
  "main": "src/air-vue-components.js",
11
11
  "scripts": {
@@ -90,11 +90,11 @@
90
90
  paletaPastel () {
91
91
  return [
92
92
  '#F7B7B7',
93
- '#BFE7C2',
93
+ '#D7C6FF',
94
94
  '#BFD7FF',
95
95
  '#FFD6A5',
96
96
  '#FBC4E2',
97
- '#D7C6FF',
97
+ '#BFE7C2',
98
98
  '#BFEFEA',
99
99
  '#FFF1A8'
100
100
  ]
@@ -31,18 +31,24 @@
31
31
  </template>
32
32
  <script>
33
33
  export default {
34
- props: ['codigo'],
34
+ props: {
35
+ codigo: { type: String, default: null },
36
+ user: { type: Object, default: null }
37
+ },
35
38
  data () {
36
39
  return {
37
- user: null,
40
+ userLocal: null,
38
41
  fotoErro: false,
39
42
  avatarBg: null,
40
43
  defaultFoto: require('../assets/default_user_profile.jpg')
41
44
  }
42
45
  },
43
46
  computed: {
47
+ userEfetivo () {
48
+ return this.user || this.userLocal
49
+ },
44
50
  emailBase () {
45
- return (this.usuarioLogado && this.usuarioLogado.email) || ''
51
+ return (this.userEfetivo && this.userEfetivo.email) || ''
46
52
  },
47
53
  avatarSrc () {
48
54
  try {
@@ -53,13 +59,13 @@
53
59
  },
54
60
  fotoSrc () {
55
61
  if (this.fotoErro) return this.avatarSrc
56
- return (this.usuarioLogado.codigo)
57
- ? 'https://air.sumicity.net.br/usuario/foto/' + this.usuarioLogado.codigo
62
+ return (this.userEfetivo && this.userEfetivo.codigo)
63
+ ? 'https://air.sumicity.net.br/usuario/foto/' + this.userEfetivo.codigo
58
64
  : this.avatarSrc
59
65
  }
60
66
  },
61
67
  watch: {
62
- 'usuarioLogado.foto' () {
68
+ 'userEfetivo.foto' () {
63
69
  this.fotoErro = false
64
70
  },
65
71
  emailBase () {
@@ -77,7 +83,9 @@
77
83
  },
78
84
  methods: {
79
85
  carregar () {
80
- this.httpGet(this.$URL.USUARIO.CODIGO + this.codigo).then(res => { this.user = res })
86
+ if (!this.user && this.codigo) {
87
+ this.httpGet(this.$URL.USUARIO.CODIGO + this.codigo).then(res => { this.userLocal = res })
88
+ }
81
89
  },
82
90
  onFotoErro (e) {
83
91
  if (this.fotoErro) return
@@ -102,11 +110,11 @@
102
110
  paletaPastel () {
103
111
  return [
104
112
  '#F7B7B7',
105
- '#BFE7C2',
113
+ '#D7C6FF',
106
114
  '#BFD7FF',
107
115
  '#FFD6A5',
108
116
  '#FBC4E2',
109
- '#D7C6FF',
117
+ '#BFE7C2',
110
118
  '#BFEFEA',
111
119
  '#FFF1A8'
112
120
  ]
@@ -153,19 +161,19 @@
153
161
  const fg = this.escurecerHex(bg, 0.55)
154
162
 
155
163
  const svg = `
156
- <svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128">
157
- <rect width="128" height="128" rx="64" ry="64" fill="${bg}"/>
158
- <text x="64" y="64"
159
- text-anchor="middle"
160
- dominant-baseline="central"
161
- font-family="Arial, Helvetica, sans-serif"
162
- font-size="56"
163
- font-weight="700"
164
- fill="${fg}">
165
- ${iniciais}
166
- </text>
167
- </svg>
168
- `.trim()
164
+ <svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128">
165
+ <rect width="128" height="128" rx="64" ry="64" fill="${bg}"/>
166
+ <text x="64" y="64"
167
+ text-anchor="middle"
168
+ dominant-baseline="central"
169
+ font-family="Arial, Helvetica, sans-serif"
170
+ font-size="56"
171
+ font-weight="700"
172
+ fill="${fg}">
173
+ ${iniciais}
174
+ </text>
175
+ </svg>
176
+ `.trim()
169
177
 
170
178
  return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg)
171
179
  }
@@ -153,11 +153,11 @@
153
153
  paletaPastel () {
154
154
  return [
155
155
  '#F7B7B7',
156
- '#BFE7C2',
156
+ '#D7C6FF',
157
157
  '#BFD7FF',
158
158
  '#FFD6A5',
159
159
  '#FBC4E2',
160
- '#D7C6FF',
160
+ '#BFE7C2',
161
161
  '#BFEFEA',
162
162
  '#FFF1A8'
163
163
  ]
@@ -90,11 +90,11 @@
90
90
  paletaPastel () {
91
91
  return [
92
92
  '#F7B7B7',
93
- '#BFE7C2',
93
+ '#D7C6FF',
94
94
  '#BFD7FF',
95
95
  '#FFD6A5',
96
96
  '#FBC4E2',
97
- '#D7C6FF',
97
+ '#BFE7C2',
98
98
  '#BFEFEA',
99
99
  '#FFF1A8'
100
100
  ]
@@ -24,6 +24,7 @@
24
24
  export default {
25
25
  data () {
26
26
  return {
27
+ user: null,
27
28
  fotoErro: false,
28
29
  avatarBg: null,
29
30
  defaultFoto: require('../assets/default_user_profile.jpg')
@@ -49,12 +50,20 @@
49
50
  default: 'is-dark'
50
51
  }
51
52
  },
53
+ created () {
54
+ if (this.$URL.USUARIO && this.$URL.USUARIO.CODIGO) {
55
+ this.carregar()
56
+ } else {
57
+ this.$toast.open('Constante URL.USUARIO.CODIGO indisponível.')
58
+ console.error('$URL.USUARIO.CODIGO não existe')
59
+ }
60
+ },
52
61
  computed: {
53
62
  label () {
54
63
  return this.equipe ? this.codigo + ' - ' + this.equipe : this.codigo
55
64
  },
56
65
  emailBase () {
57
- return (this.usuarioLogado && this.usuarioLogado.email) || ''
66
+ return (this.user && this.user.email) || ''
58
67
  },
59
68
  avatarSrc () {
60
69
  try {
@@ -71,7 +80,7 @@
71
80
  }
72
81
  },
73
82
  watch: {
74
- 'usuarioLogado.foto' () {
83
+ 'user.foto' () {
75
84
  this.fotoErro = false
76
85
  },
77
86
  emailBase () {
@@ -80,11 +89,14 @@
80
89
  }
81
90
  },
82
91
  methods: {
92
+ carregar () {
93
+ this.httpGet(this.$URL.USUARIO.CODIGO + this.codigo).then(res => { this.user = res })
94
+ },
83
95
  mostrarDetalhes () {
84
96
  this.$modal.open({
85
97
  component: UsuarioCard,
86
98
  width: 380,
87
- props: {codigo: this.codigo, store: this.$store}
99
+ props: {codigo: this.codigo, user: this.user, store: this.$store}
88
100
  })
89
101
  },
90
102
  onFotoErro (e) {
@@ -110,11 +122,11 @@
110
122
  paletaPastel () {
111
123
  return [
112
124
  '#F7B7B7',
113
- '#BFE7C2',
125
+ '#D7C6FF',
114
126
  '#BFD7FF',
115
127
  '#FFD6A5',
116
128
  '#FBC4E2',
117
- '#D7C6FF',
129
+ '#BFE7C2',
118
130
  '#BFEFEA',
119
131
  '#FFF1A8'
120
132
  ]
@@ -7,7 +7,7 @@
7
7
 
8
8
  <div class="media" v-if="user">
9
9
  <div class="media-left">
10
- <img class="img-lg img-circle m-t-sm m-r-sm" :src="user.foto" alt="Image">
10
+ <img class="img-lg img-circle m-t-sm m-r-sm" :src="fotoSrc" alt="Image" @error="onFotoErro">
11
11
  </div>
12
12
  <div class="media-content">
13
13
  <p class="title">{{ user.nome }}</p>
@@ -31,10 +31,46 @@
31
31
  </template>
32
32
  <script>
33
33
  export default {
34
- props: ['codigo'],
34
+ props: {
35
+ codigo: { type: String, default: null },
36
+ user: { type: Object, default: null }
37
+ },
35
38
  data () {
36
39
  return {
37
- user: null
40
+ userLocal: null,
41
+ fotoErro: false,
42
+ avatarBg: null,
43
+ defaultFoto: require('../assets/default_user_profile.jpg')
44
+ }
45
+ },
46
+ computed: {
47
+ userEfetivo () {
48
+ return this.user || this.userLocal
49
+ },
50
+ emailBase () {
51
+ return (this.userEfetivo && this.userEfetivo.email) || ''
52
+ },
53
+ avatarSrc () {
54
+ try {
55
+ return this.gerarAvatarDataUrl(this.emailBase)
56
+ } catch (err) {
57
+ return this.defaultFoto
58
+ }
59
+ },
60
+ fotoSrc () {
61
+ if (this.fotoErro) return this.avatarSrc
62
+ return (this.userEfetivo && this.userEfetivo.codigo)
63
+ ? 'https://air.sumicity.net.br/usuario/foto/' + this.userEfetivo.codigo
64
+ : this.avatarSrc
65
+ }
66
+ },
67
+ watch: {
68
+ 'userEfetivo.foto' () {
69
+ this.fotoErro = false
70
+ },
71
+ emailBase () {
72
+ this.fotoErro = false
73
+ this.avatarBg = null
38
74
  }
39
75
  },
40
76
  created () {
@@ -47,7 +83,99 @@
47
83
  },
48
84
  methods: {
49
85
  carregar () {
50
- this.httpGet(this.$URL.USUARIO.CODIGO + this.codigo).then(res => { this.user = res })
86
+ if (!this.user && this.codigo) {
87
+ this.httpGet(this.$URL.USUARIO.CODIGO + this.codigo).then(res => { this.userLocal = res })
88
+ }
89
+ },
90
+ onFotoErro (e) {
91
+ if (this.fotoErro) return
92
+ this.fotoErro = true
93
+ e.target.src = this.avatarSrc
94
+ },
95
+ gerarIniciaisDoEmail (email) {
96
+ const local = String(email || '').split('@')[0].trim()
97
+ if (!local) return '?'
98
+
99
+ const partes = local
100
+ .split('.')
101
+ .map(p => p.trim())
102
+ .filter(Boolean)
103
+
104
+ const primeira = (partes[0] || '')[0] || ''
105
+ const segunda = (partes[1] || '')[0] || ''
106
+
107
+ const iniciais = (primeira + segunda).toUpperCase()
108
+ return iniciais || '?'
109
+ },
110
+ paletaPastel () {
111
+ return [
112
+ '#F7B7B7',
113
+ '#D7C6FF',
114
+ '#BFD7FF',
115
+ '#FFD6A5',
116
+ '#FBC4E2',
117
+ '#BFE7C2',
118
+ '#BFEFEA',
119
+ '#FFF1A8'
120
+ ]
121
+ },
122
+ corPastelPorLetra (letra) {
123
+ const paleta = this.paletaPastel()
124
+
125
+ const ch = String(letra || '?').toUpperCase()
126
+ const code = ch.charCodeAt(0)
127
+
128
+ if (code >= 65 && code <= 90) {
129
+ const idx = (code - 65) % paleta.length
130
+ return paleta[idx]
131
+ }
132
+
133
+ return paleta[0]
134
+ },
135
+ hexParaRgb (hex) {
136
+ const h = String(hex || '').replace('#', '').trim()
137
+ if (h.length !== 6) return null
138
+ const r = parseInt(h.slice(0, 2), 16)
139
+ const g = parseInt(h.slice(2, 4), 16)
140
+ const b = parseInt(h.slice(4, 6), 16)
141
+ if ([r, g, b].some(n => Number.isNaN(n))) return null
142
+ return { r, g, b }
143
+ },
144
+ rgbParaHex ({ r, g, b }) {
145
+ const toHex = (n) => Math.max(0, Math.min(255, Math.round(n))).toString(16).padStart(2, '0')
146
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`
147
+ },
148
+ escurecerHex (hex, fator = 0.55) {
149
+ const rgb = this.hexParaRgb(hex)
150
+ if (!rgb) return '#2E2E2E'
151
+ return this.rgbParaHex({
152
+ r: rgb.r * (1 - fator),
153
+ g: rgb.g * (1 - fator),
154
+ b: rgb.b * (1 - fator)
155
+ })
156
+ },
157
+ gerarAvatarDataUrl (email) {
158
+ const iniciais = this.gerarIniciaisDoEmail(email)
159
+ const primeiraLetra = (iniciais && iniciais !== '?') ? iniciais[0] : '?'
160
+ const bg = this.corPastelPorLetra(primeiraLetra)
161
+ const fg = this.escurecerHex(bg, 0.55)
162
+
163
+ const svg = `
164
+ <svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128">
165
+ <rect width="128" height="128" rx="64" ry="64" fill="${bg}"/>
166
+ <text x="64" y="64"
167
+ text-anchor="middle"
168
+ dominant-baseline="central"
169
+ font-family="Arial, Helvetica, sans-serif"
170
+ font-size="56"
171
+ font-weight="700"
172
+ fill="${fg}">
173
+ ${iniciais}
174
+ </text>
175
+ </svg>
176
+ `.trim()
177
+
178
+ return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg)
51
179
  }
52
180
  }
53
181
  }