add tls
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { FindDiff } from '@/plugins/utils'
|
||||
import HttpUtils from '@/plugins/httputil'
|
||||
import { defineStore } from 'pinia'
|
||||
import { onMounted } from 'vue'
|
||||
|
||||
const Data = defineStore('Data', {
|
||||
state: () => ({
|
||||
@@ -9,9 +8,10 @@ const Data = defineStore('Data', {
|
||||
reloadItems: localStorage.getItem("reloadItems")?.split(',')?? <string[]>[],
|
||||
subURI: "",
|
||||
onlines: {inbound: <string[]>[], outbound: <string[]>[], user: <string[]>[]},
|
||||
oldData: <{config: any, clients: any[]}>{},
|
||||
oldData: <{config: any, clients: any[], tlsConfigs: any[]}>{},
|
||||
config: {},
|
||||
clients: [],
|
||||
tlsConfigs: [],
|
||||
}),
|
||||
actions: {
|
||||
async loadData() {
|
||||
@@ -21,20 +21,23 @@ const Data = defineStore('Data', {
|
||||
|
||||
// Set new data
|
||||
const data = JSON.parse(msg.obj)
|
||||
if (data.subURI) this.subURI = data.subURI
|
||||
if (data.config) this.config = data.config
|
||||
if (data.clients) this.clients = data.clients
|
||||
if (data.subURI) this.subURI = data.subURI
|
||||
if (data.tls) this.tlsConfigs = data.tls
|
||||
this.onlines = data.onlines
|
||||
|
||||
// To avoid ref copy
|
||||
if (data.config) this.oldData.config = { ...JSON.parse(msg.obj).config }
|
||||
if (data.clients) this.oldData.clients = [ ...JSON.parse(msg.obj).clients ]
|
||||
if (data.tls) this.oldData.tlsConfigs = [ ...JSON.parse(msg.obj).tls ]
|
||||
}
|
||||
},
|
||||
async pushData() {
|
||||
const diff = {
|
||||
config: JSON.stringify(FindDiff.Config(this.config,this.oldData.config)),
|
||||
clients: JSON.stringify(FindDiff.Clients(this.clients,this.oldData.clients)),
|
||||
tls: JSON.stringify(FindDiff.Clients(this.tlsConfigs,this.oldData.tlsConfigs)),
|
||||
}
|
||||
const msg = await HttpUtils.post('api/save',diff)
|
||||
if(msg.success) {
|
||||
@@ -45,6 +48,7 @@ const Data = defineStore('Data', {
|
||||
const diff = {
|
||||
config: JSON.stringify([{key: "inbounds", action: "del", index: index, obj: null}]),
|
||||
clients: JSON.stringify(FindDiff.Clients(this.clients,this.oldData.clients)),
|
||||
tls: JSON.stringify(FindDiff.Clients(this.tlsConfigs,this.oldData.tlsConfigs)),
|
||||
}
|
||||
const msg = await HttpUtils.post('api/save',diff)
|
||||
if(msg.success) {
|
||||
@@ -69,6 +73,15 @@ const Data = defineStore('Data', {
|
||||
if(msg.success) {
|
||||
this.loadData()
|
||||
}
|
||||
},
|
||||
async delTls(id: number) {
|
||||
const diff = {
|
||||
tls:JSON.stringify([{key: "tls", action: "del", index: id, obj: null}]),
|
||||
}
|
||||
const msg = await HttpUtils.post('api/save',diff)
|
||||
if(msg.success) {
|
||||
this.loadData()
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user