grid cell 包含toobarbutton显示错乱bug的临时解决办法

错乱效果修复
本文介绍了一个表格布局中出现的错乱效果及其临时解决方案。通过调整工具栏按钮的宽度,可以有效解决错乱问题,实现良好的视觉呈现。

错乱效果

 

 

测试代码

 

 

<grid>
		<columns>
			<column label="时间" width="85px" align="center"></column>
			<column label="任务" align="center"></column>
			<column label="进度" align="center"></column>
			<column label="操作" align="center"></column>
		</columns>
		<rows>
			<row>
				<cell>2011-01-23 10:10:10</cell>
				<cell width="200px" align="left">test234234234234324</cell>
				<cell>
					<progressmeter value="69" width="100%"></progressmeter>
				</cell>
				<cell>
					<toolbarbutton label="上移"></toolbarbutton>
				</cell>
			</row>
		</rows>
	</grid>

 

 

临时解决办法:给toolbarbutton设置宽度 <toolbarbutton label="上移"  width="40px"></toolbarbutton>

 

效果

 

 

 

 

 

 

 

<template> <div> <title>{{$route.name}}</title> <h1>{{$route.name}}</h1> <aui-form id="editForm"> <div class="first-field" :class="isShowMore?'showMore':'hideMore'"> <aui-form-item label="版本号" label-width="110px"> <aui-dropdown size="small" v-model="searchForm.planId" :op="planIdOp" place-holder="请选择"></aui-dropdown> </aui-form-item> <aui-form-item label="厂区" label-width="110px"> <aui-dropdown size="small" v-model="searchForm.locationCodeStr" :op="siteCodeOp" place-holder="请选择"></aui-dropdown> </aui-form-item> <aui-form-item label="部门" label-width="110px"> <aui-dropdown size="small" ref="deptCodeRef" v-model="searchForm.deptNameStr" :op="deptOp" place-holder="请选择"></aui-dropdown> </aui-form-item> <aui-form-item label="工序" label-width="110px"> <aui-dropdown size="small" v-model="searchForm.workSerctionStr" :op="workSerctionOp"></aui-dropdown> </aui-form-item> <aui-form-item label="产品线" label-width="110px"> <aui-dropdown size="small" ref="prodLineCnNameRef" v-model="searchForm.prodLineCnNameStr" :op="prodLineOp" place-holder="请选择"></aui-dropdown> </aui-form-item> <aui-form-item label="产品族" label-width="110px"> <aui-dropdown size="small" ref="prodFamilyEnNameRef" v-model="searchForm.prodFamilyEnNameStr" :op="prodFamilyOp" place-holder="请选择"></aui-dropdown> </aui-form-item> <aui-form-item label="产品型号" label-width="110px"> <aui-dropdown size="small" ref="prodModelCodeRef" v-model="searchForm.prodModelCodeStr" :op="prodModelCodeOp" place-holder="请选择"></aui-dropdown> </aui-form-item> <aui-form-item label="物料编码" label-width="110px"> <aui-input size="small" ref="itemCodeRef" v-model="searchForm.itemCodeStr" placeholder="连续首字母或者字符可模糊匹配"></aui-input> </aui-form-item> <aui-form-item label="类型" label-width="110px"> <aui-dropdown size="small" v-model="searchForm.dataTypeStr" :op="dataTypeOp" place-holder="请选择"></aui-dropdown> </aui-form-item> <aui-form-item class="first-field-btn" label-width="0px" style="width: 265px"> <i v-show="isTriangleIconShow" class="hae-icon" :class="isShowMore?'icon-down':'icon-left-o'" @click="isShowMore = !isShowMore "></i> <aui-button type="primary" size="mini" round @click="findClick">查询</aui-button> <aui-button type="primary" size="mini" round @click="reset" style="margin-right: 8px">重置</aui-button> <FormTempBtn style="width:100px;" :form-code="formId" :formData="searchForm" @templateChanged="setFormData"></FormTempBtn> </aui-form-item> </div> </aui-form> <div class="table-auto"> <aui-grid height="100%" auto-resize ref="grid" :auto-load="false" resizable :row-class-name="rowClassName" :pager="pagerConfig" border :span-method="colspanMethod" :fetch-data="fetchData"> <template #toolbar> <aui-grid-toolbar id="scheduleSupplyDemandGridId" :setting="{ showIndex: true, sortable: Sortable, }" ref="auiToolbar" @remote-setting="remoteSetting" @save-setting="saveSetting"> <template #buttons> <div style="width: 800px; display: inline-block"> <aui-button size="mini" @click="exportData">导出</aui-button> <aui-button size="mini" @click="showBaseLoggerInfo">版本日志</aui-button> </div> </template> </aui-grid-toolbar> </template> <aui-grid-column fixed="left" title="版本" field="planId" min-width="100" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="厂区" field="locationName" min-width="100" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="部门" field="deptName" min-width="120" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="产品线" field="prodLineCnName" min-width="80" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="产品族" field="prodFamilyEnName" min-width="80" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="产品型号" field="prodModelCode" min-width="80" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="工序" field="workSerction" min-width="80" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="物料编码" field="itemCode" min-width="90" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="类型" field="dataType" min-width="80" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="库存" field="invQty" min-width="80" show-overflow header-align="center" align="center"> <template #default="{ row }"> <div style="color: #189ff0 !important;cursor: pointer;text-decoration: underline;" @click="operateRow(row, 'invQty')">{{ row.invQty }}</div> </template> </aui-grid-column> <aui-grid-column fixed="left" title="历史" field="hisQty" min-width="100" show-overflow header-align="center" align="center"> <template #default="{ row }"> <div :class="{ 'row-link_click': ['预计供应', '过站供应', '排产需求'].includes(row.dataType), 'row-link-red': String(row.hisQty) && row.hisQty < 0 }" @click="operateRow(row, 'hisQty')">{{ row.hisQty }}</div> </template> </aui-grid-column> <aui-grid-column v-for="(item, i) in dateItem" :key="i" :field="item.field" :title="item.title" :renderer="renderFunction" min-width="50" align="center"> <template #default="{ row }"> <a v-if="row.dataType === '排产'" :style="{ textDecoration: 'underline', cursor: 'pointer' }" @click="planCellClick(row, item.field)">{{ row[item.field] }} </a> <a v-else-if="row.dataType === '排产需求'" :style="{ textDecoration: 'underline', cursor: 'pointer' }" @click="handleDateCellClick(row, item.field)">{{ row[item.field] }} </a> <template v-else> {{ row[item.field] }} </template> </template> </aui-grid-column> </aui-grid> </div> <StockDialog v-if="showStock" :rowData="rowData" @changeDialog="changeDialog"></StockDialog> <InProcessWorkOrderSchedule v-if="showInProcess" :rowData="rowData" @changeDialog="changeDialog" :dateItem="dateItem"></InProcessWorkOrderSchedule> <WorkOrderScheduleHistory v-if="showHistory" :rowData="rowData" @changeDialog="changeDialog" :dateItem="dateItem"></WorkOrderScheduleHistory> <WorkOrdel v-if="showPlan" :rowData="rowData" @changeDialog="changeDialog" :dateItem="dateItem"></WorkOrdel> <aui-dialog-box title="版本日志" class="history-Info" v-model="isShowBaseLoggerInfo" width="90%" top="8%" :dragable="true" :modal-closable="false"> <base-logger-info v-bind:apiUrl="getLoggerInfoUrl" v-if="isShowBaseLoggerInfo"></base-logger-info> </aui-dialog-box> </div> </template> <script> import { Form, FormItem, Dropdown, Hae, $, DialogBox } from '@aurora/ui3' import { Grid, GridColumn, Modal, Pager, Button, GridToolbar } from '@aurora/vue3' import { FormTempBtn } from '@mxdesign/ui' import Sortable from 'sortablejs' import { remoteSettingFn, saveSettingFn, getCustomConfigsFn } from '@/utils/personSettings' import StockDialog from '@/components/supplydemandmgt/StockDialog' import InProcessWorkOrderSchedule from '@/components/supplydemandmgt/InProcessWorkOrderSchedule' import WorkOrderScheduleHistory from '@/components/supplydemandmgt/WorkOrderScheduleHistory' import BaseLoggerInfo from '../basedata/BaseLoggerInfo.vue' import WorkOrdel from '@/components/supplydemandmgt/WorkOrdel' export default { components: { AuiDialogBox: DialogBox, AuiButton: Button, AuiForm: Form, AuiFormItem: FormItem, AuiDropdown: Dropdown, AuiGrid: Grid, AuiGridColumn: GridColumn, AuiGridToolbar: GridToolbar, FormTempBtn, StockDialog, InProcessWorkOrderSchedule, WorkOrderScheduleHistory, BaseLoggerInfo, WorkOrdel }, computed: { tableData() { return this.$refs.grid && this.$refs.grid.getTableData() ? this.$refs.grid.getTableData().tableData : [] } }, data() { return { Sortable, isShowBaseLoggerInfo: false, getLoggerInfoUrl: 'services/supplyRequireItemHeadService/getSupplyRequireLogList/page/{{pageSize}}/{{curPage}}', formId: 'scheduleSupplyDemandId', toolBoxShow: false, isShowMore: true, isTriangleIconShow: true, searchForm: { planId: '', // 版本号 locationCodeStr: '', // 厂区 deptNameStr: '', // 部门 prodLineCnNameStr: '', // 产品线 prodFamilyEnNameStr: '', // 产品族 prodModelCodeStr: '', // 产品型号 workSerctionStr: '', // 工序 itemCodeStr: '', // 编码 dataTypeStr: '' // 类型 }, // 版本号 planIdOp: { multi: false, showClearBtn: true, autoSelect: false, alwaysLoad: true, editable: true, id: 'planId', validation: { required: true }, textField: 'planId', valueField: 'planId', placeHolder: '-----请选择-----', dataset: { source: { type: 'post', url: 'services/apsSupplyRequireService/getAllPlanIdList' } } }, // 厂区 siteCodeOp: { multi: true, id: 'locationCodeId', showClearBtn: true, autoSelect: false, alwaysLoad: true, editable: true, textField: 'locationName', valueField: 'locationCode', placeHolder: '-----请选择-----', emptyDataMsg: '-----没有数据-----', dataset: { source: { type: 'post', url: 'services/apsSupplyRequireService/getAllLocationInfo' } } }, // 部门 deptOp: { multi: true, // 是否多选 id: 'deptCodeId', showClearBtn: true, autoSelect: false, alwaysLoad: true, editable: true, textField: 'deptName', valueField: 'deptName', placeHolder: '-----请选择-----', emptyDataMsg: '-----请选择厂区-----', dataset: { source: { type: 'POST', url: 'services/apsSupplyRequireService/getDeptInfo' } }, cascade: [ { trigger: '#locationCodeId', allowEmpty: false, // 是否允许空值参加级联 name: 'locationCodeStr' } ] }, // 工序 workSerctionOp: { id: 'workSerctionId', multi: true, showClearBtn: true, autoSelect: false, alwaysLoad: true, editable: true, placeHolder: '-----请选择-----', textField: 'valueInfo', valueField: 'valueInfo', dataset: { source: { type: 'post', url: 'services/apsSupplyRequireService/getAllWorkSerction' } } }, // 产品线 prodLineOp: { multi: true, id: 'prodLineId', showClearBtn: true, autoSelect: false, alwaysLoad: true, editable: true, textField: 'prodLineCnName', valueField: 'prodLineCnName', placeHolder: '-----请选择-----', dataset: { source: { type: 'post', url: 'services/apsSupplyRequireService/getProdLineList' } } }, // 产品族(系列) prodFamilyOp: { multi: true, id: 'prodFamilyId', showClearBtn: true, autoSelect: false, alwaysLoad: true, editable: true, textField: 'prodSeriesEnName', valueField: 'prodSeriesEnName', placeHolder: '-----请选择-----', dataset: { source: { type: 'post', url: 'services/apsSupplyRequireService/getProdSeriesList' } }, cascade: [ { trigger: '#prodLineId', allowEmpty: true, // 是否允许空值参加级联 name: 'prodLineCnNameStr' } ], emptyDataMsg: '-----请选择产品线-----' }, // 产品型号 prodModelCodeOp: { multi: true, id: 'prodModelId', showClearBtn: true, autoSelect: false, alwaysLoad: true, editable: true, textField: 'prodModelCode', valueField: 'prodModelCode', placeHolder: '-----请选择-----', dataset: { source: { type: 'post', url: 'services/apsSupplyRequireService/getAllProdModelList' } }, cascade: [ { trigger: '#prodFamilyId', allowEmpty: false, name: 'prodSeriesEnNameStr' } ], emptyDataMsg: '-----请选择产品族-----' }, // 类型 dataTypeOp: { multi: true, id: 'dataTypeId', showClearBtn: true, autoSelect: false, editable: true, textField: 'label', valueField: 'value', placeHolder: '-----请选择-----', dataset: { value: [ { value: '排产', label: '排产' }, { value: '预计供应', label: '预计供应' }, { value: '过站供应', label: '过站供应' }, { value: '排产需求', label: '排产需求' }, { value: '供需匹配', label: '供需匹配' } ] } }, pageFlag: false, pagerConfig: { component: Pager, attrs: { currentPage: 1, pageSize: 15, pageSizes: [15, 30, 50, 100], total: 0, layout: 'total, sizes, prev, pager, next, jumper' } }, dateItem: [], fetchData: { api: this.getData }, clickSearchForm: {}, rowData: {}, showStock: false, showInProcess: false, showHistory: false, showPlan: false, settingType: 'scheduleSupplyDemand', setTableColumn: [] } }, methods: { showBaseLoggerInfo() { this.isShowBaseLoggerInfo = true }, // 导出 exportData() { let formData = this.searchForm Hae.ajax({ url: 'services/exportFileUtilService/exportApsSupplyRequire', data: formData, type: 'post', success: () => { Hae.confirm('导出任务已开始,你可以进入[我的导入导出>导出查询]中查看任务状态并下载导出文件!', (bool) => { if (bool) { window.open('#/ListExport') } }) } }) }, // 行合并 colspanMethod({ row, column, rowIndex, columnIndex }) { let fields = ['mergerKey', 'invQty'] // 获取当前行的 mergerKey const currentGroupKey = row.mergerKey // 获取当前列的 prop const columnProp = column.property // 计算相同 mergerKey 的行范围 const groupRows = this.tableData.filter((item) => item.mergerKey === currentGroupKey && currentGroupKey) const firstGroupRowIndex = this.tableData.findIndex( (item) => item.mergerKey === currentGroupKey && currentGroupKey ) const lastGroupRowIndex = firstGroupRowIndex + groupRows.length - 1 // 对于 fields 列,合并相同 mergerKey 的所有行 if (fields.includes(columnProp)) { if (rowIndex === firstGroupRowIndex) { return { rowspan: groupRows.length, colspan: 1 } } else { return { rowspan: 0, colspan: 0 } } } }, // 行渲染 renderFunction(h, { row, column }) { if (row.dataType === '排产需求'&& Number(row[column.property]) < 0) { return <span style={{ color: '#000', fontSize: '12px' }}>{row[column.property]}</span> } if (String(row[column.property]) && Number(row[column.property]) < 0) { return <span style={{ color: '#fe281f', fontSize: '12px' }}>{row[column.property]}</span> } else { return <span style={{ color: '#000', fontSize: '12px' }}>{row[column.property]}</span> } }, rowClassName({ seq, row, rowIndex, $rowIndex }) { if (row.dataType === '排产') { return 'row__word--remarked' } else { return '' } }, setFormData(data) { let tempArr = Object.keys(data) this.resData = data if (tempArr.length === 0) { return } this.searchForm.planId = data.planId // 版本号 this.searchForm.locationCodeStr = data.locationCodeStr // 厂区 this.searchForm.prodLineCnNameStr = data.prodLineCnNameStr // 产品线 this.searchForm.workSerctionStr = data.workSerctionStr // 工序 this.searchForm.dataTypeStr = data.dataTypeStr // 类型 // 级联关系接口先后执行 setTimeout(() => { this.$refs.deptCodeRef.widget.setValueByField(data.deptNameStr, 'deptName') // 注意: 第二个参数是下拉的value值,不是v-model的值 }, 500) setTimeout(() => { this.$refs.prodFamilyEnNameRef.widget.setValueByField(data.prodFamilyEnNameStr, 'prodSeriesEnName') }, 800) setTimeout(() => { this.$refs.prodModelCodeRef.widget.setValueByField(data.prodModelCodeStr, 'prodModelCode') }, 1500) setTimeout(() => { this.$refs.itemCodeRef.widget.setValueByField(data.itemCodeStr, 'prodItemCode') }, 2000) }, operateRow(row, flag) { this.rowData = row this.rowData.dialogFlag = flag if (flag === 'invQty') { this.showStock = true } else { if (['排产需求'].includes(row.dataType)) { this.showHistory = true } if (['预计供应', '过站供应'].includes(row.dataType)) { this.showInProcess = true } } }, handleDateCellClick(row, field) { this.rowData = { ...row, date: field, quantity: row[field] }; this.showHistory = true; }, planCellClick(row, field) { this.rowData = { ...row, date: field, quantity: row[field] }; this.showPlan=true; }, changeDialog() { this.rowData = {} this.showStock = false this.showHistory = false this.showPlan = false this.showInProcess = false }, reset() { // 清空选择 this.searchForm = { planId: '', // 版本号 locationCodeStr: '', // 厂区 deptNameStr: '', // 部门 prodLineCnNameStr: '', // 产品线 prodFamilyEnNameStr: '', // 产品族 prodModelCodeStr: '', // 产品型号 workSerctionStr: '', // 工序 itemCodeStr: '', // 编码 dataTypeStr: '' // 类型 } this.clickSearchForm = JSON.parse(JSON.stringify(this.searchForm)) }, // 动态日期列 columnDate() { this.dateItem = [] let params = { ...this.searchForm } this.$service.network.post('services/apsSupplyRequireService/getHeadBucketList', params).then(({ data }) => { this.pageFlag = false if (data && data.length) { data.forEach((element) => { // 将完整日期转换为月日格式 MM/DD const dateParts = element.split('-') const monthDay = dateParts.length >= 3 ? `${dateParts[1]}/${dateParts[2]}` : element this.dateItem.push({ title: monthDay, field: element }) }) } }) }, findClick() { Hae.validForm($('#editForm'), (valid) => { if (valid) { this.pageFlag = true this.getCustomConfigs() this.clickSearchForm = JSON.parse(JSON.stringify(this.searchForm)) setTimeout(() => { this.$refs.grid.handleFetch() }, 500) } }) }, // 查询 getData({ page }) { let { pageSize } = page if (this.pageFlag) { page.currentPage = 1 } let curPage = page.currentPage return new Promise((resolve, reject) => { let params = { ...this.clickSearchForm } this.$service.network .post(`services/apsSupplyRequireService/getApsSupplyRequireList/page/${pageSize}/${curPage}`, params) .then(({ data }) => { this.pageFlag = false this.isShowMore = false this.columnDate() let totalRows = data.pageVO && data.pageVO.totalRows ? data.pageVO.totalRows : 0 let result = data.result && data.result.length ? data.result : [] resolve({ result, page: { total: totalRows } }) }) }) }, getCustomConfigs() { let config = { settingType: this.settingType, grid: 'grid', auiToolbar: 'auiToolbar', setTableColumn: 'setTableColumn', dragSort: true } getCustomConfigsFn.call(this, config) }, remoteSetting(settings) { remoteSettingFn.call(this, settings, 'grid') }, saveSetting() { let customConfigs = arguments[0].columns let config = { settingType: this.settingType, customConfigs } saveSettingFn.call(this, config) } }, mounted() { let that = this // 判断是否有更多条件显示隐藏小三角 let editFormHeight = $('.first-field').outerHeight() that.isTriangleIconShow = !(editFormHeight < 38) that.isShowMore = false this.getCustomConfigs() } } </script> <style scoped src="./../unit/css/newModelPublic.css"></style> <style scoped> .first-field { padding-right: 300px !important; } :deep(.table-auto .aui-grid .aui-grid-cell) { width: 100% !important; font-size: 12px; } .table-auto { height: calc(100vh - 140px) !important; } :deep(.table-auto .aui-grid__body-wrapper) { height: calc(100vh - 280px) !important; } :deep(.aui-grid__body-wrapper::-webkit-scrollbar) { height: 12px !important; width: 12px !important; } :deep(.aui-grid__body .aui-grid-body__column .aui-grid-cell .row-link) { color: #189ff0 !important; cursor: pointer; text-decoration: underline; } :deep(.aui-grid-toolbar) { padding: 5px 0; } :deep(.aui-grid-toolbar .aui-grid-custom__wrapper) { height: 24px !important; width: 24px !important; } :deep(.aui-grid__body .aui-grid-body__column .aui-grid-cell .row-link_click) { color: #189ff0 !important; cursor: pointer; text-decoration: underline; } :deep(.aui-grid__body .aui-grid-body__column .aui-grid-cell .row-link-red) { color: #fe281f !important; } :deep(.aui-grid.fixed__sticky .row__word--remarked) { --body-background-color: #ebf1de !important; } :deep(.row__word--remarked) { background-color: #ebf1de !important; } :deep(.aui-grid .aui-pager) { padding-top: 6px !important; } </style> <style> /* 隐藏aui3个性化重置按钮 */ .aui-grid-modal__box .aui-grid-custom .aui-grid-custom__footer .aui-button:nth-child(2) { display: none !important; } </style> 这个页面往下拉之后,行距会和列名的行距不一致
08-16
<template> <div> <el-dialog title="设备导入" :visible.sync="dialogVisible" width="600px" custom-class="ota-dialog" :close-on-click-modal="false" > <div class="dialog-content"> <div class="action-section"> <div class="upload-section"> <el-upload action="#" :auto-upload="false" :before-upload="beforeUpload" :on-change="handleFileChange" :limit="1" :on-exceed="handleExceed" :file-list="fileList" drag > <i class="el-icon-upload"></i> <div class="el-upload__text"> <div>点击或拖拽文件到此处上传</div> <div class="el-upload__tip">支持.xlsx、.xls格式文件</div> </div> </el-upload> <div v-if="fileList.length" class="file-card"> <div class="file-info"> <i class="el-icon-document"></i> <div class="file-details"> <div class="file-name">{{ fileList[0].name }}</div> <div class="file-size">{{ formatFileSize(fileList[0].size) }}</div> <div v-if="firstRowString" class="file-data"> <el-tooltip effect="dark" :content="firstRowString" placement="top"> <span>首行数据: {{ truncateString(firstRowString) }}</span> </el-tooltip> </div> </div> </div> <div class="file-actions"> <i v-if="loading" class="el-icon-loading"></i> <el-button v-else type="danger" icon="el-icon-delete" circle @click="clearFile" ></el-button> </div> </div> </div> </div> </div> <div slot="footer" class="dialog-footer"> <el-button @click="dialogVisible = false">取 消</el-button> <el-button type="primary" @click="handleConfirm" :disabled="!fileList.length || loading" > {{ loading ? '处理中...' : '确 定' }} </el-button> </div> </el-dialog> </div> </template> <script> import * as XLSX from 'xlsx'; export default { data() { return { dialogVisible: false, fileList: [], firstRowString: '', loading: false }; }, methods: { init() { this.dialogVisible = true; this.fileList = []; this.firstRowString = ''; }, beforeUpload(file) { const isValidType = [ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel' ].includes(file.type); if (!isValidType) { this.$message.error('请上传Excel格式的文件 (.xlsx 或 .xls)'); } return isValidType; }, // 处理文件选择变化 handleFileChange(file) { if (!file) return; const validTypes = [ 'application/vnd.ms-excel', // .xls 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' // .xlsx ]; if (!validTypes.includes(file.raw.type)) { this.$message.error('请上传Excel格式的文件 (.xlsx 或 .xls)'); this.clearFile(); return; } this.fileList = [file]; this.readExcelFirstRow(file.raw); }, // 读取Excel文件第一行 readExcelFirstRow(file) { this.loading = true; const reader = new FileReader(); reader.onload = (e) => { try { const data = new Uint8Array(e.target.result); const workbook = XLSX.read(data, { type: 'array' }); // 获取第一个工作表 const firstSheetName = workbook.SheetNames[0]; const worksheet = workbook.Sheets[firstSheetName]; // 获取第一行数据 const range = XLSX.utils.decode_range(worksheet['!ref']); const firstRow = []; // 遍历第一行的所有列 for (let col = range.s.c; col <= range.e.c; col++) { const cellAddress = XLSX.utils.encode_cell({ r: 0, c: col }); const cell = worksheet[cellAddress]; firstRow.push(cell ? cell.v : ''); } // 用分号拼接第一行数据 this.firstRowString = firstRow.join(';'); this.$message.success('Excel文件解析成功'); } catch (error) { console.error('Excel解析错误:', error); this.$message.error('Excel文件解析失败,请检查文件格式'); this.firstRowString = ''; } finally { this.loading = false; } }; reader.onerror = () => { this.$message.error('文件读取失败'); this.loading = false; }; reader.readAsArrayBuffer(file); }, // 处理确认操作 handleConfirm() { if (!this.firstRowString) { this.$message.warning('未解析到有效数据'); return; } this.$message.success(`已获取首行数据: ${this.firstRowString}`); // 这里可以添加将数据发送到服务器的逻辑 // this.otaBatchUpgradeConfirm(this.firstRowString); // 关闭对话框 this.dialogVisible = false; }, // 清空文件 clearFile() { this.fileList = []; this.firstRowString = ''; }, handleExceed() { this.$message.warning('每次只能上传一个文件'); }, formatFileSize(size) { if (size < 1024) return size + ' B'; if (size < 1024 * 1024) return (size / 1024).toFixed(1) + ' KB'; return (size / (1024 * 1024)).toFixed(1) + ' MB'; }, // 截断长字符串 truncateString(str, maxLength = 30) { if (str.length <= maxLength) return str; return str.substring(0, maxLength) + '...'; } } }; </script> <style scoped> .action-section { display: flex; flex-direction: column; gap: 20px; } .upload-section { position: relative; display: flex; justify-content: center; } .file-card { margin-top: 15px; padding: 15px; border-radius: 8px; background-color: #f5f7fa; display: flex; align-items: center; justify-content: space-between; border: 1px solid #ebeef5; } .file-info { display: flex; align-items: center; gap: 12px; flex: 1; } .file-info i { font-size: 28px; color: #409EFF; } .file-details { line-height: 1.5; flex: 1; } .file-name { font-weight: 500; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .file-size { font-size: 12px; color: #909399; } .file-data { font-size: 12px; color: #67C23A; margin-top: 5px; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .file-actions { margin-left: 10px; } .dialog-footer { display: flex; justify-content: flex-end; padding-top: 15px; border-top: 1px solid #ebeef5; } .has-file >>> .el-upload-dragger { border: 1px dashed #67C23A; background-color: rgba(103, 194, 58, 0.05); } .el-icon-loading { font-size: 20px; color: #409EFF; margin-right: 10px; } </style> 上传文件后布局混乱
07-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值