7dad9c87 by 任超

style:全局接口增加loading

1 parent 40b69927
...@@ -12,7 +12,8 @@ export function getQlxxDictList (data) { ...@@ -12,7 +12,8 @@ export function getQlxxDictList (data) {
12 return request({ 12 return request({
13 url: '/sys/dict/getQlxxDictList', 13 url: '/sys/dict/getQlxxDictList',
14 method: 'post', 14 method: 'post',
15 data 15 data,
16 showLoading: true
16 }) 17 })
17 } 18 }
18 /* 19 /*
...@@ -34,6 +35,7 @@ export function editDictNode (data) { ...@@ -34,6 +35,7 @@ export function editDictNode (data) {
34 return request({ 35 return request({
35 url: '/sys/dict/editDictNode', 36 url: '/sys/dict/editDictNode',
36 method: 'post', 37 method: 'post',
37 data 38 data,
39 showLoading: true
38 }) 40 })
39 } 41 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -7,7 +7,8 @@ export function getSysSqdjywBysearch (data) { ...@@ -7,7 +7,8 @@ export function getSysSqdjywBysearch (data) {
7 return request({ 7 return request({
8 url: '/system/sysSqdjyw/getSysSqdjywBysearch', 8 url: '/system/sysSqdjyw/getSysSqdjywBysearch',
9 method: 'post', 9 method: 'post',
10 data 10 data,
11 showLoading: true
11 }) 12 })
12 } 13 }
13 /* 14 /*
......
...@@ -31,6 +31,13 @@ ...@@ -31,6 +31,13 @@
31 margin-top: 8px; 31 margin-top: 8px;
32 @include flex-center; 32 @include flex-center;
33 } 33 }
34
35 .is-fullscreen {
36 position: absolute;
37 top: 50%;
38 left: 50%;
39 transform: translate(-50%, -50%) !important;
40 }
34 } 41 }
35 42
36 .dialog_title { 43 .dialog_title {
...@@ -82,10 +89,3 @@ ...@@ -82,10 +89,3 @@
82 left: 50%; 89 left: 50%;
83 transform: translate(-50%, -50%); 90 transform: translate(-50%, -50%);
84 } 91 }
...\ No newline at end of file ...\ No newline at end of file
85
86 .is-fullscreen {
87 position: absolute;
88 top: 50%;
89 left: 50%;
90 transform: translate(-50%, -50%) !important;
91 }
...\ No newline at end of file ...\ No newline at end of file
......
1 <template> 1 <template>
2 <el-dialog :visible.sync="dialogVisible" :width="width" v-loading="saveloding" :element-loading-text="loadingText" 2 <el-dialog :visible.sync="dialogVisible" :width="width" :fullscreen="fullscreen" top="0" :append-to-body="true"
3 element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" :fullscreen="fullscreen" 3 :lock-scroll="true" :close-on-click-modal="false" @close="closeDialog" :key="key"
4 top="0" :append-to-body="true" :lock-scroll="true" :close-on-click-modal="false" @close="closeDialog" :key="key"
5 :custom-class="isMain ? 'mainCenter dialogBox' : 'contentCenter dialogBox'" :destroy-on-close="true" ref="dialogBox" 4 :custom-class="isMain ? 'mainCenter dialogBox' : 'contentCenter dialogBox'" :destroy-on-close="true" ref="dialogBox"
6 id="dialogBox"> 5 id="dialogBox">
7 <div slot="title"> 6 <div slot="title">
......
...@@ -10,11 +10,10 @@ ...@@ -10,11 +10,10 @@
10 10
11 <template> 11 <template>
12 <div :class="['lb-table', customClass]"> 12 <div :class="['lb-table', customClass]">
13 <el-table v-if="!heightNumSetting" class="table-fixed" ref="elTable" :border='border' v-loading="loading" 13 <el-table v-if="!heightNumSetting" class="table-fixed" ref="elTable" :border='border'
14 element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" 14 :row-class-name="tableRowClassName" :show-header='showHeader' :header-cell-style="{ background: '#f5f7fa' }"
15 element-loading-background="rgba(0, 0, 0, 0.8)" :row-class-name="tableRowClassName" :show-header='showHeader' 15 v-bind="$attrs" :height="tableHeight" v-on="$listeners" :data="data" style="width: 100%"
16 :header-cell-style="{ background: '#f5f7fa' }" v-bind="$attrs" :height="tableHeight" v-on="$listeners" 16 :span-method="this.merge ? this.mergeMethod : this.spanMethod">
17 :data="data" style="width: 100%" :span-method="this.merge ? this.mergeMethod : this.spanMethod">
18 <lb-column v-bind="$attrs" v-for="(item, index) in column" :key="index" :column="item"> 17 <lb-column v-bind="$attrs" v-for="(item, index) in column" :key="index" :column="item">
19 </lb-column> 18 </lb-column>
20 </el-table> 19 </el-table>
...@@ -41,10 +40,6 @@ export default { ...@@ -41,10 +40,6 @@ export default {
41 column: Array, 40 column: Array,
42 data: Array, 41 data: Array,
43 spanMethod: Function, 42 spanMethod: Function,
44 loading: {
45 type: Boolean,
46 default: false,
47 },
48 pagination: { 43 pagination: {
49 type: Boolean, 44 type: Boolean,
50 default: true, 45 default: true,
......
1 /**
2 * 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器
3 */
1 import axios from 'axios' 4 import axios from 'axios'
2 import { MessageBox, Message } from 'element-ui' 5 import { Message } from 'element-ui'
3 import store from '@/store' 6 import { startLoadingAddCount, endLoadingSubCount } from './requestLoading'
4 import Cookies from 'js-cookie'; 7
5 const CONTENT_TYPE = "application/json";
6 // create an axios instance 8 // create an axios instance
7 const service = axios.create({ 9 const service = axios.create({
8 baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url 10 baseURL: process.env.VUE_APP_BASE_API,
9 // withCredentials: true, // send cookies when cross-domain requests 11 withCredentials: true, //是否允许跨域
10 headers: { 12 headers: {
11 "content-type": CONTENT_TYPE, 13 'Content-Type': 'application/json; charset=utf-8'
12 'Authorization':'bearer AT-16-oqkOHiUSsDdFA-eAZ49k2rJQDTzQpClO'
13 }, 14 },
14 timeout: 50000 // request timeout 15 timeout: 15000
15 }) 16 })
16 17
17 // request interceptor 18 // request interceptor
18 service.interceptors.request.use( 19 service.interceptors.request.use(
19 config => { 20 config => {
20 config.headers['token'] = Cookies.get('token') 21 if (config.showLoading) {
22 startLoadingAddCount(config.loadingTarget);
23 }
21 return config 24 return config
22 }, 25 },
23 error => { 26 error => {
24 console.log(error) // for debug 27 if (config.showLoading) {
28 endLoadingSubCount(config.loadingTarget);
29 }
30 Message.error('请求超时!');
25 return Promise.reject(error) 31 return Promise.reject(error)
26 } 32 }
27 ) 33 )
...@@ -29,83 +35,59 @@ service.interceptors.request.use( ...@@ -29,83 +35,59 @@ service.interceptors.request.use(
29 // response interceptor 35 // response interceptor
30 service.interceptors.response.use( 36 service.interceptors.response.use(
31 response => { 37 response => {
32 const res = response.data 38 if (response.config.showLoading) {
33 const { code } = res 39 endLoadingSubCount();
34 if (code === undefined) {
35 return res
36 } 40 }
37 // if the custom code is not 20000, it is judged as an error. 41 /**
38 if (code !== 200) { 42 * 对响应数据判断:
39 if (code === 600) { 43 * 如果成功返回数据,就通过return把数据返出去
40 Message({ 44 * 如果请求不成功,就在拦截器这里统一处理(组件的代码就不用关注错误的情况了)
41 message: res.message || 'Error', 45 */
42 type: 'error', 46 if (response.status == 200) {
43 duration: 5 * 1000 47 return response.data;
44 })
45 } else if (code === 402) {
46 MessageBox.confirm('登录已失效,可以取消继续留在该页面,或者重新登录', '确定登出', {
47 confirmButtonText: '重新登录',
48 cancelButtonText: '取消',
49 type: 'warning'
50 }).then(() => {
51 store.dispatch('user/resetToken').then(() => {
52 location.reload()// 为了重新实例化vue-router对象 避免bug
53 })
54 })
55 } else if (code === 401) {
56 store.dispatch('user/resetToken').then(() => {
57 location.reload()// 为了重新实例化vue-router对象 避免bug
58 })
59 } else if (code === 403) {
60 if (res.message == 'Bad credentials') {
61 Message({
62 message: '账号、密码输入有误',
63 type: 'error',
64 duration: 5 * 1000
65 })
66 } else { 48 } else {
67 Message({ 49 handleErrorData(response.data);
68 message: res.message,
69 type: 'error',
70 duration: 5 * 1000
71 })
72 }
73
74 } 50 }
75 else { 51 return response;
76 Message({
77 message: '服务器异常,请联系管理员',
78 type: 'error',
79 duration: 5 * 1000
80 })
81 }
82 // 401:未登录;
83 return Promise.reject('error')
84 } else {
85 return res
86 }
87
88 }, 52 },
89 error => { 53 error => {
90 let str = '600'; //新增了token 返回状态码为600 54 // 对响应错误做点什么
91 if (error.toString().indexOf(str) !== -1) {
92 MessageBox.confirm('登录已失效,可以取消继续留在该页面,或者重新登录', '确定登出', {
93 confirmButtonText: '重新登录',
94 cancelButtonText: '取消',
95 type: 'warning'
96 }).then(() => {
97 store.dispatch('user/resetToken').then(() => {
98 location.reload()// 为了重新实例化vue-router对象 避免bug
99 })
100 })
101 } else {
102 Message({ 55 Message({
103 message: '服务器异常,请联系管理员', 56 message: '服务器异常,请联系管理员',
104 type: 'error', 57 type: 'error',
105 duration: 5 * 1000 58 duration: 5 * 1000
106 }) 59 })
107 } 60 endLoadingSubCount();
108 return Promise.reject(error) 61 return Promise.reject(error);
109 } 62 }
110 ) 63 )
64 //对错误信息的处理函数
65 function handleErrorData (errMes) {
66 if (errMes.message) {
67 Message.error(errMes.message);
68 } else {
69 switch (errMes.code) {
70 case 401:
71 Message.error("未授权,请重新登录!");
72 break;
73 case 403:
74 Message.error("拒绝访问");
75 break;
76 case 404:
77 Message.error("很抱歉,资源未找到!");
78 break;
79 case 500:
80 Message.error("服务器错误!");
81 break;
82 case 504:
83 Message.error("网络超时!");
84 break;
85 default:
86 Message.error("服务正在联调中,请稍后!");
87 break;
88 }
89 }
90 }
91
111 export default service 92 export default service
93
......
1 import { Loading } from 'element-ui'
2 // 定义 loading
3 let loading
4
5 // loading开始 方法
6 function startLoading (LoadingText = '拼命加载中...') {
7 // element-ui loading 服务调用方式
8 loading = Loading.service({
9 text: LoadingText,
10 spinner: 'el-icon-loading', // 自定义图标
11 background: 'rgba(0, 0, 0, 0.8)'
12 })
13 }
14
15 // loading结束 方法
16 function endLoading () {
17 loading.close()
18 }
19 // 定义一个变量,有请求变量加一,收到响应变量减一
20 let loadingCount = 0
21
22 /**
23 * 调用一次startLoadingAddCount() 方法 开启Loading 并 loadingCount + 1
24 * 调用一次endLoadingSubCount() 方法 loadingCount - 1 直到为0 关闭loading
25 */
26 export function startLoadingAddCount (LoadingText) {
27 if (loadingCount === 0) {
28 startLoading(LoadingText)
29 }
30 loadingCount++
31 }
32
33 export function endLoadingSubCount () {
34 loadingCount--
35 if (loadingCount === 0) {
36 endLoading()
37 }
38 }
...\ No newline at end of file ...\ No newline at end of file
1 <template> 1 <template>
2 <!-- 编辑 --> 2 <!-- 编辑 -->
3 <dialogBox submitForm="submitForm" @closeDialog="closeDialog" @submitForm="handleSubmit" width="80%" v-model="myValue" 3 <dialogBox submitForm="submitForm" @closeDialog="closeDialog" @submitForm="handleSubmit" width="80%" v-model="myValue"
4 :isSave="details.isenable == 1" title="字典信息" :saveloding="saveloding"> 4 :isSave="details.isenable == 1" title="字典信息">
5 <el-form :model="ruleForm" ref="ruleForm" label-width="120px"> 5 <el-form :model="ruleForm" ref="ruleForm" label-width="120px">
6 <el-row :gutter="20"> 6 <el-row :gutter="20">
7 <el-col :span="6"> 7 <el-col :span="6">
...@@ -170,8 +170,7 @@ export default { ...@@ -170,8 +170,7 @@ export default {
170 } 170 }
171 } 171 }
172 ], 172 ],
173 tableData: [], 173 tableData: []
174 saveloding: false
175 } 174 }
176 }, 175 },
177 watch: { 176 watch: {
...@@ -220,14 +219,12 @@ export default { ...@@ -220,14 +219,12 @@ export default {
220 removeTreeListItem(this.tableData, row.bsmDict) 219 removeTreeListItem(this.tableData, row.bsmDict)
221 }, 220 },
222 handleSubmit () { 221 handleSubmit () {
223 this.saveloding = true
224 editDictNode({ 222 editDictNode({
225 bsmDict: this.details.rowData.bsmDict, 223 bsmDict: this.details.rowData.bsmDict,
226 typeid: this.details.rowData.typeid, 224 typeid: this.details.rowData.typeid,
227 children: this.tableData 225 children: this.tableData
228 }).then(res => { 226 }).then(res => {
229 if (res.code === 200) { 227 if (res.code === 200) {
230 this.saveloding = false
231 this.$emit('input', false) 228 this.$emit('input', false)
232 } 229 }
233 }) 230 })
......
...@@ -25,9 +25,9 @@ ...@@ -25,9 +25,9 @@
25 </div> 25 </div>
26 <!-- 表格 --> 26 <!-- 表格 -->
27 <div class="from-clues-content"> 27 <div class="from-clues-content">
28 <lb-table :page-size="pageData.pageSize" :loading="loading" :current-page.sync="pageData.currentPage" 28 <lb-table :page-size="pageData.pageSize" :current-page.sync="pageData.currentPage" :total="tableData.total"
29 :total="tableData.total" @size-change="handleSizeChange" @p-current-change="handleCurrentChange" 29 @size-change="handleSizeChange" @p-current-change="handleCurrentChange" :column="tableData.columns"
30 :column="tableData.columns" :data="tableData.data"> 30 :data="tableData.data">
31 </lb-table> 31 </lb-table>
32 </div> 32 </div>
33 <editDialog v-model="isDialog" :details="details" /> 33 <editDialog v-model="isDialog" :details="details" />
...@@ -49,7 +49,6 @@ export default { ...@@ -49,7 +49,6 @@ export default {
49 }, 49 },
50 data () { 50 data () {
51 return { 51 return {
52 loading: false,
53 isDialog: false, 52 isDialog: false,
54 details: { 53 details: {
55 dataList: [], 54 dataList: [],
...@@ -70,9 +69,7 @@ export default { ...@@ -70,9 +69,7 @@ export default {
70 methods: { 69 methods: {
71 // 初始化数据 70 // 初始化数据
72 fetchData () { 71 fetchData () {
73 this.loading = true
74 getQlxxDictList({ ...this.ruleForm, ...this.pageData }).then(res => { 72 getQlxxDictList({ ...this.ruleForm, ...this.pageData }).then(res => {
75 this.loading = false
76 let { records, total } = res.result 73 let { records, total } = res.result
77 this.tableData.data = records 74 this.tableData.data = records
78 this.tableData.total = total 75 this.tableData.total = total
......
...@@ -207,6 +207,8 @@ export default { ...@@ -207,6 +207,8 @@ export default {
207 that.$emit('input', false) 207 that.$emit('input', false)
208 }, 500) 208 }, 500)
209 } 209 }
210 }).catch(error => {
211 that.saveloding = false
210 }) 212 })
211 }, 213 },
212 closeDialog () { 214 closeDialog () {
......
...@@ -73,6 +73,8 @@ export default { ...@@ -73,6 +73,8 @@ export default {
73 let { records, total } = res.result 73 let { records, total } = res.result
74 this.tableData.data = records 74 this.tableData.data = records
75 this.tableData.total = total 75 this.tableData.total = total
76 }).catch(error => {
77 this.loading = false
76 }) 78 })
77 }, 79 },
78 editClick (row) { 80 editClick (row) {
......
...@@ -81,8 +81,8 @@ export default { ...@@ -81,8 +81,8 @@ export default {
81 }, 81 },
82 methods: { 82 methods: {
83 handleSelect (item) { 83 handleSelect (item) {
84 if (!item.checked) { 84 if (item.checked) {
85 item.radio = 0 85 item.selected = '0'
86 } 86 }
87 }, 87 },
88 handleSelectall () { 88 handleSelectall () {
......
1 <template> 1 <template>
2 <dialogBox title="申请业务规则配置" @submitForm="submitForm" @closeDialog="closeDialog" v-model="myValue" 2 <dialogBox title="申请业务规则配置" @submitForm="submitForm" @closeDialog="closeDialog" v-model="myValue">
3 :saveloding="saveloding">
4 <ul class="edit-title-list" v-if="titleList.length > 0"> 3 <ul class="edit-title-list" v-if="titleList.length > 0">
5 <li v-for="(item, index) in titleList" @click="handleTitleSelct(item, index)" :key="index" 4 <li v-for="(item, index) in titleList" @click="handleTitleSelct(item, index)" :key="index"
6 :class="{ active: index == tn }">{{ 5 :class="{ active: index == tn }">{{
...@@ -157,7 +156,6 @@ export default { ...@@ -157,7 +156,6 @@ export default {
157 data () { 156 data () {
158 return { 157 return {
159 myValue: this.value, 158 myValue: this.value,
160 saveloding: false,
161 tn: 0, 159 tn: 0,
162 titleList: [], 160 titleList: [],
163 imgUploadUrl: fileController.uploadUrl(), 161 imgUploadUrl: fileController.uploadUrl(),
...@@ -244,10 +242,8 @@ export default { ...@@ -244,10 +242,8 @@ export default {
244 this.$refs['ruleForm'].validate(async (valid) => { 242 this.$refs['ruleForm'].validate(async (valid) => {
245 let that = this 243 let that = this
246 if (valid) { 244 if (valid) {
247 that.saveloding = true
248 this.subData.ywDetail = this.ruleForm 245 this.subData.ywDetail = this.ruleForm
249 saveSqdjyw(this.subData).then(res => { 246 saveSqdjyw(this.subData).then(res => {
250 that.saveloding = false
251 that.$emit('input', false) 247 that.$emit('input', false)
252 }) 248 })
253 } else { 249 } else {
......
...@@ -28,9 +28,9 @@ ...@@ -28,9 +28,9 @@
28 </div> 28 </div>
29 <!-- 表格 --> 29 <!-- 表格 -->
30 <div class="from-clues-content"> 30 <div class="from-clues-content">
31 <lb-table :page-size="pageData.pageSize" :loading="loading" :current-page.sync="pageData.currentPage" 31 <lb-table :page-size="pageData.pageSize" :current-page.sync="pageData.currentPage" :total="tableData.total"
32 :total="tableData.total" @size-change="handleSizeChange" @p-current-change="handleCurrentChange" 32 @size-change="handleSizeChange" @p-current-change="handleCurrentChange" :column="tableData.columns"
33 :column="tableData.columns" :data="tableData.data"> 33 :data="tableData.data">
34 </lb-table> 34 </lb-table>
35 </div> 35 </div>
36 <editDialog v-model="isDialog" :detailList="detailList" /> 36 <editDialog v-model="isDialog" :detailList="detailList" />
...@@ -52,7 +52,6 @@ export default { ...@@ -52,7 +52,6 @@ export default {
52 }, 52 },
53 data () { 53 data () {
54 return { 54 return {
55 loading: false,
56 isDialog: false, 55 isDialog: false,
57 queryForm: { 56 queryForm: {
58 qllx: "", 57 qllx: "",
...@@ -74,10 +73,8 @@ export default { ...@@ -74,10 +73,8 @@ export default {
74 }, 73 },
75 // 初始化数据 74 // 初始化数据
76 fetchData () { 75 fetchData () {
77 this.loading = true
78 getSysSqdjywBysearch({ ...this.queryForm, ...this.pageData }).then(res => { 76 getSysSqdjywBysearch({ ...this.queryForm, ...this.pageData }).then(res => {
79 if (res.code === 200) { 77 if (res.code === 200) {
80 this.loading = false
81 let { total, records } = res.result 78 let { total, records } = res.result
82 this.tableData.total = total 79 this.tableData.total = total
83 this.tableData.data = records 80 this.tableData.data = records
......