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