You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
4.5 KiB
144 lines
4.5 KiB
<template> |
|
<div class="my-table"> |
|
<el-table :size="state.size.size" :data="page ? data.data : data" @selection-change="selectionChange" |
|
:height="height || (page ? state.size.pTableHeight : state.size.tableHeight)" highlight-current-row |
|
:row-key="rowKey" :tree-porps="treeProps"> |
|
|
|
<el-table-column v-for="item in props" :key="item.code" :prop="item.code" :label="item.name || t(item.i18n)" |
|
:type="item.type" :min-width="item.width" :width="item.type ? item.width : ''" :fixed="item.fixed" |
|
:align="item.align ? item.align : 'center'" show-overflow-tooltip :formatter="formatter"> |
|
|
|
<template v-if="item.slot" #default="scope"> |
|
<slot :name="item.code" :row="scope.row"></slot> |
|
</template> |
|
|
|
<template v-if="item.dict" #default="{ row }"> |
|
{{ formatterByDist(item.dict, row[item.code]) }} |
|
</template> |
|
|
|
</el-table-column> |
|
|
|
</el-table> |
|
</div> |
|
<div v-if="page" class="my-pagination"> |
|
<el-pagination :small="state.size.size == 'small'" @size-change="handleSizeChange" |
|
@current-change="handleCurrentChange" :current-page="example.page" :page-sizes="[10, 20, 50, 100, 200]" |
|
:page-size="example.size" layout="total, sizes, prev, pager, next, jumper" :total="data.total"> |
|
</el-pagination> |
|
</div> |
|
</template> |
|
|
|
<script lang="ts" setup> |
|
import { useStore } from "vuex"; |
|
import { reactive, onMounted, ref } from "vue"; |
|
import { useI18n } from "vue3-i18n"; |
|
// import { PageExample } from "noob-mengyxu"; |
|
const { t } = useI18n(); |
|
const { state } = useStore(); |
|
|
|
const prop = defineProps({ |
|
data: { |
|
type: Object, |
|
default: null |
|
}, |
|
props: { |
|
type: Array<any>(), |
|
default: [], |
|
}, |
|
page: { |
|
type: Boolean, |
|
default: false, |
|
}, |
|
height: { |
|
type: Number, |
|
default: null, |
|
}, |
|
example: { |
|
type: Object, |
|
default: {}, |
|
}, |
|
rowKey: { |
|
type: String, |
|
default: null, |
|
}, |
|
treeProps: { |
|
type: Object, |
|
default: null, |
|
}, |
|
}); |
|
|
|
const emit = defineEmits(["query", "selection-change"]); |
|
|
|
const selectionChange = selection => { |
|
emit("selection-change", selection); |
|
}; |
|
|
|
const handleSizeChange = (val) => { |
|
prop.example.size = val; |
|
emit("query"); |
|
}; |
|
|
|
const handleCurrentChange = (val) => { |
|
prop.example.page = val; |
|
emit("query"); |
|
}; |
|
|
|
const getValue = ( |
|
row: any, |
|
column: string, |
|
value: any, |
|
index?: number |
|
) => { |
|
if ((value == null || value == '') && value !== 0) { |
|
return '--'; |
|
} |
|
return value; |
|
}; |
|
|
|
const formatter = (row: any, column: any, value: any, index: number) => { |
|
if (row.scheme) |
|
return formatterByDist(row.scheme + '_' + column.property, value); |
|
return getValue(null, '', value); |
|
}; |
|
|
|
const formatterByDist = (dictKey, value) => { |
|
if (!dictKey) { |
|
return getValue(null, '', value); |
|
} |
|
const mapping = state.dict[dictKey]; |
|
if (mapping == null) { |
|
return getValue(null, '', value); |
|
} |
|
return mapping[value] == null ? value : mapping[value]; |
|
}; |
|
onMounted(() => { }); |
|
</script> |
|
<style lang="scss" scoped> |
|
.my-table * { |
|
--el-table-bg-color: v-bind('state.style.tableBg') !important; |
|
--el-table-tr-bg-color: v-bind('state.style.tableBg') !important; |
|
--el-table-expanded-cell-bg-color: v-bind('state.style.tableBg') !important; |
|
|
|
--el-table-border-color: v-bind('state.style.tableBorderColor'); |
|
--el-table-border: 1px solid var(--el-table-border-color); |
|
--el-table-text-color: v-bind('state.style.tableColor'); |
|
--el-table-header-text-color: v-bind('state.style.tableColor'); |
|
--el-table-row-hover-bg-color: v-bind('state.style.tableCurBg'); |
|
--el-table-current-row-bg-color: v-bind('state.style.tableCurBg'); |
|
--el-table-header-bg-color: v-bind('state.style.tableHeadBg'); |
|
--el-bg-color: v-bind('state.style.tableBg') !important; |
|
} |
|
|
|
::v-deep .el-table__row--level-1, |
|
::v-deep .el-table__row--level-3 { |
|
background: v-bind('state.style.tableChildBg') !important; |
|
} |
|
|
|
.my-pagination * { |
|
--el-pagination-bg-color: v-bind('state.style.bodyBg') !important; |
|
--el-pagination-disabled-bg-color: v-bind('state.style.bodyBg') !important; |
|
--el-pagination-text-color: v-bind('state.style.color') !important; |
|
--el-pagination-button-color: v-bind('state.style.color') !important; |
|
--el-pagination-button-disabled-bg-color: v-bind('state.style.bodyBg') !important; |
|
} |
|
</style> |