You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

info-table.vue 4.6 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /** Copyright 2020 Tianshu AI Platform. All Rights Reserved.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. * =============================================================
  15. */
  16. <template>
  17. <div class="info-data-table">
  18. <el-table
  19. ref="table"
  20. v-loading="state.loading"
  21. highlight-current-row
  22. v-bind="tableAttrs"
  23. :data="state.list"
  24. >
  25. <InfoTableColumn
  26. v-for="col in columns"
  27. :key="col.prop"
  28. :refresh="refresh"
  29. :setPageInfo="setPageInfo"
  30. v-bind="col"
  31. />
  32. <slot />
  33. </el-table>
  34. <el-pagination
  35. v-if="showPagination"
  36. :style="`text-align:${align};margin-top: 8px;`"
  37. layout="total, prev, pager, next, sizes"
  38. v-bind="pageAttrs"
  39. :page-size="pageInfo.pageSize"
  40. :total="pageInfo.total"
  41. :current-page="pageInfo.current"
  42. @size-change="sizeChange"
  43. @current-change="pageChange"
  44. />
  45. </div>
  46. </template>
  47. <script>
  48. import { onMounted, reactive, watch } from '@vue/composition-api';
  49. import InfoTableColumn from './column';
  50. export default {
  51. name: 'InfoTable',
  52. components: {
  53. InfoTableColumn,
  54. },
  55. props: {
  56. request: Function,
  57. params: {
  58. type: Object,
  59. default: () => ({}),
  60. },
  61. columns: {
  62. type: Array,
  63. default: () => [],
  64. },
  65. pagination: {
  66. type: Object,
  67. default: () => ({
  68. pageSizes: [10, 20, 50],
  69. }),
  70. },
  71. tableAttrs: {
  72. type: Object,
  73. default: () => ({}),
  74. },
  75. align: {
  76. type: String,
  77. default: 'center',
  78. },
  79. showPagination: {
  80. type: Boolean,
  81. default: true,
  82. },
  83. dataSource: Array,
  84. actionRef: Function,
  85. },
  86. setup(props) {
  87. const { request, pagination = {}, actionRef } = props;
  88. const state = reactive({
  89. list: [],
  90. loading: false,
  91. });
  92. const pageAttrs = {
  93. ...pagination,
  94. };
  95. const pageInfo = reactive({
  96. current: pagination.current || 1,
  97. total: 0,
  98. pageSize: pagination.pageSize || 10,
  99. });
  100. // 更新分页信息
  101. const setPageInfo = (info = {}) => {
  102. Object.assign(pageInfo, info);
  103. };
  104. // 更新数据
  105. const setData = (data) => {
  106. Object.assign(state, {
  107. list: data,
  108. });
  109. };
  110. // 更新分页信息
  111. const setLoading = (loading) => {
  112. Object.assign(state, {
  113. loading,
  114. });
  115. };
  116. const sizeChange = (size) => {
  117. setPageInfo({
  118. pageSize: size,
  119. });
  120. };
  121. const pageChange = (current) => {
  122. setPageInfo({
  123. current,
  124. });
  125. };
  126. const queryList = async(cfg = {}) => {
  127. if (state.loading) {
  128. return;
  129. }
  130. setLoading(true);
  131. const { pageSize, current } = pageInfo;
  132. try {
  133. const res = await request({
  134. current,
  135. size: pageSize,
  136. ...props.params,
  137. ...cfg,
  138. });
  139. // 这边按照统一的 result, page 来进行管理
  140. const { result = [], page = {}} = res || {};
  141. setPageInfo({ total: page.total });
  142. setData(result);
  143. } finally {
  144. setLoading(false);
  145. }
  146. };
  147. onMounted(() => {
  148. // 首先判断是否为异步请求
  149. if(typeof request === 'function') {
  150. queryList();
  151. if (typeof actionRef === 'function') {
  152. actionRef().value = {
  153. refresh: queryList,
  154. };
  155. }
  156. } else if(Array.isArray(props.dataSource)) {
  157. // 检测是否为静态数据源
  158. setData(props.dataSource);
  159. }
  160. });
  161. watch(() => pageInfo.pageSize, () => {
  162. setPageInfo({ ...pageInfo, current: 1 });
  163. queryList();
  164. }, {
  165. lazy: true,
  166. });
  167. watch(() => props.dataSource, (next) => {
  168. setData(next);
  169. }, {
  170. lazy: true,
  171. });
  172. watch(() => pageInfo.current, () => {
  173. queryList();
  174. }, {
  175. lazy: true,
  176. });
  177. return {
  178. state,
  179. pageAttrs,
  180. pageInfo,
  181. refresh: queryList,
  182. setPageInfo: info =>
  183. setPageInfo({
  184. ...pageInfo,
  185. ...info,
  186. }),
  187. sizeChange,
  188. pageChange,
  189. };
  190. },
  191. };
  192. </script>

一站式算法开发平台、高性能分布式深度学习框架、先进算法模型库、视觉模型炼知平台、数据可视化分析平台等一系列平台及工具,在模型高效分布式训练、数据处理和可视分析、模型炼知和轻量化等技术上形成独特优势,目前已在产学研等各领域近千家单位及个人提供AI应用赋能

Contributors (1)