Skip to content

Commit

Permalink
feat: 样式修改
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 24398
  • Loading branch information
hyunfa committed Nov 20, 2024
1 parent 36f3c27 commit 9ccf230
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 18 deletions.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}
},
"dependencies": {
"@blueking/bkui-form": "^0.0.42-beta.14",
"@blueking/bkui-form": "^0.0.42-beta.15",
"@blueking/crypto-js-sdk": "0.0.4",
"@blueking/ip-selector": "0.2.0-beta",
"@blueking/login-modal": "^1.0.1",
Expand Down
20 changes: 13 additions & 7 deletions frontend/src/components/RussianDolls/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export const transformSchema = (schema: any, parentRequired: any[] = [], key: st
prop['minItems'] = 1;
prop['ui:group'] = {
"props": {
"verifiable": true,
"verifiable": false,
},
};
}
Expand Down Expand Up @@ -232,13 +232,19 @@ export const transformSchema = (schema: any, parentRequired: any[] = [], key: st
if (schema.required !== undefined) {
delete schema.required; // 删除数组项中的 required
}
// 不展示组校验
schema['ui:group'] = {
"props": {
"verifiable": false,
},
};
// 添加样式修改
schema['ui:props'] = {
"size": 'large'
};
// 处理描述信息
if (schema.description) {
schema['ui:group'] = {
"props": {
"description": schema.description,
},
};
schema['ui:group']['props']['description'] = schema.description;
}
if (schema.items.properties && Object.keys(schema.items.properties).length >= 2) {
// 如果是 key 和 value,添加 ui:component
Expand All @@ -255,7 +261,7 @@ export const transformSchema = (schema: any, parentRequired: any[] = [], key: st
};
}
if (schema.items.type === 'string' || schema.items.type === 'boolean' || schema.items.type === 'integer') {
parentRequired.push(key);
// parentRequired.push(key);
}
}

Expand Down
199 changes: 199 additions & 0 deletions frontend/src/components/common/key-value.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<template>
<div class="bfArray">
<template v-if="modelValue.length">
<div v-for="(item, index) in modelValue" :key="index" class="key-value-item">
<bk-input
v-model="item.key"
:placeholder="`Key ${index + 1}`"
:class="['key-input', { 'is-error': schema.items.required.includes('key') && item.key === '' && isValid[index]}]"
>
<span
slot="append"
class="error-tip is-error"
v-bk-tooltips="$t('必填项')">
<template v-if="schema.items.required.includes('key') && item.key === '' && isValid[index]">
<i class="bk-icon icon-exclamation-circle-shape"></i>
</template>
</span>
</bk-input>
<bk-input
v-model="item.value"
:placeholder="`Value ${index + 1}`"
:class="['value-input', { 'is-error': schema.items.required.includes('value') && item.value === '' && isValid[index] }]"
>
<span
slot="append"
class="error-tip is-error"
v-bk-tooltips="$t('必填项')">
<template v-if="schema.items.required.includes('value') && item.value === '' && isValid[index]">
<i class="bk-icon icon-exclamation-circle-shape"></i>
</template>
</span>
</bk-input>
<!-- 新增的增加按钮 -->
<bk-button @click="addItemAt(index)" icon="bk-icon icon-plus-circle" class="add-btn"></bk-button>
<bk-button @click="removeItem(index)" icon="bk-icon icon-minus-circle" class="remove-btn"></bk-button>
</div>
</template>
<div v-else>
<div :class="{'add-bar': schema['ui:props'].size === 'large'}" @click.stop="() => addItem()">
<i class="nodeman-icon nc-plus" />
{{ $t('添加') }}{{ schema['ui:props'].size === 'large' ? schema.title : '' }}
</div>
</div>

</div>
</template>

<script>
import { defineComponent, ref, watch, onMounted } from 'vue';
import bus from '@/common/bus';
export default defineComponent({
name: 'KeyValueComponent',
props: {
schema: {
type: Object,
default: () => ({}),
},
// 当前路径(唯一标识)
path: {
type: String,
default: '',
},
// 是否必须字段
required: {
type: Boolean,
default: false,
},
// 全量数据(只读)
rootData: {
type: Object,
default: () => ({}),
},
// 当前值
value: {
type: [String, Number, Array, Object, Boolean],
},
// 布局配置
layout: {
type: Object,
default: () => ({}),
},
// 当前全局变量上下文
context: {
type: Object,
default: () => ({}),
},
// 当前项是否可移除
removeable: {
type: Boolean,
default: false,
},
},
setup(props, { emit }) {
const modelValue = ref([...props.value]);
// 填充校验,true表示已校验
const isValid = ref(new Array(props.value.length).fill(false));
watch(modelValue, (newValue) => {
emit('input', newValue);
}, { deep: true });
const addItem = () => {
isValid.value.push(false);
modelValue.value.push({ key: '', value: '' });
};
// 在指定位置插入新项
const addItemAt = (index) => {
isValid.value.push(false);
modelValue.value.splice(index + 1, 0, { key: '', value: '' });
};
const removeItem = (index) => {
isValid.value.pop();
modelValue.value.splice(index, 1);
};
const handleBlur = (index) => {
isValid.value[index] = true;
}
const handleFocus = (index) => {
isValid.value[index] = false;
}
const validate = (cb) => {
isValid.value.fill(true);
isValid.value = [...isValid.value];
const hasEmpty = modelValue.value.some((item) =>
(item.key === '' && props.schema.items.required.includes('key'))
|| (item.value === '' && props.schema.items.required.includes('value')));
if (hasEmpty) {
cb(false);
}else{
cb(true);
}
}
onMounted(() => {
bus.$on('validate', validate)
});
return {
isValid,
modelValue,
handleBlur,
handleFocus,
addItem,
addItemAt,
removeItem
};
}
});
</script>

<style lang="postcss" scoped>
.key-value-item {
display: flex;
align-items: center;
flex: 1;
padding-right: 20px;
background: #f5f7fa;
margin-bottom: 12px;
width: 100%;
}
.key-input{
margin-right: 20px;
}
.add-btn,.remove-btn {
border: none;
background-color: transparent;
}
.add-bar {
border: 1px dashed #3a84ff;
border-radius: 2px;
color: #3a84ff;
cursor: pointer;
text-align: center;
}
.key-input, .value-input {
position: relative;
}
.is-error {
/deep/ input[type=text] {
border-color: #ff5656;
color: #ff5656;
}
&.error-tip {
position: absolute;
right: 8px;
font-size: 16px;
color: #ea3636;
cursor: pointer;
}
}
/deep/ .bk-form-control .group-box {
border: none !important;
}
</style>
1 change: 1 addition & 0 deletions frontend/src/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ export default {
选择版本: 'Choose version',
'静态 - IP 选择': 'Static-IP selection',
'动态 - 拓扑选择': 'Dynamic-Topo selection',
添加: 'Add',
已部署: 'Deployed',
全部主机: 'All hosts',
搜索拓扑节点: 'Search topology node',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ export default {
升级版本: '升级版本',
升级目标: '升级目标',
参数配置: '参数配置',
添加: '添加',
执行预览: '执行预览',
部署目标: '部署目标',
部署版本: '部署版本',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,14 @@ import { pluginOperate } from '../../operateConfig';
import bus from '@/common/bus';
import createForm from '@blueking/bkui-form';
import '@blueking/bkui-form/dist/bkui-form.css';
import { transformSchema } from '@/components/RussianDolls/create'
import { transformSchema } from '@/components/RussianDolls/create';
import keyValue from '@/components/common/key-value';
const BKUIFrom = createForm()
const BKUIFrom = createForm({
components: {
bfArray: keyValue
}
})
interface IVariables {
title: string
Expand Down Expand Up @@ -613,11 +618,10 @@ export default class ParamsConfig extends Vue {
// 检查表单
public async handleValidateForm() {
// const validateRes: boolean[] = [];
// bus.$emit('validate', (result: boolean) => {
// validateRes.push(result);
// });
// if(validateRes.some(res => !res)) return true;
const validateRes: boolean[] = [];
bus.$emit('validate', (result: boolean) => {
validateRes.push(result);
});
// const checkList: Promise<boolean>[] = [];
// this.list.forEach((item: IParamsConfig) => {
Expand All @@ -642,11 +646,10 @@ export default class ParamsConfig extends Vue {
// resolve(true);
// });
// });
const validRes: boolean[] = [];
(this.$refs.bkuiFormRef as Array<any>)?.forEach((item: any) => {
validRes.push(item.validateForm());
validateRes.push(item.validateForm());
})
return validRes.some(valid => !valid);
return validateRes.some(valid => !valid);
}
// 更新策略的 params 和 configs 属性
Expand Down

0 comments on commit 9ccf230

Please sign in to comment.