Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/ncform-common/src/mixins/vue/layout-array-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ export default {
idxChain: {
type: String,
default: ""
},

paths: {
type: String,
default: ""
}
},

Expand Down
5 changes: 5 additions & 0 deletions packages/ncform-common/src/mixins/vue/layout-object-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export default {
idxChain: {
type: String,
default: ""
},

paths: {
type: String,
default: ""
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<!-- array item 是 正常的 object 类型 -->
<template v-if="isNormalObjSchema(dataItem.__dataSchema)">
<ncform-object v-show="mergeConfig.disableItemCollapse || dataItem.__dataSchema._expand" :schema="dataItem.__dataSchema" :form-data="formData" :idx-chain="(idxChain ? idxChain + ',' : '') + idx" :config="dataItem.__dataSchema.ui.widgetConfig" :show-legend="false">
<ncform-object v-show="mergeConfig.disableItemCollapse || dataItem.__dataSchema._expand" :schema="dataItem.__dataSchema" :form-data="formData" :idx-chain="(idxChain ? idxChain + ',' : '') + idx" :config="dataItem.__dataSchema.ui.widgetConfig" :show-legend="false" :paths="paths + '[' + (idxChain ? idxChain + ',' : '') + idx + ']'">

<template v-for="(fieldSchema, fieldName) in (dataItem.__dataSchema.properties || {__notObjItem: dataItem.__dataSchema})" :slot="fieldName"><!-- 注意:__notObjItem 这个Key为与form-item约定好的值,其它名字不生效 -->
<slot :name="fieldName" :schema="fieldSchema" :idx="idx"></slot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!-- 垂直布局,即label上,control下 -->
<div v-if="mergeConfig.layout === 'v'" v-show="!collapsed" class="el-row v-layout" style="width: 100%">

<div v-for="(fieldSchema, field) in schema.properties"
<div v-for="(fieldSchema, field) in filteredPropreties"
:key="field"
:class="['el-col-' + (fieldSchema.ui.columns * 2 || 24)]"
:style="{display: _analyzeVal(fieldSchema.ui.hidden) ? 'none' : ''}"
Expand All @@ -20,9 +20,9 @@
<i v-if="_analyzeVal(fieldSchema.rules.required) === true || (typeof fieldSchema.rules.required === 'object' && _analyzeVal(fieldSchema.rules.required.value) === true)" class="text-danger">*</i>
{{_analyzeVal(fieldSchema.ui.label)}}
<!-- 提示信息 -->
<el-tooltip class="item" effect="dark" :content="fieldSchema.ui.help.content" placement="right-start">
<el-tooltip v-if="fieldSchema.ui.help.show === true" class="item" effect="dark" :content="fieldSchema.ui.help.content" placement="right-start">
<div slot="content" v-html="fieldSchema.ui.help.content"></div>
<a class="help" v-if="fieldSchema.ui.help.show === true" href="#"><span :class="fieldSchema.ui.help.iconCls">{{fieldSchema.ui.help.text}}</span></a>
<a class="help" href="#"><span :class="fieldSchema.ui.help.iconCls">{{fieldSchema.ui.help.text}}</span></a>
</el-tooltip>
</label>

Expand All @@ -41,7 +41,7 @@

<!-- 水平布局,即label左,control右 -->
<div v-if="mergeConfig.layout === 'h'" v-show="!collapsed" class="el-row h-layout" style="width: 100%">
<div v-for="(fieldSchema, field) in schema.properties"
<div v-for="(fieldSchema, field) in filteredPropreties"
:key="field"
:class="['el-col-' + (fieldSchema.ui.columns * 2 || 24)]"
:style="{display: _analyzeVal(fieldSchema.ui.hidden) ? 'none' : ''}"
Expand Down Expand Up @@ -161,6 +161,7 @@

<script>
import ncformCommon from '@ncform/ncform-common';
import _set from "lodash-es/set";

const ncformUtils = ncformCommon.ncformUtils;
const layoutObjectMixin = ncformCommon.mixins.vue.layoutObjectMixin;
Expand All @@ -172,6 +173,25 @@ export default {
default: true
}
},
computed: {
filteredPropreties() {
const { paths } = this
const { properties } = this.schema
return Object.keys(properties).reduce((result, curkey) => {
const curval = properties[curkey]
const remove = this._analyzeVal(curval.ui.remove)

if (remove) {
const fullkey = paths ? paths + '.' + curkey : curkey
_set(this.formData, fullkey, undefined)
} else {
result[curkey] = curval
}

return result
}, {})
}
},
methods: {
legendEnable(fieldSchema) {
return fieldSchema.ui && fieldSchema.ui.showLegend && fieldSchema.ui.legend;
Expand Down
6 changes: 3 additions & 3 deletions packages/ncform/src/components/vue-ncform/form-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div :class="[(!!schema.__validationResult && !schema.__validationResult.result) ? 'invalid' : '', schema.ui.itemClass]">

<!-- object 类型 -->
<component v-if="isNormalObjSchema(schema)" :is="'ncform-' + schema.ui.widget" :schema="schema" :form-data="formData" :temp-data="tempData" :global-const="globalConfig.constants" :idx-chain="idxChain" :config="schema.ui.widgetConfig">
<component v-if="isNormalObjSchema(schema)" :is="'ncform-' + schema.ui.widget" :schema="schema" :paths="paths" :form-data="formData" :temp-data="tempData" :global-const="globalConfig.constants" :idx-chain="idxChain" :config="schema.ui.widgetConfig">

<template v-for="(fieldSchema, fieldName) in schema.properties" :slot="fieldName">
<form-item :schema="fieldSchema" :form-data="formData" :temp-data="tempData" :global-const="globalConfig.constants" :key="fieldName" :global-config="globalConfig" :idx-chain="idxChain" :complete-schema="completeSchema" :paths="paths ? paths + '.' + fieldName : fieldName" :form-name="formName"></form-item>
Expand All @@ -12,10 +12,10 @@
</component>

<!-- array 类型 -->
<component v-else-if="isNormalArrSchema(schema)" :is="'ncform-' + schema.ui.widget" :schema="schema" :form-data="formData" :temp-data="tempData" :global-const="globalConfig.constants" :idx-chain="idxChain" :config="schema.ui.widgetConfig" class="__ncform-control">
<component v-else-if="isNormalArrSchema(schema)" :is="'ncform-' + schema.ui.widget" :schema="schema" :paths="paths" :form-data="formData" :temp-data="tempData" :global-const="globalConfig.constants" :idx-chain="idxChain" :config="schema.ui.widgetConfig" class="__ncform-control">

<template v-for="(fieldSchema, fieldName) in (schema.items.properties || {__notObjItem: schema.items})" :slot="fieldName" slot-scope="props">
<form-item :schema="props.schema" :key="fieldName" :form-data="formData" :temp-data="tempData" :global-const="globalConfig.constants" :idx-chain="(idxChain ? idxChain + ',' : '') + props.idx" :global-config="globalConfig" :complete-schema="completeSchema" :paths="paths + '[' + props.idx + ']'" :form-name="formName"></form-item>
<form-item :schema="props.schema" :key="fieldName" :form-data="formData" :temp-data="tempData" :global-const="globalConfig.constants" :idx-chain="(idxChain ? idxChain + ',' : '') + props.idx" :global-config="globalConfig" :complete-schema="completeSchema" :paths="paths + '[' + props.idx + ']' + '.' + fieldName" :form-name="formName"></form-item>
</template>

</component>
Expand Down
11 changes: 11 additions & 0 deletions packages/ncform/src/components/vue-ncform/ncform.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ export default {
checkValidation(schema, __path, __dataPath, __idxChain) {
__idxChain = __idxChain === undefined ? '' : __idxChain; // 不在参数命名的时候给默认值是因为会传了undifine进来导致错误

// 如果移除字段,则忽略校验规则
const isRemove = ncformUtils.smartAnalyzeVal(schema.ui.remove, {
idxChain: __idxChain,
data: {
rootData: this.$data.formData,
constData: this.dataFormSchema.globalConfig.constants
}
});
if (isRemove)
return Promise.resolve({ result: true, __path, __dataPath });

if (
_get(this.dataFormSchema, 'globalConfig.ignoreRulesWhenHidden', true)
) {
Expand Down