Newer
Older
xc-business-system / src / views / business / taskMeasure / measureData / components / thirteenth / templateTable.vue
dutingting on 5 Mar 11 KB 暂存
<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'
import { mergeTableRow } from '@/commonMethods/useMergeTableRow'

// ------------------定义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 standardVoltageList = ref<dictType[]>([]) // 电压单位
const standardTimeUnitList = ref<dictType[]>([]) // 时间单位

/**
 * 获取字典
 */
function getDict() {
  // 电压单位--公用/垂直偏转系数(/div)单位
  getDictByCode('standardVoltage').then((response) => {
    standardVoltageList.value = response.data
  })
  // 时间单位
  getDictByCode('standardTimeUnit').then((response) => {
    standardTimeUnitList.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 selectionChange(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 handleSelectionChange = (val: any) => {
  emit('multiSelect', val)
}
// 清除多选选中
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%;"
    :span-method="mergeTableRow"
    @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">
        <precision-input-number
          v-if="pageType !== 'detail' && (item.value === 'timeBaseAbsoluteError' || item.value === 'referenceAmplitude' || item.value === 'measureAmplitude')"
          v-model="scope.row[item.value]"
          :placeholder="pageType === 'detail' ? '' : `${item.text}`"
          :disabled="pageType === 'detail'"
          class="full-width-input"
        />
        <!-- 顶部测量值、底部测量值 -->
        <div v-if="props.type === '校准信号(数字示波器)' && ((item.value === 'topMeasureValue' && scope.row.itemType === '幅度') || (item.value === 'bottomMeasureValue' && scope.row.itemType === '幅度'))" style="display: flex;justify-content: center;align-items: center;">
          <precision-input-number
            v-if="pageType !== 'detail'"
            v-model="scope.row[item.value]"
            :placeholder="pageType === 'detail' ? '' : `${item.text}`"
            :disabled="pageType === 'detail'"
            class="full-width-input"
          />
          <span v-if="pageType === 'detail'">{{ scope.row[item.value] }}</span>
          <!-- 标称值单位 -->
          <div :class="pageType === 'detail' ? 'unit-class' : 'unit-class-margin-left' ">
            {{ scope.row.nominalValueUnit }}
          </div>
        </div>

        <!-- 带单位number -->
        <div v-if="((item.value === 'measureValue' && scope.row.itemType !== '幅度') || item.value === 'outputSignalAmplitude' || item.value === 'nominalValue' || item.value === 'riseTime' || item.value === 'measureAmplitudeValue' || item.value === 'measureFrequencyValue' || item.value === 'amplitude')" style="display: flex;justify-content: center;align-items: center;">
          <precision-input-number
            v-if="pageType !== 'detail'"
            v-model="scope.row[item.value]"
            :placeholder="pageType === 'detail' ? '' : `${item.text}`"
            :disabled="pageType === 'detail'"
            class="full-width-input"
            :precision="scope.row.standardValueUnit === 'V' ? 3 : scope.row.standardValueUnit === 'mV' ? 2 : (props.type === '输入电阻(模拟示波器)' || props.type === '输入电阻(数字示波器)') ? 4 : undefined"
          />
          <span v-if="pageType === 'detail'">{{ scope.row[item.value] }}</span>
          <!-- 标准值单位 -->
          <div v-if="props.type !== '触发灵敏度' && props.type !== '垂直幅度' && props.type !== '频带宽度'" :class="pageType === 'detail' ? 'unit-class' : 'unit-class-margin-left' ">
            {{ scope.row.standardValueUnit }}
          </div>
          <!-- 标称值单位 -->
          <div v-if="props.type === '触发灵敏度' || props.type === '输入电阻(数字示波器)' || props.type === '校准信号(数字示波器)' || (props.type === '扫描时间系数及扩展' && item.value === 'nominalValue')" :class="pageType === 'detail' ? 'unit-class' : 'unit-class-margin-left' ">
            {{ scope.row.nominalValueUnit }}
          </div>
          <!-- 水平刻度单位 -->
          <div v-if="props.type === '扫描时间系数及扩展' && item.value !== 'nominalValue'" :class="pageType === 'detail' ? 'unit-class' : 'unit-class-margin-left'">
            {{ scope.row.horizontalScaleGearUnit }}
          </div>
          <!-- 处置刻度档位单位 -->
          <div v-if="props.type === '垂直幅度'" :class="pageType === 'detail' ? 'unit-class' : 'unit-class-margin-left'">
            {{ scope.row.verticalScaleGearUnit || (item.value === 'measureValue' && scope.row.measureValueUnit) }}
          </div>
          <!-- 技术指标的单位 -->
          <div v-if="props.type === '频带宽度(模拟示波器)'" :class="pageType === 'detail' ? 'unit-class' : 'unit-class-margin-left'">
            {{ scope.row.technicalIndexUnit || (item.value === 'measureValue' && scope.row.measureValueUnit) }}
          </div>
          <div v-if="props.type === '触发特性'" :class="pageType === 'detail' ? 'unit-class' : 'unit-class-margin-left'">
            {{ scope.row.technicalIndexUnit }}
          </div>
          <!-- 上升时间单位 -->
          <div v-if="props.type === '上升时间(模拟示波器)' && item.value === 'riseTime'" :class="pageType === 'detail' ? 'unit-class' : 'unit-class-margin-left'">
            ns
          </div>
          <!-- 幅度标称值单位 -->
          <div v-if="props.type === '校准信号(模拟示波器)'" :class="pageType === 'detail' ? 'unit-class' : 'unit-class-margin-left'">
            {{ scope.row.nominalAmplitudeValueUnit }}
          </div>
          <!-- 幅度单位 -->
          <div v-if="props.type === '上升时间(模拟示波器)' && item.value === 'nominalValue'" :class="pageType === 'detail' ? 'unit-class' : 'unit-class-margin-left'">
            {{ scope.row.amplitudeUnit || scope.row.nominalValueUnit }}
          </div>
          <!-- 阻抗单位 -->
          <div v-if="props.type === '输入电阻(模拟示波器)'" :class="pageType === 'detail' ? 'unit-class' : 'unit-class-margin-left'">
            {{ scope.row.impedanceUnit }}
          </div>
          <span
            v-if="scope.row.exceedMark === 1 && (props.type === '触发灵敏度' || props.type === '上升时间(数字示波器)'
              || props.type === '频带宽度(模拟示波器)' || props.type === '触发特性')" style="color: red;"
          > * </span>
        </div>

        <!-- 标准值--直流偏置 -->
        <div v-if="item.value === 'standardValue'" style="display: flex;justify-content: center;align-items: center;">
          <precision-input-number
            v-if="pageType !== 'detail'"
            v-model="scope.row[item.value]"
            :placeholder="pageType === 'detail' ? '' : `${item.text}`"
            :disabled="pageType === 'detail'"
            class="full-width-input"
          />
          <div :class="pageType === 'detail' ? 'unit-class' : 'unit-class-margin-left' ">
            {{ scope.row.standardValueUnit }}
          </div>
        </div>

        <!-- 电压单位(公用)  -->
        <el-select
          v-if="pageType !== 'detail' && (item.value === 'measureAmplitudeUnit' || item.value === 'referenceAmplitudeUnit')"
          v-model="scope.row[item.value]"
          :disabled="props.pageType === 'detail'"
          class="full-width-input"
        >
          <el-option v-for="item of standardVoltageList" :key="item.value" :label="item.name" :value="item.name" />
        </el-select>

        <!-- 时间 单位  -->
        <el-select
          v-if="pageType !== 'detail' && (props.type === '上升时间(数字示波器)' && item.value === 'measureValueUnit')"
          v-model="scope.row[item.value]"
          :disabled="props.pageType === 'detail'"
          class="full-width-input"
        >
          <el-option v-for="item of standardTimeUnitList" :key="item.value" :label="item.name" :value="item.name" />
        </el-select>

        <!-- 不在范围内标* -->
        <div
          v-if="item.value === 'timeBaseRelativeError' || (item.value === 'relativeError' && props.type !== '直流偏置') || item.value === 'errorValue'
            || item.value === 'decibelNumber' || item.value === 'correctRiseTime' || item.value === 'amplitudeDeviation'"
        >
          <span>{{ scope.row[item.value] }}</span>
          <span v-if="scope.row.exceedMark === 1" style="color: red;"> * </span>
        </div>
        <div
          v-if="item.value === 'frequencyDeviation'"
        >
          <span>{{ scope.row[item.value] }}</span>
          <span v-if="scope.row.exceedMarkOne === 1" style="color: red;"> * </span>
        </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;
  }
}

.unit-class {
  margin-left: 0;
  white-space: nowrap;
}

.unit-class-margin-left {
  margin-left: 10px;
  white-space: nowrap;
}
</style>

<style lang="scss">
.normal-table {
  .el-radio__label {
    display: none !important;
  }
}
</style>