From c1d2051abc8ca88cd07f0d7c56c0dbf8165d5c33 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期四, 18 九月 2025 17:02:22 +0800 Subject: [PATCH] 2025.9.18 数据产品(待完成) --- src/components/table/FYTable.vue | 151 +++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 125 insertions(+), 26 deletions(-) diff --git a/src/components/table/FYTable.vue b/src/components/table/FYTable.vue index c519077..a85de22 100644 --- a/src/components/table/FYTable.vue +++ b/src/components/table/FYTable.vue @@ -1,23 +1,49 @@ <template> <el-row ref="searchRef"> <FYSearchBar @search="onSearch"> - <template #options> + <template #options v-if="$slots.options"> <slot name="options"></slot> + </template> + <template #buttons v-if="$slots.buttons"> + <slot name="buttons"></slot> </template> </FYSearchBar> </el-row> - <el-row ref="expandRef"> - <slot name="options-expand"></slot> + <el-row ref="expandRef" justify="space-between"> + <el-col span="22"> + <slot name="options-expand"></slot> + </el-col> + <el-col span="2"> + <el-space :wrap="false"> + <el-text size="small">瀛椾綋</el-text> + <el-radio-group v-model="fontSize" size="small"> + <el-radio-button value="small">灏�</el-radio-button> + <el-radio-button value="default">涓�</el-radio-button> + <el-radio-button value="large">澶�</el-radio-button> + </el-radio-group> + </el-space> + </el-col> </el-row> + <div ref="expand2Ref"> + <slot name="options-expand2"></slot> + </div> <el-table + v-bind="$attrs" + ref="tableRef" :data="tableData" v-loading="loading" table-layout="fixed" :row-class-name="tableRowClassName" :height="tableHeight" + :size="fontSize" + @cell-click="cellClick" + :cell-class-name="cellClassName" + @paste="handlePaste" + @sort-change="handleSortChange" + :show-overflow-tooltip="true" border > - <slot name="table-column"></slot> + <slot name="table-column" :size="fontSize"></slot> </el-table> <el-pagination @@ -43,11 +69,31 @@ * 浣跨敤鏃堕渶瑕佸湪<slot #options>涓坊鍔犺嚜瀹氫箟鏌ヨ閫夐」锛屽湪<slot #table-column>涓坊鍔犺嚜瀹氫箟琛ㄦ牸鍒楋紝鍚屾椂瀹炵幇瑙﹀彂鍑芥暟search */ export default { + inject: ['contentMaxHeight'], props: { rowClassName: undefined, + cellClassName: Function || String, pagination: { type: Boolean, default: true + }, + // '' | 'small' | 'default' | 'large' + size: { + type: String, + default: 'default' + }, + data: { + type: Array, + default: () => [] + }, + totalCount: { + type: Number, + default: 0 + }, + // 棰濆鐨勯珮搴︼紝鐢ㄤ簬璁$畻琛ㄦ牸楂樺害 + extraHeight: { + type: Number, + default: 0 } }, data() { @@ -57,22 +103,49 @@ total: 0, currentPage: 1, pageSize: 20, - loading: false - } + loading: false, + fontSize: 'default' + }; }, - emits: ['search'], + emits: ['search', 'cellClick', 'tablePaste', 'sortChange'], watch: { currentPage(nValue, oValue) { if (nValue != oValue) { - this.onSearch() + this.onSearch(); } }, pageSize(nValue, oValue) { if (nValue != oValue) { - this.onSearch() + this.onSearch(); } + }, + size: { + handler(nValue, oValue) { + if (nValue != oValue) { + this.fontSize = nValue; + } + }, + immediate: true + }, + data(nValue, oValue) { + if (nValue != oValue) { + this.tableData = nValue; + } + }, + totalCount(nValue, oValue) { + if (nValue != oValue) { + this.total = nValue; + } + }, + extraHeight: { + handler(nValue, oValue) { + if (nValue != oValue) { + this.tableHeight = this.calcTableHeight(); + } + }, } }, + computed: {}, methods: { /** * 琛ㄦ牸鏁版嵁鏌ヨ锛屼紶閫掍袱缁勫弬鏁帮紝鍒嗛〉淇℃伅鍜屽洖璋冨嚱鏁� @@ -80,7 +153,7 @@ * 鍥炶皟鍑芥暟鎺ユ敹涓�涓璞★紝鍖呮嫭琛ㄦ牸鏁版嵁鏁扮粍data鍜屾暟鎹�绘暟total */ onSearch() { - this.loading = true + this.loading = true; this.$emit( 'search', { @@ -88,37 +161,63 @@ pageSize: this.pageSize }, (res) => { - this.tableData = res.data - this.total = res.total ? res.total : 0 - this.loading = false + if (res) { + if (res.data) { + this.tableData = res.data; + } + if (res.total) { + this.total = res.total; + } + } + this.loading = false; + this.doLayout(); } - ) + ); }, calcTableHeight() { - const h1 = this.$refs.searchRef.$el.offsetHeight - const h2 = this.$refs.paginationRef ? this.$refs.paginationRef.$el.offsetHeight : 0 - const h3 = this.$refs.expandRef.$el.offsetHeight - const h = h1 + h2 + h3 - // return `calc(100vh - ${h1}px - ${h2}px - var(--el-main-padding) * 2 - var(--el-header-height))`; - return `calc(100vh - ${h}px - 60px - var(--el-main-padding) * 2)` + const h1 = this.$refs.searchRef.$el.offsetHeight; + const h2 = this.$refs.paginationRef + ? this.$refs.paginationRef.$el.offsetHeight + : 0; + const h3 = this.$refs.expandRef.$el.offsetHeight; + const h4 = this.$refs.expand2Ref.offsetHeight; + + const h = h1 + h2 + h3 + h4 + this.extraHeight; + return this.contentMaxHeight.value - h + 'px'; + // return `calc(100vh - ${h}px - 60px - var(--el-main-padding) * 2)`; }, tableRowClassName({ row }) { if (this.rowClassName) { if (typeof this.rowClassName == 'string') { - return this.rowClassName + return this.rowClassName; } else if (typeof this.rowClassName == 'function') { - return this.rowClassName({ row }) + return this.rowClassName({ row }); } } else { - return row.extension1 != '0' ? 'online-row' : 'offline-row' + return row.extension1 != '0' ? 'online-row' : 'offline-row'; } + }, + cellClick(row, column, cell, event) { + this.$emit('cellClick', row, column, cell, event); + }, + handlePaste(event) { + this.$emit('tablePaste', event); + }, + doLayout() { + this.$refs.tableRef.doLayout(); + }, + handleSortChange({ column, prop, order }) { + this.$emit('sortChange', { column, prop, order }); + }, + clearSort() { + this.$refs.tableRef.clearSort(); } }, mounted() { - this.tableHeight = this.calcTableHeight() - this.onSearch() + this.tableHeight = this.calcTableHeight(); + this.onSearch(); } -} +}; </script> <style> -- Gitblit v1.9.3