|
|
@@ -6,7 +6,7 @@
|
|
|
<div class="custom-table-btn">
|
|
|
<div class="ct-btn">
|
|
|
<slot v-if="slots.tableLeftBtn" name="tableLeftBtn"></slot>
|
|
|
- <a-button type="text" style="width: 100%">
|
|
|
+ <a-button type="text" style="width: 100%" @click="handleAddBtn">
|
|
|
<template #icon> <PlusOutlined /></template>
|
|
|
<span>新增</span>
|
|
|
</a-button>
|
|
|
@@ -26,10 +26,11 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="jsx">
|
|
|
-import {useSlots, h, ref, toRefs, onMounted, nextTick} from 'vue';
|
|
|
+ import { useSlots, h, ref, toRefs, onMounted, nextTick, watch } from 'vue';
|
|
|
import BsTable, { useBsTable } from '/@/components/BsUi/Table';
|
|
|
import { DeleteOutlined, PlusOutlined } from '@ant-design/icons-vue';
|
|
|
import { cloneDeep, isEmpty } from 'lodash';
|
|
|
+ import { DISPLAY_STATE } from '/@/components/BsUi/constant.js';
|
|
|
|
|
|
const props = defineProps({
|
|
|
customColumns: {
|
|
|
@@ -44,14 +45,9 @@ import {useSlots, h, ref, toRefs, onMounted, nextTick} from 'vue';
|
|
|
required: false,
|
|
|
default: 'id',
|
|
|
},
|
|
|
-
|
|
|
- getBsTableAdapter: {
|
|
|
- required: true,
|
|
|
- default: null,
|
|
|
- },
|
|
|
});
|
|
|
|
|
|
- const emits = defineEmits('change');
|
|
|
+ const emits = defineEmits('change', 'update:value', 'add');
|
|
|
const slots = useSlots();
|
|
|
|
|
|
const selectedData = ref([]);
|
|
|
@@ -59,7 +55,7 @@ import {useSlots, h, ref, toRefs, onMounted, nextTick} from 'vue';
|
|
|
|
|
|
const bsTableAdapter = {
|
|
|
toolbarConfig: {
|
|
|
- enable: true,
|
|
|
+ enable: false,
|
|
|
},
|
|
|
searchConfig: {
|
|
|
enable: false,
|
|
|
@@ -67,7 +63,6 @@ import {useSlots, h, ref, toRefs, onMounted, nextTick} from 'vue';
|
|
|
gridOptions: {
|
|
|
border: true,
|
|
|
minHeight: '0',
|
|
|
- maxHeight: '300',
|
|
|
data: [],
|
|
|
columns: [],
|
|
|
onCheckboxChange(props) {
|
|
|
@@ -81,28 +76,24 @@ import {useSlots, h, ref, toRefs, onMounted, nextTick} from 'vue';
|
|
|
},
|
|
|
pagerConfig: {
|
|
|
enable: false,
|
|
|
+ isFixed: false,
|
|
|
},
|
|
|
};
|
|
|
|
|
|
const bsTableBean = useBsTable({ tableOptions: bsTableAdapter });
|
|
|
|
|
|
- const {
|
|
|
- tableOptions,
|
|
|
- setTablePropsValue: setValue,
|
|
|
- getTablePropsValue: getValue,
|
|
|
- getGridRef,
|
|
|
- } = bsTableBean;
|
|
|
+ const { tableOptions, setTablePropsValue: setValue, getTablePropsValue: getValue, getGridRef } = bsTableBean;
|
|
|
|
|
|
const selectAndSeqCols = [
|
|
|
- { type: 'checkbox', width: 30, align: 'center' },
|
|
|
- { type: 'seq', width: 50, align: 'center' },
|
|
|
+ { type: 'checkbox', width: 60, align: 'center', fixed: 'left' },
|
|
|
+ { type: 'seq', width: 50, align: 'center', fixed: 'left' },
|
|
|
];
|
|
|
|
|
|
const optionsCols = [
|
|
|
{
|
|
|
field: 'btnOption',
|
|
|
headerAlign: 'center',
|
|
|
- width: "50",
|
|
|
+ width: '50',
|
|
|
align: 'center',
|
|
|
fixed: 'right',
|
|
|
slots: {
|
|
|
@@ -118,7 +109,9 @@ import {useSlots, h, ref, toRefs, onMounted, nextTick} from 'vue';
|
|
|
const tableData = getValue('gridOptions.data');
|
|
|
const deepCloneData = cloneDeep(tableData);
|
|
|
deepCloneData.splice(rowIndex, 1);
|
|
|
- setValue('gridOptions.data', deepCloneData);
|
|
|
+ // setValue('gridOptions.data', deepCloneData);
|
|
|
+ emits('update:value', deepCloneData);
|
|
|
+ emits('change', deepCloneData);
|
|
|
}}
|
|
|
></a-button>
|
|
|
</a-tooltip>
|
|
|
@@ -135,26 +128,35 @@ import {useSlots, h, ref, toRefs, onMounted, nextTick} from 'vue';
|
|
|
},
|
|
|
},
|
|
|
];
|
|
|
-
|
|
|
const gridOptions = getValue('gridOptions');
|
|
|
-
|
|
|
gridOptions.columns = [...selectAndSeqCols, ...optionsCols];
|
|
|
-
|
|
|
if (!isEmpty(props.customColumns)) {
|
|
|
gridOptions.columns = [...selectAndSeqCols, ...props.customColumns, ...optionsCols];
|
|
|
}
|
|
|
+ const handleAddBtn = () => {
|
|
|
+ const tableData = getValue('gridOptions.data');
|
|
|
+ emits('add', {
|
|
|
+ gridRef: getGridRef(),
|
|
|
+ bsTable: bsTableBean,
|
|
|
+ tableData,
|
|
|
+ });
|
|
|
+ };
|
|
|
|
|
|
const handleBatchDelete = () => {
|
|
|
const tableData = getValue('gridOptions.data');
|
|
|
const newTableData = tableData.filter((v) => selectedData.value.findIndex((v1) => v[props.rowKey] === v1[props.rowKey]) === -1);
|
|
|
- setValue('gridOptions.data', newTableData);
|
|
|
- selectedData.value = [];
|
|
|
+ // setValue('gridOptions.data', newTableData);
|
|
|
+ emits('update:value', newTableData);
|
|
|
+ emits('change', newTableData);
|
|
|
};
|
|
|
|
|
|
- onMounted(() => {
|
|
|
- props.getBsTableAdapter && props.getBsTableAdapter(bsTableBean);
|
|
|
- setValue("gridOptions.data", props.value);
|
|
|
- })
|
|
|
+ watch(
|
|
|
+ () => props.value,
|
|
|
+ (val) => {
|
|
|
+ setValue('gridOptions.data', val);
|
|
|
+ },
|
|
|
+ { immediate: true }
|
|
|
+ );
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
@@ -166,6 +168,17 @@ import {useSlots, h, ref, toRefs, onMounted, nextTick} from 'vue';
|
|
|
:deep(.vxe-grid--table-container) {
|
|
|
padding: 0;
|
|
|
}
|
|
|
+
|
|
|
+ :deep(.vxe-grid--layout-body-content-wrapper) {
|
|
|
+ padding: 0;
|
|
|
+ }
|
|
|
+ :deep(.vxe-grid--layout-body-wrapper) {
|
|
|
+ padding: 10px;
|
|
|
+ }
|
|
|
+
|
|
|
+ :deep(.top-bottom) {
|
|
|
+ padding: 0;
|
|
|
+ }
|
|
|
.table-bottom-btns {
|
|
|
display: flex;
|
|
|
width: 100%;
|