Skip to content

Commit 30b2c22

Browse files
author
oguzhan.onder
committed
After service calling toast message and some improvements
1 parent ba6c3f1 commit 30b2c22

File tree

12 files changed

+425
-203
lines changed

12 files changed

+425
-203
lines changed

package-lock.json

Lines changed: 113 additions & 138 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
"@coreui/icons": "^1.0.1",
1616
"@coreui/utils": "^1.3.1",
1717
"bootstrap": "^4.4.1",
18-
"vue": "~2.6.11",
18+
"vue": "~2.6.12",
1919
"vue-resource": "^1.5.1",
20-
"vue-router": "^3.1.6",
21-
"vuex": "^3.3.0"
20+
"vue-router": "^3.4.4",
21+
"vuex": "^3.5.1"
2222
},
2323
"browserslist": [
2424
"> 1%",
@@ -33,10 +33,10 @@
3333
"cross-env": "^5.0.5",
3434
"css-loader": "^0.28.7",
3535
"file-loader": "^1.1.4",
36-
"vue-loader": "^13.0.5",
37-
"vue-template-compiler": "^2.4.4",
36+
"vue-loader": "^13.7.3",
37+
"vue-template-compiler": "^2.6.12",
3838
"webpack": "^3.7.1",
39-
"webpack-dev-server": "^2.9.1",
39+
"webpack-dev-server": "^2.11.5",
4040
"js-yaml": ">=3.13.1",
4141
"sass-loader": "^7.2.0",
4242
"node-sass": "^4.0.0"

src/App.vue

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
11
<template>
22
<div id="app">
33
<router-view></router-view>
4-
<CElementCover v-if ="this.$store.getters.getIsLoading"
5-
:boundaries="[{ sides: ['top', 'left'], query: '.media-body' }]"
6-
:opacity="0.8"
4+
<CElementCover v-if="getIsLoading"
5+
:boundaries="[{ sides: ['top', 'left'], query: '.media-body' }]"
6+
:opacity="0.8"
77
>
8-
<h1 class="d-inline">Loading... </h1><CSpinner size="5xl" color="success"/>
8+
<h1 class="d-inline">Loading... </h1>
9+
<CSpinner size="5xl" color="success"/>
910
</CElementCover>
11+
<CToaster :autohide="5000" position="top-right">
12+
<MyCToast :show.sync="getMyToast.show" :header="getMyToast.header">
13+
<CIcon :height="42" :name="getMyToast.icon"/>
14+
<b>{{getMyToast.message}}</b>
15+
</MyCToast>
16+
</CToaster>
1017
</div>
1118
</template>
1219

1320
<script>
1421
22+
import {mapGetters} from 'vuex';
23+
import MyCToast from "./components/MyCToast";
24+
1525
1626
export default {
1727
name: 'app',
28+
components: {MyCToast},
1829
data() {
1930
return {}
2031
},
2132
created() {
22-
/*if (this.$store.getters.getIsLogin == null) {
23-
this.$store.dispatch("initIsLogin");
24-
}*/
25-
if (this.$store.getters.getIsLogin) {
33+
if (this.getIsLoading) {
2634
this.$store.dispatch("getTradeResult");
27-
//this.$store.dispatch("initApp");
2835
}
29-
36+
},
37+
computed: {
38+
...mapGetters(["getIsLoading", "getMyToast"]),
3039
}
3140
}
3241
</script>

src/assets/icons/icons.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
cibCcVisa,
2121
cibStripe,
2222
cibPaypal,
23-
cibGooglePay,
23+
cibGooglePay,
2424
cibCcAmex
2525
} from '@coreui/icons'
2626
import {
@@ -41,6 +41,7 @@ import {
4141
cilCloudDownload,
4242
cilChartPie,
4343
cilCheck,
44+
cilWarning,
4445
cilChevronBottom,
4546
cilChevronTop,
4647
cilCheckCircle,
@@ -94,6 +95,7 @@ export const iconsSet = Object.assign(
9495
cilCloudDownload,
9596
cilChartPie,
9697
cilCheck,
98+
cilWarning,
9799
cilChevronBottom,
98100
cilChevronTop,
99101
cilCheckCircle,
@@ -157,10 +159,10 @@ export const iconsSet = Object.assign(
157159
cibBehance,
158160
cibReddit,
159161
cibVimeo,
160-
cibCcMastercard,
161-
cibCcVisa,
162-
cibStripe,
163-
cibPaypal,
162+
cibCcMastercard,
163+
cibCcVisa,
164+
cibStripe,
165+
cibPaypal,
164166
cibGooglePay,
165167
cibCcAmex
166168
}

src/components/MyCToast.vue

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<template>
2+
<transition :name="props.fade ? 'fade' : null" :appear="true">
3+
<div
4+
v-if="isShowed"
5+
class="toast"
6+
role="alert"
7+
aria-live="assertive"
8+
aria-atomic="true"
9+
>
10+
<div
11+
v-if="header !== undefined || $slots.header"
12+
class="toast-header"
13+
>
14+
<slot name="header">
15+
<strong class="mr-auto">{{header}}</strong>
16+
</slot>
17+
<CButtonClose
18+
v-if="props.closeButton"
19+
@click="close()"
20+
class="ml-2 mb-1"
21+
/>
22+
</div>
23+
<div class="toast-body">
24+
<slot></slot>
25+
</div>
26+
</div>
27+
</transition>
28+
</template>
29+
30+
<script>
31+
import {props} from '@coreui/vue/src/components/toast/toast-props'
32+
import CButtonClose from '@coreui/vue/src/components/button/CButtonClose'
33+
34+
export default {
35+
name: 'MyCToast',
36+
components: {
37+
CButtonClose
38+
},
39+
props: {
40+
...props,
41+
show: Boolean,
42+
header: String
43+
},
44+
inject: {
45+
toaster: {
46+
default: false
47+
}
48+
},
49+
data() {
50+
return {
51+
isShowed: this.show,
52+
hideTimeout: null,
53+
closeTimeout: null
54+
}
55+
},
56+
watch: {
57+
show: {
58+
immediate: true,
59+
handler(val) {
60+
val ? this.display() : this.close()
61+
}
62+
}
63+
},
64+
computed: {
65+
directlyDeclaredProps() {
66+
return Object.keys(this.$options.propsData)
67+
},
68+
injectedProps() {
69+
return this.toaster && this.toaster.props ? this.toaster.props : {}
70+
},
71+
props() {
72+
return Object.keys(props).reduce((computedProps, key) => {
73+
const propIsDirectlyDeclared = this.directlyDeclaredProps.includes(key)
74+
const parentPropExists = this.injectedProps[key] !== undefined
75+
const propIsInherited = parentPropExists && !propIsDirectlyDeclared
76+
computedProps[key] = propIsInherited ? this.injectedProps[key] : this[key]
77+
return computedProps
78+
}, {})
79+
}
80+
},
81+
methods: {
82+
display() {
83+
this.isShowed = true
84+
this.$nextTick(() => {
85+
if (this.props.autohide) {
86+
this.setAutohide()
87+
}
88+
})
89+
},
90+
close() {
91+
this.isShowed = false
92+
this.$emit('update:show', false)
93+
if (this.$el) {
94+
this.$el.removeEventListener('mouseover', this.onHover)
95+
this.$el.removeEventListener('mouseover', this.restoreHiddingToast)
96+
this.$el.removeEventListener('mouseout', this.onHoverOut)
97+
}
98+
99+
},
100+
setHiddingMode() {
101+
this.isShowed = false;
102+
this.$el.removeEventListener('mouseover', this.onHover)
103+
this.closeTimeout = setTimeout(() => this.close(), 1500)
104+
this.$el.addEventListener('mouseover', this.restoreHiddingToast)
105+
106+
107+
},
108+
restoreHiddingToast() {
109+
clearTimeout(this.closeTimeout)
110+
this.display()
111+
},
112+
onHover() {
113+
this.$el.removeEventListener('mouseover', this.onHover)
114+
clearTimeout(this.hideTimeout)
115+
this.$el.addEventListener('mouseout', this.onHoverOut)
116+
117+
118+
},
119+
onHoverOut() {
120+
this.$el.removeEventListener('mouseout', this.onHoverOut)
121+
this.setAutohide()
122+
},
123+
setAutohide() {
124+
this.hideTimeout = setTimeout(() => {
125+
this.setHiddingMode()
126+
}, this.props.autohide)
127+
this.$el.addEventListener('mouseover', this.onHover)
128+
}
129+
}
130+
}
131+
</script>
132+
133+
<style scoped>
134+
.toast {
135+
opacity: inherit;
136+
}
137+
138+
.fade-enter-active {
139+
transition: opacity .5s;
140+
}
141+
142+
.fade-leave-active {
143+
transition: opacity 2s;
144+
}
145+
146+
.fade-enter, .fade-leave-to {
147+
opacity: 0;
148+
}
149+
</style>

src/store/actions.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,63 @@ export const setTradeResult = ({state, commit}, tradeResult) => {
66
if (response) {
77
commit("updateTradeResult", response.data);
88
}
9-
});
9+
util.common.control(response);
10+
}).catch(error => {
11+
util.common.control(error)
12+
});
1013
};
1114

