diff --git a/components/layouts/pc/main.vue b/components/layouts/pc/main.vue
index 15b4d23..38ba69f 100644
--- a/components/layouts/pc/main.vue
+++ b/components/layouts/pc/main.vue
@@ -4,7 +4,7 @@
-
+
diff --git a/pages/admin.vue b/pages/admin.vue
index e968c88..e06a58a 100644
--- a/pages/admin.vue
+++ b/pages/admin.vue
@@ -3,7 +3,7 @@
-
+
-
+
@@ -42,6 +42,7 @@
diff --git a/pages/admin/articles.vue b/pages/admin/articles.vue
index bb5b231..e4f9545 100644
--- a/pages/admin/articles.vue
+++ b/pages/admin/articles.vue
@@ -204,9 +204,6 @@ export default {
openLink(link) {
window.open(link);
}
- },
- mounted() {
- this.$store.commit("setActiveMenu", "admin-articles");
}
}
diff --git a/pages/admin/bank-accounts.vue b/pages/admin/bank-accounts.vue
index 0059f7b..6362a3c 100644
--- a/pages/admin/bank-accounts.vue
+++ b/pages/admin/bank-accounts.vue
@@ -147,9 +147,6 @@ export default {
endDate: endDate
})
}
- },
- mounted() {
- this.$store.commit("setActiveMenu", "admin-bank-accounts");
}
}
diff --git a/pages/admin/banks.vue b/pages/admin/banks.vue
index ce2f04a..48612f2 100644
--- a/pages/admin/banks.vue
+++ b/pages/admin/banks.vue
@@ -157,9 +157,6 @@ export default {
}
})
}
- },
- mounted() {
- this.$store.commit("setActiveMenu", "admin-banks");
}
}
diff --git a/pages/admin/comments.vue b/pages/admin/comments.vue
index 8a50fec..65d18f2 100644
--- a/pages/admin/comments.vue
+++ b/pages/admin/comments.vue
@@ -150,9 +150,6 @@ export default {
})
},
toggleStatus() {}
- },
- mounted() {
- this.$store.commit("setActiveMenu", "admin-comments");
}
}
diff --git a/pages/admin/currency-rules.vue b/pages/admin/currency-rules.vue
index 63e0e45..6c64a9a 100644
--- a/pages/admin/currency-rules.vue
+++ b/pages/admin/currency-rules.vue
@@ -151,9 +151,6 @@ export default {
}
})
}
- },
- mounted() {
- this.$store.commit("setActiveMenu", "admin-currency-rules");
}
}
diff --git a/pages/admin/dashboard.vue b/pages/admin/dashboard.vue
index 5228568..ebdd346 100644
--- a/pages/admin/dashboard.vue
+++ b/pages/admin/dashboard.vue
@@ -592,9 +592,11 @@ export default {
},
},
mounted() {
- this.$store.commit("setActiveMenu", "admin-dashboard");
- this.initLastThirtyDaysCharts(this.lastThirtyDays)
- this.initHistoryCharts(this.history)
+ let _ts = this
+ Vue.nextTick(() => {
+ _ts.initLastThirtyDaysCharts(_ts.lastThirtyDays)
+ _ts.initHistoryCharts(_ts.history)
+ })
}
}
diff --git a/pages/admin/products.vue b/pages/admin/products.vue
index 8469984..9cf9fa6 100644
--- a/pages/admin/products.vue
+++ b/pages/admin/products.vue
@@ -156,9 +156,6 @@ export default {
})
},
handleEdit(index ,row) {}
- },
- mounted() {
- this.$store.commit("setActiveMenu", "admin-products");
}
}
diff --git a/pages/admin/tag/post/_tag_id.vue b/pages/admin/tag/post/_tag_id.vue
index 1da85b2..f2e2209 100644
--- a/pages/admin/tag/post/_tag_id.vue
+++ b/pages/admin/tag/post/_tag_id.vue
@@ -346,7 +346,6 @@ export default {
}).then(() => {
next();
}).catch(() => {
- _ts.$store.commit("setActiveMenu", "admin-tag-post");
return false
});
} else {
@@ -369,7 +368,6 @@ export default {
return '关闭提示';
});
let _ts = this;
- _ts.$store.commit('setActiveMenu', 'admin-tag-post');
_ts.$axios.$get('/api/upload/simple/token').then(function (res) {
if (res) {
_ts.$store.commit('setUploadHeaders', res.uploadToken);
diff --git a/pages/admin/tags.vue b/pages/admin/tags.vue
index 4e5ee15..8b340b9 100644
--- a/pages/admin/tags.vue
+++ b/pages/admin/tags.vue
@@ -104,9 +104,6 @@
path: '/admin/tag/post/' + id
})
}
- },
- mounted() {
- this.$store.commit("setActiveMenu", "admin-tags");
}
}
diff --git a/pages/admin/topic/post/_topic_id.vue b/pages/admin/topic/post/_topic_id.vue
index e3f186e..8404dfc 100644
--- a/pages/admin/topic/post/_topic_id.vue
+++ b/pages/admin/topic/post/_topic_id.vue
@@ -351,7 +351,6 @@ export default {
}).then(() => {
next();
}).catch(() => {
- _ts.$store.commit("setActiveMenu", "admin-topic-post");
return false
});
} else {
@@ -374,7 +373,6 @@ export default {
return '关闭提示';
});
let _ts = this;
- _ts.$store.commit("setActiveMenu", "admin-topic-post");
_ts.$axios.$get('/api/upload/simple/token').then(function (res) {
if (res) {
_ts.$store.commit('setUploadHeaders', res.uploadToken);
diff --git a/pages/admin/topics.vue b/pages/admin/topics.vue
index 2b864b4..c9a6b70 100644
--- a/pages/admin/topics.vue
+++ b/pages/admin/topics.vue
@@ -65,9 +65,6 @@
path: '/admin/topic/post'
})
}
- },
- mounted() {
- this.$store.commit("setActiveMenu", "admin-topics");
}
}
diff --git a/pages/admin/users.vue b/pages/admin/users.vue
index e740506..49b45e3 100644
--- a/pages/admin/users.vue
+++ b/pages/admin/users.vue
@@ -227,9 +227,6 @@ export default {
getUserPath(nickname) {
return `/user/${nickname}`
}
- },
- mounted() {
- this.$store.commit("setActiveMenu", "admin-users");
}
}
diff --git a/pages/answer.vue b/pages/answer.vue
index 6dec761..514a94e 100644
--- a/pages/answer.vue
+++ b/pages/answer.vue
@@ -63,7 +63,8 @@ import {mapState} from 'vuex';
export default {
name: "answer",
middleware: 'auth',
- fetch({store, params, error}) {
+ fetch() {
+ let {store, params, error} = this.$nuxt.context
return Promise.all([
store
.dispatch('answer/fetchDetail', params)
diff --git a/pages/article/post/_article_id.vue b/pages/article/post/_article_id.vue
index feb3626..12e4c99 100644
--- a/pages/article/post/_article_id.vue
+++ b/pages/article/post/_article_id.vue
@@ -70,7 +70,8 @@
}
return params.article_id && !isNaN(Number(params.article_id))
},
- fetch({store, params, error}) {
+ fetch() {
+ let {store, params, error} = this.$nuxt.context
return Promise.all([
store.dispatch('article/fetchPostDetail', params)
.catch(err => error({statusCode: 404}))
diff --git a/pages/draft/_draft_id.vue b/pages/draft/_draft_id.vue
index 54dae58..ae88b7a 100644
--- a/pages/draft/_draft_id.vue
+++ b/pages/draft/_draft_id.vue
@@ -75,7 +75,8 @@
validate({params, store}) {
return params.draft_id && !isNaN(Number(params.draft_id))
},
- fetch({store, params, error}) {
+ fetch() {
+ let {store, params, error} = this.$nuxt.context
return Promise.all([
store
.dispatch('draft/fetchDetail', params)
diff --git a/pages/index.vue b/pages/index.vue
index ec1032e..a5f4999 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -19,8 +19,10 @@ export default {
])
},
watch: {
- '$route.query': function () {
- this.$store.dispatch('article/fetchList', {page: this.$route.query.page || 1})
+ '$route'(to, from) {
+ if (from.query.page && to.query.page) {
+ this.$router.go()
+ }
}
},
components: {
diff --git a/pages/open-data.vue b/pages/open-data.vue
index 7ba5d18..458fb0f 100644
--- a/pages/open-data.vue
+++ b/pages/open-data.vue
@@ -154,8 +154,11 @@ export default {
}
},
mounted() {
- this.$store.commit("setActiveMenu", "open-data");
- this.initLastThirtyDaysCharts(this.lastThirtyDays)
+ let _ts = this
+ _ts.$store.commit("setActiveMenu", "open-data");
+ Vue.nextTick(() => {
+ _ts.initLastThirtyDaysCharts(_ts.lastThirtyDays)
+ })
}
}
diff --git a/pages/portfolio/_portfolio_id.vue b/pages/portfolio/_portfolio_id.vue
index 4c774b9..809edcf 100644
--- a/pages/portfolio/_portfolio_id.vue
+++ b/pages/portfolio/_portfolio_id.vue
@@ -60,7 +60,8 @@ export default {
validate({params, store}) {
return params.portfolio_id && !isNaN(Number(params.portfolio_id))
},
- fetch({store, params, query, error}) {
+ fetch() {
+ let {store, params, query, error} = this.$nuxt.context
params.page = query.page || 1
return Promise.all([
store
@@ -70,11 +71,10 @@ export default {
])
},
watch: {
- '$route.query': function () {
- this.$store.dispatch('portfolio/fetchArticleList', {
- page: this.$route.query.page || 1,
- portfolio_id: this.routePortfolioId
- })
+ '$route'(to, from) {
+ if (from.query.page && to.query.page) {
+ this.$router.go()
+ }
}
},
computed: {
diff --git a/pages/portfolio/manager/_portfolio_id.vue b/pages/portfolio/manager/_portfolio_id.vue
index 4d0f929..13c7af0 100644
--- a/pages/portfolio/manager/_portfolio_id.vue
+++ b/pages/portfolio/manager/_portfolio_id.vue
@@ -66,7 +66,8 @@
validate({params, store}) {
return params.portfolio_id && !isNaN(Number(params.portfolio_id))
},
- fetch({store, params, error}) {
+ fetch() {
+ let {store, params, error} = this.$nuxt.context
return Promise.all([
store
.dispatch('portfolio/fetchDetail', params)
diff --git a/pages/portfolio/manager/bind/_portfolio_id.vue b/pages/portfolio/manager/bind/_portfolio_id.vue
index 87d36f1..4146b96 100644
--- a/pages/portfolio/manager/bind/_portfolio_id.vue
+++ b/pages/portfolio/manager/bind/_portfolio_id.vue
@@ -31,7 +31,8 @@
validate({params, store}) {
return params.portfolio_id && !isNaN(Number(params.portfolio_id))
},
- fetch({store, params, error}) {
+ fetch() {
+ let {store, params, error} = this.$nuxt.context
return Promise.all([
store
.dispatch('portfolio/fetchUnBindArticleList', params)
diff --git a/pages/portfolios.vue b/pages/portfolios.vue
index e0c2caf..b1b5926 100644
--- a/pages/portfolios.vue
+++ b/pages/portfolios.vue
@@ -25,8 +25,10 @@ export default {
])
},
watch: {
- '$route.query': function () {
- this.$store.dispatch('portfolio/fetchList', {page: this.$route.query.page || 1})
+ '$route'(to, from) {
+ if (from.query.page && to.query.page) {
+ this.$router.go()
+ }
}
},
computed: {
diff --git a/pages/product/_product_id.vue b/pages/product/_product_id.vue
index 8643e1d..4384187 100644
--- a/pages/product/_product_id.vue
+++ b/pages/product/_product_id.vue
@@ -24,7 +24,8 @@ export default {
validate({params, store}) {
return params.product_id && !isNaN(Number(params.product_id))
},
- fetch({store, params, error}) {
+ fetch() {
+ let {store, params, error} = this.$nuxt.context
return Promise.all([
store
.dispatch('product/fetchDetail', params)
diff --git a/pages/products.vue b/pages/products.vue
index de00d76..0dfb8e8 100644
--- a/pages/products.vue
+++ b/pages/products.vue
@@ -22,8 +22,10 @@ export default {
])
},
watch: {
- '$route.query': function () {
- this.$store.dispatch('product/fetchList', {page: this.$route.query.page || 1})
+ '$route'(to, from) {
+ if (from.query.page && to.query.page) {
+ this.$router.go()
+ }
}
},
computed: {
diff --git a/pages/rules/currency.vue b/pages/rules/currency.vue
index bd9e7a0..1b690ec 100644
--- a/pages/rules/currency.vue
+++ b/pages/rules/currency.vue
@@ -43,7 +43,8 @@ import { mapState } from 'vuex';
export default {
name: "currency",
- fetch({store, params, error}) {
+ fetch() {
+ let {store, params, error} = this.$nuxt.context
return Promise.all([
store
.dispatch('rule/fetchCurrencyRules', params)
diff --git a/pages/topic/_topic_uri.vue b/pages/topic/_topic_uri.vue
index 05e62ec..3555095 100644
--- a/pages/topic/_topic_uri.vue
+++ b/pages/topic/_topic_uri.vue
@@ -30,12 +30,10 @@ export default {
])
},
watch: {
- '$route.query': function () {
- let _ts = this
- _ts.$store.dispatch('article/fetchList', {
- topic_uri: _ts.defaultParams.topic_uri,
- page: _ts.defaultParams.page || 1
- })
+ '$route'(to, from) {
+ if (from.query.page && to.query.page) {
+ this.$router.go()
+ }
}
},
computed: {
diff --git a/plugins/axios.js b/plugins/axios.js
index 1e14d33..0c80e84 100644
--- a/plugins/axios.js
+++ b/plugins/axios.js
@@ -1,14 +1,54 @@
import {Message} from 'element-ui'
export default function ({app, $axios, store, redirect}) {
+
+ function generateReqKey(config) {
+ const { method, url, params, data } = config;
+ return [method, url, JSON.stringify(params), JSON.stringify(data)].join("&");
+ }
+
+ const pendingRequest = new Map();
+ function addPendingRequest(config) {
+ const requestKey = generateReqKey(config);
+ config.cancelToken = config.cancelToken || new $axios.CancelToken((cancel) => {
+ if (!pendingRequest.has(requestKey)) {
+ pendingRequest.set(requestKey, cancel);
+ }
+ });
+ }
+
+ function removePendingRequest(config) {
+ const requestKey = generateReqKey(config);
+ if (pendingRequest.has(requestKey)) {
+ const cancelToken = pendingRequest.get(requestKey);
+ cancelToken(requestKey);
+ pendingRequest.delete(requestKey);
+ }
+ }
+
$axios.onRequest(config => {
let fingerprint = store.state.fingerprint;
if (fingerprint) {
config.headers['fingerprint'] = fingerprint
}
})
+
+ $axios.interceptors.request.use(
+ function (config) {
+ // 检查是否存在重复请求,若存在则取消已发的请求
+ removePendingRequest(config);
+ // 把当前请求信息添加到pendingRequest对象中
+ addPendingRequest(config);
+ return config;
+ },
+ (error) => {
+ return Promise.reject(error);
+ }
+ );
+
$axios.onResponse(response => {
return new Promise((resolve, reject) => {
+ removePendingRequest(response.config);
//返回数据逻辑处理 比如:error_code错误处理
let message;
if (typeof (response.data.data) !== 'undefined') {
@@ -36,11 +76,18 @@ export default function ({app, $axios, store, redirect}) {
});
$axios.onError(error => {
- const code = parseInt(error.response && error.response.status)
- if (code === 400) {
- redirect('/400');
+ removePendingRequest(error.config || {}); // 从pendingRequest对象中移除请求
+ if ($axios.isCancel(error)) {
+ // console.log("已取消的重复请求:" + error.message);
} else {
- console.log(error.data);
+ // 添加异常处理
+ const code = parseInt(error.response && error.response.status)
+ if (code === 400) {
+ redirect('/400');
+ } else {
+ console.log(error.data);
+ }
}
+
})
}