From 6693072c49fad1cc6087c6652459fe846c6d8cb6 Mon Sep 17 00:00:00 2001
From: CalciumIon <1808837298@qq.com>
Date: Sat, 30 Nov 2024 17:43:03 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E6=A0=87=E7=AD=BE?=
=?UTF-8?q?=E7=BC=96=E8=BE=91=EF=BC=88=E4=BC=98=E5=85=88=E7=BA=A7=EF=BC=8C?=
=?UTF-8?q?=E6=9D=83=E9=87=8D=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
web/src/components/ChannelsTable.js | 110 +++++++++++++++++--
web/src/components/{ => custom}/TextInput.js | 0
web/src/components/custom/TextNumberInput.js | 21 ++++
web/src/pages/Channel/EditTagModal.js | 2 +-
4 files changed, 121 insertions(+), 12 deletions(-)
rename web/src/components/{ => custom}/TextInput.js (100%)
create mode 100644 web/src/components/custom/TextNumberInput.js
diff --git a/web/src/components/ChannelsTable.js b/web/src/components/ChannelsTable.js
index 55816940..2ffa83fe 100644
--- a/web/src/components/ChannelsTable.js
+++ b/web/src/components/ChannelsTable.js
@@ -12,15 +12,16 @@ import {
import { CHANNEL_OPTIONS, ITEMS_PER_PAGE } from '../constants';
import {
+ getQuotaPerUnit,
renderGroup,
renderNumberWithPoint,
- renderQuota
+ renderQuota, renderQuotaWithPrompt
} from '../helpers/render';
import {
Button, Divider,
Dropdown,
- Form,
- InputNumber,
+ Form, Input,
+ InputNumber, Modal,
Popconfirm,
Space,
SplitButtonGroup,
@@ -34,6 +35,7 @@ import EditChannel from '../pages/Channel/EditChannel';
import { IconList, IconTreeTriangleDown } from '@douyinfe/semi-icons';
import { loadChannelModels } from './utils.js';
import EditTagModal from '../pages/Channel/EditTagModal.js';
+import TextNumberInput from './custom/TextNumberInput.js';
function renderTimestamp(timestamp) {
return <>{timestamp2string(timestamp)}>;
@@ -200,7 +202,29 @@ const ChannelsTable = () => {
);
} else {
return <>
-
+ {
+ Modal.warning({
+ title: '修改子渠道优先级',
+ content: '确定要修改所有子渠道优先级为 ' + e.target.value + ' 吗?',
+ onOk: () => {
+ if (e.target.value === '') {
+ return;
+ }
+ submitTagEdit('priority', {
+ tag: record.key,
+ priority: e.target.value
+ })
+ },
+ })
+ }}
+ innerButtons
+ defaultValue={record.priority}
+ min={-999}
+ />
>;
}
}
@@ -227,12 +251,29 @@ const ChannelsTable = () => {
);
} else {
return (
-
+ {
+ Modal.warning({
+ title: '修改子渠道权重',
+ content: '确定要修改所有子渠道权重为 ' + e.target.value + ' 吗?',
+ onOk: () => {
+ if (e.target.value === '') {
+ return;
+ }
+ submitTagEdit('weight', {
+ tag: record.key,
+ weight: e.target.value
+ })
+ },
+ })
+ }}
+ innerButtons
+ defaultValue={record.weight}
+ min={-999}
+ />
);
}
}
@@ -397,6 +438,8 @@ const ChannelsTable = () => {
const [showEditTag, setShowEditTag] = useState(false);
const [editingTag, setEditingTag] = useState('');
const [selectedChannels, setSelectedChannels] = useState([]);
+ const [showEditPriority, setShowEditPriority] = useState(false);
+
const removeRecord = (id) => {
let newDataSource = [...channels];
@@ -444,7 +487,9 @@ const ChannelsTable = () => {
name: '标签:' + tag,
group: '',
used_quota: 0,
- response_time: 0
+ response_time: 0,
+ priority: -1,
+ weight: -1,
};
tagChannelDates.children = [];
channelDates.push(tagChannelDates);
@@ -452,6 +497,20 @@ const ChannelsTable = () => {
// found, add to the tag
tagChannelDates = channelDates.find((item) => item.key === tag);
}
+ if (tagChannelDates.priority === -1) {
+ tagChannelDates.priority = channels[i].priority;
+ } else {
+ if (tagChannelDates.priority !== channels[i].priority) {
+ tagChannelDates.priority = '';
+ }
+ }
+ if (tagChannelDates.weight === -1) {
+ tagChannelDates.weight = channels[i].weight;
+ } else {
+ if (tagChannelDates.weight !== channels[i].weight) {
+ tagChannelDates.weight = '';
+ }
+ }
if (tagChannelDates.group === '') {
tagChannelDates.group = channels[i].group;
@@ -855,6 +914,35 @@ const ChannelsTable = () => {
}
};
+ const submitTagEdit = async (type, data) => {
+ switch (type) {
+ case 'priority':
+ if (data.priority === undefined || data.priority === '') {
+ showInfo('优先级必须是整数!');
+ return;
+ }
+ data.priority = parseInt(data.priority);
+ break;
+ case 'weight':
+ if (data.weight === undefined || data.weight < 0 || data.weight === '') {
+ showInfo('权重必须是非负整数!');
+ return;
+ }
+ data.weight = parseInt(data.weight);
+ break
+ }
+
+ try {
+ const res = await API.put('/api/channel/tag', data);
+ if (res?.data?.success) {
+ showSuccess('更新成功!');
+ await refresh();
+ }
+ } catch (error) {
+ showError(error);
+ }
+ }
+
const closeEdit = () => {
setShowEdit(false);
};
diff --git a/web/src/components/TextInput.js b/web/src/components/custom/TextInput.js
similarity index 100%
rename from web/src/components/TextInput.js
rename to web/src/components/custom/TextInput.js
diff --git a/web/src/components/custom/TextNumberInput.js b/web/src/components/custom/TextNumberInput.js
new file mode 100644
index 00000000..e25c7725
--- /dev/null
+++ b/web/src/components/custom/TextNumberInput.js
@@ -0,0 +1,21 @@
+import { Input, InputNumber, Typography } from '@douyinfe/semi-ui';
+import React from 'react';
+
+const TextNumberInput = ({ label, name, value, onChange, placeholder }) => {
+ return (
+ <>
+
+ {label}
+
+ onChange(value)}
+ value={value}
+ autoComplete="new-password"
+ />
+ >
+ );
+}
+
+export default TextNumberInput;
\ No newline at end of file
diff --git a/web/src/pages/Channel/EditTagModal.js b/web/src/pages/Channel/EditTagModal.js
index 6f2ecbab..55ccd315 100644
--- a/web/src/pages/Channel/EditTagModal.js
+++ b/web/src/pages/Channel/EditTagModal.js
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react';
import { API, showError, showInfo, showSuccess, showWarning, verifyJSON } from '../../helpers';
import { SideSheet, Space, Button, Input, Typography, Spin, Modal, Select, Banner, TextArea } from '@douyinfe/semi-ui';
-import TextInput from '../../components/TextInput.js';
+import TextInput from '../../components/custom/TextInput.js';
import { getChannelModels } from '../../components/utils.js';
const MODEL_MAPPING_EXAMPLE = {