|
@@ -72,46 +72,53 @@
|
|
|
</div>
|
|
|
</ContentWrap>
|
|
|
|
|
|
- <ContentWrap>
|
|
|
- <el-table
|
|
|
- ref="tableRef"
|
|
|
- v-loading="loading"
|
|
|
- :data="list"
|
|
|
- :stripe="true"
|
|
|
- :show-overflow-tooltip="true"
|
|
|
- @row-click="handleRowClick">
|
|
|
- <el-table-column width="80" :label="t('workOrderMaterial.select')">
|
|
|
- <template #default="{ row }">
|
|
|
- <el-checkbox
|
|
|
- :model-value="selectedRows.some(item => item.id === row.id)"
|
|
|
- @click.stop="selectRow(row)"
|
|
|
- class="no-label-radio"
|
|
|
- />
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column :label="t('workOrderMaterial.materialName')" align="center" prop="name" />
|
|
|
- <el-table-column :label="t('workOrderMaterial.materialCode')" align="center" prop="code" />
|
|
|
- <el-table-column :label="t('workOrderMaterial.unit')" align="center" prop="unit" />
|
|
|
- <el-table-column :label="t('route.quantity')" align="center" prop="quantity">
|
|
|
- <template #default="scope">
|
|
|
- <el-input
|
|
|
- type="number"
|
|
|
- :controls="false"
|
|
|
- v-model="scope.row.quantity"
|
|
|
- @click.stop=""
|
|
|
- @focus="handleInputFocus(scope.row)"
|
|
|
- @blur="(event) => handleQuantityBlur(event, scope.row)"
|
|
|
- />
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column
|
|
|
- :label="t('deviceList.createTime')"
|
|
|
- align="center"
|
|
|
- prop="createTime"
|
|
|
- width="180"
|
|
|
- :formatter="dateFormatter"
|
|
|
- />
|
|
|
- </el-table>
|
|
|
+ <ContentWrap class="table-content-wrap">
|
|
|
+ <div class="flex-table-container">
|
|
|
+ <el-table
|
|
|
+ ref="tableRef"
|
|
|
+ v-loading="loading"
|
|
|
+ :data="list"
|
|
|
+ :stripe="true"
|
|
|
+ :row-key="rowKey"
|
|
|
+ :show-overflow-tooltip="true"
|
|
|
+ table-layout="auto"
|
|
|
+ @row-click="handleRowClick"
|
|
|
+ class="full-width-table" >
|
|
|
+ <el-table-column :label="t('workOrderMaterial.select')" class-name="select-column" min-width="30">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <el-checkbox
|
|
|
+ :model-value="selectedRows.some(item => item.id === row.id)"
|
|
|
+ @click.stop="selectRow(row)"
|
|
|
+ class="no-label-radio"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column :label="t('workOrderMaterial.materialName')" align="center" prop="name"
|
|
|
+ class-name="name-column" min-width="180"/>
|
|
|
+ <el-table-column :label="t('workOrderMaterial.materialCode')" align="center" prop="code" min-width="130"/>
|
|
|
+ <el-table-column :label="t('workOrderMaterial.unit')" align="center" prop="unit" min-width="50"/>
|
|
|
+ <el-table-column :label="t('route.quantity')" align="center" prop="quantity" min-width="80" class-name="quantity-column">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-input
|
|
|
+ type="number"
|
|
|
+ :controls="false"
|
|
|
+ v-model="scope.row.quantity"
|
|
|
+ @click.stop=""
|
|
|
+ @focus="handleInputFocus(scope.row)"
|
|
|
+ @blur="(event) => handleQuantityBlur(event, scope.row)"
|
|
|
+ class="quantity-input"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column
|
|
|
+ :label="t('deviceList.createTime')"
|
|
|
+ align="center"
|
|
|
+ prop="createTime"
|
|
|
+ min-width="100"
|
|
|
+ :formatter="dateFormatter"
|
|
|
+ />
|
|
|
+ </el-table>
|
|
|
+ </div>
|
|
|
<!-- 分页 -->
|
|
|
<Pagination
|
|
|
:total="total"
|
|
@@ -120,6 +127,7 @@
|
|
|
@pagination="getList"
|
|
|
/>
|
|
|
</ContentWrap>
|
|
|
+
|
|
|
</Dialog>
|
|
|
</template>
|
|
|
|
|
@@ -147,7 +155,7 @@ const queryFormRef = ref() // 搜索的表单
|
|
|
const list = ref<MaterialApi.MaterialVO[]>([]) // 列表的数据
|
|
|
const total = ref(0) // 列表的总页数
|
|
|
const selectedRows = ref<MaterialApi.MaterialVO[]>([]); // 多选数据(存储所有选中行的数组)
|
|
|
-const tableRef = ref();
|
|
|
+const tableRef = ref<InstanceType<typeof ElTable>>();
|
|
|
|
|
|
const deviceCategoryName = ref('') // 存储设备分类名称
|
|
|
const bomNodeName = ref('') // 存储BOM节点名称
|
|
@@ -172,6 +180,13 @@ const updateSelectedRowQuantity = (row: MaterialApi.MaterialVO) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+const adjustColumnWidths = () => {
|
|
|
+ nextTick(() => {
|
|
|
+ if (tableRef.value) {
|
|
|
+ tableRef.value.doLayout();
|
|
|
+ }
|
|
|
+ });
|
|
|
+};
|
|
|
|
|
|
// 处理单选逻辑
|
|
|
const selectRow = (row) => {
|
|
@@ -214,6 +229,9 @@ const getList = async () => {
|
|
|
row.quantity = selectedItem.quantity;
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ // 数据加载后自动调整列宽
|
|
|
+ adjustColumnWidths();
|
|
|
} finally {
|
|
|
loading.value = false
|
|
|
}
|
|
@@ -276,6 +294,44 @@ const handleInputFocus = (row: MaterialApi.MaterialVO) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 计算列宽
|
|
|
+const flexColumnWidth = (prop: string, label: string, data: any[]) => {
|
|
|
+ if (!data || !data.length) return 'auto';
|
|
|
+
|
|
|
+ const contentWidths = data.map(item => {
|
|
|
+ const value = prop && item[prop] ? String(item[prop]) : '';
|
|
|
+ return getTextWidth(value);
|
|
|
+ });
|
|
|
+
|
|
|
+ const labelWidth = getTextWidth(label);
|
|
|
+ const maxContentWidth = Math.max(...contentWidths);
|
|
|
+ const maxWidth = Math.max(labelWidth, maxContentWidth);
|
|
|
+
|
|
|
+ return Math.min(Math.max(maxWidth + 10, 120), 600) + 'px'; // 10px内边距,120px最小宽度
|
|
|
+};
|
|
|
+
|
|
|
+// 获取文本宽度
|
|
|
+const getTextWidth = (text: string) => {
|
|
|
+ if (!text) return 0;
|
|
|
+
|
|
|
+ const span = document.createElement('span');
|
|
|
+ span.style.visibility = 'hidden';
|
|
|
+ span.style.position = 'absolute';
|
|
|
+ span.style.whiteSpace = 'nowrap';
|
|
|
+ span.style.font = '14px Microsoft YaHei'; // 匹配表格字体
|
|
|
+ span.textContent = text;
|
|
|
+ document.body.appendChild(span);
|
|
|
+
|
|
|
+ const width = span.offsetWidth;
|
|
|
+ document.body.removeChild(span);
|
|
|
+ return width;
|
|
|
+};
|
|
|
+
|
|
|
+// 生成行唯一标识
|
|
|
+const rowKey = (row: any) => {
|
|
|
+ return `${row.id}-${Date.now()}`; // 确保行更新时重新渲染
|
|
|
+};
|
|
|
+
|
|
|
// 确认选择
|
|
|
const handleConfirm = () => {
|
|
|
// 同步当前页所有选中行的最新数量
|
|
@@ -320,6 +376,12 @@ onMounted(async () => {
|
|
|
materialGroupList.value = handleTree(await MaterialGroupApi.getSimpleMaterialGroupList())
|
|
|
await getList()
|
|
|
})
|
|
|
+
|
|
|
+// 清除事件监听
|
|
|
+onUnmounted(() => {
|
|
|
+ window.removeEventListener('resize', adjustColumnWidths);
|
|
|
+});
|
|
|
+
|
|
|
</script>
|
|
|
<style lang="scss" scoped>
|
|
|
.no-label-radio .el-radio__label {
|
|
@@ -329,6 +391,54 @@ onMounted(async () => {
|
|
|
margin-right: 0;
|
|
|
}
|
|
|
|
|
|
+.table-content-wrap {
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ flex: 1;
|
|
|
+ min-height: 300px; // 确保有最小高度
|
|
|
+}
|
|
|
+
|
|
|
+.flex-table-container {
|
|
|
+ flex: 1;
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ overflow: hidden;
|
|
|
+
|
|
|
+ // 确保表格填满容器
|
|
|
+ .full-width-table {
|
|
|
+ width: 100%;
|
|
|
+ flex: 1;
|
|
|
+
|
|
|
+ // 让表格头与内容同步宽度
|
|
|
+ :deep(.el-table__header) {
|
|
|
+ width: 100% !important;
|
|
|
+ }
|
|
|
+
|
|
|
+ :deep(.el-table__body) {
|
|
|
+ width: 100% !important;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 名称列:优先分配剩余空间
|
|
|
+:deep(.name-column) {
|
|
|
+ flex-grow: 1 !important;
|
|
|
+ min-width: 180px;
|
|
|
+
|
|
|
+ .cell {
|
|
|
+ white-space: nowrap;
|
|
|
+ overflow: hidden;
|
|
|
+ text-overflow: ellipsis;
|
|
|
+ max-width: 100%;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/* 新增表格容器样式 */
|
|
|
+.table-container {
|
|
|
+ width: 100%;
|
|
|
+ overflow-x: auto;
|
|
|
+}
|
|
|
+
|
|
|
/* 自定义淡绿色按钮 */
|
|
|
:deep(.custom-green-button) {
|
|
|
background-color: #e1f3d8;
|
|
@@ -349,7 +459,7 @@ onMounted(async () => {
|
|
|
border-color: #c2dca8;
|
|
|
}
|
|
|
|
|
|
-// 新增标签样式
|
|
|
+// 标签样式
|
|
|
.close-icon {
|
|
|
cursor: pointer;
|
|
|
color: #999;
|
|
@@ -370,4 +480,9 @@ onMounted(async () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/* 调整输入框宽度 */
|
|
|
+:deep(.el-input) {
|
|
|
+ width: 95% !important; /* 保留5%空间避免溢出 */
|
|
|
+}
|
|
|
+
|
|
|
</style>
|