|
|
|
|
@ -1,15 +1,16 @@
|
|
|
|
|
<script>
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
import {getToken} from "@/utils/auth";
|
|
|
|
|
import axios from "axios";
|
|
|
|
|
import { getToken } from "@/utils/auth";
|
|
|
|
|
export default {
|
|
|
|
|
props: {
|
|
|
|
|
//请求相关
|
|
|
|
|
action:[String,Function], //String传入请求地址 Function传入返回promise的方法
|
|
|
|
|
reqOpt:Object, //请求参数配置
|
|
|
|
|
resProp:{
|
|
|
|
|
type:String,
|
|
|
|
|
default:'data'
|
|
|
|
|
},//请求后需要获取表格数据键名
|
|
|
|
|
action: [String, Function], //String传入请求地址 Function传入返回promise的方法
|
|
|
|
|
destroyAction: [Function], //删除promise方法
|
|
|
|
|
reqOpt: Object, //请求参数配置
|
|
|
|
|
resProp: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: "data",
|
|
|
|
|
}, //请求后需要获取表格数据键名
|
|
|
|
|
|
|
|
|
|
//操作权限
|
|
|
|
|
auths: {
|
|
|
|
|
@ -171,19 +172,20 @@ export default {
|
|
|
|
|
return {
|
|
|
|
|
isBtns: false,
|
|
|
|
|
tableHeight: null,
|
|
|
|
|
//document.documentElement.clientHeight -50 -37 - 20- 25 - 76,
|
|
|
|
|
//document.documentElement.clientHeight -50 -37 - 20- 25 - 76,
|
|
|
|
|
isShowPage: true,
|
|
|
|
|
checkTable: this.tableItem.map((item) => item?.prop),
|
|
|
|
|
loading: false,
|
|
|
|
|
visibleBtn: true, //操作按钮显示
|
|
|
|
|
sortFlag:0,
|
|
|
|
|
|
|
|
|
|
totalData:0,
|
|
|
|
|
listData:[],
|
|
|
|
|
selectOpt:{
|
|
|
|
|
page:1,
|
|
|
|
|
page_size:10,
|
|
|
|
|
sort_name:'',
|
|
|
|
|
sort_type:''
|
|
|
|
|
totalData: 0,
|
|
|
|
|
listData: [],
|
|
|
|
|
selectOpt: {
|
|
|
|
|
page: 1,
|
|
|
|
|
page_size: 10,
|
|
|
|
|
sort_name: "",
|
|
|
|
|
sort_type: "",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
@ -191,7 +193,9 @@ export default {
|
|
|
|
|
//方法
|
|
|
|
|
initLoad() {
|
|
|
|
|
let clientHeight = document.documentElement.clientHeight;
|
|
|
|
|
let lxheader = document.querySelector('.v-header').getBoundingClientRect()
|
|
|
|
|
let lxheader = document
|
|
|
|
|
.querySelector(".v-header")
|
|
|
|
|
.getBoundingClientRect();
|
|
|
|
|
let lxHeader_height = lxheader.height + 25; //查询 头部
|
|
|
|
|
let paginationHeight = 37; //分页的高度
|
|
|
|
|
let topHeight = 50; //页面 头部
|
|
|
|
|
@ -199,61 +203,71 @@ export default {
|
|
|
|
|
clientHeight - lxHeader_height - topHeight - paginationHeight - 20 - 25;
|
|
|
|
|
//console.log(this.tableHeight)
|
|
|
|
|
},
|
|
|
|
|
getTableData(isRefresh = false){
|
|
|
|
|
if(isRefresh){
|
|
|
|
|
this.selectOpt.page = 1
|
|
|
|
|
getTableData(isRefresh = false) {
|
|
|
|
|
if (isRefresh) {
|
|
|
|
|
this.selectOpt.page = 1;
|
|
|
|
|
}
|
|
|
|
|
switch (typeof this.action){
|
|
|
|
|
switch (typeof this.action) {
|
|
|
|
|
case "string":
|
|
|
|
|
this.loading = true
|
|
|
|
|
this.loading = true;
|
|
|
|
|
axios({
|
|
|
|
|
baseURL:process.env.VUE_APP_BASE_API,
|
|
|
|
|
url:this.action,
|
|
|
|
|
headers:{
|
|
|
|
|
Authorization:"Bearer " + getToken()
|
|
|
|
|
baseURL: process.env.VUE_APP_BASE_API,
|
|
|
|
|
url: this.action,
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: "Bearer " + getToken(),
|
|
|
|
|
},
|
|
|
|
|
params:(this.reqOpt.method && this.reqOpt.method === 'get') ? this.selectOpt : '',
|
|
|
|
|
data:(this.reqOpt.method && this.reqOpt.method === 'post') ? this.selectOpt : '',
|
|
|
|
|
...this.reqOpt
|
|
|
|
|
}).then(res => {
|
|
|
|
|
this.listData = this.getByStrkey(res.data,this.resProp)
|
|
|
|
|
this.totalData = res.data.total
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.loading = false
|
|
|
|
|
},300)
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
console.error(err)
|
|
|
|
|
this.loading = false
|
|
|
|
|
params:
|
|
|
|
|
this.reqOpt.method && this.reqOpt.method === "get"
|
|
|
|
|
? this.selectOpt
|
|
|
|
|
: "",
|
|
|
|
|
data:
|
|
|
|
|
this.reqOpt.method && this.reqOpt.method === "post"
|
|
|
|
|
? this.selectOpt
|
|
|
|
|
: "",
|
|
|
|
|
...this.reqOpt,
|
|
|
|
|
})
|
|
|
|
|
.then((res) => {
|
|
|
|
|
this.listData = this.getByStrkey(res.data, this.resProp);
|
|
|
|
|
this.totalData = res.data.total;
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.loading = false;
|
|
|
|
|
}, 300);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.error(err);
|
|
|
|
|
this.loading = false;
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case "function":
|
|
|
|
|
this.loading = true
|
|
|
|
|
this.action(false,{
|
|
|
|
|
this.loading = true;
|
|
|
|
|
this.action({
|
|
|
|
|
...this.selectOpt,
|
|
|
|
|
...this.reqOpt
|
|
|
|
|
}).then(res => {
|
|
|
|
|
this.listData = this.getByStrkey(res,this.resProp)
|
|
|
|
|
this.totalData = res.total
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.loading = false
|
|
|
|
|
},300)
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
console.error(err)
|
|
|
|
|
this.loading = false
|
|
|
|
|
})
|
|
|
|
|
...this.reqOpt,
|
|
|
|
|
},false)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
this.listData = this.getByStrkey(res, this.resProp);
|
|
|
|
|
this.totalData = res.total;
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.loading = false;
|
|
|
|
|
}, 300);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.error(err);
|
|
|
|
|
this.loading = false;
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
getByStrkey(obj,str){
|
|
|
|
|
if(!str) return obj
|
|
|
|
|
getByStrkey(obj, str) {
|
|
|
|
|
if (!str) return obj;
|
|
|
|
|
let res = this.deepCopy(obj);
|
|
|
|
|
let keys = str.split('.')
|
|
|
|
|
keys.forEach(key => {
|
|
|
|
|
res = res[key]
|
|
|
|
|
})
|
|
|
|
|
let keys = str.split(".");
|
|
|
|
|
keys.forEach((key) => {
|
|
|
|
|
res = res[key];
|
|
|
|
|
});
|
|
|
|
|
return res;
|
|
|
|
|
},
|
|
|
|
|
deepCopy(data){
|
|
|
|
|
deepCopy(data) {
|
|
|
|
|
//string,number,bool,null,undefined,symbol
|
|
|
|
|
//object,array,date
|
|
|
|
|
if (data && typeof data === "object") {
|
|
|
|
|
@ -294,19 +308,26 @@ export default {
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
sortListener({column, prop, order}){
|
|
|
|
|
this.selectOpt.sort_name = prop
|
|
|
|
|
switch (order){
|
|
|
|
|
case "ascending":
|
|
|
|
|
this.selectOpt.sort_type = 'ASC'
|
|
|
|
|
break;
|
|
|
|
|
case "descending":
|
|
|
|
|
this.selectOpt.sort_type = 'DESC'
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
this.selectOpt.sort_type = ''
|
|
|
|
|
sortListener({ column, prop, order }) {
|
|
|
|
|
if(prop === this.selectOpt.sort_name){
|
|
|
|
|
this.sortFlag ++
|
|
|
|
|
}else{
|
|
|
|
|
this.sortFlag = 0
|
|
|
|
|
}
|
|
|
|
|
this.getTableData()
|
|
|
|
|
this.selectOpt.sort_name = prop;
|
|
|
|
|
this.selectOpt.sort_type = ['ASC','DESC',null][this.sortFlag % 3]
|
|
|
|
|
// TODO: 优化
|
|
|
|
|
// switch (order) {
|
|
|
|
|
// case "ascending":
|
|
|
|
|
// this.selectOpt.sort_type = "ASC";
|
|
|
|
|
// break;
|
|
|
|
|
// case "descending":
|
|
|
|
|
// this.selectOpt.sort_type = "DESC";
|
|
|
|
|
// break;
|
|
|
|
|
// default:
|
|
|
|
|
// this.selectOpt.sort_type = "";
|
|
|
|
|
// }
|
|
|
|
|
this.getTableData();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
//element table方法
|
|
|
|
|
@ -399,10 +420,21 @@ export default {
|
|
|
|
|
this.$emit("expand-change", row, expanded);
|
|
|
|
|
},
|
|
|
|
|
deleteClick(row) {
|
|
|
|
|
this.$emit('delete', row)
|
|
|
|
|
this.$emit("delete", row);
|
|
|
|
|
if (this.destroyAction) {
|
|
|
|
|
this.destroyAction({
|
|
|
|
|
id: row.id,
|
|
|
|
|
},false).then((res) => {
|
|
|
|
|
this.$message({
|
|
|
|
|
type: "success",
|
|
|
|
|
message: "删除成功",
|
|
|
|
|
});
|
|
|
|
|
this.getTableData();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
editorClick(row) {
|
|
|
|
|
this.$emit('editor', row)
|
|
|
|
|
this.$emit("editor", row);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
createPage() {
|
|
|
|
|
@ -418,27 +450,31 @@ export default {
|
|
|
|
|
show-total={true}
|
|
|
|
|
page-size={this.pageSize}
|
|
|
|
|
v-show={this.isShowPage}
|
|
|
|
|
total={this.action ? (this.totalData || this.listData.length) : this.total}
|
|
|
|
|
total={
|
|
|
|
|
this.action
|
|
|
|
|
? this.totalData || this.listData.length
|
|
|
|
|
: this.total
|
|
|
|
|
}
|
|
|
|
|
size="small"
|
|
|
|
|
show-elevator={true}
|
|
|
|
|
show-sizer={this.showSizer}
|
|
|
|
|
class="xy-table__page"
|
|
|
|
|
on={{
|
|
|
|
|
["on-page-size-change"]: (e) => {
|
|
|
|
|
if(this.action){
|
|
|
|
|
this.selectOpt.page_size = e
|
|
|
|
|
this.selectOpt.page = 1
|
|
|
|
|
this.getTableData()
|
|
|
|
|
if (this.action) {
|
|
|
|
|
this.selectOpt.page_size = e;
|
|
|
|
|
this.selectOpt.page = 1;
|
|
|
|
|
this.getTableData();
|
|
|
|
|
}
|
|
|
|
|
this.$emit("pageSizeChange", e)
|
|
|
|
|
this.$emit("pageSizeChange", e);
|
|
|
|
|
},
|
|
|
|
|
["on-change"]: (e) => {
|
|
|
|
|
if(this.action){
|
|
|
|
|
this.selectOpt.page = e
|
|
|
|
|
this.getTableData()
|
|
|
|
|
if (this.action) {
|
|
|
|
|
this.selectOpt.page = e;
|
|
|
|
|
this.getTableData();
|
|
|
|
|
}
|
|
|
|
|
this.$emit("pageIndexChange", e)
|
|
|
|
|
}
|
|
|
|
|
this.$emit("pageIndexChange", e);
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
></Page>
|
|
|
|
|
</transition>
|
|
|
|
|
@ -452,11 +488,13 @@ export default {
|
|
|
|
|
return (
|
|
|
|
|
<el-checkbox-group v-model={this.checkTable}>
|
|
|
|
|
{this.$props?.tableItem?.map((item, index) => {
|
|
|
|
|
return item.type !== 'expand' ? (
|
|
|
|
|
return item.type !== "expand" ? (
|
|
|
|
|
<el-checkbox label={item.prop} key={item.prop}>
|
|
|
|
|
{item.label}
|
|
|
|
|
</el-checkbox>
|
|
|
|
|
) : ''
|
|
|
|
|
) : (
|
|
|
|
|
""
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</el-checkbox-group>
|
|
|
|
|
);
|
|
|
|
|
@ -573,7 +611,7 @@ export default {
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
this.getTableData()
|
|
|
|
|
this.getTableData();
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.initLoad();
|
|
|
|
|
@ -581,7 +619,7 @@ export default {
|
|
|
|
|
updated() {
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
this.doLayout();
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
render(h) {
|
|
|
|
|
let { $scopedSlots } = this;
|
|
|
|
|
@ -638,7 +676,9 @@ export default {
|
|
|
|
|
["row-dblclick"]: this.rowDblclick,
|
|
|
|
|
["header-click"]: this.headerClick,
|
|
|
|
|
["header-contextmenu"]: this.headerContextmenu,
|
|
|
|
|
["sort-change"]: this.action ? this.sortListener : this.sortChange,
|
|
|
|
|
["sort-change"]: this.action
|
|
|
|
|
? this.sortListener
|
|
|
|
|
: this.sortChange,
|
|
|
|
|
["filter-change"]: this.filterChange,
|
|
|
|
|
["current-change"]: this.currentChange,
|
|
|
|
|
["header-dragend"]: this.headerDragend,
|
|
|
|
|
@ -651,9 +691,12 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<el-table-column
|
|
|
|
|
key={String(Math.random())+index}
|
|
|
|
|
// TODO: 随机key值与sort优化问题
|
|
|
|
|
//key={`xy-table-col-${item.prop}`}
|
|
|
|
|
key={String(Math.random()) + index}
|
|
|
|
|
type={item.type}
|
|
|
|
|
index={item.index}
|
|
|
|
|
//column-key={`xy-table-column-${item.prop}`}
|
|
|
|
|
column-key={String(Math.random())}
|
|
|
|
|
label={item.label}
|
|
|
|
|
prop={item.prop}
|
|
|
|
|
@ -694,17 +737,18 @@ export default {
|
|
|
|
|
: ""
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{ item.multiHd
|
|
|
|
|
{item.multiHd
|
|
|
|
|
? item.multiHd.map((item1, index1) => {
|
|
|
|
|
return (
|
|
|
|
|
<el-table-column
|
|
|
|
|
key={`xy-table-col-multi-${item1.prop}`}
|
|
|
|
|
//key={`xy-table-col-multi-${item1.prop}`}
|
|
|
|
|
key={String(Math.random()) + index1}
|
|
|
|
|
prop={`${item.pProp ? item.pProp + "." : ""}${
|
|
|
|
|
item1.prop
|
|
|
|
|
}`}
|
|
|
|
|
type={item1.type}
|
|
|
|
|
index={item1.index}
|
|
|
|
|
column-key={String(Math.random())}
|
|
|
|
|
column-key={String(Math.random() + index1)}
|
|
|
|
|
label={item1.label}
|
|
|
|
|
prop={item1.prop}
|
|
|
|
|
width={item1.width ?? "auto"}
|
|
|
|
|
@ -717,7 +761,9 @@ export default {
|
|
|
|
|
sort-orders={item1.sortOrders}
|
|
|
|
|
resizale={item1.resizale ?? false}
|
|
|
|
|
formatter={item1.formatter}
|
|
|
|
|
show-overflow-tooltip={item1.showOverflowTooltip ?? true}
|
|
|
|
|
show-overflow-tooltip={
|
|
|
|
|
item1.showOverflowTooltip ?? true
|
|
|
|
|
}
|
|
|
|
|
align={item1.align ?? "center"}
|
|
|
|
|
header-align={item1.headerAlign ?? "center"}
|
|
|
|
|
class-name={`xy-table__row-fade ${item1.className}`}
|
|
|
|
|
@ -745,10 +791,10 @@ export default {
|
|
|
|
|
</el-table-column>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
{ $scopedSlots.btns ? $scopedSlots.btns() : this.isCreateAuthBtns() }
|
|
|
|
|
{$scopedSlots.btns ? $scopedSlots.btns() : this.isCreateAuthBtns()}
|
|
|
|
|
</el-table>
|
|
|
|
|
) : (
|
|
|
|
|
<el-table height={this.height ?? this.tableHeight} />
|
|
|
|
|
<el-table ref="table" height={this.height ?? this.tableHeight} />
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<el-backtop
|
|
|
|
|
@ -757,7 +803,7 @@ export default {
|
|
|
|
|
bottom={100}
|
|
|
|
|
right={36}
|
|
|
|
|
></el-backtop>
|
|
|
|
|
{ this.createPage() }
|
|
|
|
|
{this.createPage()}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
|