|
@@ -13,27 +13,37 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- convertTableJson(tableData, list, attributes = {
|
|
|
- isAdd: true,
|
|
|
- isDel: true,
|
|
|
- isUpdate: true,
|
|
|
- isConfirm: true,
|
|
|
- isEdit: true,
|
|
|
- isTemElm: true,
|
|
|
- confirmText: "",
|
|
|
- editText: "",
|
|
|
- delText: "",
|
|
|
- }, funs = {
|
|
|
- add: function () { },
|
|
|
- confirm: function () { },
|
|
|
- delete: function () { },
|
|
|
- update: function () { },
|
|
|
- verify: function () { },
|
|
|
- }) {
|
|
|
+ convertTableJson(
|
|
|
+ tableData,
|
|
|
+ list,
|
|
|
+ attributes = {
|
|
|
+ isAdd: true,
|
|
|
+ isDel: true,
|
|
|
+ isUpdate: true,
|
|
|
+ isConfirm: true,
|
|
|
+ isEdit: true,
|
|
|
+ isTemElm: true,
|
|
|
+ confirmText: '',
|
|
|
+ editText: '',
|
|
|
+ delText: ''
|
|
|
+ },
|
|
|
+ funs = {
|
|
|
+ add: function () {},
|
|
|
+ confirm: function () {},
|
|
|
+ delete: function () {},
|
|
|
+ update: function () {},
|
|
|
+ verify: function () {},
|
|
|
+ btnSlot: function () {}
|
|
|
+ }
|
|
|
+ ) {
|
|
|
var newList = list.map(item => {
|
|
|
if (item.editRender && item.viewRender) {
|
|
|
item.render = (h, { row, column, index }) => {
|
|
|
- if (attributes?.isTemElm !== undefined ? setShowElement(attributes?.isTemElm, { row, column, index }) : index == this.isEditTableIndex) {
|
|
|
+ if (
|
|
|
+ attributes?.isTemElm !== undefined
|
|
|
+ ? setShowElement(attributes?.isTemElm, { row, column, index })
|
|
|
+ : index == this.isEditTableIndex
|
|
|
+ ) {
|
|
|
return item.editRender(h, { row, column, index })
|
|
|
} else {
|
|
|
return item.viewRender(h, { row, column, index })
|
|
@@ -41,7 +51,7 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
return item
|
|
|
- });
|
|
|
+ })
|
|
|
if (setShowElement(attributes?.isEdit)) {
|
|
|
newList.push({
|
|
|
columnAttributes: {
|
|
@@ -49,56 +59,91 @@ export default {
|
|
|
width: 100
|
|
|
},
|
|
|
render: (h, { row, column, index }) => {
|
|
|
- return <div style="padding-left:10px">
|
|
|
- {(attributes?.isConfirm !== undefined ? setShowElement(attributes?.isConfirm, { row, column, index }) : this.isEditTableIndex == index) && <el-button type="text" onClick={async () => {
|
|
|
- if (funs.verify && !await funs.verify({ row, column, index }, this.isEditTableIndex)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (funs.confirm) {
|
|
|
- funs.confirm({ row, column, index })
|
|
|
- } else {
|
|
|
- this.isEditTableIndex = -1
|
|
|
- }
|
|
|
- }}>{attributes?.confirmText || '确定'}</el-button>}
|
|
|
- {(attributes?.isUpdate !== undefined ? setShowElement(attributes?.isUpdate, { row, column, index }) : this.isEditTableIndex == -1) && <el-button type="text" onClick={async () => {
|
|
|
- if (funs.verify && !await funs.verify({ row, column, index }, this.isEditTableIndex)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (funs.update) {
|
|
|
- funs.update({ row, column, index })
|
|
|
- } else {
|
|
|
- this.isEditTableIndex = index
|
|
|
- }
|
|
|
- }}>{attributes?.editText || '编辑'}</el-button>}
|
|
|
- {setShowElement(attributes?.isDel, { row, column, index }) && <el-button type="text" onClick={async () => {
|
|
|
- if (funs.delete) {
|
|
|
- funs.delete({ row, column, index }, function(){
|
|
|
- tableData.splice(index, 1)
|
|
|
- })
|
|
|
- } else {
|
|
|
- tableData.splice(index, 1)
|
|
|
- }
|
|
|
- }}>{attributes?.delText || '删除'}</el-button>}
|
|
|
- </div>
|
|
|
+ return (
|
|
|
+ <div style="padding-left:10px">
|
|
|
+ {(attributes?.isConfirm !== undefined
|
|
|
+ ? setShowElement(attributes?.isConfirm, { row, column, index })
|
|
|
+ : this.isEditTableIndex == index) && (
|
|
|
+ <el-button
|
|
|
+ type="text"
|
|
|
+ onClick={async () => {
|
|
|
+ if (funs.verify && !(await funs.verify({ row, column, index }, this.isEditTableIndex))) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (funs.confirm) {
|
|
|
+ funs.confirm({ row, column, index })
|
|
|
+ } else {
|
|
|
+ this.isEditTableIndex = -1
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {attributes?.confirmText || '确定'}
|
|
|
+ </el-button>
|
|
|
+ )}
|
|
|
+ {(attributes?.isUpdate !== undefined
|
|
|
+ ? setShowElement(attributes?.isUpdate, { row, column, index })
|
|
|
+ : this.isEditTableIndex == -1) && (
|
|
|
+ <el-button
|
|
|
+ type="text"
|
|
|
+ onClick={async () => {
|
|
|
+ if (funs.verify && !(await funs.verify({ row, column, index }, this.isEditTableIndex))) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (funs.update) {
|
|
|
+ funs.update({ row, column, index })
|
|
|
+ } else {
|
|
|
+ this.isEditTableIndex = index
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {attributes?.editText || '编辑'}
|
|
|
+ </el-button>
|
|
|
+ )}
|
|
|
+ {setShowElement(attributes?.isDel, { row, column, index }) && (
|
|
|
+ <el-button
|
|
|
+ type="text"
|
|
|
+ onClick={async () => {
|
|
|
+ if (funs.delete) {
|
|
|
+ funs.delete({ row, column, index }, function () {
|
|
|
+ tableData.splice(index, 1)
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ tableData.splice(index, 1)
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {attributes?.delText || '删除'}
|
|
|
+ </el-button>
|
|
|
+ )}
|
|
|
+ {funs.btnSlot ? funs.btnSlot({ row, column, index }) : null}
|
|
|
+ </div>
|
|
|
+ )
|
|
|
}
|
|
|
})
|
|
|
- };
|
|
|
- return <div>
|
|
|
- {setShowElement(attributes?.isAdd) ? <div>
|
|
|
- <el-button size="mini" type="primary" onClick={async () => {
|
|
|
- if (funs.verify && !await funs.verify({}, this.isEditTableIndex)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (funs.add) {
|
|
|
- funs.add()
|
|
|
- }
|
|
|
- }}>新增</el-button>
|
|
|
- </div> : null}
|
|
|
- <zj-table
|
|
|
- columns={newList}
|
|
|
- table-data={tableData}
|
|
|
- />
|
|
|
- </div>
|
|
|
+ }
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ {setShowElement(attributes?.isAdd) ? (
|
|
|
+ <div>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="primary"
|
|
|
+ onClick={async () => {
|
|
|
+ if (funs.verify && !(await funs.verify({}, this.isEditTableIndex))) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (funs.add) {
|
|
|
+ funs.add()
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 新增
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ ) : null}
|
|
|
+ <zj-table columns={newList} table-data={tableData} />
|
|
|
+ </div>
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
}
|