fetch config

This commit is contained in:
Dmitry Belyaev 2021-06-08 14:08:45 +03:00
parent 47a594dda2
commit fc67d035f7
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
5 changed files with 52 additions and 10 deletions

View File

@ -7,7 +7,16 @@
</template>
<script>
export default {};
import { mapActions } from "vuex";
export default {
methods: {
...mapActions(["fetchConfig"]),
},
async mounted() {
await this.fetchConfig();
},
};
</script>
<style lang="less">

View File

@ -73,10 +73,6 @@ import { mapGetters, mapActions } from "vuex";
import InfobaseURLEditor from "@/components/InfobaseURLEditor.vue";
import ItemLoading from "@/components/ItemLoading.vue";
import config from "@/config.js";
const url_base = config.publication.url_base;
export default {
name: "InfobaseListItem",
components: {
@ -97,7 +93,7 @@ export default {
},
},
computed: {
...mapGetters(["getInfobaseByName"]),
...mapGetters(["getInfobaseByName, Config"]),
name() {
return this.infobase.name;
},
@ -108,7 +104,7 @@ export default {
return this.infobase.url;
},
url_full() {
return `${url_base}${this.infobase.url}`;
return `${this.$store.getters.Config.url_prefix}${this.infobase.url}`;
},
is_locked() {
return this.$store.getters.isInfobaseLocked(this.infobase.name);

View File

@ -1,6 +1,4 @@
{
"api": "http://localhost:17653",
"publication": {
"url_base": "http://localhost:11111"
}
"url_prefix": "http://localhost:11111"
}

View File

@ -2,10 +2,12 @@ import { createStore } from "vuex";
import infobases from "@/store/modules/infobases.js";
import apache_restart from "@/store/modules/apache_restart.js";
import config from "@/store/modules/config.js";
export default createStore({
modules: {
infobases,
apache_restart,
config,
},
});

View File

@ -0,0 +1,37 @@
import axios from "axios";
import const_config from "@/config.js";
const api_base = const_config.api;
export default {
state: {
config: {
...const_config,
},
},
mutations: {
setConfig(state, new_config) {
state.config = {
...const_config,
...new_config,
};
},
},
actions: {
async fetchConfig(ctx) {
try {
const res = await axios.get(`${api_base}/config`);
const new_config = res.data;
ctx.commit("setConfig", new_config);
} catch (err) {
console.error(err);
}
},
},
getters: {
Config(state) {
return state.config;
},
},
};