hugo-theme-cyberscopes/assets/js/main.ts

45 lines
767 B
TypeScript

import { createApp } from './lib/petite-vue.es.js'
const apiUrl = '/api/system/poll/service/pclt-0001'
const appdata = {
$delimiters: ['{|', '|}'],
urlParams: new URL(location.href).searchParams,
poll,
newdata: '',
data: '',
save,
mounted() {
console.log('app mounted')
}
}
createApp(appdata).mount()
appdata.poll()
// method definitions
function save() {
this.data += '\n' + this.newdata
this.newdata = ''
}
async function dopoll(obj: typeof appdata, url: string) {
while (true) {
try {
let res = await fetch(url)
let data = await res.json()
console.log(data)
obj.newdata = data['status']
} catch (error) {
console.log(error)
await new Promise(r => setTimeout(r, 10000))
}
}
}
function poll() {
dopoll(this, apiUrl)
}