vue通过样式实现可编辑单元格

//templete
<el-dialog
        title=" 编辑"
        :visible.sync="isShowEdit"
        width="60%"
        :close-on-click-modal="false"
        :before-close="handleCloseEdit"
        class="label">
    <el-table
            :data="tableDataEdit"
            style="width: 100%">
        <el-table-column
                type="index"
                label="序号"
                width="60">
        </el-table-column>
        <el-table-column
                key="brandName"
                prop="brandName"
                label="品牌">
            <template slot-scope="scope">
                <el-input :class="[scope.row.isEdit ? 'editInput' : '']" :readOnly="!scope.row.isEdit"
                          v-model="scope.row.brandName"></el-input>
            </template>
        </el-table-column>
        <el-table-column
                key="zYellow"
                prop="zYellow"
                label="在途黄色提示">
            <template slot-scope="scope">
                <el-input :class="[scope.row.isEdit ? 'editInput' : '']" :readOnly="!scope.row.isEdit"
                          v-model="scope.row.zYellow"></el-input>
            </template>
        </el-table-column>
        <el-table-column
                key="zRed"
                prop="zRed"
                label="在途红色提示">
            <template slot-scope="scope">
                <el-input :class="[scope.row.isEdit ? 'editInput' : '']" :readOnly="!scope.row.isEdit"
                          v-model="scope.row.zRed"></el-input>
            </template>
        </el-table-column>
        <el-table-column
                key="cYellow"
                prop="cYellow"
                label="存放时间黄色提示">
            <template slot-scope="scope">
                <el-input :class="[scope.row.isEdit ? 'editInput' : '']" :readOnly="!scope.row.isEdit"
                          v-model="scope.row.cYellow"></el-input>
            </template>
        </el-table-column>
        <el-table-column
                key="cRed"
                prop="cRed"
                label="存放时间红色提示">
            <template slot-scope="scope">
                <el-input :class="[scope.row.isEdit ? 'editInput' : '']" :readOnly="!scope.row.isEdit"
                          v-model="scope.row.cRed"></el-input>
            </template>
        </el-table-column>
        <el-table-column
                key="cScale"
                prop="cScale"
                label="存放比例提示">
            <template slot-scope="scope">
                <el-input :class="[scope.row.isEdit ? 'editInput' : '']" :readOnly="!scope.row.isEdit"
                          v-model="scope.row.cScale"></el-input>
            </template>
        </el-table-column>
        <el-table-column
                key="sYellow"
                prop="sYellow"
                label="赎货周期黄色提示">
            <template slot-scope="scope">
                <el-input :class="[scope.row.isEdit ? 'editInput' : '']" :readOnly="!scope.row.isEdit"
                          v-model="scope.row.sYellow"></el-input>
            </template>
        </el-table-column>
        <el-table-column
                key="sRred"
                prop="sRred"
                label="赎货周期红色提示">
            <template slot-scope="scope">
                <el-input :class="[scope.row.isEdit ? 'editInput' : '']" :readOnly="!scope.row.isEdit"
                          v-model="scope.row.sRred"></el-input>
            </template>
        </el-table-column>
        <el-table-column
                key="num"
                prop="num"
                label="关联经销商数量">
            <template slot-scope="scope">
                <el-input :class="[scope.row.isEdit ? 'editInput' : '']" :readOnly="!scope.row.isEdit"
                          v-model="scope.row.num"></el-input>
            </template>
        </el-table-column>
        <el-table-column
                label="操作">
            <template slot-scope="scope">
                <el-button style="display: inline-block" v-show="!scope.row.isEdit"
                           @click="handleEditLabel(scope.row)" type="text" size="small">编辑
                </el-button>
                <el-button style="display: inline-block" v-show="scope.row.isEdit"
                           @click="handleSaveLabel(scope.row)" type="text" size="small">保存
                </el-button>
                <el-button style="display: inline-block" v-show="scope.row.isEdit"
                           @click="scope.row.isEdit = false" type="text" size="small">取消
                </el-button>
                <el-button style="display: inline-block" v-show="!scope.row.isEdit"
                           @click="handleDelete(scope.row)" type="text" size="small">删除
                </el-button>
            </template>
        </el-table-column>
    </el-table>

    <div class="pagination">
        <span>第1/10页 共100条</span>
        <el-pagination
                background
                @current-change="handleCurrentChange"
                layout="prev, pager, next, jumper"
                :total="1000">
        </el-pagination>
    </div>
</el-dialog>

//js

