ele-table表格列表內(nèi)雙擊編輯部分信息的示例代碼(el-table組件同理)
說(shuō)明
ele-table 為公司內(nèi)部組件,重點(diǎn)看 【主要代碼】 部分代碼
ele-table表格列表內(nèi):雙擊需要編輯的區(qū)域,編輯部分信息
實(shí)現(xiàn)
雙擊需要編輯的數(shù)據(jù),展示輸入框/日期選擇,
展示輸入框:修改完之后,按鍵盤(pán)回車(chē)鍵,提交修改數(shù)據(jù)展示日期選擇:修改完之后,點(diǎn)擊 √ 按鈕,提交修改數(shù)據(jù)
頁(yè)面展示
代碼
<!-- 機(jī)動(dòng)車(chē)巡查 --> <template> <div class="container"> <ele-form-search class="container_search" :form-data="searchData" :form-desc="searchDesc" @search="fetchData" /> <div class="container_btn"> <el-button class="el-icon-plus" type="primary" size="mini" @click="operationHandler('add')"> 錄入 </el-button> <el-button size="mini" @click="operationHandler('auto')">自動(dòng)錄入設(shè)置</el-button> <a href="/downloadCenter/核查處理通知書(shū).docx" rel="external nofollow" > <el-button size="mini">整改說(shuō)明書(shū)下載</el-button> </a> </div> <ele-table class="contariner_table" :table-options="options" :columns-options="columns" :page.sync="searchData.page" :page-size.sync="searchData.rows" :total="total" :show-fixed-control="false" > <template #sffxwt="{ row }"> <el-switch v-model="row.sffxwt" active-color="#13ce66" active-value="yes" inactive-value="no" @change="sffxwtChange($event, row)" > </el-switch> </template> <!-- 【主要代碼】 start --> <template #czwt="{ row }"> <el-input v-if="row.czwtIsEdit" v-model="editValue" placeholder="請(qǐng)輸入內(nèi)容" size="mini" @keyup.enter.native="dbClickSubmit('czwt', row)" ></el-input> <span v-else @dblclick="dbClickEdit('czwt', row)">{{ row.czwt }}</span> </template> <template #ccrq="{ row }"> <div v-if="row.ccrqIsEdit" class="ccrq"> <el-date-picker v-model="editValue" type="date" placeholder="選擇日期" size="mini" format="yyyy-MM-dd" value-format="yyyy-MM-dd" /> <el-button type="text" class="el-icon-check" @click="dbClickSubmit('ccrq', row)" ></el-button> </div> <span v-else @dblclick="dbClickEdit('ccrq', row)">{{ row.ccrq }}</span> </template> <!-- 【主要代碼】 end --> <template #operation="{ row }"> <el-button type="text" @click="detailHandler(row)">查看</el-button> <el-button :disabled="row.sffxwt === 'no'" type="text" @click="operationHandler('upload', row)" >上傳</el-button > <el-button type="text" @click="operationHandler('issued', row)">下發(fā)</el-button> </template> </ele-table> <DetailDialog ref="DetailDialogRef" @update="fetchData" /> <OperationDialog ref="OperationDialogRef" @update="fetchData" /> </div> </template> <script> import { mapGetters } from 'vuex' import { listPage, update } from '@/api/neimeng/vehicle-inspection-feedback' import { searchDesc } from './constant/formList' import { columns } from './constant/columns' import DetailDialog from './components/DetailDialog' import OperationDialog from './components/OperationDialog' export default { name: 'VehicleInspection', components: { DetailDialog, OperationDialog }, filters: {}, data() { return { searchData: { page: 1, rows: 10 }, tableData: [], total: 0, editValue: '' } }, computed: { ...mapGetters(['glbmList']), searchDesc() { return searchDesc(this) }, options() { return { data: this.tableData } }, columns() { return columns(this) } }, watch: {}, created() { this.fetchData() }, methods: { fetchData() { let { time, ...params } = this.searchData if (time && time.length) { params.kssj = time[0] params.jssj = time[1] } listPage(params).then((res) => { this.common.CheckCode(res, null, () => { this.tableData = res.data.rows || [] this.total = res.data.total || 0 }) }) }, sffxwtChange(val, row) { update({ sffxwt: val, id: row.id }).then((res) => { this.$common.CheckCode(res, null, () => { this.fetchData() }) }) }, /** ** 【主要代碼】 start ****/ getIndex(rowData) { return this.tableData.findIndex((item) => item.id === rowData.id) }, dbClickEdit(key, rowData) { const isCanEdit = this.tableData.some((item) => { if (item.ccrqIsEdit || item.czwtIsEdit) return true }) if (isCanEdit) return this.$message.error('請(qǐng)先編輯完當(dāng)前數(shù)據(jù)再編輯下一個(gè)') this.editValue = key === 'ccrq' ? new Date(rowData[key]) : rowData[key] this.tableData[this.getIndex(rowData)][key + 'IsEdit'] = true this.renderDom() }, dbClickSubmit(key, rowData) { update({ [key]: this.editValue, id: rowData.id }).then((res) => { this.$common.CheckCode(res, '修改成功', () => { this.fetchData() this.tableData[this.getIndex(rowData)][key + 'IsEdit'] = false this.renderDom() this.editValue = '' }) }) }, renderDom() { this.tableData.push({}) this.tableData.pop() }, /** ** 【主要代碼】 end ****/ detailHandler(rowData) { this.$refs.DetailDialogRef.open(rowData) }, operationHandler(type, rowData) { this.$refs.OperationDialogRef.open(type, rowData) } } } </script> <style lang="scss" scoped> .container { height: calc(100% - 52px); &_search { padding: 10px; margin-bottom: 10px; ::v-deep .el-form-item__content { text-align: left; } } &_btn { background-color: #fff; padding: 10px 10px 0; text-align: left; .el-icon-plus { margin-bottom: 10px; } a { margin-left: 10px; } } .contariner_table { height: calc(100% - 100px); ::v-deep .ele-table-pagination { position: fixed; bottom: 0; justify-content: center; z-index: 10; } .upload-demo { display: inline-block; } .ccrq { width: 100%; display: inline-block; ::v-deep .el-date-editor { width: calc(100% - 22px); } .el-icon-check { padding: 0; cursor: pointer; font-size: 20px; } } } } .blue-theme { .container_btn { background-color: #293f60; color: #fff; } } .night-theme { .container_btn { background-color: #1a2331; color: #fff; } } </style>
./constant/formList.js
import { getToken } from '@/utils/auth' const sffxwtOptions = [ { value: 'yes', text: '是' }, { value: 'no', text: '否' } ] export const searchDesc = (_this) => { return { jczmc: { type: 'input', label: '監(jiān)測(cè)站名稱(chēng)', attrs: { clearable: true }, layout: 8 }, fzjg: { type: 'input', label: '盟市', attrs: { clearable: true }, layout: 8 }, sffxwt: { type: 'select', label: '是否發(fā)現(xiàn)問(wèn)題', attrs: { clearable: true }, layout: 8, options: sffxwtOptions }, time: { type: 'daterange', label: '巡查時(shí)間', attrs: { clearable: true, valueFormat: 'yyyy-MM-dd' }, layout: 8 } } } export const detailFormDesc = (_this) => { return { carInfo: { hpzl: { type: 'select', label: '號(hào)牌種類(lèi)', layout: 8, render: (h, content, value) => { return <span>{_this.common.filter_dic('mon_business_hpzl', value)}</span> } }, hphm: { type: 'input', label: '號(hào)牌號(hào)碼', layout: 8 }, jdczt: { type: 'input', label: '機(jī)動(dòng)車(chē)狀態(tài)', layout: 8 }, syr: { type: 'input', label: '所有人', layout: 8 }, sfzmhm: { type: 'input', label: '身份證號(hào)', layout: 8 }, lxfs: { type: 'input', label: '聯(lián)系方式', layout: 8 }, zsxxdz: { type: 'input', label: '住址', layout: 8 }, zzxxdz: { type: 'input', label: '暫住地址', layout: 8 }, ccdjrq: { type: 'input', label: '初次登記日期', layout: 8 }, yxqz: { type: 'input', label: '有效期止', layout: 8 }, qzbfqz: { type: 'input', label: '強(qiáng)制報(bào)廢日期止', layout: 8 }, yqjyqzbfqz: { type: 'input', label: '逾期檢驗(yàn)強(qiáng)制報(bào)廢期止', layout: 8 }, syq: { vif: _this.drawerType === 'detail', type: 'input', label: '所有權(quán)', layout: 8, render: (h, content, value) => { const cur = sffxwtOptions.find((i) => i.value === value) return <span>{(cur && cur.text) || '暫無(wú)'}</span> } }, sqztmc: { vif: _this.drawerType === 'detail', type: 'input', label: '申請(qǐng)狀態(tài)', layout: 8 }, bz: { vif: _this.drawerType === 'detail', type: 'input', label: '車(chē)輛備注信息', layout: 8 } }, applyInfo: { clbz: { type: 'input', label: '車(chē)輛備注信息', layout: _this.drawerType === 'apply' ? 24 : 8, default: _this.carInfo.bz, disabled: true }, [_this.drawerType === 'apply' ? 'zrbm' : 'zrbmmc']: { type: 'select', label: '申請(qǐng)轉(zhuǎn)入部門(mén)', layout: _this.drawerType === 'apply' ? 24 : 8, required: true, options: _this.glbmOptions, prop: { value: 'value', text: 'label' }, attrs: { clearable: true } }, bz: { type: 'textarea', label: '申請(qǐng)備注', layout: _this.drawerType === 'apply' ? 24 : 8, attrs: { clearable: true } }, cjr: { vif: ['examineDetail', 'examine'].includes(_this.drawerType), type: 'input', label: '申請(qǐng)人', layout: 8 }, sqbm: { vif: ['examineDetail', 'examine'].includes(_this.drawerType), type: 'input', label: '申請(qǐng)人部門(mén)', layout: 8 }, sqsj: { vif: ['examineDetail', 'examine'].includes(_this.drawerType), type: 'input', label: '申請(qǐng)時(shí)間', layout: 8 } }, examineInfo: { clyj: { type: 'textarea', label: '審核備注', layout: _this.drawerType === 'examine' ? 24 : 16, attrs: { clearable: true } }, clr: { vif: ['examineDetail'].includes(_this.drawerType), type: 'input', label: '審核人', layout: 8 }, clsj: { vif: ['examineDetail'].includes(_this.drawerType), type: 'input', label: '審核時(shí)間', layout: 16 } } } } export const operationFormDesc = (_this) => { return { auto: { lrpl: { type: 'input', label: '', labelWidth: 0, layout: 24 }, lrsl: { type: 'input', label: '', labelWidth: 0, layout: 24 } }, issued: { xfbm: { type: 'select', label: '下發(fā)部門(mén)', layout: 24, options: _this.glbmOptions, prop: { value: 'value', text: 'label' }, attrs: { clearable: true } } }, upload: { zgsms: { type: 'upload', label: '上傳文件', layout: 24, attrs: { // accept: 'image/*', label: '上傳文件', multiple: false, autoUpload: true, limit: 1, // listType: 'picture-card', blockSize: 'middle', params: { relativePath: 'NMXCFile/' }, uploadAPI: '/supervise_basic/upload/oss/fileupload', token: getToken(), beforeUpload: _this.beforeUploadHandler, 'on-exceed': () => { _this.$message('最多允許傳一個(gè)文件') } } } } } }
./constant/columns.js
import moment from 'moment' export const columns = (_this) => { return [ { type: 'index', label: '序號(hào)', index: (index) => { return (_this.searchData.page - 1) * _this.searchData.rows + index + 1 } }, { prop: 'fzjg', label: '盟市' }, { prop: 'lsh', label: '流水號(hào)' }, { prop: 'jczmc', label: '監(jiān)測(cè)站名稱(chēng)' }, { prop: 'hphm', label: '車(chē)牌號(hào)' }, { prop: 'cllx', label: '車(chē)輛類(lèi)型' }, { prop: 'sffxwt', label: '是否發(fā)現(xiàn)問(wèn)題' }, { prop: 'czwt', label: '存在問(wèn)題' }, { prop: 'ccrq', label: '抽查日期' }, { prop: 'operation', label: '操作', fixed: 'right', width: 150 } ] }
到此這篇關(guān)于ele-table表格列表內(nèi),雙擊編輯部分信息(el-table組件同理)的文章就介紹到這了,更多相關(guān)ele-table表格雙擊編輯信息內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
javascript中Date對(duì)象應(yīng)用之簡(jiǎn)易日歷實(shí)現(xiàn)
這篇文章主要為大家詳細(xì)介紹了javascript中Date對(duì)象應(yīng)用之簡(jiǎn)易日歷實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07jquery $(document).ready()和window.onload的區(qū)別淺析
這篇文章主要介紹了jquery $(document).ready()和 window.onload的區(qū)別淺析,本文總結(jié)了執(zhí)行時(shí)間、編寫(xiě)個(gè)數(shù)不同、簡(jiǎn)化寫(xiě)法等不同的地方,需要的朋友可以參考下2015-02-02JavaScript中的作用域與閉包、原型與原型鏈、異步與單線(xiàn)程
JavaScript的三座大山指的是:作用域和閉包、原型和原型鏈、異步與單線(xiàn)程,這些概念在日常的開(kāi)發(fā)工作中經(jīng)常被提及,并對(duì)我們理解和編寫(xiě)高質(zhì)量的JavaScript代碼至關(guān)重要2024-02-02hammer.js實(shí)現(xiàn)圖片手勢(shì)放大效果
這篇文章主要為大家詳細(xì)介紹了hammer.js實(shí)現(xiàn)圖片手勢(shì)放大效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08JavaScript類(lèi)型檢測(cè)的方法實(shí)例教程
這篇文章主要給大家介紹了關(guān)于JavaScript類(lèi)型檢測(cè)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04js驗(yàn)證框架之RealyEasy驗(yàn)證詳解
這篇文章主要為大家詳細(xì)介紹了js驗(yàn)證框架之RealyEasy驗(yàn)證,記錄了RealyEasy驗(yàn)證的使用步驟,感興趣的小伙伴們可以參考一下2016-06-06js實(shí)現(xiàn)網(wǎng)站最上邊可關(guān)閉的浮動(dòng)廣告條代碼
這篇文章主要介紹了js實(shí)現(xiàn)網(wǎng)站最上邊可關(guān)閉的浮動(dòng)廣告條代碼,涉及javascript基于鼠標(biāo)事件操作頁(yè)面元素樣式的實(shí)現(xiàn)技巧,需要的朋友可以參考下2015-09-09