mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
refactor reading predefined queries
This commit is contained in:
@@ -113,5 +113,12 @@ export default {
|
|||||||
document.body.append(uploader)
|
document.body.append(uploader)
|
||||||
}
|
}
|
||||||
uploader.click()
|
uploader.click()
|
||||||
|
},
|
||||||
|
|
||||||
|
readPredefinedQueries () {
|
||||||
|
return fetch('./queries.json')
|
||||||
|
.then(resp => {
|
||||||
|
return resp.json()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,35 +13,7 @@ import '@/assets/styles/scrollbars.css'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'MainView',
|
name: 'MainView',
|
||||||
components: { MainMenu },
|
components: { MainMenu }
|
||||||
created () {
|
|
||||||
this.readPredefinedQueries()
|
|
||||||
.then(queries => {
|
|
||||||
this.$store.commit('updatePredefinedQueries', queries)
|
|
||||||
})
|
|
||||||
.catch(console.error)
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
readPredefinedQueries () {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const xhr = new XMLHttpRequest()
|
|
||||||
xhr.open('GET', './queries.json')
|
|
||||||
xhr.onload = () => {
|
|
||||||
if (xhr.readyState === 4) {
|
|
||||||
if (xhr.status === 200) {
|
|
||||||
resolve(JSON.parse(xhr.responseText || '[]'))
|
|
||||||
} else {
|
|
||||||
reject(xhr.statusText)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xhr.onerror = () => {
|
|
||||||
reject(xhr.statusText)
|
|
||||||
}
|
|
||||||
xhr.send()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -214,7 +214,14 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
|
storedQueries.readPredefinedQueries()
|
||||||
|
.then(queries => {
|
||||||
|
this.$store.commit('updatePredefinedQueries', queries)
|
||||||
|
})
|
||||||
|
.catch(console.error)
|
||||||
|
.finally(() => {
|
||||||
this.queries = storedQueries.getStoredQueries()
|
this.queries = storedQueries.getStoredQueries()
|
||||||
|
})
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
this.resizeObserver = new ResizeObserver(this.calcMaxTableHeight)
|
this.resizeObserver = new ResizeObserver(this.calcMaxTableHeight)
|
||||||
|
|||||||
Reference in New Issue
Block a user