Commit 9460c6c7 by limin

Merge branch 'master' of http://192.168.3.233:8090/npm/glsx-components into master

2 parents a10ae227 c7cb8f65
<template> <template>
<div class="glsx-table" :class="{'hasTableContent':showClass}"> <div class="glsx-table" :class="{ hasTableContent: showClass }">
<el-table id="initTable" :ref="tableParams.mutiSelectName + 'MutiTable' || 'MutiTable'" :data="getListApi ? data : tableData" :row-key="tableParams.mutiSelectUniqueKey || ''" v-loading="loading" :border="border" :highlight-current-row="true" :stripe="true" @sort-change="sortChange" @selection-change="handleSelect" :size="size" :header-cell-style="headerStyle"> <el-table
<el-table-column v-if="tableParams.mutiSelectUniqueKey && tableParams.mutiSelectName" type="selection" width="55" :selectable="checkSelectable" :reserve-selection="true"></el-table-column> id="initTable"
<el-table-column v-if="hasNum" align="center" width="60px" label="序号" type="index" :index="index => index + (page[this.pageConf.pageNum] - 1) * page[this.pageConf.pageSize] + 1"></el-table-column> :ref="tableParams.mutiSelectName + 'MutiTable' || 'MutiTable'"
<el-table-column v-for="(item, index) in tableColumns" :key="index" :label="item.label" :prop="item.prop" :width="item.width" :min-width="item.minWidth" :align="item.align || 'center'" :sortable="item.sortable"> :data="getListApi ? data : tableData"
:row-key="tableParams.mutiSelectUniqueKey || ''"
v-loading="loading"
:border="border"
:highlight-current-row="true"
:stripe="true"
@sort-change="sortChange"
@selection-change="handleSelect"
:size="size"
:header-cell-style="headerStyle"
>
<el-table-column
v-if="tableParams.mutiSelectUniqueKey && tableParams.mutiSelectName"
type="selection"
width="55"
:selectable="checkSelectable"
:reserve-selection="true"
></el-table-column>
<el-table-column
v-if="hasNum"
align="center"
width="60px"
label="序号"
type="index"
:index="
(index) =>
index + (page[this.pageConf.pageNum] - 1) * page[this.pageConf.pageSize] + 1
"
></el-table-column>
<el-table-column
v-for="(item, index) in tableColumns"
:key="index"
:label="item.label"
:prop="item.prop"
:width="item.width"
:min-width="item.minWidth"
:align="item.align || 'center'"
:sortable="item.sortable"
>
<template slot-scope="scope"> <template slot-scope="scope">
<slot v-if="item.addHtml" :name="item.addHtml" :scope="scope.row" :prop="item.prop" :width="item.width"></slot> <slot
v-if="item.addHtml"
:name="item.addHtml"
:scope="scope.row"
:prop="item.prop"
:width="item.width"
></slot>
<template v-else-if="item.formatter"> <template v-else-if="item.formatter">
<span class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }" :title="item.formatter(scope.row)" v-text="item.formatter(scope.row)"></span> <span
class="line-ellipsis"
:style="{ '-webkit-line-clamp': item.line ? item.line : '' }"
:title="item.formatter(scope.row)"
v-text="item.formatter(scope.row)"
></span>
</template> </template>
<template v-else-if="getListApi"> <template v-else-if="getListApi">
<span class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }" :title="scope.row[item.prop]" v-text="scope.row[item.prop]"></span> <span
class="line-ellipsis"
:style="{ '-webkit-line-clamp': item.line ? item.line : '' }"
:title="scope.row[item.prop]"
v-text="scope.row[item.prop]"
></span>
</template> </template>
<template v-else> <template v-else>
<span class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }" :title="tableData[scope.$index][item.prop]" v-text="tableData[scope.$index][item.prop]"></span> <span
class="line-ellipsis"
:style="{ '-webkit-line-clamp': item.line ? item.line : '' }"
:title="tableData[scope.$index][item.prop]"
v-text="tableData[scope.$index][item.prop]"
></span>
</template> </template>
<template v-if="item.addSymbol"> <template v-if="item.addSymbol">
<span v-text="item.addSymbol"></span> <span v-text="item.addSymbol"></span>
</template> </template>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column v-if="tableParams.tableOption" label="操作" :align="tableParams.tableOption.align || 'center'" :width="tableParams.tableOption.width || '200'" fixed="right"> <el-table-column
v-if="tableParams.tableOption"
label="操作"
:align="tableParams.tableOption.align || 'center'"
:width="tableParams.tableOption.width || '200'"
fixed="right"
>
<template slot-scope="scope"> <template slot-scope="scope">
<slot name="auth-button" :scope="scope.row"></slot> <slot name="auth-button" :scope="scope.row"></slot>
</template> </template>
...@@ -31,29 +96,39 @@ ...@@ -31,29 +96,39 @@
<slot name="additionalContent"></slot> <slot name="additionalContent"></slot>
</div> </div>
</el-table> </el-table>
<el-pagination v-if="hasPage" background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page[this.pageConf.pageNum]" :page-sizes="[10, 20, 30, 40]" :page-size="page[this.pageConf.pageSize]" :total="getListApi ? total : tableTotal" :layout="layout"></el-pagination> <el-pagination
v-if="hasPage"
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="page[this.pageConf.pageNum]"
:page-sizes="[10, 20, 30, 40]"
:page-size="page[this.pageConf.pageSize]"
:total="getListApi ? total : tableTotal"
:layout="layout"
></el-pagination>
</div> </div>
</template> </template>
<script> <script>
import { Table, TableColumn, Pagination } from 'element-ui' import { Table, TableColumn, Pagination } from "element-ui";
export default { export default {
name: 'GLTable', name: "GLTable",
components: { components: {
[Table.name]: Table, [Table.name]: Table,
[TableColumn.name]: TableColumn, [TableColumn.name]: TableColumn,
[Pagination.name]: Pagination [Pagination.name]: Pagination,
}, },
props: { props: {
size: { size: {
type: String, type: String,
default: 'medium' default: "medium",
}, },
height: { height: {
type: String, type: String,
default: '' default: "",
}, },
// maxHeight:{ // maxHeight:{
// type:String, // type:String,
...@@ -61,76 +136,80 @@ export default { ...@@ -61,76 +136,80 @@ export default {
// }, // },
noDataImg: { noDataImg: {
type: String, type: String,
default: '' default: "",
}, },
noDataText: { noDataText: {
type: String, type: String,
default: '暂无数据' default: "暂无数据",
}, },
border: { border: {
type: Boolean, type: Boolean,
default: false default: false,
}, },
headerStyle: { headerStyle: {
type: Object, type: Object,
default: () => {} default: () => {},
}, },
// 搜索条件 // 搜索条件
searchForm: { searchForm: {
type: Object, type: Object,
default: () => {} default: () => {},
}, },
// 是否定制表头 // 是否定制表头
isCustomHead: { isCustomHead: {
type: Boolean, type: Boolean,
default: false default: false,
}, },
// 表头展示 // 表头展示
customHeadShowList: { customHeadShowList: {
type: Array, type: Array,
default: () => [] default: () => [],
}, },
// 表格数据-外部传入 // 表格数据-外部传入
tableData: { tableData: {
type: Array, type: Array,
default: () => [] default: () => [],
}, },
tableTotal: { tableTotal: {
type: Number, type: Number,
default: 0 default: 0,
}, },
// 获取列表接口 // 获取列表接口
getListApi: { getListApi: {
type: Function, type: Function,
default: null default: null,
}, },
// 搜索前操作 // 搜索前操作
beforeSearchFn: { beforeSearchFn: {
type: Function, type: Function,
default: () => { default: () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve() resolve();
}) });
} },
}, },
// 分页,默认有 // 分页,默认有
hasPage: { hasPage: {
type: Boolean, type: Boolean,
default: true default: true,
}, },
pageConf: { pageConf: {
type: Object, type: Object,
default: () => ({ pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'totalCount' }) default: () => ({
pageSize: "pageSize",
pageNum: "pageNum",
totalCount: "totalCount",
}),
}, },
// 分页组件配置 // 分页组件配置
layout: { layout: {
type: String, type: String,
default: 'sizes,total,->,prev,pager,next,jumper' default: "sizes,total,->,prev,pager,next,jumper",
}, },
// 序号,默认有 // 序号,默认有
hasNum: { hasNum: {
type: Boolean, type: Boolean,
default: true default: true,
}, },
tableParams: { tableParams: {
type: Object, type: Object,
...@@ -149,17 +228,17 @@ export default { ...@@ -149,17 +228,17 @@ export default {
// 设置禁止选中的行数据 // 设置禁止选中的行数据
checkSelectKey: { checkSelectKey: {
type: String, type: String,
default: '' default: "",
}, },
// 设置禁止选中的值 // 设置禁止选中的值
checkSelectVal: { checkSelectVal: {
type: Array, type: Array,
default: () => [] default: () => [],
}, },
// 后端返回列表参数名 // 后端返回列表参数名
listName: { listName: {
type: String, type: String,
default: '' default: "",
}, },
// 表格操作,默认没有 // 表格操作,默认没有
// tableOption: { // tableOption: {
...@@ -169,11 +248,11 @@ export default { ...@@ -169,11 +248,11 @@ export default {
// 表格栏 // 表格栏
tableColumns: { tableColumns: {
type: Array, type: Array,
default: () => [] default: () => [],
} },
} };
} },
} },
}, },
data() { data() {
...@@ -187,130 +266,138 @@ export default { ...@@ -187,130 +266,138 @@ export default {
mutiSelectArr: {}, mutiSelectArr: {},
tableColumns: [], tableColumns: [],
showClass:false showClass: false,
} };
}, },
watch: { watch: {
customHeadShowList(val) { customHeadShowList(val) {
this.isCustomHead && this.findShowHeadCol() this.isCustomHead && this.findShowHeadCol();
}, },
data:{ data: {
immediate:true, immediate: true,
handler(val){ handler(val) {
this.showClass=val.length>0 ? true :false; this.showClass = val.length > 0 ? true : false;
},
deep: true,
}, },
deep:true
}
}, },
methods: { methods: {
findShowHeadCol() { findShowHeadCol() {
this.tableColumns = [] this.tableColumns = [];
this.tableParams.tableColumns.forEach(item => { this.tableParams.tableColumns.forEach((item) => {
let isCustomCol = item.hasOwnProperty('isCustomCol') let isCustomCol = item.hasOwnProperty("isCustomCol");
if (!isCustomCol || (isCustomCol && this.customHeadShowList.includes(item.label))) { if (
this.tableColumns.push(item) !isCustomCol ||
(isCustomCol && this.customHeadShowList.includes(item.label))
) {
this.tableColumns.push(item);
} }
}) });
}, },
// 设置禁止选中的行数据 // 设置禁止选中的行数据
checkSelectable(row) { checkSelectable(row) {
if (this.tableParams.checkSelectKey && this.tableParams.checkSelectVal.length > 0) { if (this.tableParams.checkSelectKey && this.tableParams.checkSelectVal.length > 0) {
return this.tableParams.checkSelectVal.indexOf(row[this.tableParams.checkSelectKey]) == -1 return (
this.tableParams.checkSelectVal.indexOf(row[this.tableParams.checkSelectKey]) ==
-1
);
} else { } else {
return true return true;
} }
}, },
// 排序 // 排序
sortChange({ column, prop, order }) { sortChange({ column, prop, order }) {
this.$emit('sortChange', { column, prop, order }) this.$emit("sortChange", { column, prop, order });
}, },
// 多选 // 多选
handleSelect(val) { handleSelect(val) {
this.mutiSelectArr[this.tableParams.mutiSelectName] = val this.mutiSelectArr[this.tableParams.mutiSelectName] = val;
}, },
// 清空多选 // 清空多选
clearMutiSelect() { clearMutiSelect() {
this.mutiSelectArr[this.tableParams.mutiSelectName] = [] this.mutiSelectArr[this.tableParams.mutiSelectName] = [];
this.$refs[this.tableParams.mutiSelectName + 'MutiTable'].clearSelection() this.$refs[this.tableParams.mutiSelectName + "MutiTable"].clearSelection();
}, },
//设置表格高度 //设置表格高度
setTableHeightFun(){ setTableHeightFun(navHeight = 0) {
let offsettop = document.getElementById('initTable').offsetTop //navHeight 传值底部高度
console.log('表格距离顶部', offsettop) let paginationHeight;
let clientHeight = document.documentElement.clientHeight if(document.querySelector(".el-pagination")) {
console.log('页面整体高度',clientHeight) paginationHeight = document.querySelector(".el-pagination").clientHeight + 20;
}else {
paginationHeight = 0;
console.log(document.getElementsByClassName('scrm-base-nav').length)
if(document.getElementsByClassName('scrm-base-nav').length && document.getElementsByClassName('scrm-base-nav').length){
var baseNavHeight=document.getElementsByClassName('scrm-base-nav')[0].clientHeight;
var subNavHeight=document.getElementsByClassName('scrm-base-sub-nav')[0].clientHeight
document.getElementById('initTable').style.height= (clientHeight - offsettop - 121-baseNavHeight-subNavHeight)+'px';
}else{
document.getElementById('initTable').style.height= (clientHeight - offsettop - 121)+'px';
} }
let offsettop = document.getElementById("initTable").offsetTop;
let clientHeight = document.documentElement.clientHeight;
document.getElementById("initTable").style.height =
}, clientHeight - offsettop - paginationHeight - navHeight + "px";
},
refreshTable(isResetPageNum = true, isClearMuti = true) { refreshTable(isResetPageNum = true, isClearMuti = true) {
this.beforeSearchFn().then(res => { this.beforeSearchFn().then((res) => {
// 清空多选 // 清空多选
isClearMuti && this.clearMutiSelect() isClearMuti && this.clearMutiSelect();
this.loading = true this.loading = true;
isResetPageNum && (this.page[this.pageConf.pageNum] = 1) isResetPageNum && (this.page[this.pageConf.pageNum] = 1);
var params = { var params = {
...this.page, ...this.page,
...this.searchForm ...this.searchForm,
} };
this.getListApi(params) this.getListApi(params)
.then(res => { .then((res) => {
console.log(res) console.log(res);
this.data = this.findVal(res, this.tableParams.listName) this.data = this.findVal(res, this.tableParams.listName);
this.total = this.findVal(res, this.pageConf.totalCount) this.total = this.findVal(res, this.pageConf.totalCount);
this.loading = false this.loading = false;
}) })
.catch(() => { .catch(() => {
this.loading = false this.loading = false;
}) });
}) });
}, },
// 找返回值 // 找返回值
findVal(res, rankStr) { findVal(res, rankStr) {
var rankList = rankStr.split('.') var rankList = rankStr.split(".");
if (!rankStr) { if (!rankStr) {
return res return res;
} }
return this.findVal(res[rankList[0]], rankList.splice(1).join('.')) return this.findVal(res[rankList[0]], rankList.splice(1).join("."));
}, },
// 每页条数 // 每页条数
handleSizeChange(value) { handleSizeChange(value) {
let offsettop = document.getElementById('initTable').offsetTop let offsettop = document.getElementById("initTable").offsetTop;
console.log('表格距离顶部1', offsettop) console.log("表格距离顶部1", offsettop);
this.page[this.pageConf.pageSize] = value this.page[this.pageConf.pageSize] = value;
this.getListApi ? this.refreshTable(false, false) : this.$emit('refreshTable', this.page) this.getListApi
? this.refreshTable(false, false)
: this.$emit("refreshTable", this.page);
}, },
// 页码 // 页码
handleCurrentChange(value) { handleCurrentChange(value) {
this.page[this.pageConf.pageNum] = value this.page[this.pageConf.pageNum] = value;
this.getListApi ? this.refreshTable(false, false) : this.$emit('refreshTable', this.page) this.getListApi
} ? this.refreshTable(false, false)
: this.$emit("refreshTable", this.page);
},
}, },
mounted() { mounted() {
this.isCustomHead ? this.findShowHeadCol() : (this.tableColumns = this.tableParams.tableColumns) this.isCustomHead
this.page = {} ? this.findShowHeadCol()
this.page[this.pageConf.pageSize] = 10 : (this.tableColumns = this.tableParams.tableColumns);
this.page[this.pageConf.pageNum] = 1 this.page = {};
this.getListApi && this.refreshTable() this.page[this.pageConf.pageSize] = 10;
this.page[this.pageConf.pageNum] = 1;
this.getListApi && this.refreshTable();
// this.$nextTick(() => { // this.$nextTick(() => {
// var _this=this // var _this=this
...@@ -322,9 +409,8 @@ export default { ...@@ -322,9 +409,8 @@ export default {
// }, 200) // }, 200)
// }) // })
} },
}; };
</script> </script>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!