Sfoglia il codice sorgente

请求失败,表格提示信息优化 -- “网络异常,请点击按钮刷新”

chenrui 3 anni fa
parent
commit
7c07172925
1 ha cambiato i file con 13 aggiunte e 3 eliminazioni
  1. 13 3
      src/components/Table/index.js

+ 13 - 3
src/components/Table/index.js

@@ -9,7 +9,8 @@ export default {
       selectedRowKeys: [],
       localLoading: false,
       localDataSource: [],
-      localPagination: Object.assign({}, this.pagination)
+      localPagination: Object.assign({}, this.pagination),
+      isSucceed: true //  是否请求成功
     }
   },
   props: Object.assign({}, T.props, {
@@ -123,7 +124,7 @@ export default {
     this.localPagination = ['auto', true].includes(this.showPagination) && Object.assign({}, this.localPagination, {
       current: localPageNum,
       pageSize: this.pageSize,
-      pageSizeOptions:['5','10', '20', '30', '40'],
+      pageSizeOptions: ['5', '10', '20', '30', '40'],
       showTotal: total => `共 ${total} 条记录`,
       showSizeChanger: this.showSizeChanger
     }) || false
@@ -183,8 +184,13 @@ export default {
       // eslint-disable-next-line
       if ((typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function') {
         result.then(r => {
-          const list = r.list || r.data || r
+          // const list = r.list || r.data || r
+          let list = []
+          if (r) {
+            list = r.list || r.data || r
+          }
           // console.log(r,'rrrrrrrrrr')
+          this.isSucceed = !!r
           this.localPagination = this.showPagination && Object.assign({}, this.localPagination, {
             current: r.pageNo, // 返回结果中的当前分页数
             total: Number(r.count), // 返回结果中的总记录数
@@ -329,6 +335,10 @@ export default {
       this[k] && (props[k] = this[k])
       return props[k]
     })
+    if (!this.isSucceed) { // 请求失败
+      props['locale'] = { emptyText: '网络异常,请点击按钮刷新' }
+    }
+    // isSucceed
     const table = (
       <a-table {...{ props, scopedSlots: { ...this.$scopedSlots } }} onChange={this.loadData}>
         { Object.keys(this.$slots).map(name => (<template slot={name}>{this.$slots[name]}</template>)) }