1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 16:29:17 +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"` Disabled bool `json:"disabled"`
Edit bool `json:"edit"` Edit bool `json:"edit"`
Rule string `json:"rule"` Rule string `json:"rule"`
Values []AppFormValue `json:"values"`
}
type AppFormValue struct {
Label string `json:"label"`
Value string `json:"value"`
} }
type AppResource struct { type AppResource struct {

View File

@ -68,4 +68,6 @@ type AppParam struct {
LabelZh string `json:"labelZh"` LabelZh string `json:"labelZh"`
LabelEn string `json:"labelEn"` LabelEn string `json:"labelEn"`
Type string `json:"type"` 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.LabelZh = form.LabelZh
appParam.LabelEn = form.LabelEn appParam.LabelEn = form.LabelEn
appParam.Value = v
if form.Type == "service" { if form.Type == "service" {
appInstall, _ := appInstallRepo.GetFirst(appInstallRepo.WithServiceName(v.(string))) appInstall, _ := appInstallRepo.GetFirst(appInstallRepo.WithServiceName(v.(string)))
appParam.Value = appInstall.Name appParam.ShowValue = appInstall.Name
res = append(res, appParam) } else if form.Type == "select" {
} else { for _, fv := range form.Values {
appParam.Value = v if fv.Value == v {
res = append(res, appParam) appParam.ShowValue = fv.Label
break
} }
} }
appParam.Values = form.Values
}
res = append(res, appParam)
}
} }
return res, nil return res, nil
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -42,7 +42,14 @@
{{ $t('app.toInstall') }} {{ $t('app.toInstall') }}
</el-link> </el-link>
</span> </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-row :gutter="10" v-if="p.type == 'apps'">
<el-col :span="12"> <el-col :span="12">
<el-form-item :prop="p.prop"> <el-form-item :prop="p.prop">

View File

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