From ac1d52c46ff9019fcc93cf3d5e7ab17cf850824e Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 10 八月 2023 16:05:24 +0800 Subject: [PATCH] 2023-08-10 --- src/templates/zshare/editTable/index.jsx | 87 +++++++++++++++++++++++++++++++------------ 1 files changed, 63 insertions(+), 24 deletions(-) diff --git a/src/templates/zshare/editTable/index.jsx b/src/templates/zshare/editTable/index.jsx index 205ece1..159a4c8 100644 --- a/src/templates/zshare/editTable/index.jsx +++ b/src/templates/zshare/editTable/index.jsx @@ -416,7 +416,9 @@ columns.forEach(col => { if (col.unique !== true || !unique) return - if (col.strict) { + if (col.uniqueFunc) { + unique = col.uniqueFunc(data, res.data) + } else if (col.strict) { let key = res.data[col.dataIndex].toLowerCase() let _index = data.findIndex(item => key === item[col.dataIndex].toLowerCase()) @@ -455,7 +457,9 @@ columns.forEach(col => { if (col.unique !== true || !unique) return - if (col.strict) { + if (col.uniqueFunc) { + unique = col.uniqueFunc(data, cell) + } else if (col.strict) { let _index = data.findIndex(item => cell[col.dataIndex].toLowerCase() === item[col.dataIndex].toLowerCase()) if (_index > -1) { @@ -518,15 +522,32 @@ columns.forEach(col => { if (col.unique !== true || !unique) return - let _index = newData.findIndex(item => record.uuid !== item.uuid && record[col.dataIndex] === item[col.dataIndex]) + if (col.uniqueFunc) { + unique = col.uniqueFunc(newData, record) + return + } else if (col.strict) { + let key = record[col.dataIndex].toLowerCase() + let _index = newData.findIndex(item => key === item[col.dataIndex].toLowerCase()) - if (_index > -1) { - notification.warning({ - top: 92, - message: col.title + '涓嶅彲閲嶅锛�', - duration: 5 - }) - unique = false + if (_index > -1) { + notification.warning({ + top: 92, + message: col.title + '涓嶅彲閲嶅锛�', + duration: 5 + }) + unique = false + } + } else { + let _index = newData.findIndex(item => record.uuid !== item.uuid && record[col.dataIndex] === item[col.dataIndex]) + + if (_index > -1) { + notification.warning({ + top: 92, + message: col.title + '涓嶅彲閲嶅锛�', + duration: 5 + }) + unique = false + } } }) @@ -557,31 +578,49 @@ } const newData = [...this.state.data] const index = newData.findIndex(item => uuid === item.uuid) + if (index > -1) { + row = {...newData[index], ...row} + } else { + row.uuid = uuid + } let unique = true columns.forEach(col => { if (col.unique !== true || !unique) return - let _index = newData.findIndex(item => uuid !== item.uuid && row[col.dataIndex] === item[col.dataIndex]) - - if (_index > -1) { - notification.warning({ - top: 92, - message: col.title + '涓嶅彲閲嶅锛�', - duration: 5 - }) - unique = false + if (col.uniqueFunc) { + unique = col.uniqueFunc(newData, row) + return + } else if (col.strict) { + let key = row[col.dataIndex].toLowerCase() + let _index = newData.findIndex(item => key === item[col.dataIndex].toLowerCase()) + + if (_index > -1) { + notification.warning({ + top: 92, + message: col.title + '涓嶅彲閲嶅锛�', + duration: 5 + }) + unique = false + } + } else { + let _index = newData.findIndex(item => row.uuid !== item.uuid && row[col.dataIndex] === item[col.dataIndex]) + + if (_index > -1) { + notification.warning({ + top: 92, + message: col.title + '涓嶅彲閲嶅锛�', + duration: 5 + }) + unique = false + } } }) if (!unique) return if (index > -1) { - const item = newData[index] - newData.splice(index, 1, { - ...item, - ...row, - }) + newData.splice(index, 1, row) this.setState({ data: newData, editingKey: '' }, () => { this.props.onChange(newData) }) -- Gitblit v1.8.0