1215
export const getTradeResult = ({commit}) => {
13-
commit("setIsLoading", true);
1416
util.service.get("trade/result")
1517
.then(response => {
1618
if (response) {
1719
commit("updateTradeResult", response.data);
1820
}
19-
commit("setIsLoading", false);
21+
util.common.control(response);
2022
}).catch(error => {
2123
util.common.control(error)
2224
})
2325
};
2426

25-
export const registerConfirm = (vueContext,param) => {
27+
export const registerConfirm = (vueContext, param) => {
2628
return util.service.get("user/registrationConfirm/" + param)
2729
.then(response => {
2830
if (response) {
31+
util.common.control(response);
2932
return response;
3033
}
3134
}).catch(error => {
32-
util.common.control(error)
33-
})
35+
util.common.control(error)
36+
})
3437
};
3538

3639

3740
export const login = (vueContext, loginData) => {
3841
loginData.password = util.randomCode(loginData.password);
3942
loginData.username = util.randomCode(loginData.username);
40-
vueContext.commit("setIsLoading", true);
4143
return util.service.post("auth/login", loginData)
4244
.then(response => {
43-
loginData = {};
45+
loginData.password = null;
46+
loginData.username = null;
4447
if (response) {
4548
util.common.loginSuccessfully(response.data);
46-
//vueContext.dispatch("initApp");
4749
vueContext.dispatch("getTradeResult");
4850
util.common.routePush("dashboard");
51+
util.common.control(response);
4952
}
50-
vueContext.commit("setIsLoading", false);
5153
}).catch(error => {
52-
loginData = {};
54+
loginData.password = null;
55+
loginData.username = null;
56+
util.common.control(error);
5357
});
5458
};
5559

56-
export const logout = (vueContext) => {
60+
export const logout = () => {
5761
return util.service.post("auth/logout")
5862
.then(res => {
5963
if (res) {
6064
util.common.logoutSuccessfully();
61-
util.common.routePush("login");
65+
util.common.control(res);
6266
}
6367
}).catch(err => {
6468
util.common.control(err);
@@ -71,8 +75,11 @@ export const userRegister = (vueContext, registerData) => {
7175
if (response) {
7276
return response;
7377
}
78+
util.common.control(response);
79+
7480
}).catch(error => {
7581
registerData = {};
82+
util.common.control(error);
7683
})
7784
};
7885

src/store/getters.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ export const getIsLogin = (state) =>{
1313
export const getIsLoading = (state) =>{
1414
return state.isLoading;
1515
}
16+
17+
export const getMyToast = (state)=>{
18+
return state.myToast;
19+
}

0 commit comments

Comments
 (0)