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" />
<div class="container">
<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>
</template>
@ -38,10 +38,10 @@
if(this.heartbeat) window.clearInterval(this.heartbeat);
else {
[
{ path: '/', component: RouteSchedule, props: { client: this.client } },
{ path: '/patient', component: RoutePatientLookup, props: { client: this.client } },
{ path: '/patient/:id', component: RoutePatientDetail, props: { client: this.client } },
{ path: '/recall', component: RouteRecall, props: { client: this.client } },
{ path: '/', component: RouteSchedule },
{ path: '/patient', component: RoutePatientLookup },
{ path: '/patient/:id', component: RoutePatientDetail },
{ path: '/recall', component: RouteRecall },
].forEach(route => this.$root.$router.addRoute(route));
await this.$root.$router.replace(this.$route);
}

View File

@ -73,7 +73,6 @@
data() {
return {
show: false,
host: vistax.state.host,
x_client: this.client,
x_server: this.server,
x_user: this.user,
@ -82,10 +81,34 @@
verifycode: null
};
},
computed: {
host: {
get() {
return vistax.state.host;
},
set(value) {
vistax.state.host = value;
}
}
},
watch: {
host(value) {
vistax.state.host = value;
this.logout();
host: {
async handler(value) {
this.logout();
this.x_client = await (value ? vistax.Client.fromCookie(this.secret, value) : vistax.Client.fromCookie(this.secret));
this.banner = await this.x_client.XUS_INTRO_MSG();
if((await this.x_client.userinfo()).result) try {
var user = await this.x_client.XUS_GET_USER_INFO();
this.x_user = user[0] ? user : null
} catch(ex) {
this.x_user = null;
}
this.$emit('update:user', this.x_user);
this.show = !this.x_user;
this.$emit('update:server', this.x_server = (await this.x_client.serverinfo()).result);
console.log('Backend secret', this.secret);
console.log(this.banner);
}, immediate: true
},
client(value) { this.x_client = value; },
x_client(value) { this.$emit('update:client', value); },
@ -94,38 +117,19 @@
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();
if((await this.x_client.userinfo()).result) try {
var user = await this.x_client.XUS_GET_USER_INFO();
this.x_user = user[0] ? user : null
} catch(ex) {
this.x_user = null;
}
this.$emit('update:user', this.x_user);
this.show = !this.x_user;
this.$emit('update:server', this.x_server = (await this.x_client.serverinfo()).result);
console.log('Backend secret', this.secret);
console.log(this.banner);
return this.x_client;
},
async login(evt) {
if(!this.x_client) await this.connect();
var res = await ((this.accesscode && this.verifycode) ? this.x_client.authenticate(this.accesscode + ';' + this.verifycode) : this.x_client.authenticate());
if(!!res.result[0]) {
var user = await this.x_client.XUS_GET_USER_INFO();
this.x_user = user[0] ? user : null
} else this.x_user = null;
this.$emit('update:user', this.x_user);
this.show = !this.x_user;
this.$emit('update:server', this.x_server = (await this.x_client.serverinfo()).result);
console.log('Authenticate', res);
if(this.x_client) {
var res = await ((this.accesscode && this.verifycode) ? this.x_client.authenticate(this.accesscode + ';' + this.verifycode) : this.x_client.authenticate());
if(!!res.result[0]) {
var user = await this.x_client.XUS_GET_USER_INFO();
this.x_user = user[0] ? user : null
} else this.x_user = null;
this.$emit('update:user', this.x_user);
this.show = !this.x_user;
this.$emit('update:server', this.x_server = (await this.x_client.serverinfo()).result);
console.log('Authenticate', res);
}
},
async logout(evt) {
if(this.x_client) {
@ -134,6 +138,8 @@
this.$emit('update:server', this.x_server = null);
this.$emit('update:user', this.x_user = null);
}
this.banner = null;
this.show = true;
}
}
};