Merge pull request #63 from ronger-x/master

🎨 钱包账号调整为手动激活
This commit is contained in:
ronger 2022-11-01 22:54:41 +08:00 committed by GitHub
commit 69487c3d06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 241 additions and 283 deletions

View File

@ -90,7 +90,8 @@
</el-link>
</el-dropdown-item>
<el-dropdown-item command="user">个人中心</el-dropdown-item>
<el-dropdown-item command="answer">每日一题</el-dropdown-item>
<el-dropdown-item command="answer" v-if="$auth.user.bankAccount">每日一题</el-dropdown-item>
<el-dropdown-item command="answer" v-else :disabled="true">每日一题<small>(开通钱包账号激活)</small></el-dropdown-item>
<el-dropdown-item command="drafts" divided>我的草稿</el-dropdown-item>
<el-dropdown-item command="wallet">我的钱包</el-dropdown-item>
<el-dropdown-item command="user-info" divided>设置</el-dropdown-item>
@ -184,8 +185,6 @@ export default {
},
handleSelectMenu(item) {
let _ts = this;
let activeMenu = _ts.$store.state.activeMenu;
if (activeMenu !== item) {
switch (item) {
case 'topic':
_ts.$router.push({
@ -220,7 +219,6 @@ export default {
}
)
}
}
},
handleCommand(item) {
let _ts = this;

View File

@ -4,7 +4,7 @@
<header-view/>
</el-header>
<el-main>
<nuxt :nuxt-child-key="$route.name" keep-alive :keep-alive-props="{max: 16}"/>
<nuxt keep-alive/>
</el-main>
<el-footer height="5rem">
<footer-view/>

View File

@ -3,7 +3,7 @@
<el-col v-if="hasPermissions" :span="20">
<el-col :span="4">
<el-menu
:default-active="getActiveMenu"
:default-active="activeMenu"
class="el-menu-vertical-demo"
@select="handleSelectMenu">
<template v-for="menu in menus">
@ -15,7 +15,7 @@
</el-menu>
</el-col>
<el-col :span="20">
<el-tabs v-model="editableTabsValue" type="card" @tab-remove="handleRemoveTab" @tab-click="handleClick">
<el-tabs :value="editableTabsValue" type="card" @tab-remove="handleRemoveTab" @tab-click="handleClick">
<el-tab-pane
:key="item.name"
v-for="(item, index) in editableTabs"
@ -23,7 +23,7 @@
:name="item.name"
:closable="item.closable"
>
<nuxt keep-alive :nuxt-child-key="item.name"/>
<nuxt-child keep-alive :keep-alive-props="{exclude: ['login', 'register', 'admin-dashboard'],max: 10}"/>
</el-tab-pane>
</el-tabs>
</el-col>
@ -42,6 +42,7 @@
<script>
import _ from 'lodash'
import {mapState} from 'vuex';
export default {
name: "Admin",
@ -130,23 +131,18 @@ export default {
}
},
computed: {
...mapState({
editableTabs() {
return this.$store.state.admin.tabs;
},
editableTabsValue: {
get() {
editableTabsValue() {
return this.$store.state.admin.activeTab;
},
set(value) {
this.$store.commit('admin/updateActiveTab', value);
}
},
getActiveMenu() {
return this.$store.state.activeMenu;
},
activeMenu: state => state.activeMenu,
hasPermissions() {
return this.$auth.hasScope('admin') || this.$auth.hasScope('blog_admin');
}
})
},
methods: {
handleRemoveTab(targetName) {
@ -162,35 +158,13 @@ export default {
}
});
}
this.$store.commit('admin/updateActiveTab', activeName);
this.$store.commit('admin/updateTags', tabs.filter(tab => tab.name !== targetName))
this.$router.push({
name: activeName,
params: {
reset: '0'
}
})
this.handleSelectMenu(activeName)
},
handleClick(item) {
let _ts = this
this.$store.commit('admin/updateActiveTab', item.name);
let result = _.findIndex(_ts.editableTabs, function (tab) {
return tab.name === item.name;
})
if (result === -1) {
let index = _.findIndex(_ts.menus, function (menu) {
return menu.name === item.name;
})
_ts.$store.commit('admin/pushTags', _ts.menus[index])
}
_ts.$router.push({
name: item.name,
params: {
reset: '0'
}
})
this.handleSelectMenu(item.name)
},
handleSelectTab(item) {
let _ts = this
@ -221,6 +195,9 @@ export default {
_ts.handleSelectTab(item)
}
}
},
mounted() {
this.handleSelectMenu(this.$route.name)
}
}
</script>

