Worked web app

This commit is contained in:
2019-11-09 19:15:58 +03:00
parent 639888d227
commit 988d4b24b4
12 changed files with 197 additions and 294 deletions

View File

@ -1,42 +1,56 @@
<template>
<div id="app">
<a v-if="started" v-on:click.prevent="finish" href="#">Закончить</a>
<a v-else v-on:click.prevent="start" href="#">Начать</a>
<section class="timer" v-bind:class="{ overtime: isOvertime }">
{{ time }}
</section>
<section class="actions">
<a v-if="started" v-on:click.prevent="finish" href="#">Закончить</a>
<a v-else v-on:click.prevent="start" href="#">Начать</a>
</section>
<p class="profile-info">Профиль: {{ profileId }}</p>
</div>
</template>
<script>
import qs from 'qs';
import h from './helpers';
export default {
data() {
return {
profileId: null,
started: false,
status: '',
hours: 0,
minutes: 0,
};
},
created() {
const haystack = window.location.search || window.location.hash;
const q = haystack.substring(haystack.indexOf('?') + 1, haystack.length);
const query = qs.parse(q);
const profile = query['profile'] || '';
console.log('PROFILE', query, profile);
const p = fetch('/api/status?profile_id=' + profile, {
method: 'GET',
});
p.then(response => {
return response.json();
}).then(data => {
this.started = data.started;
console.log('DATA', data);
});
this.profileId = h.extract_profile_id();
this.get_status();
setInterval(() => this.get_status(), 30 * 1000);
},
computed: {
time() {
const sign = this.isOvertime ? '+' : '';
return sign + this.hours + ':' + String(this.minutes).padStart(2, '0');
},
isOvertime() {
return this.status === 'overtime';
},
},
methods: {
get_status() {
h.get_status(this.profileId).then(data => {
this.started = data.started;
this.status = data.status;
this.hours = data.hours;
this.minutes = data.minutes;
});
},
start() {
console.log('START');
this.started = true;
h.start(this.profileId).then(() => this.get_status());
},
finish() {
console.log('FINISH');
this.started = false;
h.finish(this.profileId).then(() => this.get_status());
},
},
};
@ -48,19 +62,18 @@ export default {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 3em;
}
#nav {
padding: 30px;
.timer {
font-size: 600%;
}
a {
font-weight: bold;
color: #2c3e50;
.overtime {
color: green;
}
&.router-link-exact-active {
color: #42b983;
}
}
.actions {
font-size: 240%;
}
</style>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -1,130 +0,0 @@
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<p>
For a guide and recipes on how to configure / customize this project,<br />
check out the
<a href="https://cli.vuejs.org" target="_blank" rel="noopener"
>vue-cli documentation</a
>.
</p>
<h3>Installed CLI Plugins</h3>
<ul>
<li>
<a
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel"
target="_blank"
rel="noopener"
>babel</a
>
</li>
<li>
<a
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-router"
target="_blank"
rel="noopener"
>router</a
>
</li>
<li>
<a
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-vuex"
target="_blank"
rel="noopener"
>vuex</a
>
</li>
<li>
<a
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint"
target="_blank"
rel="noopener"
>eslint</a
>
</li>
</ul>
<h3>Essential Links</h3>
<ul>
<li>
<a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a>
</li>
<li>
<a href="https://forum.vuejs.org" target="_blank" rel="noopener"
>Forum</a
>
</li>
<li>
<a href="https://chat.vuejs.org" target="_blank" rel="noopener"
>Community Chat</a
>
</li>
<li>
<a href="https://twitter.com/vuejs" target="_blank" rel="noopener"
>Twitter</a
>
</li>
<li>
<a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a>
</li>
</ul>
<h3>Ecosystem</h3>
<ul>
<li>
<a href="https://router.vuejs.org" target="_blank" rel="noopener"
>vue-router</a
>
</li>
<li>
<a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a>
</li>
<li>
<a
href="https://github.com/vuejs/vue-devtools#vue-devtools"
target="_blank"
rel="noopener"
>vue-devtools</a
>
</li>
<li>
<a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener"
>vue-loader</a
>
</li>
<li>
<a
href="https://github.com/vuejs/awesome-vue"
target="_blank"
rel="noopener"
>awesome-vue</a
>
</li>
</ul>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
props: {
msg: String,
},
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>

37
assets/helpers.js Normal file
View File

@ -0,0 +1,37 @@
import qs from 'qs';
const PROFILE_QUERY = 'profile';
function extract_profile_id() {
const haystack = window.location.search || window.location.hash;
const q = haystack.substring(haystack.indexOf('?') + 1, haystack.length);
const query = qs.parse(q);
const profile = query[PROFILE_QUERY] || '';
console.log('PROFILE', query, profile);
return profile;
}
async function check_profile(profileId) {}
async function get_status(profileId) {
const response = await fetch('/api/status?profile_id=' + profileId, {
method: 'GET',
});
const data = await response.json();
console.log('DATA', data);
return data;
}
async function start(profileId) {
const response = await fetch('/api/start?profile_id=' + profileId, {
method: 'POST',
});
}
async function finish(profileId) {
const response = await fetch('/api/finish?profile_id=' + profileId, {
method: 'POST',
});
}
export default { extract_profile_id, check_profile, get_status, start, finish };

View File

@ -1,12 +1,10 @@
import Vue from "vue";
import App from "./App.vue";
// import router from "./router";
// import store from "./store";
import Vue from 'vue';
import App from './App.vue';
Vue.config.productionTip = false;
new Vue({
// router,
// store,
render: h => h(App)
}).$mount("#app");
render: h => h(App),
}).$mount('#app');

View File

@ -1,11 +0,0 @@
import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
export default new Vuex.Store({
state: {},
mutations: {},
actions: {},
modules: {}
});

View File

@ -1,5 +0,0 @@
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>

View File

@ -1,18 +0,0 @@
<template>
<div class="home">
<img alt="Vue logo" src="../assets/logo.png" />
<HelloWorld msg="Welcome to Your Vue.js App" />
</div>
</template>
<script>
// @ is an alias to /src
import HelloWorld from '../components/HelloWorld.vue';
export default {
name: 'home',
components: {
HelloWorld,
},
};
</script>