Seamless host switching

This commit is contained in:
Jiang Yio 2022-09-27 19:22:57 -04:00
parent 8b76181b4d
commit 9785af43a0
2 changed files with 45 additions and 39 deletions

View File

@ -3,7 +3,7 @@
<Navbar v-model:server="server" :user="user" /> <Navbar v-model:server="server" :user="user" />
<div class="container"> <div class="container">
<Login :secret="secret" v-model:client="client" v-model:server="server" v-model:user="user" /> <Login :secret="secret" v-model:client="client" v-model:server="server" v-model:user="user" />
<router-view v-if="user"></router-view> <router-view v-if="user" :client="client"></router-view>
</div> </div>
</div> </div>
</template> </template>
@ -38,10 +38,10 @@
if(this.heartbeat) window.clearInterval(this.heartbeat); if(this.heartbeat) window.clearInterval(this.heartbeat);
else { else {
[ [
{ path: '/', component: RouteSchedule, props: { client: this.client } }, { path: '/', component: RouteSchedule },
{ path: '/patient', component: RoutePatientLookup, props: { client: this.client } }, { path: '/patient', component: RoutePatientLookup },
{ path: '/patient/:id', component: RoutePatientDetail, props: { client: this.client } }, { path: '/patient/:id', component: RoutePatientDetail },
{ path: '/recall', component: RouteRecall, props: { client: this.client } }, { path: '/recall', component: RouteRecall },
].forEach(route => this.$root.$router.addRoute(route)); ].forEach(route => this.$root.$router.addRoute(route));
await this.$root.$router.replace(this.$route); await this.$root.$router.replace(this.$route);
} }

View File

@ -73,7 +73,6 @@
data() { data() {
return { return {
show: false, show: false,
host: vistax.state.host,
x_client: this.client, x_client: this.client,
x_server: this.server, x_server: this.server,
x_user: this.user, x_user: this.user,
@ -82,25 +81,21 @@
verifycode: null verifycode: null
}; };
}, },
watch: { computed: {
host(value) { host: {
get() {
return vistax.state.host;
},
set(value) {
vistax.state.host = value; vistax.state.host = value;
}
}
},
watch: {
host: {
async handler(value) {
this.logout(); this.logout();
}, this.x_client = await (value ? vistax.Client.fromCookie(this.secret, value) : vistax.Client.fromCookie(this.secret));
client(value) { this.x_client = value; },
x_client(value) { this.$emit('update:client', value); },
server(value) { this.x_server = value; },
x_server(value) { this.$emit('update:server', value); },
user(value) { this.x_user = value; },
x_user(value) { this.$emit('update:user', value); }
},
async mounted() {
this.connect();
},
methods: {
async connect() {
if(this.x_client) return this.x_client;
this.x_client = await vistax.Client.fromCookie(this.secret);
this.banner = await this.x_client.XUS_INTRO_MSG(); this.banner = await this.x_client.XUS_INTRO_MSG();
if((await this.x_client.userinfo()).result) try { if((await this.x_client.userinfo()).result) try {
var user = await this.x_client.XUS_GET_USER_INFO(); var user = await this.x_client.XUS_GET_USER_INFO();
@ -113,10 +108,18 @@
this.$emit('update:server', this.x_server = (await this.x_client.serverinfo()).result); this.$emit('update:server', this.x_server = (await this.x_client.serverinfo()).result);
console.log('Backend secret', this.secret); console.log('Backend secret', this.secret);
console.log(this.banner); console.log(this.banner);
return this.x_client; }, immediate: true
}, },
client(value) { this.x_client = value; },
x_client(value) { this.$emit('update:client', value); },
server(value) { this.x_server = value; },
x_server(value) { this.$emit('update:server', value); },
user(value) { this.x_user = value; },
x_user(value) { this.$emit('update:user', value); }
},
methods: {
async login(evt) { async login(evt) {
if(!this.x_client) await this.connect(); if(this.x_client) {
var res = await ((this.accesscode && this.verifycode) ? this.x_client.authenticate(this.accesscode + ';' + this.verifycode) : this.x_client.authenticate()); var res = await ((this.accesscode && this.verifycode) ? this.x_client.authenticate(this.accesscode + ';' + this.verifycode) : this.x_client.authenticate());
if(!!res.result[0]) { if(!!res.result[0]) {
var user = await this.x_client.XUS_GET_USER_INFO(); var user = await this.x_client.XUS_GET_USER_INFO();
@ -126,6 +129,7 @@
this.show = !this.x_user; this.show = !this.x_user;
this.$emit('update:server', this.x_server = (await this.x_client.serverinfo()).result); this.$emit('update:server', this.x_server = (await this.x_client.serverinfo()).result);
console.log('Authenticate', res); console.log('Authenticate', res);
}
}, },
async logout(evt) { async logout(evt) {
if(this.x_client) { if(this.x_client) {
@ -134,6 +138,8 @@
this.$emit('update:server', this.x_server = null); this.$emit('update:server', this.x_server = null);
this.$emit('update:user', this.x_user = null); this.$emit('update:user', this.x_user = null);
} }
this.banner = null;
this.show = true;
} }
} }
}; };