Commit 6db3ce8f33c06a0de97175168541946ec112dfc8

Authored by wuxw
1 parent 468b84d2

优化 post 显示动画

src/api/community/communityManageApi.js
@@ -30,7 +30,7 @@ export function listAreas(params) { @@ -30,7 +30,7 @@ export function listAreas(params) {
30 }).then(response => { 30 }).then(response => {
31 const res = response.data 31 const res = response.data
32 32
33 - resolve(res) 33 + resolve(res)
34 34
35 }).catch(error => { 35 }).catch(error => {
36 reject(error) 36 reject(error)
@@ -67,11 +67,8 @@ export function updateCommunity(data) { @@ -67,11 +67,8 @@ export function updateCommunity(data) {
67 data 67 data
68 }).then(response => { 68 }).then(response => {
69 const res = response.data 69 const res = response.data
70 - if (res.code === 0) {  
71 - resolve(res)  
72 - } else {  
73 - reject(new Error(res.msg || '更新小区失败'))  
74 - } 70 + resolve(res)
  71 +
75 }).catch(error => { 72 }).catch(error => {
76 reject(error) 73 reject(error)
77 }) 74 })
@@ -87,11 +84,8 @@ export function deleteCommunity(data) { @@ -87,11 +84,8 @@ export function deleteCommunity(data) {
87 data 84 data
88 }).then(response => { 85 }).then(response => {
89 const res = response.data 86 const res = response.data
90 - if (res.code === 0) {  
91 - resolve(res)  
92 - } else {  
93 - reject(new Error(res.msg || '删除小区失败'))  
94 - } 87 + resolve(res)
  88 +
95 }).catch(error => { 89 }).catch(error => {
96 reject(error) 90 reject(error)
97 }) 91 })
@@ -107,11 +101,8 @@ export function sendCommunityToIot(data) { @@ -107,11 +101,8 @@ export function sendCommunityToIot(data) {
107 data 101 data
108 }).then(response => { 102 }).then(response => {
109 const res = response.data 103 const res = response.data
110 - if (res.code === 0) {  
111 - resolve(res)  
112 - } else {  
113 - reject(new Error(res.msg || '同步到IOT失败'))  
114 - } 104 + resolve(res)
  105 +
115 }).catch(error => { 106 }).catch(error => {
116 reject(error) 107 reject(error)
117 }) 108 })
@@ -127,11 +118,9 @@ export function auditEnterCommunity(data) { @@ -127,11 +118,9 @@ export function auditEnterCommunity(data) {
127 data 118 data
128 }).then(response => { 119 }).then(response => {
129 const res = response.data 120 const res = response.data
130 - if (res.code === 0) {  
131 - resolve(res)  
132 - } else {  
133 - reject(new Error(res.msg || '撤回审核失败'))  
134 - } 121 +
  122 + resolve(res)
  123 +
135 }).catch(error => { 124 }).catch(error => {
136 reject(error) 125 reject(error)
137 }) 126 })
src/components/community/communityDataToIot.vue
1 <template> 1 <template>
2 - <el-dialog  
3 - :title="$t('communityDataToIot.title')"  
4 - :visible.sync="visible"  
5 - width="30%"  
6 - @close="closeCommunityDataToIotModel"  
7 - > 2 + <el-dialog :title="$t('communityDataToIot.title')" :visible.sync="visible" width="30%"
  3 + @close="closeCommunityDataToIotModel">
8 <div style="text-align: center"> 4 <div style="text-align: center">
9 <p>{{ $t('communityDataToIot.confirmText') }}</p> 5 <p>{{ $t('communityDataToIot.confirmText') }}</p>
10 </div> 6 </div>
src/utils/request.js
1 import axios from 'axios' 1 import axios from 'axios'
2 -import { Message } from 'element-ui' 2 +import { Message, Loading } from 'element-ui'
3 import config from '@/conf/config' 3 import config from '@/conf/config'
4 import { getHeader } from './header' 4 import { getHeader } from './header'
5 5
  6 +// 创建loading实例
  7 +let loadingInstance = null
  8 +
6 // 创建axios实例 9 // 创建axios实例
7 const service = axios.create({ 10 const service = axios.create({
8 baseURL: config.baseApi, // 基础URL 11 baseURL: config.baseApi, // 基础URL
9 timeout: config.apiTimeout // 请求超时时间 12 timeout: config.apiTimeout // 请求超时时间
10 }) 13 })
11 14
  15 +// 显示加载动画
  16 +const showLoading = () => {
  17 + loadingInstance = Loading.service({
  18 + lock: true,
  19 + text: '加载中...',
  20 + spinner: 'el-icon-loading',
  21 + background: 'rgba(0, 0, 0, 0.7)'
  22 + })
  23 +}
  24 +
  25 +// 隐藏加载动画
  26 +const hideLoading = () => {
  27 + if (loadingInstance) {
  28 + loadingInstance.close()
  29 + loadingInstance = null
  30 + }
  31 +}
