feat: 封装响应拦截

This commit is contained in:
王奥斯 2021-10-26 11:30:25 +08:00
parent f81a0c0418
commit 1323a2c3a2
23 changed files with 57 additions and 61 deletions

View File

@ -26,9 +26,7 @@ export default {
this.$httpApi this.$httpApi
.loginAdminTest({ loginname: 'admin', pwd: '123456' }) .loginAdminTest({ loginname: 'admin', pwd: '123456' })
.then((res) => { .then((res) => {
if (!res.success) { console.log(res)
return this.$message.error(res.msg)
}
this.getPermission() this.getPermission()
}) })
} else { } else {
@ -52,9 +50,6 @@ export default {
}, },
getPermission() { getPermission() {
this.$httpApi.getPermission().then((res) => { this.$httpApi.getPermission().then((res) => {
if (!res.success) {
return this.$message.error(res.msg)
}
let permissionsList = res.data.permissionsList let permissionsList = res.data.permissionsList
for (let i in permissionsList) { for (let i in permissionsList) {

View File

@ -1,6 +1,6 @@
import axios from "axios" import axios from "axios"
import Qs from "qs" import Qs from "qs"
import { Message } from 'element-ui';
// 请求封装 // 请求封装
export default function httpAjax (config) { export default function httpAjax (config) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -10,7 +10,11 @@ export default function httpAjax (config) {
config.params = config.data config.params = config.data
delete config.data delete config.data
}else if (config.header === "form" && ['post', 'put', 'patch'].some(item => item === method)) config.data = Qs.stringify(config.data) }else if (config.header === "form" && ['post', 'put', 'patch'].some(item => item === method)) config.data = Qs.stringify(config.data)
axios(config).then(response => resolve(response.data)).catch( error => reject(error)) // 响应拦截
axios(config).then(response => {
if(!response.data.success) return Message.success('测试环境');
resolve(response.data)
}).catch( error => reject(error))
}) })
} }

View File

@ -95,7 +95,7 @@ export default {
}, },
loadDefaultTemplate() { loadDefaultTemplate() {
this.$httpApi.defaultTemplate().then((res) => { this.$httpApi.defaultTemplate().then((res) => {
if (res.code !== 0) return this.$message.error(res.msg)
console.log(res) console.log(res)
this.dtList = res.data.defaultTemplateList this.dtList = res.data.defaultTemplateList
}) })

View File

@ -112,7 +112,7 @@ export default {
// //
selectDataApi() { selectDataApi() {
this.$httpApi.selectData().then((res) => { this.$httpApi.selectData().then((res) => {
if (res.code !== 0) return this.$message.error(res.msg)
this.options = res.data.posterList this.options = res.data.posterList
this.selectType = res.data.posterList[0].title this.selectType = res.data.posterList[0].title
// //
@ -138,7 +138,7 @@ export default {
}) })
.then((res) => { .then((res) => {
loading.close() loading.close()
if (res.code !== 0) return this.$message.error(res.msg)
this.$message({ this.$message({
message: '海报加载成功', message: '海报加载成功',
type: 'success', type: 'success',

View File

@ -12,13 +12,13 @@
:src="datas.botLogo" :src="datas.botLogo"
style="width: 110px; margin-left: 35%; margin-top: 10px" style="width: 110px; margin-left: 35%; margin-top: 10px"
/> --> /> -->
<p class="yinjia" :style="{ 'margin-top': datas ? '0px' : '10px' }"> <!-- <p class="yinjia" :style="{ 'margin-top': datas ? '0px' : '10px' }">
<img <img
draggable="false" draggable="false"
class="logo" class="logo"
src="@/assets/images/Robot.png" src="@/assets/images/Robot.png"
/><span></span> /><span></span>
</p> </p> -->
</div> </div>
</template> </template>

View File

@ -295,7 +295,7 @@ export default {
/* 获取下拉框内容 */ /* 获取下拉框内容 */
getOption() { getOption() {
this.$httpApi.shopTemplate().then((res) => { this.$httpApi.shopTemplate().then((res) => {
if (res.code !== 0) return this.$message.error(res.msg)
this.options = res.data.shopTemplateList this.options = res.data.shopTemplateList
}) })
}, },

View File

@ -236,8 +236,7 @@ export default {
// //
getShopInfo() { getShopInfo() {
this.$httpApi.queryShopInfo().then((res) => { this.$httpApi.queryShopInfo().then((res) => {
// console.log('shop info ', res)
if (res.code !== 0) return this.$message.error(res.msg)
this.shopData.shopName = res.data.name // this.shopData.shopName = res.data.name //
this.shopData.shopPic = res.data.icon // this.shopData.shopPic = res.data.icon //
@ -257,7 +256,6 @@ export default {
this.$httpApi.updateShopInfo(params).then((res) => { this.$httpApi.updateShopInfo(params).then((res) => {
console.log('change shop info ::', res) console.log('change shop info ::', res)
if (res.code !== 0) return this.$message.error(res.msg)
this.$message.success(res.msg) this.$message.success(res.msg)
}) })
}, },

View File

@ -156,7 +156,7 @@ export default {
/* 获取视频,音频,直播信息 */ /* 获取视频,音频,直播信息 */
this.$httpApi.newsList({ type: linkType }).then((res) => { this.$httpApi.newsList({ type: linkType }).then((res) => {
this.activ = 0 this.activ = 0
if (res.code !== 0) return this.$message.error(res.msg)
res.data.length === 0 ? (this.emptyText = '暂无数据') : null res.data.length === 0 ? (this.emptyText = '暂无数据') : null
this.options = res.data this.options = res.data
@ -169,7 +169,7 @@ export default {
} else if (linkType === '10') { } else if (linkType === '10') {
// //
this.$httpApi.shopTemplate().then((res) => { this.$httpApi.shopTemplate().then((res) => {
if (res.code !== 0) return this.$message.error(res.msg)
this.options = res.data.shopTemplateList this.options = res.data.shopTemplateList
// //

View File

@ -403,7 +403,7 @@ export default {
/* 获取视频,音频,直播信息 */ /* 获取视频,音频,直播信息 */
this.$httpApi.newsList({ type: linkType }).then((res) => { this.$httpApi.newsList({ type: linkType }).then((res) => {
this.activ = 0 this.activ = 0
if (res.code !== 0) return this.$message.error(res.msg)
res.data.length === 0 ? (this.emptyText = '暂无数据') : null res.data.length === 0 ? (this.emptyText = '暂无数据') : null
this.options = res.data this.options = res.data
@ -416,7 +416,7 @@ export default {
} else if (linkType === '10') { } else if (linkType === '10') {
// //
this.$httpApi.shopTemplate().then((res) => { this.$httpApi.shopTemplate().then((res) => {
if (res.code !== 0) return this.$message.error(res.msg)
this.options = res.data.shopTemplateList this.options = res.data.shopTemplateList
// //

View File

@ -627,7 +627,7 @@ export default {
/* 获取下拉框内容 */ /* 获取下拉框内容 */
getOption() { getOption() {
this.$httpApi.shopTemplate().then((res) => { this.$httpApi.shopTemplate().then((res) => {
if (res.code !== 0) return this.$message.error(res.msg)
this.options = res.data.shopTemplateList this.options = res.data.shopTemplateList
}) })
}, },

View File

@ -237,12 +237,12 @@ export default {
/* 获取视频,音频,直播信息 */ /* 获取视频,音频,直播信息 */
this.$httpApi.newsList({ type: res }).then((res) => { this.$httpApi.newsList({ type: res }).then((res) => {
this.activ = 0 this.activ = 0
if (res.code !== 0) return this.$message.error(res.msg)
this.options = res.data this.options = res.data
}) })
} else if (res === '10') { } else if (res === '10') {
this.$httpApi.shopTemplate().then((res) => { this.$httpApi.shopTemplate().then((res) => {
if (res.code !== 0) return this.$message.error(res.msg)
this.options = res.data.shopTemplateList this.options = res.data.shopTemplateList
}) })
} }

View File

@ -534,7 +534,7 @@ export default {
/* 获取视频,音频,直播信息 */ /* 获取视频,音频,直播信息 */
this.$httpApi.newsList({ type: linkType }).then((res) => { this.$httpApi.newsList({ type: linkType }).then((res) => {
this.activ = 0 this.activ = 0
if (res.code !== 0) return this.$message.error(res.msg)
res.data.length === 0 ? (this.emptyText = '暂无数据') : null res.data.length === 0 ? (this.emptyText = '暂无数据') : null
this.options = res.data this.options = res.data
@ -546,7 +546,7 @@ export default {
}) })
} else if (linkType === '10') { } else if (linkType === '10') {
this.$httpApi.shopTemplate().then((res) => { this.$httpApi.shopTemplate().then((res) => {
if (res.code !== 0) return this.$message.error(res.msg)
this.options = res.data.shopTemplateList this.options = res.data.shopTemplateList
// //

View File

@ -349,7 +349,7 @@ export default {
/* 获取视频,音频,直播信息 */ /* 获取视频,音频,直播信息 */
this.$httpApi.newsList({ type: linkType }).then((res) => { this.$httpApi.newsList({ type: linkType }).then((res) => {
this.activ = 0 this.activ = 0
if (res.code !== 0) return this.$message.error(res.msg)
res.data.length === 0 ? (this.emptyText = '暂无数据') : null res.data.length === 0 ? (this.emptyText = '暂无数据') : null
this.options = res.data this.options = res.data
@ -362,7 +362,7 @@ export default {
} else if (linkType === '10') { } else if (linkType === '10') {
// //
this.$httpApi.shopTemplate().then((res) => { this.$httpApi.shopTemplate().then((res) => {
if (res.code !== 0) return this.$message.error(res.msg)
this.options = res.data.shopTemplateList this.options = res.data.shopTemplateList
// //

View File

@ -453,7 +453,7 @@ export default {
/* 获取视频,音频,直播信息 */ /* 获取视频,音频,直播信息 */
this.$httpApi.newsList({ type: linkType }).then((res) => { this.$httpApi.newsList({ type: linkType }).then((res) => {
this.activ = 0 this.activ = 0
if (res.code !== 0) return this.$message.error(res.msg)
res.data.length === 0 ? (this.emptyText = '暂无数据') : null res.data.length === 0 ? (this.emptyText = '暂无数据') : null
this.options = res.data this.options = res.data
@ -466,7 +466,7 @@ export default {
} else if (linkType === '10') { } else if (linkType === '10') {
// //
this.$httpApi.shopTemplate().then((res) => { this.$httpApi.shopTemplate().then((res) => {
if (res.code !== 0) return this.$message.error(res.msg)
this.options = res.data.shopTemplateList this.options = res.data.shopTemplateList
// //
@ -484,13 +484,13 @@ export default {
/* 获取视频,音频,直播信息 */ /* 获取视频,音频,直播信息 */
this.$httpApi.newsList({ type: res }).then((res) => { this.$httpApi.newsList({ type: res }).then((res) => {
this.activ = 0 this.activ = 0
if (res.code !== 0) return this.$message.error(res.msg)
this.options1 = res.data this.options1 = res.data
}) })
} else if (res === '10') { } else if (res === '10') {
// //
this.$httpApi.shopTemplate().then((res) => { this.$httpApi.shopTemplate().then((res) => {
if (res.code !== 0) return this.$message.error(res.msg)
this.options1 = res.data.shopTemplateList this.options1 = res.data.shopTemplateList
}) })
} }

View File

@ -104,7 +104,7 @@ export default {
/* 获取视频,音频,直播信息 */ /* 获取视频,音频,直播信息 */
this.$httpApi.newsList({ type: linkType }).then((res) => { this.$httpApi.newsList({ type: linkType }).then((res) => {
this.activ = 0 this.activ = 0
if (res.code !== 0) return this.$message.error(res.msg)
res.data.length === 0 ? (this.emptyText = '暂无数据') : null res.data.length === 0 ? (this.emptyText = '暂无数据') : null
this.options = res.data this.options = res.data
@ -117,7 +117,7 @@ export default {
} else if (linkType === '10') { } else if (linkType === '10') {
// //
this.$httpApi.shopTemplate().then((res) => { this.$httpApi.shopTemplate().then((res) => {
if (res.code !== 0) return this.$message.error(res.msg)
this.options = res.data.shopTemplateList this.options = res.data.shopTemplateList
// //

View File

@ -258,7 +258,7 @@ export default {
/* 获取视频,音频,直播信息 */ /* 获取视频,音频,直播信息 */
this.$httpApi.newsList({ type: linkType }).then((res) => { this.$httpApi.newsList({ type: linkType }).then((res) => {
this.activ = 0 this.activ = 0
if (res.code !== 0) return this.$message.error(res.msg)
res.data.length === 0 ? (this.emptyText = '暂无数据') : null res.data.length === 0 ? (this.emptyText = '暂无数据') : null
this.options = res.data this.options = res.data
@ -271,7 +271,7 @@ export default {
} else if (linkType === '10') { } else if (linkType === '10') {
// //
this.$httpApi.shopTemplate().then((res) => { this.$httpApi.shopTemplate().then((res) => {
if (res.code !== 0) return this.$message.error(res.msg)
this.options = res.data.shopTemplateList this.options = res.data.shopTemplateList
// //

View File

@ -71,7 +71,7 @@ export default {
/* 获取视频信息 */ /* 获取视频信息 */
this.$httpApi.newsList({ type: 1 }).then((res) => { this.$httpApi.newsList({ type: 1 }).then((res) => {
this.activ = 0 this.activ = 0
if (res.code !== 0) return this.$message.error(res.msg)
this.videoList = res.data this.videoList = res.data
}) })
}, },

View File

@ -67,7 +67,7 @@ export default {
this.$httpApi.newsList({ type: 3 }).then((res) => { this.$httpApi.newsList({ type: 3 }).then((res) => {
this.activ = 0 this.activ = 0
console.log(res.data) console.log(res.data)
if (res.code !== 0) return this.$message.error(res.msg)
this.voicerList = res.data this.voicerList = res.data
}) })

View File

@ -142,7 +142,7 @@ export default {
/* 获取视频,音频,直播信息 */ /* 获取视频,音频,直播信息 */
this.$httpApi.newsList({ type: linkType }).then((res) => { this.$httpApi.newsList({ type: linkType }).then((res) => {
this.activ = 0 this.activ = 0
if (res.code !== 0) return this.$message.error(res.msg)
res.data.length === 0 ? (this.emptyText = '暂无数据') : null res.data.length === 0 ? (this.emptyText = '暂无数据') : null
this.options = res.data this.options = res.data
@ -155,7 +155,7 @@ export default {
} else if (linkType === '10') { } else if (linkType === '10') {
// //
this.$httpApi.shopTemplate().then((res) => { this.$httpApi.shopTemplate().then((res) => {
if (res.code !== 0) return this.$message.error(res.msg)
this.options = res.data.shopTemplateList this.options = res.data.shopTemplateList
// //

View File

@ -283,7 +283,7 @@ export default {
/* 取消加载 */ /* 取消加载 */
loading.close() loading.close()
if (res.code !== 0) return this.$message.error(res.msg)
let datas = res.data.shopTemplate let datas = res.data.shopTemplate
//idnull, //idnull,
@ -363,7 +363,7 @@ export default {
this.$httpApi.shelves({ shopTemplateId: this.id }).then((res) => { this.$httpApi.shelves({ shopTemplateId: this.id }).then((res) => {
/* 取消加载 */ /* 取消加载 */
loadingss.close() loadingss.close()
if (res.code !== 0) return this.$message.error(res.msg) console.log(res)
this.$router.push({ path: 'establishShop' }) this.$router.push({ path: 'establishShop' })
this.id = null this.id = null
@ -387,8 +387,7 @@ export default {
this.$httpApi.shelves({ shopTemplateId: this.id }).then((res) => { this.$httpApi.shelves({ shopTemplateId: this.id }).then((res) => {
/* 取消加载 */ /* 取消加载 */
loadingss.close() loadingss.close()
if (res.code !== 0) return this.$message.error(res.msg) console.log(res)
this.$message({ this.$message({
message: '上架成功', message: '上架成功',
type: 'success', type: 'success',
@ -468,7 +467,7 @@ export default {
/* 取消加载 */ /* 取消加载 */
loadings.close() loadings.close()
if (res.code !== 0) return this.$message.error(res.msg)
this.$message({ this.$message({
message: '上传成功', message: '上传成功',
@ -519,7 +518,7 @@ export default {
type: 'success', type: 'success',
}) })
if (res.code !== 0) return this.$message.error(res.msg)
/* 获取图片链接 */ /* 获取图片链接 */
callBack(res.data.src) callBack(res.data.src)
}) })

View File

@ -4,7 +4,7 @@ import VueRouter from 'vue-router'
Vue.use(VueRouter) Vue.use(VueRouter)
const routes = [ const routes = [
{ path: '/', redirect: '/establishShop' }, // { path: '/', redirect: '/establishShop' },
{ {
path: '/', path: '/',
name: 'layout', name: 'layout',

View File

@ -386,7 +386,7 @@ export default {
.then((res) => { .then((res) => {
/* 取消加载 */ /* 取消加载 */
if (res.code !== 0) return this.$message.error(res.msg)
this.total = res.count - 1 this.total = res.count - 1
@ -461,8 +461,8 @@ export default {
/* 设为主页按钮 */ /* 设为主页按钮 */
setHomePage(id) { setHomePage(id) {
this.$httpApi.homePage({ id }).then((res) => { this.$httpApi.homePage({ id }).then(() => {
if (res.code !== 0) return this.$message.error(res.msg)
/* 成功弹框 */ /* 成功弹框 */
this.$message({ this.$message({
message: '设置为主页成功', message: '设置为主页成功',
@ -474,8 +474,8 @@ export default {
}, },
/* 设置为模板 */ /* 设置为模板 */
setDefaultTemplate(id, type) { setDefaultTemplate(id, type) {
this.$httpApi.saveDefaultTemplate({ id, type }).then((res) => { this.$httpApi.saveDefaultTemplate({ id, type }).then(() => {
if (res.code !== 0) return this.$message.error(res.msg)
/* 成功弹框 */ /* 成功弹框 */
this.$message({ this.$message({
message: '设置为模板成功', message: '设置为模板成功',
@ -496,11 +496,11 @@ export default {
spinner: 'el-icon-loading', spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)', background: 'rgba(0, 0, 0, 0.7)',
}) })
this.$httpApi.delete({ id }).then((res) => { this.$httpApi.delete({ id }).then(() => {
/* 取消加载 */ /* 取消加载 */
loadingss.close() loadingss.close()
if (res.code !== 0) return this.$message.error(res.msg)
/* 成功弹框 */ /* 成功弹框 */
this.$message({ this.$message({
@ -542,11 +542,11 @@ export default {
spinner: 'el-icon-loading', spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)', background: 'rgba(0, 0, 0, 0.7)',
}) })
this.$httpApi.copy({ id }).then((res) => { this.$httpApi.copy({ id }).then(() => {
/* 取消加载 */ /* 取消加载 */
loadingss.close() loadingss.close()
if (res.code !== 0) return this.$message.error(res.msg)
/* 成功弹框 */ /* 成功弹框 */
this.$message({ this.$message({
@ -574,7 +574,7 @@ export default {
this.$httpApi.exportTemplate({ shopTemplateId: id }).then((res) => { this.$httpApi.exportTemplate({ shopTemplateId: id }).then((res) => {
/* 取消加载 */ /* 取消加载 */
loadingss.close() loadingss.close()
if (res.code !== 0) return this.$message.error(res.msg)
let data = res.data.exportData let data = res.data.exportData
let fileName = name + '.yhxl' let fileName = name + '.yhxl'
@ -624,11 +624,11 @@ export default {
spinner: 'el-icon-loading', spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)', background: 'rgba(0, 0, 0, 0.7)',
}) })
this.$httpApi.importTemplate({ id }).then((res) => { this.$httpApi.importTemplate({ id }).then(() => {
/* 取消加载 */ /* 取消加载 */
loadingss.close() loadingss.close()
if (res.code !== 0) return this.$message.error(res.msg)
/* 成功弹框 */ /* 成功弹框 */
this.$message({ this.$message({
@ -674,7 +674,7 @@ export default {
.then((res) => { .then((res) => {
this.loading = false this.loading = false
if (res.code !== 0) return this.$message.error(res.msg)
console.log(res.data.shopCommodity, '------------------shopCommodity') console.log(res.data.shopCommodity, '------------------shopCommodity')
localStorage.setItem( localStorage.setItem(
'shopCommodity', 'shopCommodity',

View File

@ -12,7 +12,7 @@ module.exports = {
open: true, open: true,
proxy: { proxy: {
'/api': { '/api': {
target: 'https://xxx.xxx.xxx/', target: 'https://shop.starfirelink.com/',
ws: true, ws: true,
changeOrigin: true, changeOrigin: true,
pathRewrite: { pathRewrite: {