Convert admin page to Vue
This commit is contained in:
67
src/Spot.vue
Normal file
67
src/Spot.vue
Normal file
@@ -0,0 +1,67 @@
|
||||
<script>
|
||||
import Project from './components/project.vue';
|
||||
import Admin from './components/admin.vue';
|
||||
|
||||
const aoRoutes = {
|
||||
'project': Project,
|
||||
'admin': Admin
|
||||
};
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
//spot: window.oSpot,
|
||||
hash: {}
|
||||
};
|
||||
},
|
||||
inject: ['spot'],
|
||||
computed: {
|
||||
currentView() {
|
||||
this.spot.vars('page', this.hash.page);
|
||||
return aoRoutes[this.hash.page];
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
window.addEventListener('hashchange', () => {this.onHashChange();});
|
||||
var oEvent = new Event('hashchange');
|
||||
window.dispatchEvent(oEvent);
|
||||
}
|
||||
,
|
||||
methods: {
|
||||
_hash(hash, bReboot) {
|
||||
bReboot = bReboot || false;
|
||||
if(!hash) return window.location.hash.slice(1);
|
||||
else window.location.hash = '#'+hash;
|
||||
|
||||
if(bReboot) location.reload();
|
||||
},
|
||||
onHashChange() {
|
||||
let asHash = this.getHash();
|
||||
if(asHash.hash !='' && asHash.page != '') this.hash = asHash;
|
||||
else if(!this.hash.page) this.setHash(this.spot.consts.default_page);
|
||||
},
|
||||
getHash() {
|
||||
let sHash = this._hash();
|
||||
let asHash = sHash.split(this.spot.consts.hash_sep);
|
||||
let sPage = asHash.shift() || '';
|
||||
return {hash:sHash, page:sPage, items:asHash};
|
||||
},
|
||||
setHash(sPage, asItems, bReboot) {
|
||||
bReboot = bReboot || false;
|
||||
sPage = sPage || '';
|
||||
asItems = asItems || [];
|
||||
if(typeof asItems == 'string') asItems = [asItems];
|
||||
|
||||
if(sPage != '') {
|
||||
let sItems = (asItems.length > 0)?this.spot.consts.hash_sep+asItems.join(this.spot.consts.hash_sep):'';
|
||||
this._hash(sPage+sItems, bReboot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div id="#main">
|
||||
<component :is="currentView" />
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user