12 32
13 // 请求拦截器 33 // 请求拦截器
14 service.interceptors.request.use( 34 service.interceptors.request.use(
@@ -19,19 +39,26 @@ service.interceptors.request.use( @@ -19,19 +39,26 @@ service.interceptors.request.use(
19 config.headers['Accept'] = 'application/json' 39 config.headers['Accept'] = 'application/json'
20 config.headers['app-id'] = _header['app-id'] 40 config.headers['app-id'] = _header['app-id']
21 config.headers['TRANSACTION-ID'] = _header['TRANSACTION-ID'] 41 config.headers['TRANSACTION-ID'] = _header['TRANSACTION-ID']
22 - config.headers['REQ-TIME'] = _header['REQ-TIME']  
23 - config.headers['SIGN'] = _header['SIGN']  
24 - config.headers['user-id'] = _header['user-id'] 42 + config.headers['REQ-TIME'] = _header['REQ-TIME']
  43 + config.headers['SIGN'] = _header['SIGN']
  44 + config.headers['user-id'] = _header['user-id']
25 config.headers['X-Requested-With'] = 'XMLHttpRequest' 45 config.headers['X-Requested-With'] = 'XMLHttpRequest'
26 // 这里可以添加token等认证信息 46 // 这里可以添加token等认证信息
27 config.headers['Authorization'] = _header['Authorization'] 47 config.headers['Authorization'] = _header['Authorization']
28 - if(config.url.indexOf('/app/') == -1 && config.url.indexOf('/callComponent/') == -1){ 48 + if (config.url.indexOf('/app/') == -1 && config.url.indexOf('/callComponent/') == -1) {
29 config.baseURL = "/app" 49 config.baseURL = "/app"
30 } 50 }
  51 + // GET请求不显示加载动画,其他请求显示
  52 + if (config.method !== 'get' && config.showLoading !== false) {
  53 + showLoading()
  54 + }
  55 +
31 return config 56 return config
32 }, 57 },
33 error => { 58 error => {
34 console.log(error) 59 console.log(error)
  60 + // 请求错误时也要隐藏加载动画
  61 + hideLoading()
35 return Promise.reject(error) 62 return Promise.reject(error)
36 } 63 }
37 ) 64 )
@@ -39,6 +66,9 @@ service.interceptors.request.use( @@ -39,6 +66,9 @@ service.interceptors.request.use(
39 // 响应拦截器 66 // 响应拦截器
40 service.interceptors.response.use( 67 service.interceptors.response.use(
41 response => { 68 response => {
  69 + // 隐藏加载动画
  70 + hideLoading()
  71 +
42 const res = response.data 72 const res = response.data
43 73
44 if (res.code && res.code != 0) { 74 if (res.code && res.code != 0) {
@@ -47,28 +77,31 @@ service.interceptors.response.use( @@ -47,28 +77,31 @@ service.interceptors.response.use(
47 type: 'error', 77 type: 'error',
48 duration: 5 * 1000 78 duration: 5 * 1000
49 }) 79 })
50 - return Promise.reject(new Error(res.message || 'Error')) 80 + return Promise.reject()
51 } else { 81 } else {
52 return response 82 return response
53 } 83 }
54 }, 84 },
55 error => { 85 error => {
56 console.log(error) 86 console.log(error)
57 - 87 +
  88 + // 隐藏加载动画
  89 + hideLoading()
  90 +
58 // 判断是否为401未授权错误 91 // 判断是否为401未授权错误
59 if (error.response && error.response.status === 401) { 92 if (error.response && error.response.status === 401) {
60 // 清除本地存储的token 93 // 清除本地存储的token
61 localStorage.removeItem('token') 94 localStorage.removeItem('token')
62 // 跳转到登录页面 95 // 跳转到登录页面
63 window.location.href = '/#/views/user/login' 96 window.location.href = '/#/views/user/login'
64 - 97 +
65 // Message({ 98 // Message({
66 // message: '登录已过期,请重新登录', 99 // message: '登录已过期,请重新登录',
67 // type: 'error', 100 // type: 'error',
68 // duration: 5 * 1000 101 // duration: 5 * 1000
69 // }) 102 // })
70 } 103 }
71 - 104 +
72 return Promise.reject(error) 105 return Promise.reject(error)
73 } 106 }
74 ) 107 )
src/views/community/communityManageList.vue
@@ -80,9 +80,9 @@ @@ -80,9 +80,9 @@
80 @current-change="handleCurrentChange" /> 80 @current-change="handleCurrentChange" />
81 </el-card> 81 </el-card>
82 <!-- 组件 --> 82 <!-- 组件 -->
83 - <add-community ref="addCommunity" @listData="_queryCommunityMethod"/>  
84 - <edit-community ref="editCommunity" @listData="_queryCommunityMethod"/>  
85 - <delete-community ref="deleteCommunity" @listData="_queryCommunityMethod"/> 83 + <add-community ref="addCommunity" @listData="_queryCommunityMethod" />
  84 + <edit-community ref="editCommunity" @listData="_queryCommunityMethod" />
  85 + <delete-community ref="deleteCommunity" @listData="_queryCommunityMethod" />
86 <community-data-to-iot ref="communityDataToIot" /> 86 <community-data-to-iot ref="communityDataToIot" />
87 </div> 87 </div>
88 </template> 88 </template>
@@ -202,7 +202,7 @@ export default { @@ -202,7 +202,7 @@ export default {
202 const { data } = await getAttrSpecList({ 202 const { data } = await getAttrSpecList({
203 page: 1, 203 page: 1,
204 row: 100, 204 row: 100,
205 - tableName:'building_community_attr' 205 + tableName: 'building_community_attr'
206 }) 206 })
207 this.communityManageInfo.listColumns = [] 207 this.communityManageInfo.listColumns = []
208 data.forEach(item => { 208 data.forEach(item => {