Skip to content

Commit

Permalink
pref: 优化应用安装表单选择器组件支持多选 (1Panel-dev#3918)
Browse files Browse the repository at this point in the history
  • Loading branch information
almas1992 authored Feb 20, 2024
1 parent 3035bb2 commit 1781362
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
44 changes: 28 additions & 16 deletions backend/app/service/app_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,11 @@ func (a *AppInstallService) GetParams(id uint) (*response.AppConfig, error) {
for _, form := range appForm.FormFields {
if v, ok := envs[form.EnvKey]; ok {
appParam := response.AppParam{
Edit: false,
Key: form.EnvKey,
Rule: form.Rule,
Type: form.Type,
Edit: false,
Key: form.EnvKey,
Rule: form.Rule,
Type: form.Type,
Multiple: form.Multiple,
}
if form.Edit {
appParam.Edit = true
Expand All @@ -654,25 +655,36 @@ func (a *AppInstallService) GetParams(id uint) (*response.AppConfig, error) {
appInstall, _ := appInstallRepo.GetFirst(appInstallRepo.WithServiceName(v.(string)))
appParam.ShowValue = appInstall.Name
} else if form.Type == "select" {
for _, fv := range form.Values {
if fv.Value == v {
appParam.ShowValue = fv.Label
break
if form.Multiple {
if v == "" {
appParam.Value = []string{}
} else {
if str, ok := v.(string); ok {
appParam.Value = strings.Split(str, ",")
}
}
} else {
for _, fv := range form.Values {
if fv.Value == v {
appParam.ShowValue = fv.Label
break
}
}
}
appParam.Values = form.Values
}
params = append(params, appParam)
} else {
params = append(params, response.AppParam{
Edit: form.Edit,
Key: form.EnvKey,
Rule: form.Rule,
Type: form.Type,
LabelZh: form.LabelZh,
LabelEn: form.LabelEn,
Value: form.Default,
Values: form.Values,
Edit: form.Edit,
Key: form.EnvKey,
Rule: form.Rule,
Type: form.Type,
LabelZh: form.LabelZh,
LabelEn: form.LabelEn,
Value: form.Default,
Values: form.Values,
Multiple: form.Multiple,
})
}
}
Expand Down
6 changes: 6 additions & 0 deletions backend/app/service/app_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,12 @@ func handleMap(params map[string]interface{}, envParams map[string]string) {
envParams[k] = strconv.Itoa(int(t))
case int:
envParams[k] = strconv.Itoa(t)
case []interface{}:
strArray := make([]string, len(t))
for i := range t {
strArray[i] = strings.ToLower(fmt.Sprintf("%v", t[i]))
}
envParams[k] = strings.Join(strArray, ",")
default:
envParams[k] = t.(string)
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/app-store/detail/params/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
{{ $t('app.toInstall') }}
</el-link>
</span>
<el-select v-model="form[p.envKey]" v-if="p.type == 'select'">
<el-select v-model="form[p.envKey]" v-if="p.type == 'select'" :multiple="p.multiple">
<el-option
v-for="service in p.values"
:key="service.label"
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/views/app-store/installed/detail/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
v-model.number="paramModel.params[p.key]"
:disabled="!p.edit"
></el-input>
<el-select v-model="paramModel.params[p.key]" v-else-if="p.type == 'select'">
<el-select
v-model="paramModel.params[p.key]"
v-else-if="p.type == 'select'"
:multiple="p.multiple"
>
<el-option
v-for="value in p.values"
:key="value.label"
Expand Down Expand Up @@ -201,6 +205,7 @@ const get = async () => {
type: d.type,
values: d.values,
showValue: d.showValue,
multiple: d.multiple,
});
rules.params[d.key] = [Rules.requiredInput];
if (d.rule) {
Expand Down

0 comments on commit 1781362

Please sign in to comment.