View File

@ -200,9 +200,6 @@ export default {
openLink(link) {
window.open(link);
}
},
mounted() {
this.$store.commit("setActiveMenu", "admin-articles");
}
}
</script>

View File

@ -147,9 +147,6 @@ export default {
endDate: endDate
})
}
},
mounted() {
this.$store.commit("setActiveMenu", "admin-bank-accounts");
}
}
</script>

View File

@ -157,9 +157,6 @@ export default {
}
})
}
},
mounted() {
this.$store.commit("setActiveMenu", "admin-banks");
}
}
</script>

View File

@ -150,9 +150,6 @@ export default {
})
},
toggleStatus() {}
},
mounted() {
this.$store.commit("setActiveMenu", "admin-comments");
}
}
</script>

View File

@ -151,9 +151,6 @@ export default {
}
})
}
},
mounted() {
this.$store.commit("setActiveMenu", "admin-currency-rules");
}
}
</script>

View File

@ -42,143 +42,91 @@
<el-col :span="24" style="text-align: left;">
<h3>新增文章列表</h3>
</el-col>
<el-table
:data="articles.list"
style="width: 100%">
<el-table-column
label="#"
width="60"
prop="idArticle">
<el-table :data="articles.list" style="width: 100%">
<el-table-column label="#" width="60" prop="idArticle">
</el-table-column>
<el-table-column
label="标题"
prop="articleTitle">
<el-table-column label="标题" prop="articleTitle">
<template slot-scope="scope">
<el-button type="text" @click="openLink(scope.row.articlePermalink)">{{ scope.row.articleTitle }}</el-button>
<el-button type="text" @click="openLink(scope.row.articlePermalink)">{{ scope.row.articleTitle }}
</el-button>
</template>
</el-table-column>
<el-table-column
label="标签"
prop="articleTitle">
<el-table-column label="标签" prop="articleTitle">
<template slot-scope="scope">
<el-tag
style="margin-left: 0.5rem;"
v-for="tag in scope.row.tags"
:key="tag.idTag"
size="mini"
<el-tag style="margin-left: 0.5rem;" v-for="tag in scope.row.tags" :key="tag.idTag" size="mini"
effect="plain">
# {{ tag.tagTitle }}
</el-tag>
</template>
</el-table-column>
<el-table-column
label="最后更新时间"
width="180"
prop="updatedTime">
<el-table-column label="最后更新时间" width="180" prop="updatedTime">
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button v-if="scope.row.articlePerfect === '1'" size="mini" @click="cancelPreference(scope.$index, scope.row.idArticle)" plain>取消优选</el-button>
<el-button v-else size="mini" @click="setPreference(scope.$index, scope.row.idArticle)" plain>设为优选</el-button>
<el-button size="mini" type="primary"
@click="updateTags(scope.$index, scope.row)" plain>编辑标签
<el-button v-if="scope.row.articlePerfect === '1'" size="mini"
@click="cancelPreference(scope.$index, scope.row.idArticle)" plain>取消优选</el-button>
<el-button v-else size="mini" @click="setPreference(scope.$index, scope.row.idArticle)" plain>设为优选
</el-button>
<el-button size="mini" type="primary" @click="updateTags(scope.$index, scope.row)" plain>编辑标签
</el-button>
<el-button v-if="scope.row.articleStatus === '0'" size="mini" type="danger"
@click="toggleStatus(scope.$index, scope.row)" plain>下架
</el-button>
<el-button v-else size="mini" type="success"
@click="toggleStatus(scope.$index, scope.row)" plain>上架
<el-button v-else size="mini" type="success" @click="toggleStatus(scope.$index, scope.row)" plain>上架
</el-button>
</template>
</el-table-column>
</el-table>
</el-col>
<el-col>
<el-pagination
:hide-on-single-page="true"
@size-change="handleArticleSizeChange"
@current-change="handleArticleCurrentChange"
:current-page="articles.pageNum"
:page-sizes="[10, 20, 50, 100]"
:page-size="articles.pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="articles.total">
<el-pagination :hide-on-single-page="true" @size-change="handleArticleSizeChange"
@current-change="handleArticleCurrentChange" :current-page="articles.pageNum"
:page-sizes="[10, 20, 50, 100]" :page-size="articles.pageSize"
layout="total, sizes, prev, pager, next, jumper" :total="articles.total">
</el-pagination>
</el-col>
<el-col :span="24">
<el-col :span="24" style="text-align: left;">
<h3>新增用户列表</h3>
</el-col>
<el-table :data="users.list"
style="width: 100%">
<el-table-column
label="#"
width="40"
prop="idUser">
<el-table :data="users.list" style="width: 100%">
<el-table-column label="#" width="40" prop="idUser">
</el-table-column>
<el-table-column
label="头像"
width="60"
prop="avatarUrl">
<el-table-column label="头像" width="60" prop="avatarUrl">
<template slot-scope="scope">
<el-avatar v-if="scope.row.avatarUrl" size="medium" :src="scope.row.avatarUrl"></el-avatar>
<el-avatar v-else size="medium" src="https://rymcu.com/article/1578475481946.png"></el-avatar>
</template>
</el-table-column>
<el-table-column
label="昵称"
width="140"
prop="nickname">
<el-table-column label="昵称" width="140" prop="nickname">
<template slot-scope="scope">
<el-link type="primary" :href="getUserPath(scope.row.account)" :underline="false">
{{ scope.row.nickname }}
</el-link>
</template>
</el-table-column>
<el-table-column
label="注册时间"
width="180"
prop="createdTime">
<el-table-column label="注册时间" width="180" prop="createdTime">
</el-table-column>
</el-table>
</el-col>
<el-col>
<el-pagination
:hide-on-single-page="true"
@size-change="handleUserSizeChange"
@current-change="handleUserCurrentChange"
:current-page="users.pageNum"
:page-sizes="[10, 20, 50, 100]"
:page-size="users.pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="users.total">
<el-pagination :hide-on-single-page="true" @size-change="handleUserSizeChange"
@current-change="handleUserCurrentChange" :current-page="users.pageNum" :page-sizes="[10, 20, 50, 100]"
:page-size="users.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="users.total">
</el-pagination>
</el-col>
<el-col :span="24">
<el-col :span="24" style="text-align: left;">
<h3>新增账户列表</h3>
</el-col>
<el-table :data="bankAccounts.list"
style="width: 100%">
<el-table-column
label="#"
width="40"
prop="idBank">
<el-table :data="bankAccounts.list" style="width: 100%">
<el-table-column label="#" width="40" prop="idBank">
</el-table-column>
<el-table-column
label="银行账户"
width="180"
prop="bankAccount">
<el-table-column label="银行账户" width="180" prop="bankAccount">
</el-table-column>
<el-table-column
label="账户所有者"
width="180"
prop="accountOwnerName">
<el-table-column label="账户所有者" width="180" prop="accountOwnerName">
</el-table-column>
<el-table-column
label="账户余额 (巴旦木)"
width="180"
prop="accountBalance">
<el-table-column label="账户余额 (巴旦木)" width="180" prop="accountBalance">
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
@ -188,15 +136,10 @@
</el-table>
</el-col>
<el-col>
<el-pagination
:hide-on-single-page="true"
@size-change="handleBankAccountSizeChange"
@current-change="handleBankAccountCurrentChange"
:current-page="bankAccounts.pageNum"
:page-sizes="[10, 20, 50, 100]"
:page-size="bankAccounts.pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="bankAccounts.total">
<el-pagination :hide-on-single-page="true" @size-change="handleBankAccountSizeChange"
@current-change="handleBankAccountCurrentChange" :current-page="bankAccounts.pageNum"
:page-sizes="[10, 20, 50, 100]" :page-size="bankAccounts.pageSize"
layout="total, sizes, prev, pager, next, jumper" :total="bankAccounts.total">
</el-pagination>
</el-col>
</div>
@ -229,10 +172,7 @@
</el-col>
<el-col>
<el-dialog :visible.sync="tagsDialogVisible">
<edit-tags
:idArticle="idArticle"
:tags="articleTags"
@closeDialog="closeTagsDialog">
<edit-tags :idArticle="idArticle" :tags="articleTags" @closeDialog="closeTagsDialog">
</edit-tags>
</el-dialog>
</el-col>
@ -241,7 +181,7 @@
<script>
import Vue from 'vue';
import {mapState} from 'vuex';
import { mapState } from 'vuex';
import echarts from 'echarts';
import EditTags from '~/components/widget/tags';
@ -253,11 +193,11 @@ export default {
EditTags
},
fetch() {
let {store, params, error} = this.$nuxt.context
let { store, params, error } = this.$nuxt.context
return Promise.all([
store
.dispatch('dashboard/fetchDashboard', params)
.catch(err => error({statusCode: 404})),
.catch(err => error({ statusCode: 404 })),
store.dispatch("dashboard/fetchLastThirtyDays", params),
store.dispatch("dashboard/fetchHistory", params),
store.dispatch("dashboard/fetchNewUsers", params),
@ -540,7 +480,7 @@ export default {
_ts.$set(_ts, 'articleTags', article.articleTags);
_ts.$set(_ts, 'tagsDialogVisible', true);
},
toggleStatus() {},
toggleStatus() { },
closeTagsDialog() {
this.$set(this, 'tagsDialogVisible', false);
},
@ -593,7 +533,6 @@ export default {
this.initLastThirtyDaysCharts(this.lastThirtyDays)
this.initHistoryCharts(this.history)
}, 500);
}
}
</script>

