From 190316f66e9c34d37866cb3db8881725f0e4bc5c Mon Sep 17 00:00:00 2001 From: FENG Date: Mon, 5 Aug 2024 22:35:16 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=E6=B8=A0=E9=81=93=E5=A4=9A=E5=88=86?= =?UTF-8?q?=E7=BB=84=EF=BC=8C=E4=BC=98=E5=8C=96=E5=88=86=E7=BB=84=20like?= =?UTF-8?q?=20=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/channel.go | 8 +- web/src/components/ChannelsTable.js | 801 ++++++++++++++-------------- 2 files changed, 404 insertions(+), 405 deletions(-) diff --git a/model/channel.go b/model/channel.go index 3f9d9ed..8000537 100644 --- a/model/channel.go +++ b/model/channel.go @@ -90,13 +90,11 @@ func GetAllChannels(startIdx int, num int, selectAll bool, idSort bool) ([]*Chan func SearchChannels(keyword string, group string, model string) ([]*Channel, error) { var channels []*Channel keyCol := "`key`" - groupCol := "`group`" modelsCol := "`models`" // 如果是 PostgreSQL,使用双引号 if common.UsingPostgreSQL { keyCol = `"key"` - groupCol = `"group"` modelsCol = `"models"` } @@ -106,9 +104,9 @@ func SearchChannels(keyword string, group string, model string) ([]*Channel, err // 构造WHERE子句 var whereClause string var args []interface{} - if group != "" { - whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + groupCol + " = ? AND " + modelsCol + " LIKE ?" - args = append(args, common.String2Int(keyword), "%"+keyword+"%", keyword, group, "%"+model+"%") + if group != "" && group != "null" { + whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + modelsCol + ` LIKE ? AND (',' || "group" || ',') LIKE ?` + args = append(args, common.String2Int(keyword), "%"+keyword+"%", keyword, "%"+model+"%", "%,"+group+",%") } else { whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + modelsCol + " LIKE ?" args = append(args, common.String2Int(keyword), "%"+keyword+"%", keyword, "%"+model+"%") diff --git a/web/src/components/ChannelsTable.js b/web/src/components/ChannelsTable.js index f2c7518..ea4e22a 100644 --- a/web/src/components/ChannelsTable.js +++ b/web/src/components/ChannelsTable.js @@ -49,9 +49,9 @@ function renderType(type) { type2label[0] = { value: 0, text: '未知类型', color: 'grey' }; } return ( - - {type2label[type]?.text} - + + {type2label[type]?.text} + ); } @@ -75,13 +75,13 @@ const ChannelsTable = () => { dataIndex: 'group', render: (text, record, index) => { return ( -
- - {text.split(',').map((item, index) => { - return renderGroup(item); - })} - -
+
+ + {text.split(',').map((item, index) => { + return renderGroup(item); + })} + +
); }, }, @@ -104,11 +104,11 @@ const ChannelsTable = () => { let reason = otherInfo['status_reason']; let time = otherInfo['status_time']; return ( -
- - {renderStatus(text)} - -
+
+ + {renderStatus(text)} + +
); } else { return renderStatus(text); @@ -127,27 +127,27 @@ const ChannelsTable = () => { dataIndex: 'expired_time', render: (text, record, index) => { return ( -
- - - - {renderQuota(record.used_quota)} - - - - { - updateChannelBalance(record); - }} - > - ${renderNumberWithPoint(record.balance)} - - - -
+
+ + + + {renderQuota(record.used_quota)} + + + + { + updateChannelBalance(record); + }} + > + ${renderNumberWithPoint(record.balance)} + + + +
); }, }, @@ -156,19 +156,19 @@ const ChannelsTable = () => { dataIndex: 'priority', render: (text, record, index) => { return ( -
- { - manageChannel(record.id, 'priority', record, e.target.value); - }} - keepFocus={true} - innerButtons - defaultValue={record.priority} - min={-999} - /> -
+
+ { + manageChannel(record.id, 'priority', record, e.target.value); + }} + keepFocus={true} + innerButtons + defaultValue={record.priority} + min={-999} + /> +
); }, }, @@ -177,19 +177,19 @@ const ChannelsTable = () => { dataIndex: 'weight', render: (text, record, index) => { return ( -
- { - manageChannel(record.id, 'weight', record, e.target.value); - }} - keepFocus={true} - innerButtons - defaultValue={record.weight} - min={0} - /> -
+
+ { + manageChannel(record.id, 'weight', record, e.target.value); + }} + keepFocus={true} + innerButtons + defaultValue={record.weight} + min={0} + /> +
); }, }, @@ -197,95 +197,95 @@ const ChannelsTable = () => { title: '', dataIndex: 'operate', render: (text, record, index) => ( -
- - - + - - - {/**/} - { - manageChannel(record.id, 'delete', record).then(() => { - removeRecord(record.id); - }); - }} - > - - - {record.status === 1 ? ( - + + + + + {/**/} + { + manageChannel(record.id, 'delete', record).then(() => { + removeRecord(record.id); + }); + }} > - 禁用 - - ) : ( + + + {record.status === 1 ? ( + + ) : ( + + )} - )} - - { - copySelectedChannel(record.id); - }} - > - - -
+ { + copySelectedChannel(record.id); + }} + > + + + ), }, ]; @@ -301,7 +301,7 @@ const ChannelsTable = () => { const [updatingBalance, setUpdatingBalance] = useState(false); const [pageSize, setPageSize] = useState(ITEMS_PER_PAGE); const [showPrompt, setShowPrompt] = useState( - shouldShowPrompt('channel-test'), + shouldShowPrompt('channel-test'), ); const [channelCount, setChannelCount] = useState(pageSize); const [groupOptions, setGroupOptions] = useState([]); @@ -357,7 +357,7 @@ const ChannelsTable = () => { const loadChannels = async (startIdx, pageSize, idSort) => { setLoading(true); const res = await API.get( - `/api/channel/?p=${startIdx}&page_size=${pageSize}&id_sort=${idSort}`, + `/api/channel/?p=${startIdx}&page_size=${pageSize}&id_sort=${idSort}`, ); if (res === undefined) { return; @@ -379,7 +379,7 @@ const ChannelsTable = () => { const copySelectedChannel = async (id) => { const channelToCopy = channels.find( - (channel) => String(channel.id) === String(id), + (channel) => String(channel.id) === String(id), ); console.log(channelToCopy); channelToCopy.name += '_复制'; @@ -412,14 +412,14 @@ const ChannelsTable = () => { // console.log('default effect') const localIdSort = localStorage.getItem('id-sort') === 'true'; const localPageSize = - parseInt(localStorage.getItem('page-size')) || ITEMS_PER_PAGE; + parseInt(localStorage.getItem('page-size')) || ITEMS_PER_PAGE; setIdSort(localIdSort); setPageSize(localPageSize); loadChannels(0, localPageSize, localIdSort) - .then() - .catch((reason) => { - showError(reason); - }); + .then() + .catch((reason) => { + showError(reason); + }); fetchGroups().then(); loadChannelModels().then(); }, []); @@ -476,27 +476,27 @@ const ChannelsTable = () => { switch (status) { case 1: return ( - - 已启用 - + + 已启用 + ); case 2: return ( - - 已禁用 - + + 已禁用 + ); case 3: return ( - - 自动禁用 - + + 自动禁用 + ); default: return ( - - 未知状态 - + + 未知状态 + ); } }; @@ -506,33 +506,33 @@ const ChannelsTable = () => { time = time.toFixed(2) + ' 秒'; if (responseTime === 0) { return ( - - 未测试 - + + 未测试 + ); } else if (responseTime <= 1000) { return ( - - {time} - + + {time} + ); } else if (responseTime <= 3000) { return ( - - {time} - + + {time} + ); } else if (responseTime <= 5000) { return ( - - {time} - + + {time} + ); } else { return ( - - {time} - + + {time} + ); } }; @@ -546,7 +546,7 @@ const ChannelsTable = () => { } setSearching(true); const res = await API.get( - `/api/channel/search?keyword=${searchKeyword}&group=${searchGroup}&model=${searchModel}`, + `/api/channel/search?keyword=${searchKeyword}&group=${searchGroup}&model=${searchModel}`, ); const { success, message, data } = res.data; if (success) { @@ -648,8 +648,8 @@ const ChannelsTable = () => { }; let pageData = channels.slice( - (activePage - 1) * pageSize, - activePage * pageSize, + (activePage - 1) * pageSize, + activePage * pageSize, ); const handlePageChange = (page) => { @@ -665,10 +665,10 @@ const ChannelsTable = () => { setPageSize(size); setActivePage(1); loadChannels(0, size, idSort) - .then() - .catch((reason) => { - showError(reason); - }); + .then() + .catch((reason) => { + showError(reason); + }); }; const fetchGroups = async () => { @@ -680,10 +680,10 @@ const ChannelsTable = () => { return; } setGroupOptions( - res.data.data.map((group) => ({ - label: group, - value: group, - })), + res.data.data.map((group) => ({ + label: group, + value: group, + })), ); } catch (error) { showError(error.message); @@ -707,225 +707,226 @@ const ChannelsTable = () => { }; return ( - <> - -
{ - searchChannels(searchKeyword, searchGroup, searchModel); - }} - labelPosition='left' - > -
+ <> + + { + searchChannels(searchKeyword, searchGroup, searchModel); + }} + labelPosition='left' + > +
+ + { + setSearchKeyword(v.trim()); + }} + /> + { + setSearchModel(v.trim()); + }} + /> + { + setSearchGroup(v); + searchChannels(searchKeyword, v, searchModel); + }} + /> + + +
+ +
- { - setSearchKeyword(v.trim()); - }} - /> - { - setSearchModel(v.trim()); - }} - /> - { - setSearchGroup(v); - searchChannels(searchKeyword, v, searchModel); - }} - /> - + + 使用ID排序 + { + localStorage.setItem('id-sort', v + ''); + setIdSort(v); + loadChannels(0, pageSize, v) + .then() + .catch((reason) => { + showError(reason); + }); + }} + > +
- -
- - - 使用ID排序 - { - localStorage.setItem('id-sort', v + ''); - setIdSort(v); - loadChannels(0, pageSize, v) - .then() - .catch((reason) => { - showError(reason); - }); - }} - > - - -
- '', - onPageSizeChange: (size) => { - handlePageSizeChange(size).then(); - }, - onPageChange: handlePageChange, - }} - loading={loading} - onRow={handleRow} - rowSelection={ - enableBatchDelete - ? { - onChange: (selectedRowKeys, selectedRows) => { - // console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows); - setSelectedChannels(selectedRows); - }, - } - : null - } - /> -
- '', + onPageSizeChange: (size) => { + handlePageSizeChange(size).then(); + }, + onPageChange: handlePageChange, + }} + loading={loading} + onRow={handleRow} + rowSelection={ + enableBatchDelete + ? { + onChange: (selectedRowKeys, selectedRows) => { + // console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows); + setSelectedChannels(selectedRows); + }, + } + : null + } + /> +
- - - - - - - - - - - - - - {/*
*/} - - {/*
*/} -
-
- - 开启批量删除 - { - setEnableBatchDelete(v); - }} - > - - - - + + + + + + + + + - - -
- +
+ {/*
*/} + + {/*
*/} +
+
+ + 开启批量删除 + { + setEnableBatchDelete(v); + }} + > + + + + + + + +
+ ); }; From c152b4de08f4747ff5ee69aed3bab4c8f8f86033 Mon Sep 17 00:00:00 2001 From: FENG Date: Tue, 6 Aug 2024 15:40:44 +0800 Subject: [PATCH 2/4] chore: indent recovery --- web/src/components/ChannelsTable.js | 806 ++++++++++++++-------------- 1 file changed, 403 insertions(+), 403 deletions(-) diff --git a/web/src/components/ChannelsTable.js b/web/src/components/ChannelsTable.js index ea4e22a..c98f73f 100644 --- a/web/src/components/ChannelsTable.js +++ b/web/src/components/ChannelsTable.js @@ -49,9 +49,9 @@ function renderType(type) { type2label[0] = { value: 0, text: '未知类型', color: 'grey' }; } return ( - - {type2label[type]?.text} - + + {type2label[type]?.text} + ); } @@ -75,13 +75,13 @@ const ChannelsTable = () => { dataIndex: 'group', render: (text, record, index) => { return ( -
- - {text.split(',').map((item, index) => { - return renderGroup(item); - })} - -
+
+ + {text.split(',').map((item, index) => { + return renderGroup(item); + })} + +
); }, }, @@ -104,11 +104,11 @@ const ChannelsTable = () => { let reason = otherInfo['status_reason']; let time = otherInfo['status_time']; return ( -
- - {renderStatus(text)} - -
+
+ + {renderStatus(text)} + +
); } else { return renderStatus(text); @@ -127,27 +127,27 @@ const ChannelsTable = () => { dataIndex: 'expired_time', render: (text, record, index) => { return ( -
- - - - {renderQuota(record.used_quota)} - - - - { - updateChannelBalance(record); - }} - > - ${renderNumberWithPoint(record.balance)} - - - -
+
+ + + + {renderQuota(record.used_quota)} + + + + { + updateChannelBalance(record); + }} + > + ${renderNumberWithPoint(record.balance)} + + + +
); }, }, @@ -156,19 +156,19 @@ const ChannelsTable = () => { dataIndex: 'priority', render: (text, record, index) => { return ( -
- { - manageChannel(record.id, 'priority', record, e.target.value); - }} - keepFocus={true} - innerButtons - defaultValue={record.priority} - min={-999} - /> -
+
+ { + manageChannel(record.id, 'priority', record, e.target.value); + }} + keepFocus={true} + innerButtons + defaultValue={record.priority} + min={-999} + /> +
); }, }, @@ -177,19 +177,19 @@ const ChannelsTable = () => { dataIndex: 'weight', render: (text, record, index) => { return ( -
- { - manageChannel(record.id, 'weight', record, e.target.value); - }} - keepFocus={true} - innerButtons - defaultValue={record.weight} - min={0} - /> -
+
+ { + manageChannel(record.id, 'weight', record, e.target.value); + }} + keepFocus={true} + innerButtons + defaultValue={record.weight} + min={0} + /> +
); }, }, @@ -197,95 +197,95 @@ const ChannelsTable = () => { title: '', dataIndex: 'operate', render: (text, record, index) => ( -
- + + + - - - - - {/**/} - { - manageChannel(record.id, 'delete', record).then(() => { - removeRecord(record.id); - }); - }} - > - - - {record.status === 1 ? ( - - ) : ( - - )} - + + + {/**/} + { + manageChannel(record.id, 'delete', record).then(() => { + removeRecord(record.id); + }); + }} + > + - { - copySelectedChannel(record.id); - }} + + {record.status === 1 ? ( + - -
+ 禁用 + + ) : ( + + )} + + { + copySelectedChannel(record.id); + }} + > + + + ), }, ]; @@ -301,7 +301,7 @@ const ChannelsTable = () => { const [updatingBalance, setUpdatingBalance] = useState(false); const [pageSize, setPageSize] = useState(ITEMS_PER_PAGE); const [showPrompt, setShowPrompt] = useState( - shouldShowPrompt('channel-test'), + shouldShowPrompt('channel-test'), ); const [channelCount, setChannelCount] = useState(pageSize); const [groupOptions, setGroupOptions] = useState([]); @@ -357,7 +357,7 @@ const ChannelsTable = () => { const loadChannels = async (startIdx, pageSize, idSort) => { setLoading(true); const res = await API.get( - `/api/channel/?p=${startIdx}&page_size=${pageSize}&id_sort=${idSort}`, + `/api/channel/?p=${startIdx}&page_size=${pageSize}&id_sort=${idSort}`, ); if (res === undefined) { return; @@ -379,7 +379,7 @@ const ChannelsTable = () => { const copySelectedChannel = async (id) => { const channelToCopy = channels.find( - (channel) => String(channel.id) === String(id), + (channel) => String(channel.id) === String(id), ); console.log(channelToCopy); channelToCopy.name += '_复制'; @@ -412,14 +412,14 @@ const ChannelsTable = () => { // console.log('default effect') const localIdSort = localStorage.getItem('id-sort') === 'true'; const localPageSize = - parseInt(localStorage.getItem('page-size')) || ITEMS_PER_PAGE; + parseInt(localStorage.getItem('page-size')) || ITEMS_PER_PAGE; setIdSort(localIdSort); setPageSize(localPageSize); loadChannels(0, localPageSize, localIdSort) - .then() - .catch((reason) => { - showError(reason); - }); + .then() + .catch((reason) => { + showError(reason); + }); fetchGroups().then(); loadChannelModels().then(); }, []); @@ -476,27 +476,27 @@ const ChannelsTable = () => { switch (status) { case 1: return ( - - 已启用 - + + 已启用 + ); case 2: return ( - - 已禁用 - + + 已禁用 + ); case 3: return ( - - 自动禁用 - + + 自动禁用 + ); default: return ( - - 未知状态 - + + 未知状态 + ); } }; @@ -506,33 +506,33 @@ const ChannelsTable = () => { time = time.toFixed(2) + ' 秒'; if (responseTime === 0) { return ( - - 未测试 - + + 未测试 + ); } else if (responseTime <= 1000) { return ( - - {time} - + + {time} + ); } else if (responseTime <= 3000) { return ( - - {time} - + + {time} + ); } else if (responseTime <= 5000) { return ( - - {time} - + + {time} + ); } else { return ( - - {time} - + + {time} + ); } }; @@ -546,7 +546,7 @@ const ChannelsTable = () => { } setSearching(true); const res = await API.get( - `/api/channel/search?keyword=${searchKeyword}&group=${searchGroup}&model=${searchModel}`, + `/api/channel/search?keyword=${searchKeyword}&group=${searchGroup}&model=${searchModel}`, ); const { success, message, data } = res.data; if (success) { @@ -648,8 +648,8 @@ const ChannelsTable = () => { }; let pageData = channels.slice( - (activePage - 1) * pageSize, - activePage * pageSize, + (activePage - 1) * pageSize, + activePage * pageSize, ); const handlePageChange = (page) => { @@ -665,10 +665,10 @@ const ChannelsTable = () => { setPageSize(size); setActivePage(1); loadChannels(0, size, idSort) - .then() - .catch((reason) => { - showError(reason); - }); + .then() + .catch((reason) => { + showError(reason); + }); }; const fetchGroups = async () => { @@ -680,10 +680,10 @@ const ChannelsTable = () => { return; } setGroupOptions( - res.data.data.map((group) => ({ - label: group, - value: group, - })), + res.data.data.map((group) => ({ + label: group, + value: group, + })), ); } catch (error) { showError(error.message); @@ -707,226 +707,226 @@ const ChannelsTable = () => { }; return ( - <> - -
{ - searchChannels(searchKeyword, searchGroup, searchModel); - }} - labelPosition='left' - > -
- - { - setSearchKeyword(v.trim()); - }} - /> - { - setSearchModel(v.trim()); - }} - /> - { - setSearchGroup(v); - searchChannels(searchKeyword, v, searchModel); - }} - /> - - -
- -
+ <> + +
{ + searchChannels(searchKeyword, searchGroup, searchModel); + }} + labelPosition='left' + > +
- - 使用ID排序 - { - localStorage.setItem('id-sort', v + ''); - setIdSort(v); - loadChannels(0, pageSize, v) - .then() - .catch((reason) => { - showError(reason); - }); - }} - > - + { + setSearchKeyword(v.trim()); + }} + /> + { + setSearchModel(v.trim()); + }} + /> + { + setSearchGroup(v); + searchChannels(searchKeyword, v, searchModel); + }} + /> +
+ +
+ + + 使用ID排序 + { + localStorage.setItem('id-sort', v + ''); + setIdSort(v); + loadChannels(0, pageSize, v) + .then() + .catch((reason) => { + showError(reason); + }); + }} + > + + +
-
'', - onPageSizeChange: (size) => { - handlePageSizeChange(size).then(); - }, - onPageChange: handlePageChange, - }} - loading={loading} - onRow={handleRow} - rowSelection={ - enableBatchDelete - ? { - onChange: (selectedRowKeys, selectedRows) => { - // console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows); - setSelectedChannels(selectedRows); - }, - } - : null - } - /> -
'', + onPageSizeChange: (size) => { + handlePageSizeChange(size).then(); + }, + onPageChange: handlePageChange, + }} + loading={loading} + onRow={handleRow} + rowSelection={ + enableBatchDelete + ? { + onChange: (selectedRowKeys, selectedRows) => { + // console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows); + setSelectedChannels(selectedRows); + }, + } + : null + } + /> +
+ - { + setEditingChannel({ + id: undefined, + }); + setShowEdit(true); + }} + > + 添加渠道 + + + + + + + + + + + + + + {/*
*/} + + {/*
*/} +
+
+ + 开启批量删除 + { + setEnableBatchDelete(v); + }} + > + - - - - - - - - - - - - - {/*
*/} - - {/*
*/} -
-
- - 开启批量删除 - { - setEnableBatchDelete(v); - }} - > - - - - - - - -
- + + +
+ ); }; From e614ca370a928605a433162b0d81e766cd8c14a0 Mon Sep 17 00:00:00 2001 From: FENG Date: Tue, 6 Aug 2024 21:30:20 +0800 Subject: [PATCH 3/4] fix: optionList bug --- web/src/components/ChannelsTable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/components/ChannelsTable.js b/web/src/components/ChannelsTable.js index c98f73f..2942a0b 100644 --- a/web/src/components/ChannelsTable.js +++ b/web/src/components/ChannelsTable.js @@ -745,7 +745,7 @@ const ChannelsTable = () => { { setSearchGroup(v); From 04f0084d978747a17cdd6f6134b6047512cbe491 Mon Sep 17 00:00:00 2001 From: CalciumIon <1808837298@qq.com> Date: Thu, 8 Aug 2024 20:45:41 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dmysql=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/channel.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/model/channel.go b/model/channel.go index 8000537..87610a4 100644 --- a/model/channel.go +++ b/model/channel.go @@ -90,11 +90,13 @@ func GetAllChannels(startIdx int, num int, selectAll bool, idSort bool) ([]*Chan func SearchChannels(keyword string, group string, model string) ([]*Channel, error) { var channels []*Channel keyCol := "`key`" + groupCol := "`group`" modelsCol := "`models`" // 如果是 PostgreSQL,使用双引号 if common.UsingPostgreSQL { keyCol = `"key"` + groupCol = `"group"` modelsCol = `"models"` } @@ -105,7 +107,13 @@ func SearchChannels(keyword string, group string, model string) ([]*Channel, err var whereClause string var args []interface{} if group != "" && group != "null" { - whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + modelsCol + ` LIKE ? AND (',' || "group" || ',') LIKE ?` + var groupCondition string + if common.UsingPostgreSQL { + groupCondition = `(',' || ` + groupCol + ` || ',') LIKE ?` + } else { + groupCondition = `CONCAT(',', ` + groupCol + `, ',') LIKE ?` + } + whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + modelsCol + ` LIKE ? AND ` + groupCondition args = append(args, common.String2Int(keyword), "%"+keyword+"%", keyword, "%"+model+"%", "%,"+group+",%") } else { whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + modelsCol + " LIKE ?"