优化 post 显示动画

This commit is contained in:
wuxw 2025-07-11 14:31:53 +08:00
parent 468b84d2f9
commit 6db3ce8f33
4 changed files with 58 additions and 40 deletions

View File

@ -67,11 +67,8 @@ export function updateCommunity(data) {
data data
}).then(response => { }).then(response => {
const res = response.data const res = response.data
if (res.code === 0) {
resolve(res) resolve(res)
} else {
reject(new Error(res.msg || '更新小区失败'))
}
}).catch(error => { }).catch(error => {
reject(error) reject(error)
}) })
@ -87,11 +84,8 @@ export function deleteCommunity(data) {
data data
}).then(response => { }).then(response => {
const res = response.data const res = response.data
if (res.code === 0) {
resolve(res) resolve(res)
} else {
reject(new Error(res.msg || '删除小区失败'))
}
}).catch(error => { }).catch(error => {
reject(error) reject(error)
}) })
@ -107,11 +101,8 @@ export function sendCommunityToIot(data) {
data data
}).then(response => { }).then(response => {
const res = response.data const res = response.data
if (res.code === 0) {
resolve(res) resolve(res)
} else {
reject(new Error(res.msg || '同步到IOT失败'))
}
}).catch(error => { }).catch(error => {
reject(error) reject(error)
}) })
@ -127,11 +118,9 @@ export function auditEnterCommunity(data) {
data data
}).then(response => { }).then(response => {
const res = response.data const res = response.data
if (res.code === 0) {
resolve(res) resolve(res)
} else {
reject(new Error(res.msg || '撤回审核失败'))
}
}).catch(error => { }).catch(error => {
reject(error) reject(error)
}) })

View File

@ -1,10 +1,6 @@
<template> <template>
<el-dialog <el-dialog :title="$t('communityDataToIot.title')" :visible.sync="visible" width="30%"
:title="$t('communityDataToIot.title')" @close="closeCommunityDataToIotModel">
:visible.sync="visible"
width="30%"
@close="closeCommunityDataToIotModel"
>
<div style="text-align: center"> <div style="text-align: center">
<p>{{ $t('communityDataToIot.confirmText') }}</p> <p>{{ $t('communityDataToIot.confirmText') }}</p>
</div> </div>

View File

@ -1,14 +1,34 @@
import axios from 'axios' import axios from 'axios'
import { Message } from 'element-ui' import { Message, Loading } from 'element-ui'
import config from '@/conf/config' import config from '@/conf/config'
import { getHeader } from './header' import { getHeader } from './header'
// 创建loading实例
let loadingInstance = null
// 创建axios实例 // 创建axios实例
const service = axios.create({ const service = axios.create({
baseURL: config.baseApi, // 基础URL baseURL: config.baseApi, // 基础URL
timeout: config.apiTimeout // 请求超时时间 timeout: config.apiTimeout // 请求超时时间
}) })
// 显示加载动画
const showLoading = () => {
loadingInstance = Loading.service({
lock: true,
text: '加载中...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
}
// 隐藏加载动画
const hideLoading = () => {
if (loadingInstance) {
loadingInstance.close()
loadingInstance = null
}
}
// 请求拦截器 // 请求拦截器
service.interceptors.request.use( service.interceptors.request.use(
@ -25,13 +45,20 @@ service.interceptors.request.use(
config.headers['X-Requested-With'] = 'XMLHttpRequest' config.headers['X-Requested-With'] = 'XMLHttpRequest'
// 这里可以添加token等认证信息 // 这里可以添加token等认证信息
config.headers['Authorization'] = _header['Authorization'] config.headers['Authorization'] = _header['Authorization']
if(config.url.indexOf('/app/') == -1 && config.url.indexOf('/callComponent/') == -1){ if (config.url.indexOf('/app/') == -1 && config.url.indexOf('/callComponent/') == -1) {
config.baseURL = "/app" config.baseURL = "/app"
} }
// GET请求不显示加载动画其他请求显示
if (config.method !== 'get' && config.showLoading !== false) {
showLoading()
}
return config return config
}, },
error => { error => {
console.log(error) console.log(error)
// 请求错误时也要隐藏加载动画
hideLoading()
return Promise.reject(error) return Promise.reject(error)
} }
) )
@ -39,6 +66,9 @@ service.interceptors.request.use(
// 响应拦截器 // 响应拦截器
service.interceptors.response.use( service.interceptors.response.use(
response => { response => {
// 隐藏加载动画
hideLoading()
const res = response.data const res = response.data
if (res.code && res.code != 0) { if (res.code && res.code != 0) {
@ -47,7 +77,7 @@ service.interceptors.response.use(
type: 'error', type: 'error',
duration: 5 * 1000 duration: 5 * 1000
}) })
return Promise.reject(new Error(res.message || 'Error')) return Promise.reject()
} else { } else {
return response return response
} }
@ -55,6 +85,9 @@ service.interceptors.response.use(
error => { error => {
console.log(error) console.log(error)
// 隐藏加载动画
hideLoading()
// 判断是否为401未授权错误 // 判断是否为401未授权错误
if (error.response && error.response.status === 401) { if (error.response && error.response.status === 401) {
// 清除本地存储的token // 清除本地存储的token

View File

@ -80,9 +80,9 @@
@current-change="handleCurrentChange" /> @current-change="handleCurrentChange" />
</el-card> </el-card>
<!-- 组件 --> <!-- 组件 -->
<add-community ref="addCommunity" @listData="_queryCommunityMethod"/> <add-community ref="addCommunity" @listData="_queryCommunityMethod" />
<edit-community ref="editCommunity" @listData="_queryCommunityMethod"/> <edit-community ref="editCommunity" @listData="_queryCommunityMethod" />
<delete-community ref="deleteCommunity" @listData="_queryCommunityMethod"/> <delete-community ref="deleteCommunity" @listData="_queryCommunityMethod" />
<community-data-to-iot ref="communityDataToIot" /> <community-data-to-iot ref="communityDataToIot" />
</div> </div>
</template> </template>
@ -202,7 +202,7 @@ export default {
const { data } = await getAttrSpecList({ const { data } = await getAttrSpecList({
page: 1, page: 1,
row: 100, row: 100,
tableName:'building_community_attr' tableName: 'building_community_attr'
}) })
this.communityManageInfo.listColumns = [] this.communityManageInfo.listColumns = []
data.forEach(item => { data.forEach(item => {