1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

feat: 应用编辑增加 select 类型处理 (#363)

This commit is contained in:
zhengkunwang223 2023-03-22 15:38:30 +08:00 committed by GitHub
parent 39e3e8f214
commit 092cbbf8da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 76 additions and 31 deletions

View File

@ -78,6 +78,12 @@ type AppFormFields struct {
Disabled bool `json:"disabled"`
Edit bool `json:"edit"`
Rule string `json:"rule"`
Values []AppFormValue `json:"values"`
}
type AppFormValue struct {
Label string `json:"label"`
Value string `json:"value"`
}
type AppResource struct {

View File

@ -68,4 +68,6 @@ type AppParam struct {
LabelZh string `json:"labelZh"`
LabelEn string `json:"labelEn"`
Type string `json:"type"`
Values interface{} `json:"values"`
ShowValue string `json:"showValue"`
}

View File

@ -486,15 +486,21 @@ func (a *AppInstallService) GetParams(id uint) ([]response.AppParam, error) {
}
appParam.LabelZh = form.LabelZh
appParam.LabelEn = form.LabelEn
appParam.Value = v
if form.Type == "service" {
appInstall, _ := appInstallRepo.GetFirst(appInstallRepo.WithServiceName(v.(string)))
appParam.Value = appInstall.Name
res = append(res, appParam)
} else {
appParam.Value = v
res = append(res, appParam)
appParam.ShowValue = appInstall.Name
} else if form.Type == "select" {
for _, fv := range form.Values {
if fv.Value == v {
appParam.ShowValue = fv.Label
break
}
}
appParam.Values = form.Values
}
res = append(res, appParam)
}
}
return res, nil
}

View File

@ -1073,7 +1073,7 @@ var doc = `{
],
"responses": {
"200": {
"description": ""
"description": "OK"
}
},
"x-panel-log": {
@ -6914,7 +6914,7 @@ var doc = `{
],
"responses": {
"200": {
"description": ""
"description": "OK"
}
}
},
@ -12327,10 +12327,14 @@ var doc = `{
"rule": {
"type": "string"
},
"showValue": {
"type": "string"
},
"type": {
"type": "string"
},
"value": {}
"value": {},
"values": {}
}
},
"response.FileInfo": {

View File

@ -1059,7 +1059,7 @@
],
"responses": {
"200": {
"description": ""
"description": "OK"
}
},
"x-panel-log": {
@ -6900,7 +6900,7 @@
],
"responses": {
"200": {
"description": ""
"description": "OK"
}
}
},
@ -12313,10 +12313,14 @@
"rule": {
"type": "string"
},
"showValue": {
"type": "string"
},
"type": {
"type": "string"
},
"value": {}
"value": {},
"values": {}
}
},
"response.FileInfo": {

View File

@ -2441,9 +2441,12 @@ definitions:
type: string
rule:
type: string
showValue:
type: string
type:
type: string
value: {}
values: {}
type: object
response.FileInfo:
properties:
@ -3288,7 +3291,7 @@ paths:
$ref: '#/definitions/dto.ComposeCreate'
responses:
"200":
description: ""
description: OK
security:
- ApiKeyAuth: []
summary: Test compose
@ -7005,7 +7008,7 @@ paths:
$ref: '#/definitions/dto.Upgrade'
responses:
"200":
description: ""
description: OK
security:
- ApiKeyAuth: []
summary: Load release notes by version

View File

@ -163,5 +163,7 @@ export namespace App {
key: string;
rule: string;
type: string;
values?: any;
showValue?: string;
}
}

View File

@ -42,7 +42,14 @@
{{ $t('app.toInstall') }}
</el-link>
</span>
<el-select v-model="form[p.envKey]" v-if="p.type == 'select'">
<el-option
v-for="service in p.values"
:key="service.label"
:value="service.value"
:label="service.label"
></el-option>
</el-select>
<el-row :gutter="10" v-if="p.type == 'apps'">
<el-col :span="12">
<el-form-item :prop="p.prop">

View File

@ -11,7 +11,7 @@
</template>
<el-descriptions border :column="1" v-if="!edit">
<el-descriptions-item v-for="(param, key) in params" :label="getLabel(param)" :key="key">
{{ param.value }}
<span>{{ param.showValue && param.showValue != '' ? param.showValue : param.value }}</span>
</el-descriptions-item>
</el-descriptions>
<el-row v-else v-loading="loading">
@ -26,6 +26,15 @@
v-model.number="paramModel[p.key]"
:disabled="!p.edit"
></el-input>
<el-select v-model="paramModel[p.key]" v-else-if="p.type == 'select'">
<el-option
v-for="value in p.values"
:key="value.label"
:value="value.value"
:label="value.label"
:disabled="!p.edit"
></el-option>
</el-select>
<el-input v-else v-model.trim="paramModel[p.key]" :disabled="!p.edit"></el-input>
</el-form-item>
</div>
@ -116,6 +125,8 @@ const get = async () => {
edit: d.edit,
key: d.key,
type: d.type,
values: d.values,
showValue: d.showValue,
});
rules[d.key] = [Rules.requiredInput];
if (d.rule) {