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

View File

@ -1,6 +1,6 @@
import axios from "axios"
import Qs from "qs"
import { Message } from 'element-ui';
// 请求封装
export default function httpAjax (config) {
return new Promise((resolve, reject) => {
@ -10,7 +10,11 @@ export default function httpAjax (config) {
config.params = config.data
delete 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() {
this.$httpApi.defaultTemplate().then((res) => {
if (res.code !== 0) return this.$message.error(res.msg)
console.log(res)
this.dtList = res.data.defaultTemplateList
})

View File

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

View File

@ -12,13 +12,13 @@
:src="datas.botLogo"
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
draggable="false"
class="logo"
src="@/assets/images/Robot.png"
/><span></span>
</p>
</p> -->
</div>
</template>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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