View File

@ -156,9 +156,6 @@ export default {
})
},
handleEdit(index ,row) {}
},
mounted() {
this.$store.commit("setActiveMenu", "admin-products");
}
}
</script>

View File

@ -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);

View File

@ -104,9 +104,6 @@
path: '/admin/tag/post/' + id
})
}
},
mounted() {
this.$store.commit("setActiveMenu", "admin-tags");
}
}
</script>

View File

@ -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);

View File

@ -65,9 +65,6 @@
path: '/admin/topic/post'
})
}
},
mounted() {
this.$store.commit("setActiveMenu", "admin-topics");
}
}
</script>

View File

@ -227,9 +227,6 @@ export default {
getUserPath(nickname) {
return `/user/${nickname}`
}
},
mounted() {
this.$store.commit("setActiveMenu", "admin-users");
}
}
</script>

View File

@ -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)

View File

@ -95,7 +95,7 @@
{{ article.articleThumbsUpCount }}
</el-button>
</el-tooltip>
<el-tooltip class="item" effect="dark" content="赞赏" placement="top-start">
<el-tooltip v-if="article.canSponsor" class="item" effect="dark" content="赞赏" placement="top-start" :disabled="!$auth.user.bankAccount">
<el-button v-if="user.idUser === article.articleAuthorId" type="text"
style="font-size: 1.2rem;">
<svg width="24" height="24">

