feat: now one channel can belong to multiple groups (close #153)
This commit is contained in:
parent
38668e7331
commit
7f9577a386
@ -30,15 +30,18 @@ func GetRandomSatisfiedChannel(group string, model string) (*Channel, error) {
|
||||
|
||||
func (channel *Channel) AddAbilities() error {
|
||||
models_ := strings.Split(channel.Models, ",")
|
||||
groups_ := strings.Split(channel.Group, ",")
|
||||
abilities := make([]Ability, 0, len(models_))
|
||||
for _, model := range models_ {
|
||||
ability := Ability{
|
||||
Group: channel.Group,
|
||||
Model: model,
|
||||
ChannelId: channel.Id,
|
||||
Enabled: channel.Status == common.ChannelStatusEnabled,
|
||||
for _, group := range groups_ {
|
||||
ability := Ability{
|
||||
Group: group,
|
||||
Model: model,
|
||||
ChannelId: channel.Id,
|
||||
Enabled: channel.Status == common.ChannelStatusEnabled,
|
||||
}
|
||||
abilities = append(abilities, ability)
|
||||
}
|
||||
abilities = append(abilities, ability)
|
||||
}
|
||||
return DB.Create(&abilities).Error
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ const EditChannel = () => {
|
||||
key: '',
|
||||
base_url: '',
|
||||
other: '',
|
||||
group: 'default',
|
||||
models: [],
|
||||
groups: ['default']
|
||||
};
|
||||
const [batch, setBatch] = useState(false);
|
||||
const [inputs, setInputs] = useState(originInputs);
|
||||
@ -37,6 +37,11 @@ const EditChannel = () => {
|
||||
} else {
|
||||
data.models = data.models.split(",")
|
||||
}
|
||||
if (data.group === "") {
|
||||
data.groups = []
|
||||
} else {
|
||||
data.groups = data.group.split(",")
|
||||
}
|
||||
setInputs(data);
|
||||
} else {
|
||||
showError(message);
|
||||
@ -94,6 +99,7 @@ const EditChannel = () => {
|
||||
}
|
||||
let res;
|
||||
localInputs.models = localInputs.models.join(",")
|
||||
localInputs.group = localInputs.groups.join(",")
|
||||
if (isEdit) {
|
||||
res = await API.put(`/api/channel/`, { ...localInputs, id: parseInt(channelId) });
|
||||
} else {
|
||||
@ -185,14 +191,14 @@ const EditChannel = () => {
|
||||
<Form.Dropdown
|
||||
label='分组'
|
||||
placeholder={'请选择分组'}
|
||||
name='group'
|
||||
name='groups'
|
||||
fluid
|
||||
search
|
||||
multiple
|
||||
selection
|
||||
allowAdditions
|
||||
additionLabel={'请在系统设置页面编辑分组倍率以添加新的分组:'}
|
||||
onChange={handleInputChange}
|
||||
value={inputs.group}
|
||||
value={inputs.groups}
|
||||
autoComplete='new-password'
|
||||
options={groupOptions}
|
||||
/>
|
||||
|
Loading…
Reference in New Issue
Block a user