Files
SPDM/src/components/common/report/reportEdit/table.vue
2026-02-26 15:48:46 +08:00

213 lines
5.1 KiB
Vue

<template>
<div class="table-content">
<Toper
title="表格"
:modeKey="titleKey"
:btns="['edit', 'del']"
:disabled="mode !== 'edit'"
@edit="diaShow = true"
@del="removeFun"
/>
<div v-if="mode === 'edit'" class="title-item">{{ titleKey || '请输入表格key ' }}</div>
<el-table :data="tableData">
<el-table-column
v-for="(item, index) in head"
:key="index"
:prop="item.key"
:label="item.title"
>
<template #default="scope">
<el-input v-model="scope.row[item.key]" clearable @input="inputFun" />
</template>
</el-table-column>
<el-table-column v-if="mode === 'input'" prop="actions" label="操作" fixed="right" width="60">
<template #default="scope">
<el-link type="danger" @click="delDataFun(scope.$index)">删除</el-link>
</template>
</el-table-column>
</el-table>
<div v-if="mode === 'input' && !disabled" class="add-column" @click="addDataFun">
<el-icon :size="22"><Plus /></el-icon>
</div>
<Dialog v-model="diaShow" diaTitle="表格设置" :width="500" @close="closeFun">
<div class="content">
<el-form label-width="auto">
<el-form-item label="表格key">
<el-input v-model="titleKey" placeholder="请输入" clearable />
</el-form-item>
<el-form-item label="表格类型">
<el-select v-model="paramsData.tableType">
<el-option label="指标" value="performance" />
<el-option label="普通" value="normal" />
</el-select>
</el-form-item>
</el-form>
<div class="table">
<el-table :data="headData">
<el-table-column prop="title" label="表头名称">
<template #default="scope">
<el-input v-model="scope.row.title" clearable />
</template>
</el-table-column>
<el-table-column prop="key" label="表头key值">
<template #default="scope">
<el-input v-model="scope.row.key" clearable />
</template>
</el-table-column>
<el-table-column prop="actions" label="操作" width="60">
<template #default="scope">
<el-link type="danger" @click="delHeadFun(scope.$index)">删除</el-link>
</template>
</el-table-column>
</el-table>
</div>
</div>
<template #footer>
<div>
<el-button @click="addFun">新增列头</el-button>
<el-button type="primary" @click="saveFun">确定</el-button>
</div>
</template>
</Dialog>
</div>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue';
import { Plus } from '@element-plus/icons-vue';
import Dialog from '@/components/common/dialog/index.vue';
import Toper from './toper.vue';
import { cloneDeep } from 'lodash-es';
const emit = defineEmits([
'update:keyValue',
'update:value',
'update:params',
'update:head',
'del',
]);
interface Props {
keyValue: any;
value: any;
params: any;
mode: string;
head?: any;
disabled?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
keyValue: '',
value: [],
params: {},
mode: '',
head: [],
disabled: false,
});
const diaShow = ref(false);
const titleKey = ref(props.keyValue);
const tableData = ref<any>([]);
const headData = ref<any>(cloneDeep(props.head));
const paramsData = ref(cloneDeep(props.params));
watch(
() => titleKey.value,
(val: any) => {
emit('update:keyValue', val);
},
{ deep: true }
);
watch(
() => paramsData.value,
(val: any) => {
emit('update:params', val);
},
{
deep: true,
}
);
watch(
() => props.head,
(val: any) => {
headData.value = cloneDeep(val) || [];
},
{ deep: true, immediate: true }
);
watch(
() => props.value,
(val: any) => {
tableData.value = cloneDeep(val) || [];
},
{ deep: true, immediate: true }
);
const inputFun = () => {
emit('update:value', tableData.value);
};
const addFun = () => {
headData.value.push({
title: '',
key: '',
});
};
const addDataFun = () => {
tableData.value.push({});
emit('update:value', tableData.value);
};
const delDataFun = (index: any) => {
tableData.value.splice(index, 1);
emit('update:value', tableData.value);
};
const delHeadFun = (index: any) => {
headData.value.splice(index, 1);
};
const saveFun = () => {
emit('update:head', headData.value);
closeFun();
};
const removeFun = () => {
emit('del');
};
const closeFun = () => {
diaShow.value = false;
};
</script>
<style lang="scss" scoped>
.table-content {
position: relative;
border-radius: 4px;
padding: 20px 10px 10px;
border: solid 1px var(--el-border-color);
.title-item {
background-color: var(--el-bg-color);
color: var(--el-text-color-placeholder);
text-align: center;
padding-top: 10px;
}
}
.add-column {
width: 30px;
height: 30px;
margin: 5px auto 0;
background-color: var(--el-color-primary);
color: #fff;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
</style>