<script lang="ts" setup name="NonthTemplateTable"> import type { Ref } from 'vue' import { ElTable } from 'element-plus' import { defineExpose, ref } from 'vue' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getDictByCode } from '@/api/system/dict' import type { dictType } from '@/global' // ------------------定义props、 emit------------------- const props = defineProps({ pageType: { type: String, default: 'detail', }, // 数据 data: { type: Array, default() { return [] }, }, // 表格高度 height: { type: Number, default() { return null }, }, // 数据列配置 columns: { type: Array<TableColumn>, default() { return () => [] }, }, // 表格大小 size: { type: String, default: 'default', }, // 表格大小,默认,small,mini等,与el-table条件相同 type: String, }) const emit = defineEmits(['change', 'selectionChange', 'rowClick', 'rowDbClick', 'multiSelect', 'filterChange']) // ------------------------------------------字典---------------------------------------------- // ------------------------------------------字典---------------------------------------------- const standardTechnicalIndexSymbolList = ref<dictType[]>([]) // 技术指标规则 const standardAmplitudeUnitList = ref<dictType[]>([]) // 幅度单位 const standardFrequencyUnitList = ref<dictType[]>([]) // 频率单位-公用 const standard10HarmonicNumberList = ref<dictType[]>([]) // 谐波次数 /** * 获取字典 */ function getDict() { // 技术指标规则 getDictByCode('standardTechnicalIndexSymbol').then((response) => { standardTechnicalIndexSymbolList.value = response.data }) // 幅度单位 getDictByCode('standardAmplitudeUnit').then((response) => { standardAmplitudeUnitList.value = response.data }) // 频率单位公用 getDictByCode('standardFrequencyUnit').then((response) => { standardFrequencyUnitList.value = response.data }) // 谐波次数 getDictByCode('standard10HarmonicNumber').then((response) => { standard10HarmonicNumberList.value = response.data }) } getDict() // -------定义数据-------------- interface columnsCheckInfo { text: string show: boolean } const columnsChecked: Ref<columnsCheckInfo[]> = ref([]) const table = ref<InstanceType<typeof ElTable>>() const singleChecked = ref('') // 单选选中id // 初始化列显示状态 function initColumnsState() { columnsChecked.value = [] for (const column of props.columns) { columnsChecked.value.push({ text: column.text, show: !!column.show }) } } // 最终展示列 const columnsFiltered: Ref<TableColumn[]> = ref([]) // 切换列 function changeColumns() { columnsFiltered.value = [] for (const i in props.columns) { if (columnsChecked.value[i].show === true) { columnsFiltered.value.push(props.columns[i]) } } } // 刷新 function refresh() { emit('change') } // 多选选中结果 function handleSelectionChange(selection: []) { emit('selectionChange', selection) } // 点击行 function rowClick(row: object, column?: any, event?: any) { emit('rowClick', row) } // 双击行 function rowDbClick(row: object, column?: any, event?: any) { emit('rowDbClick', row) } // 监听columns watch(props.columns, (val) => { initColumnsState() changeColumns() }) // 清除多选选中 const clearMulti = () => { console.log('清理选中') table.value!.clearSelection() singleChecked.value = '' } defineExpose({ clearMulti, initColumnsState, }) onBeforeMount(() => { initColumnsState() changeColumns() }) </script> <template> <el-table id="print" ref="table" :data="data" :height="height" border stripe :size="size" style="width: 100%;" @selection-change="handleSelectionChange" @row-click="rowClick" @row-dblclick="rowDbClick" > <el-table-column v-if="pageType !== 'detail'" type="selection" width="38" /> <el-table-column align="center" label="序号" width="80" type="index" /> <el-table-column v-for="item in columns" :key="item.value" :prop="item.value" :label="item.text" :width="item.width" align="center" > <template #header> <span v-show="item.required" style="color: red;">*</span><span>{{ item.text }}</span> </template> <template #default="scope"> <!-- number --> <el-input-number v-if="(item.value === 'nominalValue' && props.type !== '功率' && props.type !== '调幅深度' && props.type !== '调频频偏') || item.value === 'amplitude' || item.value === 'urel' || item.value === 'modulationRate' || (item.value === 'frequency' && (props.type === '谐波' || props.type === '非谐波')) || item.value === 'rbwValue' || item.value === 'vbwValue' || item.value === 'power' || item.value === 'offsetFrequency'" v-model="scope.row[item.value]" :placeholder="`${item.text}`" class="full-width-input" :disabled="props.pageType === 'detail'" /> <!-- 频率 单位--公用 --> <el-select v-if="item.value === 'frequencyUnit' || (item.value === 'unit' && props.type === '频率') || item.value === 'highPassFilterUnit' || item.value === 'lowerPassFilterUnit' || item.value === 'modulationRateUnit' || (item.value === 'unit' && props.type === '调频频偏') || item.value === 'rbwValueUnit' || item.value === 'vbwValueUnit' || item.value === 'offsetFrequencyUnit'" v-model="scope.row[item.value]" :disabled="props.pageType === 'detail'" class="full-width-input" > <el-option v-for="item of standardFrequencyUnitList" :key="item.value" :label="item.name" :value="item.name" /> </el-select> <!-- 幅度单位 --> <el-select v-if="item.value === 'amplitudeUnit' || (item.value === 'unit' && props.type === '功率') || item.value === 'powerUnit'" v-model="scope.row[item.value]" :placeholder="`${item.text}`" :disabled="props.pageType === 'detail'" class="full-width-input" > <el-option v-for="item of standardAmplitudeUnitList" :key="item.value" :label="item.name" :value="item.name" /> </el-select> <!-- 功率--频率 --> <select-by-dict v-if="item.value === 'frequency' && props.type !== '谐波' && props.type !== '非谐波'" v-model:model-value="scope.row[item.value]" placeholder="频率" dict-code="standard10PowerFrequency" :disabled="props.pageType === 'detail'" /> <!-- 功率--标称值 --> <select-by-dict v-if="item.value === 'nominalValue' && props.type === '功率'" v-model:model-value="scope.row[item.value]" placeholder="标称值" dict-code="standard10PowerNominalValue" :disabled="props.pageType === 'detail'" /> <!-- 调幅深度--标称值 --> <select-by-dict v-if="item.value === 'nominalValue' && props.type === '调幅深度'" v-model:model-value="scope.row[item.value]" placeholder="标称值" dict-code="standard10DepthNominalValue" :disabled="props.pageType === 'detail'" /> <!-- 高通滤波 --> <select-by-dict v-if="item.value === 'highPassFilter'" v-model:model-value="scope.row[item.value]" placeholder="高通滤波" dict-code="standard10HighPassFilter" :disabled="props.pageType === 'detail'" /> <!-- 低通滤波 --> <select-by-dict v-if="item.value === 'lowerPassFilter'" v-model:model-value="scope.row[item.value]" placeholder="高通滤波" dict-code="standard10LowerPassFilter" :disabled="props.pageType === 'detail'" /> <!-- 调频频偏--标称值 --> <select-by-dict v-if="item.value === 'nominalValue' && props.type === '调频频偏'" v-model:model-value="scope.row[item.value]" placeholder="标称值" dict-code="standard10FrequencyNominalValue" :disabled="props.pageType === 'detail'" /> <!-- 谐波次数 --> <el-select v-if="item.value === 'harmonicNumber'" v-model="scope.row[item.value]" :placeholder="`${item.text}`" :disabled="props.pageType === 'detail'" class="full-width-input" > <el-option v-for="item of standard10HarmonicNumberList" :key="item.value" :label="item.name" :value="item.name" /> </el-select> <!-- 指标上限 --> <div v-if="item.value === 'upperIndex'" style="display: flex;align-items: center;"> <el-select v-model="scope.row.upperIndexSymbol" :disabled="props.pageType === 'detail'" style="margin-right: 10px;width: 100px;" > <el-option v-for="item of standardTechnicalIndexSymbolList" :key="item.value" :label="item.name" :value="item.name" /> </el-select> <el-input-number v-model="scope.row[item.value]" :placeholder="`${item.text}`" class="full-width-input" controls-position="right" :disabled="props.pageType === 'detail'" /> <div v-if="props.type === '剩余调幅' || props.type === '非谐波' || props.type === '谐波' || props.type === '调幅深度' || props.type === '调频频偏' || props.type === '调相相偏'" style="margin-left: 10px; white-space: nowrap;" > {{ scope.row.upperIndexUnit }} </div> <!-- 频率 单位 --> <el-select v-if="props.type === '剩余调频'" v-model="scope.row.upperIndexUnit" :disabled="props.pageType === 'detail'" style="margin-left: 10px;width: 140px;" > <el-option v-for="item of standardFrequencyUnitList" :key="item.value" :label="item.name" :value="item.name" /> </el-select> </div> <!-- 技术指标 --> <div v-if="item.value === 'technicalIndex'" style="display: flex;align-items: center;"> <el-select v-model="scope.row.technicalIndexSymbol" :disabled="props.pageType === 'detail' || props.type === '频率' || props.type === '功率' || props.type === '调幅深度' || props.type === '调频频偏' || props.type === '调相相偏'" style="margin-right: 10px;width: 100px;" > <el-option v-for="item of standardTechnicalIndexSymbolList" :key="item.value" :label="item.name" :value="item.name" /> </el-select> <el-input-number v-model="scope.row[item.value]" :placeholder="`${item.text}`" class="full-width-input" controls-position="right" :disabled="props.pageType === 'detail'" /> <div v-if="props.type === '功率' || props.type === '调幅深度' || props.type === '调相相偏'" style="margin-left: 10px; white-space: nowrap;" > {{ scope.row.technicalIndexUnit }} </div> <!-- 频率 单位 --> <el-select v-if="props.type === '频率' || props.type === '调频频偏'" v-model="scope.row.technicalIndexUnit" :disabled="props.pageType === 'detail'" style="margin-left: 10px;width: 140px;" > <el-option v-for="item of standardFrequencyUnitList" :key="item.value" :label="item.name" :value="item.name" /> </el-select> </div> </template> </el-table-column> </el-table> </template> <style lang="scss" scoped> .single-table { width: 100%; :deep(.el-table th.el-table__cell:nth-child(1) .cell) { visibility: hidden; } } </style> <style lang="scss"> .normal-table { .el-radio__label { display: none !important; } } </style>