mirror of
https://github.com/EvolutionAPI/evolution-manager.git
synced 2025-07-13 15:14:49 -06:00
version controller and ui fixes
This commit is contained in:
parent
b55a7fe54b
commit
7fc7cb99da
1099
package-lock.json
generated
1099
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -28,6 +28,7 @@
|
|||||||
"pm2": "^5.3.0",
|
"pm2": "^5.3.0",
|
||||||
"roboto-fontface": "*",
|
"roboto-fontface": "*",
|
||||||
"sass": "^1.60.0",
|
"sass": "^1.60.0",
|
||||||
|
"semver": "^7.5.4",
|
||||||
"unplugin-fonts": "^1.0.3",
|
"unplugin-fonts": "^1.0.3",
|
||||||
"vite": "^4.2.0",
|
"vite": "^4.2.0",
|
||||||
"vite-plugin-vuetify": "^1.0.0",
|
"vite-plugin-vuetify": "^1.0.0",
|
||||||
|
@ -133,12 +133,18 @@
|
|||||||
</template>
|
</template>
|
||||||
</v-checkbox>
|
</v-checkbox>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="chatwootData.auto_create !== undefined">
|
|
||||||
|
<div>
|
||||||
<v-checkbox
|
<v-checkbox
|
||||||
v-model="chatwootData.auto_create"
|
v-model="chatwootData.auto_create"
|
||||||
label="Conversa pendente"
|
label="Conversa pendente"
|
||||||
:disabled="loading"
|
:disabled="loading || !AppStore.versionSatisfies('>=1.6.0')"
|
||||||
hide-details
|
:error-messages="[
|
||||||
|
!AppStore.versionSatisfies('>=1.6.0')
|
||||||
|
? 'Disponível a partir da versão 1.6.0'
|
||||||
|
: undefined,
|
||||||
|
]"
|
||||||
|
hide-details="auto"
|
||||||
class="mb-3"
|
class="mb-3"
|
||||||
density="compact"
|
density="compact"
|
||||||
>
|
>
|
||||||
@ -185,7 +191,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import ChatwootConfig from "@/components/modal/ChatwootConfig.vue";
|
import ChatwootConfig from "@/components/modal/ChatwootConfig.vue";
|
||||||
import instanceController from "@/services/instanceController";
|
import instanceController from "@/services/instanceController";
|
||||||
|
import { useAppStore } from "@/store/app";
|
||||||
const defaultObj = () => ({
|
const defaultObj = () => ({
|
||||||
enabled: false,
|
enabled: false,
|
||||||
url: "",
|
url: "",
|
||||||
@ -210,6 +216,7 @@ export default {
|
|||||||
loading: false,
|
loading: false,
|
||||||
error: false,
|
error: false,
|
||||||
valid: false,
|
valid: false,
|
||||||
|
AppStore: useAppStore(),
|
||||||
chatwootData: {
|
chatwootData: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
url: "",
|
url: "",
|
||||||
@ -264,12 +271,9 @@ export default {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const validData = chatwootData._doc || chatwootData;
|
const validData = chatwootData._doc || chatwootData;
|
||||||
|
|
||||||
this.chatwootData = Object.assign(defaultObj(), validData || {});
|
this.chatwootData = Object.assign(defaultObj(), validData || {});
|
||||||
this.defaultChatwootData = Object.assign(
|
this.defaultChatwootData = Object.assign(defaultObj(), validData || {});
|
||||||
defaultObj(),
|
|
||||||
validData || {}
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.error = e.message?.message || e.message || e;
|
this.error = e.message?.message || e.message || e;
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
</v-card>
|
</v-card>
|
||||||
<v-dialog v-model="dialog" max-width="350px">
|
<v-dialog v-model="dialog" max-width="350px">
|
||||||
<v-card :loading="loading && qrCode">
|
<v-card :loading="loading && qrCode">
|
||||||
<v-card-text>
|
<v-card-text class="pt-6">
|
||||||
<v-img v-if="qrCode" :src="qrCode" width="300px" height="300px" />
|
<v-img v-if="qrCode" :src="qrCode" width="300px" height="300px" />
|
||||||
<v-card
|
<v-card
|
||||||
v-else
|
v-else
|
||||||
@ -32,8 +32,8 @@
|
|||||||
size="small"
|
size="small"
|
||||||
block
|
block
|
||||||
@click="loadQr"
|
@click="loadQr"
|
||||||
:loading="loading"
|
:loading="loading && qrCode"
|
||||||
:disabled="disabledRefresh"
|
:disabled="disabledRefresh || !qrCode"
|
||||||
variant="tonal"
|
variant="tonal"
|
||||||
class="mt-2"
|
class="mt-2"
|
||||||
>
|
>
|
||||||
@ -107,7 +107,7 @@ export default {
|
|||||||
clearTimeout(this.timeout);
|
clearTimeout(this.timeout);
|
||||||
this.dialog = true;
|
this.dialog = true;
|
||||||
this.error = false;
|
this.error = false;
|
||||||
|
this.qrCode = null;
|
||||||
await this.loadQr();
|
await this.loadQr();
|
||||||
await this.AppStore.reconnect();
|
await this.AppStore.reconnect();
|
||||||
},
|
},
|
||||||
|
@ -13,11 +13,27 @@
|
|||||||
v-else-if="AppStore.validConnection"
|
v-else-if="AppStore.validConnection"
|
||||||
color="success"
|
color="success"
|
||||||
style="max-width: 35vw"
|
style="max-width: 35vw"
|
||||||
|
class="px-2"
|
||||||
>
|
>
|
||||||
<v-icon color="success" start> mdi-check-circle </v-icon>
|
<div class="d-flex align-center gap-1">
|
||||||
{{
|
<v-icon color="success"> mdi-check-circle </v-icon>
|
||||||
AppStore.connection.host.replace(/https?:\/\//, "").replace(/\/$/, "")
|
<div style="display: grid">
|
||||||
}}
|
<p class="text-truncate">
|
||||||
|
{{
|
||||||
|
AppStore.connection.host
|
||||||
|
.replace(/https?:\/\//, "")
|
||||||
|
.replace(/\/$/, "")
|
||||||
|
}}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<v-chip
|
||||||
|
size="x-small"
|
||||||
|
color="grey"
|
||||||
|
class="flex-shrink-0"
|
||||||
|
>
|
||||||
|
<b>{{ AppStore.version }}</b>
|
||||||
|
</v-chip>
|
||||||
|
</div>
|
||||||
</v-chip>
|
</v-chip>
|
||||||
<v-icon v-else color="error"> mdi-alert-circle </v-icon>
|
<v-icon v-else color="error"> mdi-alert-circle </v-icon>
|
||||||
<v-btn @click="openSettings" icon>
|
<v-btn @click="openSettings" icon>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Utilities
|
// Utilities
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
import semver from 'semver'
|
||||||
|
|
||||||
export const useAppStore = defineStore('app', {
|
export const useAppStore = defineStore('app', {
|
||||||
getters: {
|
getters: {
|
||||||
@ -14,10 +14,15 @@ export const useAppStore = defineStore('app', {
|
|||||||
return state.getInstance(instance).instance.apiKey ||
|
return state.getInstance(instance).instance.apiKey ||
|
||||||
state.instancesKeys[instance]
|
state.instancesKeys[instance]
|
||||||
},
|
},
|
||||||
|
version: (state) => state.connection.version,
|
||||||
|
versionSatisfies: (state) => (version) => {
|
||||||
|
return semver.satisfies(state.connection.version, version)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
state: () => ({
|
state: () => ({
|
||||||
connecting: false,
|
connecting: false,
|
||||||
connection: {
|
connection: {
|
||||||
|
|
||||||
valid: false,
|
valid: false,
|
||||||
host: null,
|
host: null,
|
||||||
globalApiKey: null,
|
globalApiKey: null,
|
||||||
@ -33,6 +38,21 @@ export const useAppStore = defineStore('app', {
|
|||||||
async setConnection({ host, globalApiKey }) {
|
async setConnection({ host, globalApiKey }) {
|
||||||
try {
|
try {
|
||||||
this.connecting = true
|
this.connecting = true
|
||||||
|
const apiResponse = await axios({
|
||||||
|
method: 'GET',
|
||||||
|
baseURL: host,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'apikey': globalApiKey
|
||||||
|
},
|
||||||
|
url: '/'
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!apiResponse.data || !apiResponse.data.message || !apiResponse.data.message.includes('Evolution API')) {
|
||||||
|
throw new Error('Essa conexão não é uma instância da evolution-api')
|
||||||
|
}
|
||||||
|
|
||||||
|
const { version } = apiResponse.data
|
||||||
const response = await axios({
|
const response = await axios({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
baseURL: host,
|
baseURL: host,
|
||||||
@ -43,10 +63,7 @@ export const useAppStore = defineStore('app', {
|
|||||||
url: '/instance/fetchInstances'
|
url: '/instance/fetchInstances'
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.data || !Array.isArray(response.data)) throw new Error('Essa conexão não é uma instância da evolution-api')
|
this.saveConnection({ host, globalApiKey, version })
|
||||||
|
|
||||||
|
|
||||||
this.saveConnection({ host, globalApiKey })
|
|
||||||
this.instancesList = response.data
|
this.instancesList = response.data
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.connection.valid = false
|
this.connection.valid = false
|
||||||
@ -59,18 +76,7 @@ export const useAppStore = defineStore('app', {
|
|||||||
async loadInstance(instanceName) {
|
async loadInstance(instanceName) {
|
||||||
try {
|
try {
|
||||||
console.log('loadInstance', instanceName)
|
console.log('loadInstance', instanceName)
|
||||||
// const { host, globalApiKey } = this.connection;
|
|
||||||
return this.reconnect()
|
return this.reconnect()
|
||||||
// const response = await axios({
|
|
||||||
// method: 'GET',
|
|
||||||
// baseURL: host,
|
|
||||||
// headers: {
|
|
||||||
// 'Content-Type': 'application/json',
|
|
||||||
// 'apikey': globalApiKey
|
|
||||||
// },
|
|
||||||
// url: `/instance/fetchInstances?instanceName=${instanceName}`
|
|
||||||
// })
|
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.connection.valid = false
|
this.connection.valid = false
|
||||||
throw e.response?.data?.response?.message || e.response || e
|
throw e.response?.data?.response?.message || e.response || e
|
||||||
@ -92,9 +98,24 @@ export const useAppStore = defineStore('app', {
|
|||||||
async reconnect() {
|
async reconnect() {
|
||||||
try {
|
try {
|
||||||
const { host, globalApiKey } = this.connection
|
const { host, globalApiKey } = this.connection
|
||||||
if (!host || !globalApiKey) {
|
if (!host || !globalApiKey) throw new Error('Invalid connection')
|
||||||
throw new Error('Invalid connection')
|
|
||||||
|
const apiResponse = await axios({
|
||||||
|
method: 'GET',
|
||||||
|
baseURL: host,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'apikey': globalApiKey
|
||||||
|
},
|
||||||
|
url: '/'
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!apiResponse.data || !apiResponse.data.message || !apiResponse.data.message.includes('Evolution API')) {
|
||||||
|
throw new Error('Essa conexão não é uma instância da evolution-api')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { version } = apiResponse.data
|
||||||
|
|
||||||
const response = await axios({
|
const response = await axios({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
baseURL: host,
|
baseURL: host,
|
||||||
@ -105,7 +126,7 @@ export const useAppStore = defineStore('app', {
|
|||||||
url: '/instance/fetchInstances'
|
url: '/instance/fetchInstances'
|
||||||
})
|
})
|
||||||
|
|
||||||
this.saveConnection({ host, globalApiKey })
|
this.saveConnection({ host, globalApiKey, version })
|
||||||
|
|
||||||
this.instancesList = response.data
|
this.instancesList = response.data
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -144,11 +165,12 @@ export const useAppStore = defineStore('app', {
|
|||||||
|
|
||||||
this.saveLocalStorage()
|
this.saveLocalStorage()
|
||||||
},
|
},
|
||||||
saveConnection({ host, globalApiKey }) {
|
saveConnection({ host, globalApiKey, version }) {
|
||||||
this.connection = {
|
this.connection = {
|
||||||
valid: true,
|
valid: true,
|
||||||
host,
|
host,
|
||||||
globalApiKey,
|
globalApiKey,
|
||||||
|
version
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentKey = this.connectionsList.findIndex(
|
const currentKey = this.connectionsList.findIndex(
|
||||||
|
Loading…
Reference in New Issue
Block a user