-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4704 from vhwweng/tttissue_4583
feat: 简化dynamic-parameter-simple组件 issue #4583
- Loading branch information
Showing
6 changed files
with
315 additions
and
0 deletions.
There are no files selected for viewing
180 changes: 180 additions & 0 deletions
180
...rontend/devops-pipeline/src/components/AtomFormComponent/DynamicParameterSimple/index.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
<template> | ||
<ul class="param-main" v-bkloading="{ isLoading }"> | ||
<li class="param-label" style="display: flex; padding-right:30px;"> | ||
<span | ||
v-for="(item, index) in curParameters[0].rowAttributes" | ||
:key="index" | ||
class="input-label" | ||
:title="item.label"> | ||
{{ item.label }}: | ||
<i class="bk-icon icon-info-circle label-desc" v-bk-tooltips.top="{ content: item.desc }" /> | ||
</span> | ||
</li> | ||
<li class="param-com" v-for="(parameter, paramIndex) in curParameters" :key="paramIndex"> | ||
<parameter-com v-for="(model, index) in parameter.rowAttributes" | ||
:class="[{ 'last-child': index === parameter.rowAttributes.length - 1 }, 'input-com']" | ||
:style="{ maxWidth: `calc(${100 / parameter.rowAttributes.length}% - ${58 / parameter.rowAttributes.length}px)` }" | ||
v-bind="model" | ||
:key="model.id" | ||
@update-key="(newValue) => updateKey(model, newValue)" | ||
@update-value="(newValue) => updateValue(model, newValue)" | ||
:param-values="paramValues" | ||
></parameter-com> | ||
<i class="bk-icon icon-plus-circle" @click="plusParam(parameter, paramIndex)"></i> | ||
<i class="bk-icon icon-minus-circle" v-if="curParameters.length > 1" @click="minusParam(paramIndex)"></i> | ||
</li> | ||
</ul> | ||
</template> | ||
|
||
<script> | ||
import mixins from '../mixins' | ||
import parameterCom from './parameterCom' | ||
export default { | ||
name: 'dynamic-parameter-simple', | ||
components: { | ||
parameterCom | ||
}, | ||
mixins: [mixins], | ||
props: { | ||
parameters: { | ||
type: Array | ||
} | ||
}, | ||
data () { | ||
return { | ||
isLoading: false, | ||
curParameters: [] | ||
} | ||
}, | ||
created () { | ||
this.initData() | ||
}, | ||
methods: { | ||
initData () { | ||
this.curParameters = JSON.parse(JSON.stringify(this.parameters)) | ||
this.setValue() | ||
}, | ||
setValue () { | ||
let values = this.atomValue[this.name] || [] | ||
if (!Array.isArray(values)) values = JSON.parse(values) | ||
if (values.length) { | ||
this.curParameters = values.map((value) => { | ||
const originAttr = this.parameters[0] | ||
const currentRowAttr = JSON.parse(JSON.stringify(originAttr)) | ||
const curKeys = Object.keys(value) | ||
const curValues = Object.values(value) | ||
const rowAttrs = currentRowAttr.rowAttributes | ||
rowAttrs.forEach((attr, index) => { | ||
attr['id'] = curKeys[index] | ||
attr['value'] = curValues[index] | ||
}) | ||
return currentRowAttr | ||
}) | ||
} | ||
this.updateParameters() | ||
}, | ||
/** | ||
* 添加一行动态参数 | ||
*/ | ||
plusParam (parameter, index) { | ||
this.curParameters.splice(index, 0, JSON.parse(JSON.stringify(parameter))) | ||
this.updateParameters() | ||
}, | ||
/** | ||
* 删除一行动态参数 | ||
*/ | ||
minusParam (index) { | ||
this.curParameters.splice(index, 1) | ||
this.updateParameters() | ||
}, | ||
/** | ||
* key更新 | ||
*/ | ||
updateKey (model, newValue) { | ||
model.id = newValue | ||
this.updateParameters() | ||
}, | ||
/** | ||
* value更新 | ||
*/ | ||
updateValue (model, newValue) { | ||
model.value = newValue | ||
this.updateParameters() | ||
}, | ||
/** | ||
* 更新参数 | ||
*/ | ||
updateParameters () { | ||
const res = this.curParameters.map((parameter) => { | ||
const rowAttributes = parameter.rowAttributes | ||
const obj = {} | ||
rowAttributes.forEach((model) => { | ||
obj[model.id] = model.value || '' | ||
return obj | ||
}) | ||
return obj | ||
}) | ||
this.handleChange(this.name, String(JSON.stringify(res))) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.param-main { | ||
margin-top: 8px; | ||
.param-title { | ||
font-size: 12px; | ||
line-height: 30px; | ||
} | ||
.param-com { | ||
margin-bottom: 10px; | ||
display: flex; | ||
align-items: center; | ||
.input-com { | ||
flex: 1; | ||
margin-right: 10px; | ||
&.last-child { | ||
margin-right: 0; | ||
} | ||
} | ||
} | ||
.param-label { | ||
display: flex; | ||
padding-right: 30px; | ||
} | ||
.input-label { | ||
flex: 1; | ||
} | ||
} | ||
.bk-icon { | ||
margin-left: 5px; | ||
font-size: 14px; | ||
cursor: pointer; | ||
} | ||
.label-desc { | ||
position: relative; | ||
bottom: 1px; | ||
right: 6px; | ||
margin-left: 0; | ||
cursor: auto; | ||
color: #C3CDD7; | ||
font-size: 14px; | ||
vertical-align: middle; | ||
} | ||
</style> |
128 changes: 128 additions & 0 deletions
128
.../devops-pipeline/src/components/AtomFormComponent/DynamicParameterSimple/parameterCom.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<template> | ||
<section class="param-input-home"> | ||
<section class="parameter-input"> | ||
<bk-input | ||
v-if="type === 'input'" | ||
class="input-main" | ||
:clearable="!disabled" | ||
:disabled="disabled" | ||
:value="value" | ||
:placeholder="placeholder" | ||
@change="(newValue) => $emit('update-value', newValue)" /> | ||
<section | ||
v-else | ||
class="parameter-select input-main"> | ||
<bk-select | ||
:disabled="disabled" | ||
v-model="value" | ||
:placeholder="placeholder" | ||
@change="(newValue) => $emit('update-value', newValue)" | ||
ext-cls="select-custom" | ||
ext-popover-cls="select-popover-custom" | ||
searchable> | ||
<bk-option v-for="option in options" | ||
:key="option.id" | ||
:id="option.id" | ||
:name="option.name"> | ||
</bk-option> | ||
</bk-select> | ||
</section> | ||
</section> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
import mixins from '../mixins' | ||
export default { | ||
mixins: [mixins], | ||
props: { | ||
id: { | ||
type: String | ||
}, | ||
type: { | ||
type: String | ||
}, | ||
value: { | ||
type: [String, Array] | ||
}, | ||
disabled: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
options: { | ||
type: Array | ||
}, | ||
placeholder: { | ||
type: String, | ||
default: '' | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.param-input-home { | ||
display: flex; | ||
align-items: flex-end; | ||
flex: 1; | ||
.param-hyphen { | ||
margin-right: 11px; | ||
} | ||
} | ||
.parameter-input { | ||
flex: 1; | ||
.input-label { | ||
max-width: 100%; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
} | ||
.input-main { | ||
flex: 1; | ||
} | ||
} | ||
.parameter-select { | ||
position: relative; | ||
.parameter-list { | ||
position: absolute; | ||
top: 32px; | ||
left: 0; | ||
right: 0; | ||
padding: 6px 0; | ||
list-style: none; | ||
border: 1px solid #dcdee5; | ||
border-radius: 2px; | ||
line-height: 32px; | ||
background: #fff; | ||
color: #63656e; | ||
overflow: auto; | ||
max-height: 216px; | ||
z-index: 2; | ||
li { | ||
padding: 0 16px; | ||
position: relative; | ||
&:hover { | ||
color: #3a84ff; | ||
background-color: #eaf3ff; | ||
} | ||
} | ||
.is-active { | ||
color: #3a84ff; | ||
background-color: #f4f6fa; | ||
&:after { | ||
content: ''; | ||
position: absolute; | ||
right: 16px; | ||
top: 11px; | ||
height: 7px; | ||
width: 3px; | ||
transform: rotate(45deg); | ||
border-bottom: 1px solid #3a84ff; | ||
border-right: 1px solid #3a84ff; | ||
} | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters