|
@@ -11,37 +11,19 @@
|
|
|
<template v-if="tableData.length || tableCols.length">
|
|
|
<div style="height: calc(100% - 40px);">
|
|
|
<el-table v-el-table-infinite-scroll="load" :data="filteredTableData" :summary-method="getSummaries" :span-method="tableSpanMethod" stripe :show-summary="showSummary" border @cell-click="cellClick" :cell-class-name="cellClass" ref="table" :height="tableHeight ? tableHeight : minHeight - 8 + 'vh'" class="table infinite-list" style=" overflow: auto" :style="{width: tableWidth ? tableWidth : '100%'}" @select="selectHandler">
|
|
|
- <el-table-column v-for="(item, index) in tableColsCopy" :sortable="item.needSort ? true : false" :key="index" :prop="item.columnName" :label="item.columnLabel" :show-overflow-tooltip="showOverflowTooltip" :formatter="formatter">
|
|
|
+ <el-table-column v-for="(item, index) in tableColsCopy" :key="index" :prop="item.columnName" :label="item.columnLabel" :show-overflow-tooltip="showOverflowTooltip" :formatter="formatter">
|
|
|
<template #header>
|
|
|
- <span class="colTips">
|
|
|
- <el-tooltip :content="item.columnDescribe" placement="top">
|
|
|
- <span>{{ item.columnLabel }}</span>
|
|
|
- </el-tooltip>
|
|
|
- </span>
|
|
|
- <span v-if="item.needFilters">
|
|
|
- <el-popover placement="bottom" trigger="click" @show="popoverShowHandler(item.columnName)" @hide="popoverHideHandler">
|
|
|
- <i slot="reference" :class="[
|
|
|
- 'filter-arrow',
|
|
|
- 'el-icon-arrow-down',
|
|
|
- arrowClass(item.columnName),
|
|
|
- ]" />
|
|
|
- <el-form>
|
|
|
- <el-form-item :label="item.columnLabel">
|
|
|
- <el-select v-model="filterValues[item.columnName]" size="small" placeholder="筛选" default-first-option filterable clearable>
|
|
|
- <el-option v-for="(option, optionIndex) in tableDataFilters[
|
|
|
- item.columnName
|
|
|
- ]" :key="option.value + optionIndex" :value="option.value" :label="option.text" />
|
|
|
- </el-select>
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
- </el-popover>
|
|
|
- </span>
|
|
|
+ <el-tooltip :content="item.columnDescribe || item.columnLabel" placement="top">
|
|
|
+ <TableHeaderCell :label="item.columnLabel" :filter-options="tableDataFilters[item.columnName]" :filter-values.sync="filterValues[item.columnName]" :sortable="item.needSort" :sort-rule.sync="tableDataSortRules[item.columnName]" />
|
|
|
+ </el-tooltip>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
<el-table-column v-if="authBtns.length" fixed="right" label="操作" :width="fixedWidth">
|
|
|
<template slot-scope="scope">
|
|
|
<div class="hd-td">
|
|
|
- <auth-button v-for="(item,index) in authBtns" :key="index" :auth="item" :row="scope.row" />
|
|
|
+ <el-scrollbar style="height: 100%">
|
|
|
+ <auth-button v-for="(item,index) in authBtns" :key="index" :auth="item" :row="scope.row" />
|
|
|
+ </el-scrollbar>
|
|
|
</div>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
@@ -136,6 +118,7 @@ import AuthButton from './components/authButton.vue';
|
|
|
import { translateDataToTreeAllTreeMsg, getAuthData } from "@/utils/validate";
|
|
|
import { Query, newData, modifyData, moveData, abnormalDataRecovery } from "@/api/webApi";
|
|
|
import { getToken } from '@/utils/auth';
|
|
|
+import TableHeaderCell from '@/components/TableHeaderCell/index.vue';
|
|
|
export default {
|
|
|
name: "DataTable",
|
|
|
props: {
|
|
@@ -187,7 +170,7 @@ export default {
|
|
|
default: "180px",
|
|
|
},
|
|
|
},
|
|
|
- components: { Dialog, NoData, AdvanceQuery, AuthButton },
|
|
|
+ components: { Dialog, NoData, AdvanceQuery, AuthButton, TableHeaderCell },
|
|
|
data () {
|
|
|
return {
|
|
|
pageTitle: '',
|
|
@@ -236,7 +219,8 @@ export default {
|
|
|
authBtnCol: [],
|
|
|
authBtnColName: [],
|
|
|
urlParams: {},
|
|
|
- authId: ''
|
|
|
+ authId: '',
|
|
|
+ tableDataSortRules: {},
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
@@ -278,22 +262,27 @@ export default {
|
|
|
|
|
|
//设置表头-下拉-选中数据
|
|
|
filteredTableData () {
|
|
|
- if (this.isTree) {
|
|
|
- this.tableData = translateDataToTreeAllTreeMsg(
|
|
|
- this.tableData,
|
|
|
- "parentID",
|
|
|
- "companyID"
|
|
|
- );
|
|
|
- }
|
|
|
- return this.tableData.filter((item) => {
|
|
|
- let flag = true;
|
|
|
- Object.entries(this.filterValues).forEach(([key, value]) => {
|
|
|
- if (value !== "" && item[key] !== value) {
|
|
|
- flag = false;
|
|
|
+ const filtered = this.tableData.filter(item => {
|
|
|
+ let flag = true
|
|
|
+ Object.entries(this.filterValues).forEach(([key, arr]) => {
|
|
|
+ if (arr.length && !arr.includes(String(item[key]))) {
|
|
|
+ flag = false
|
|
|
}
|
|
|
- });
|
|
|
- return flag;
|
|
|
- });
|
|
|
+ })
|
|
|
+ return flag
|
|
|
+ })
|
|
|
+ const sortRules = Object.entries(this.tableDataSortRules).reduce(
|
|
|
+ (pre, [key, value]) => {
|
|
|
+ if (value) {
|
|
|
+ pre[0].push(key)
|
|
|
+ value = value === 'ascending' ? 'asc' : 'desc'
|
|
|
+ pre[1].push(value)
|
|
|
+ }
|
|
|
+ return pre
|
|
|
+ },
|
|
|
+ [[], []]
|
|
|
+ )
|
|
|
+ return this._.orderBy(filtered, sortRules[0], sortRules[1])
|
|
|
},
|
|
|
},
|
|
|
mounted () {
|
|
@@ -366,6 +355,7 @@ export default {
|
|
|
}
|
|
|
this.$store.dispatch('auth/changeAuthMsg', returnData)
|
|
|
this.tableCols = returnData;
|
|
|
+ this.setTableCols();
|
|
|
if (Object.keys(this.urlParams).length) {
|
|
|
this.getQuery(this.queryId, this.urlParams);
|
|
|
} else {
|
|
@@ -379,6 +369,17 @@ export default {
|
|
|
console.log(error)
|
|
|
}
|
|
|
},
|
|
|
+ setTableCols () {
|
|
|
+ this.tableCols.forEach(({ columnName, needFilters, needSort }) => {
|
|
|
+ if (needFilters) {
|
|
|
+ this.$set(this.tableDataFilters, columnName, [])
|
|
|
+ this.$set(this.filterValues, columnName, [])
|
|
|
+ }
|
|
|
+ if (needSort) {
|
|
|
+ this.$set(this.tableDataSortRules, columnName, '')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
autoBtnObj (item) {
|
|
|
switch (item.service_type) {
|
|
|
case '1':
|
|
@@ -616,88 +617,37 @@ export default {
|
|
|
const datas = _.cloneDeep(this.tableColsCopy);
|
|
|
// const reqUts = [];
|
|
|
datas.forEach(async (item) => {
|
|
|
- this.tableDataFilters[item.columnName] = [];
|
|
|
if (item.needGroup) {
|
|
|
this.tableGroups.push(item.columnName);
|
|
|
}
|
|
|
- if (item.listqueryTemplateID || item.listqueryTemplateID == 0) {
|
|
|
- this.tableArrs.push(item.columnName);
|
|
|
- // const reqUt = this.getSelectData(item.listqueryTemplateID)
|
|
|
- // reqUts.push(reqUt)
|
|
|
- // if (!this.tableOptions[item.columnName]) {
|
|
|
- // //开始位置beginPosition 结束位置endPosition (区分开始结束位置必须传null)
|
|
|
- // if (
|
|
|
- // item.columnName !== "beginPosition" &&
|
|
|
- // item.columnName !== "endPosition"
|
|
|
- // ) {
|
|
|
- // this.tableOptions[item.columnName] = await this.getSelectData(
|
|
|
- // item.listqueryTemplateID
|
|
|
- // );
|
|
|
- // } else {
|
|
|
- // this.tableOptions[item.columnName] = await this.getSelectData(
|
|
|
- // item.listqueryTemplateID,
|
|
|
- // null
|
|
|
- // );
|
|
|
- // this.tabledatacopy[item.columnName] = _.cloneDeep(
|
|
|
- // this.tableOptions[item.columnName]
|
|
|
- // );
|
|
|
- // }
|
|
|
- // } else {
|
|
|
- // if (
|
|
|
- // item.columnName === "beginPosition" ||
|
|
|
- // item.columnName === "endPosition"
|
|
|
- // ) {
|
|
|
- // this.tableOptions[item.columnName] = await this.getSelectData(
|
|
|
- // item.listqueryTemplateID,
|
|
|
- // null
|
|
|
- // );
|
|
|
- // }
|
|
|
- // }
|
|
|
- //
|
|
|
- }
|
|
|
- // this.filterValues[item.columnName] = ''
|
|
|
});
|
|
|
- setTableFilters(this.tableData, this.tableDataFilters);
|
|
|
- this.tableGroup(this.tableData);
|
|
|
+ const dats = this.setTableFilters(this.tableData, this.tableDataFilters)
|
|
|
+ this.tableDataFilters = _.cloneDeep(dats)
|
|
|
// this.selectTableRows(this.tableData, "DeployID");
|
|
|
- this.tableOptionscp = _.cloneDeep(this.tableOptions);
|
|
|
- const arrbegin = _.cloneDeep(this.tableOptions);
|
|
|
- if (arrbegin) {
|
|
|
- setTimeout(() => {
|
|
|
- this.tableData.forEach((element) => {
|
|
|
- if (this.tableOptions.beginNode) {
|
|
|
- arrbegin.beginNode.forEach((res) => {
|
|
|
- if (res.v === element.beginNode) {
|
|
|
- element.beginNode = res.k;
|
|
|
- }
|
|
|
- });
|
|
|
- arrbegin.endNode.forEach((res) => {
|
|
|
- if (res.v == element.endNode) {
|
|
|
- element.endNode = res.k;
|
|
|
- }
|
|
|
- });
|
|
|
- arrbegin.calculationBasis.forEach((res) => {
|
|
|
- if (res.v == element.calculationBasis) {
|
|
|
- element.calculationBasis = res.k;
|
|
|
- }
|
|
|
- });
|
|
|
- //位置
|
|
|
- this.tabledatacopy.beginPosition.forEach((res) => {
|
|
|
- if (res.v == element.beginPosition) {
|
|
|
- element.beginPosition = res.k;
|
|
|
- }
|
|
|
- });
|
|
|
- this.tabledatacopy.endPosition.forEach((res) => {
|
|
|
- if (res.v == element.endPosition) {
|
|
|
- element.endPosition = res.k;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }, 100);
|
|
|
- }
|
|
|
+ this.tableGroup(this.tableData)
|
|
|
// this.getSelectDataAll(reqUts)
|
|
|
},
|
|
|
+ setTableFilters (tableData, filters) {
|
|
|
+ const tempSets = {}
|
|
|
+ Object.keys(filters).forEach(key => {
|
|
|
+ tempSets[key] = new Set()
|
|
|
+ })
|
|
|
+ tableData.forEach(item => {
|
|
|
+ Object.keys(tempSets).forEach(key => {
|
|
|
+ ; (item[key] ?? '') !== '' && tempSets[key].add(String(item[key]))
|
|
|
+ })
|
|
|
+ })
|
|
|
+ Object.keys(tempSets).forEach(key => {
|
|
|
+ filters[key] = _.orderBy(
|
|
|
+ [...tempSets[key]].map(value => ({
|
|
|
+ text: value,
|
|
|
+ value,
|
|
|
+ })),
|
|
|
+ o => o.value
|
|
|
+ )
|
|
|
+ })
|
|
|
+ return filters
|
|
|
+ },
|
|
|
//获取所有获取弹框-下拉数据-请求状态
|
|
|
getSelectDataAll (reqUts) {
|
|
|
Promise.all(reqUts)
|