123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467 |
- <template>
- <a-form-item
- v-if="
- [
- 'input',
- 'textarea',
- 'date',
- 'time',
- 'number',
- 'radio',
- 'checkbox',
- 'select',
- 'rate',
- 'switch',
- 'slider',
- 'uploadImg',
- 'uploadFile',
- 'cascader',
- 'treeSelect'
- ].includes(record.type)
- "
- :label-col="
- formConfig.layout === 'horizontal'
- ? formConfig.labelLayout === 'flex'
- ? { style: `width:${formConfig.labelWidth}px` }
- : formConfig.labelCol
- : {}
- "
- :wrapper-col="
- formConfig.layout === 'horizontal'
- ? formConfig.labelLayout === 'flex'
- ? { style: 'width:auto;flex:1' }
- : formConfig.wrapperCol
- : {}
- "
- :style="
- formConfig.layout === 'horizontal' && formConfig.labelLayout === 'flex'
- ? { display: 'flex' }
- : {}
- "
- >
- <span slot="label">
- <a-tooltip>
- <span v-text="record.label"></span>
- <span v-if="record.help" slot="title" v-html="record.help"></span>
- <a-icon
- v-if="record.help"
- class="question-circle"
- type="question-circle-o"
- />
- </a-tooltip>
- </span>
-
- <a-textarea
- :style="`width:${record.options.width}`"
- v-if="record.type === 'textarea'"
- :autoSize="{
- minRows: record.options.minRows,
- maxRows: record.options.maxRows
- }"
- :disabled="disabled || record.options.disabled"
- :placeholder="record.options.placeholder"
- :allowClear="record.options.clearable"
- :maxLength="record.options.maxLength"
- :rows="4"
- @change="handleChange($event.target.value, record.model)"
- v-decorator="[
- record.model, // input 的 name
- {
- initialValue: record.options.defaultValue, // 默认值
- rules: record.rules // 验证规则
- }
- ]"
- />
-
- <a-radio-group
- v-else-if="record.type === 'radio'"
- :options="
- !record.options.dynamic
- ? record.options.options
- : dynamicData[record.options.dynamicKey]
- ? dynamicData[record.options.dynamicKey]
- : []
- "
- :disabled="disabled || record.options.disabled"
- :placeholder="record.options.placeholder"
- @change="handleChange($event.target.value, record.model)"
- v-decorator="[
- record.model,
- {
- initialValue: record.options.defaultValue,
- rules: record.rules
- }
- ]"
- />
-
- <a-checkbox-group
- v-else-if="record.type === 'checkbox'"
- :options="
- !record.options.dynamic
- ? record.options.options
- : dynamicData[record.options.dynamicKey]
- ? dynamicData[record.options.dynamicKey]
- : []
- "
- :disabled="disabled || record.options.disabled"
- :placeholder="record.options.placeholder"
- @change="handleChange($event, record.model)"
- v-decorator="[
- record.model,
- {
- initialValue: record.options.defaultValue,
- rules: record.rules
- }
- ]"
- />
-
- <a-switch
- v-else-if="record.type === 'switch'"
- :disabled="disabled || record.options.disabled"
- @change="handleChange($event, record.model)"
- v-decorator="[
- record.model,
- {
- initialValue: record.options.defaultValue,
- valuePropName: 'checked',
- rules: record.rules
- }
- ]"
- />
-
- <div
- v-else-if="record.type === 'slider'"
- :style="`width:${record.options.width}`"
- class="slider-box"
- >
- <div class="slider">
- <a-slider
- :disabled="disabled || record.options.disabled"
- :min="record.options.min"
- :max="record.options.max"
- :step="record.options.step"
- @change="handleChange($event, record.model)"
- v-decorator="[
- record.model,
- {
- initialValue: record.options.defaultValue,
- rules: record.rules
- }
- ]"
- />
- </div>
- <div class="number" v-if="record.options.showInput">
- <a-input-number
- style="width: 100%"
- :disabled="disabled || record.options.disabled"
- :min="record.options.min"
- :max="record.options.max"
- :step="record.options.step"
- @change="handleChange($event, record.model)"
- v-decorator="[
- record.model,
- {
- initialValue: record.options.defaultValue,
- rules: [
- {
- validator: (rule, value, callback) => {
- if (
- record.options.step &&
- value % record.options.step !== 0
- ) {
- callback('输入值必须是步长的倍数');
- }
- callback();
- }
- }
- ]
- }
- ]"
- />
- </div>
- </div>
- <component
- v-else
- :style="`width:${record.options.width}`"
- v-bind="componentOption"
- :min="
- record.options.min || record.options.min === 0
- ? record.options.min
- : -Infinity
- "
- :max="
- record.options.max || record.options.max === 0
- ? record.options.max
- : Infinity
- "
- :precision="
- record.options.precision > 50 ||
- (!record.options.precision && record.options.precision !== 0)
- ? null
- : record.options.precision
- "
- :parentDisabled="disabled || record.options.disabled"
- :disabled="disabled || record.options.disabled"
- :record="record"
- :config="config"
- :filterOption="
- record.options.showSearch
- ? (inputValue, option) => {
- return (
- option.componentOptions.children[0].text
- .toLowerCase()
- .indexOf(inputValue.toLowerCase()) >= 0
- );
- }
- : false
- "
- :allowClear="record.options.clearable"
- :dynamicData="dynamicData"
- :treeData="
- !record.options.dynamic
- ? record.options.options
- : dynamicData[record.options.dynamicKey]
- ? dynamicData[record.options.dynamicKey]
- : []
- "
- :options="
- !record.options.dynamic
- ? record.options.options
- : dynamicData[record.options.dynamicKey]
- ? dynamicData[record.options.dynamicKey]
- : []
- "
- :mode="record.options.multiple ? 'multiple' : ''"
- @change="handleChange($event, record.model)"
- v-decorator="[
- record.model, // input 的 name
- {
- initialValue: record.options.defaultValue, // 默认值
- rules: record.rules // 验证规则
- }
- ]"
- :is="componentItem"
- ></component>
- </a-form-item>
-
- <a-form-item
- v-else-if="['batch', 'editor', 'selectInputList'].includes(record.type)"
- :label="!record.options.showLabel ? '' : record.label"
- :label-col="
- formConfig.layout === 'horizontal' && record.options.showLabel
- ? formConfig.labelLayout === 'flex'
- ? { style: `width:${formConfig.labelWidth}px` }
- : formConfig.labelCol
- : {}
- "
- :wrapper-col="
- formConfig.layout === 'horizontal' && record.options.showLabel
- ? formConfig.labelLayout === 'flex'
- ? { style: 'width:auto;flex:1' }
- : formConfig.wrapperCol
- : {}
- "
- :style="
- formConfig.layout === 'horizontal' &&
- formConfig.labelLayout === 'flex' &&
- record.options.showLabel
- ? { display: 'flex' }
- : {}
- "
- >
- <component
- :ref="['batch', 'selectInputList'].includes(record.type) && 'KBatch'"
- :style="`width:${record.options.width}`"
- v-bind="componentOption"
- :record="record"
- :config="config"
- :parentDisabled="disabled || record.options.disabled"
- :disabled="disabled || record.options.disabled"
- :dynamicData="dynamicData"
- @change="handleChange($event, record.model)"
- v-decorator="[
- record.model, // input 的 name
- {
- initialValue: record.options.defaultValue, // 默认值
- rules: record.rules // 验证规则
- }
- ]"
- :is="componentItem"
- ></component>
- </a-form-item>
-
- <a-form-item v-else-if="record.type === 'button'">
- <a-button
- :disabled="disabled || record.options.disabled"
- @click="
- record.options.handle === 'submit'
- ? false
- : record.options.handle === 'reset'
- ? $emit('handleReset')
- : dynamicData[record.options.dynamicFun]
- ? dynamicData[record.options.dynamicFun]()
- : false
- "
- :type="record.options.type"
- :html-type="record.options.handle === 'submit' ? 'submit' : undefined"
- v-text="record.label"
- ></a-button>
- </a-form-item>
-
- <a-form-item v-else-if="record.type === 'alert'">
- <a-alert
- :message="record.label"
- :description="record.options.description"
- :type="record.options.type"
- :showIcon="record.options.showIcon"
- :closable="record.options.closable"
- :banner="record.options.banner"
- />
- </a-form-item>
-
- <a-form-item v-else-if="record.type === 'text'">
- <div :style="{ textAlign: record.options.textAlign }">
- <label
- :class="{ 'ant-form-item-required': record.options.showRequiredMark }"
- :style="{
- fontFamily: record.options.fontFamily,
- fontSize: record.options.fontSize,
- color: record.options.color
- }"
- v-text="record.label"
- ></label>
- </div>
- </a-form-item>
-
- <div
- v-else-if="record.type === 'html'"
- v-html="record.options.defaultValue"
- ></div>
-
- <customComponent
- v-else-if="customList.includes(record.type)"
- :record="record"
- :disabled="disabled"
- :dynamicData="dynamicData"
- @change="handleChange($event, record.model)"
- :formConfig="formConfig"
- />
- <div v-else>
-
- <a-divider
- v-if="
- record.type === 'divider' &&
- record.label !== '' &&
- record.options.orientation
- "
- :orientation="record.options.orientation"
- >{{ record.label }}</a-divider
- >
- <a-divider v-else-if="record.type === 'divider' && record.label !== ''">{{
- record.label
- }}</a-divider>
- <a-divider v-else-if="record.type === 'divider' && record.label === ''" />
- </div>
- </template>
- <script>
- import customComponent from "./customComponent";
- import ComponentArray from "../core/components_use";
- const _ = require("lodash/object");
- export default {
- name: "KFormItem",
- props: {
-
- record: {
- type: Object,
- required: true
- },
-
- formConfig: {
- type: Object,
- required: true
- },
- config: {
- type: Object,
- default: () => ({})
- },
- dynamicData: {
- type: Object,
- default: () => ({})
- },
- disabled: {
- type: Boolean,
- default: false
- }
- },
- components: {
- customComponent
- },
- computed: {
- customList() {
- if (window.$customComponentList) {
- return window.$customComponentList.map(item => item.type);
- } else {
- return [];
- }
- },
-
- componentItem() {
- return ComponentArray[this.record.type];
- },
- componentOption() {
- return _.omit(this.record.options, ["defaultValue", "disabled"]);
- }
- },
- methods: {
- validationSubform() {
-
- if (!this.$refs.KBatch) return true;
- return this.$refs.KBatch.validationSubform();
- },
- handleChange(e, key) {
- let value = e;
- if (e && e.target) {
- value = e.target.value;
- }
-
- this.$emit("change", value, key);
- }
- }
- };
- </script>
- <style lang="less" scoped>
- .slider-box {
- display: flex;
- > .slider {
- flex: 1;
- margin-right: 16px;
- }
- > .number {
- width: 70px;
- }
- }
- .anticon.anticon-question-circle-o {
- margin-left: 5px;
- }
- </style>
|