// 点击编辑标签管理信息
handleEditLabel(row) {

    if (this.currentList) {

        if (this.currentList.isEdit) return this.$message.warning("请先保存当前编辑项");

    }

    row.isEdit = true
    this.currentList = row


},
// 保存信息
handleSaveLabel(row) {
    let _t = this
    console.log(row)
    row.isEdit = false
    axios.put('/updatePro', row)
        .then(
            res => {
                console.log(res);
                if (res.status == 200 && res.data.code == 100000) {

                    _t.$message(res.data.message);

                }

            }
        )
},

//css

/* 提示参数弹框样式开始 */
.edit .el-dialog__body {
   padding: 5px 34px 0 20px !important;
}
.edit .el-form-item {
   margin: 25px 0 0!important;
}
.edit .dealerName  .el-form-item{
   float: left !important;
}
.edit .el-form-item__label {
   width: 96px;
   text-align: left;
}
.edit .el-input__inner {
   background: transparent !important;
}
.edit .el-tag {
   width: 90px;
   height: 24px !important;
   line-height: 24px !important;
   color: #42DBFE;
   background: rgba(66,219,254,0.40) !important;
   border: 1px solid #389CBB;
   border-radius: 2px;
   text-align: center;
}
.edit .el-select .el-tag__close.el-icon-close {
   background: transparent !important;
   color: #389CBB !important;
}
.label .el-table .el-input__inner {
   width: 100% !important;
   text-align: center;
   background: transparent !important;
}
.label .editInput .el-input__inner {
   background: #293E56 !important;
}
.label tr:nth-child(even) .editInput .el-input__inner {
   background: #1C3044 !important;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,我之前的回答有误,x-data-spreadsheet是基于JavaScript的电子表格库,而不是Vue组件。 以下是一个使用x-data-spreadsheet库实现Excel文件导入导出和可编辑单元格样式的示例代码: HTML模板代码: ``` <template> <div> <button @click="exportExcel">导出Excel文件</button> <input type="file" ref="file" style="display:none" @change="importExcel" /> <button @click="() => { this.$refs.file.click() }">导入Excel文件</button> <div ref="spreadsheet"></div> </div> </template> ``` JS代码: ``` <script> import Spreadsheet from 'x-data-spreadsheet' import 'x-data-spreadsheet/dist/xspreadsheet.css' export default { mounted() { const el = this.$refs.spreadsheet const options = { data: [], columns: [ { title: '姓名', field: 'name', width: 120 }, { title: '年龄', field: 'age', width: 80 }, { title: '性别', field: 'gender', width: 80 }, ], style: { bgcolor: '#f1f1f1', align: 'center', valign: 'middle', textwrap: true }, row: { len: 20, height: 30 } } this.spreadsheet = new Spreadsheet(el, options) }, methods: { async exportExcel() { const data = this.spreadsheet.getData() const blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) const url = URL.createObjectURL(blob) const link = document.createElement('a') link.href = url link.download = 'excel.xlsx' link.click() }, async importExcel() { const file = this.$refs.file.files[0] const reader = new FileReader() reader.onload = async (event) => { const data = event.target.result const { arrayBuffer } = await import('xlsx') const workbook = arrayBuffer(data) const worksheet = workbook.Sheets[workbook.SheetNames[0]] const sheetData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }) const headerRow = sheetData[0] const tableData = [] for (let i = 1; i < sheetData.length; i++) { const rowData = {} for (let j = 0; j < headerRow.length; j++) { const key = headerRow[j] rowData[key] = sheetData[i][j] } tableData.push(rowData) } this.spreadsheet.loadData(tableData) } reader.readAsArrayBuffer(file) } } } </script> ``` 这个示例中,我们使用了x-data-spreadsheet库来渲染一个电子表格。在mounted钩子函数中,我们创建了一个Spreadsheet对象,并将其挂载到了页面上的一个div元素上。我们指定了表格的数据、列定义、单元格样式和行高等选项。 导出Excel文件的方法是通过调用Spreadsheet对象的getData方法获取表格的数据,然后使用Blob对象将数据转换为Excel文件格式,并创建一个a标签下载文件。 导入Excel文件的方法是通过一个input元素来获取用户选择的文件,然后使用FileReader对象将文件读取为ArrayBuffer二进制格式。接下来,我们使用xlsx库解析文件数据,获取到表格数据后,我们将其转换为x-data-spreadsheet库所需的数据格式,并使用Spreadsheet对象的loadData方法加载数据。 希望这个示例能够对您有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值