View File

@ -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}))

View File

@ -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)

View File

@ -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: {

View File

@ -47,7 +47,7 @@
<script>
import Vue from 'vue';
import {mapState} from 'vuex';
import { mapState } from 'vuex';
import echarts from 'echarts';
import gzh from "assets/rymcugzh.jpg";
@ -55,11 +55,11 @@ Vue.prototype.$echarts = echarts;
export default {
name: "openData",
fetch() {
let {store, params, error} = this.$nuxt.context
let { store, params, error } = this.$nuxt.context
return Promise.all([
store
.dispatch('open-data/fetchLastThirtyDays', params)
.catch(err => error({statusCode: 404})),
.catch(err => error({ statusCode: 404 })),
store.dispatch('open-data/fetchDashboard', params)
])
},
@ -163,14 +163,13 @@ export default {
</script>
<style scoped>
.article__wrapper {
max-width: 980px;
margin: 20px auto;
display: block;
padding-left: 1rem;
padding-right: 1rem;
box-sizing: border-box;;
box-sizing: border-box;
}
.mt-2rem {

View File

@ -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: {

View File

@ -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)

View File

@ -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)

View File

@ -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: {

View File

@ -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)

View File

@ -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: {

View File

@ -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)

View File

@ -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: {

View File

@ -8,15 +8,21 @@
<span style="font-size: 24px;"> 账号:</span> <span style="color: red;">{{ bankAccount.bankAccount }}</span>
</el-col>
<el-col class="bank-account-item">
<span style="font-size: 24px;"> 余额:</span> <span style="color: red;">{{ bankAccount.accountBalance }}</span> <span
<span style="font-size: 24px;"> 余额:</span> <span style="color: red;">{{ bankAccount.accountBalance }}</span>
<span
style="font-size: 24px;">巴旦木</span>
</el-col>
<el-col>
<records :records="records" :bankAccount="bankAccount.bankAccount" @currentChange="handleCurrentChange" @searchTransactionRecord="searchTransactionRecord"></records>
<records :records="records" :bankAccount="bankAccount.bankAccount" @currentChange="handleCurrentChange"
@searchTransactionRecord="searchTransactionRecord"></records>
</el-col>
</el-col>
<el-col v-else style="text-align: center;margin-top: 10vh;">
<el-button type="primary">开通钱包账号</el-button>
<p style="font-size: 24px;line-height: 48px;">
<code>钱包</code> 是社区非常重要的组成部分<br/>
开通钱包账号后可激活 <code>每日一题</code> , <code>赞赏</code> 等功能
</p>
<el-button type="primary" @click="createBankAccount">现在开通</el-button>
</el-col>
</el-row>
</template>
@ -28,7 +34,8 @@ import Records from "../components/common/bank/account/records";
export default {
name: "wallet",
components: {Records},
fetch({store, error}) {
fetch() {
let {store, error} = this.$nuxt.context
return Promise.all([
store
.dispatch('wallet/fetchDetail')
@ -45,8 +52,7 @@ export default {
})
},
data() {
return {
}
return {}
},
methods: {
handleCurrentChange(search) {
@ -67,6 +73,14 @@ export default {
startDate: startDate,
endDate: endDate
})
},
createBankAccount() {
let _ts = this
_ts.$axios.$post('/api/wallet/create').then(function (res) {
if (res) {
_ts.$fetch()
}
})
}
},
mounted() {
@ -80,4 +94,8 @@ export default {
font-size: 32px;
padding-left: 15vw;
}
code {
color: red;
font-weight: bold;
}
</style>

View File

@ -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 => {
removePendingRequest(error.config || {}); // 从pendingRequest对象中移除请求
if ($axios.isCancel(error)) {
// console.log("已取消的重复请求:" + error.message);
} else {
// 添加异常处理
const code = parseInt(error.response && error.response.status)
if (code === 400) {
redirect('/400');
} else {
console.log(error.data);
}
}
})
}