提交 50b498ea 编写于 作者: Shine-zwj's avatar Shine-zwj

update:更新

上级 9692ced5
<template> <template>
<div :class="classes"> <div :class="curClassName" :style="curStyle">
<div v-if="Object.is(labelPos,'NONE') || !labelPos" class="editor"> <div v-if="Object.is(labelPos, 'NONE') || !labelPos" class="editor">
<div :class="valueCheck == true ?'':'editorstyle'"> <div :class="valueCheck == true ? '' : 'editorstyle'">
<slot ></slot> <slot></slot>
<span :class="error ? 'errorstyle':''">{{error}}</span> <span :class="error ? 'errorstyle' : ''">{{ error }}</span>
</div> </div>
</div>
<div v-if="!Object.is(labelPos,'NONE')" class="app-panel-field-label">
<span v-if="required" style="color:red;">* </span>
{{isEmptyCaption ? '' : caption}}
</div>
<div v-if="Object.is(labelPos,'BOTTOM') || Object.is(labelPos,'TOP') || Object.is(labelPos,'LEFT') || Object.is(labelPos,'RIGHT')" class="editor">
<div :class="valueCheck == true ?'':'editorstyle'">
<slot ></slot>
<span :class="error ? 'errorstyle':''">{{error}}</span>
</div>
</div>
</div> </div>
<div v-if="!Object.is(labelPos, 'NONE')" class="app-panel-field-label">
<span v-if="required" style="color: red">* </span>
<span v-if="showCaption">{{caption}}</span>
</div>
<div
v-if="
Object.is(labelPos, 'BOTTOM') ||
Object.is(labelPos, 'TOP') ||
Object.is(labelPos, 'LEFT') ||
Object.is(labelPos, 'RIGHT')
"
class="editor"
>
<div :class="valueCheck == true ? '' : 'editorstyle'">
<slot></slot>
<span :class="error ? 'errorstyle' : ''">{{ error }}</span>
</div>
</div>
</div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { Vue, Component, Prop, Watch } from "vue-property-decorator"; import { Vue, Component, Prop, Watch } from "vue-property-decorator";
...@@ -29,113 +37,130 @@ export default class AppPanelField extends Vue { ...@@ -29,113 +37,130 @@ export default class AppPanelField extends Vue {
* @type {string} * @type {string}
* @memberof AppPanelField * @memberof AppPanelField
*/ */
@Prop() public caption!: string; @Prop() public name!: string;
/** /**
* 错误信息 * 标题
* *
* @type {string} * @type {string}
* @memberof AppPanelField * @memberof AppPanelField
*/ */
@Prop() public error?: string; @Prop() public caption!: string;
/** /**
* 标签位置 * 下标
* *
* @type {(string | 'BOTTOM' | 'LEFT' | 'NONE' | 'RIGHT' | 'TOP')} * @type {string}
* @memberof AppPanelField * @memberof AppPanelField
*/ */
@Prop() public labelPos?: @Prop({ default: 0 }) public index?: number;
| string
| "BOTTOM"
| "LEFT"
| "NONE"
| "RIGHT"
| "TOP";
/** /**
* 标签是否空白 * 编辑器值
* *
* @type {boolean} * @type {any}
* @memberof AppPanelField * @memberof AppPanelField
*/ */
@Prop() public isEmptyCaption?: boolean; @Prop() public value!: any;
/** /**
* 列表项名称 * 布局模型详情
* *
* @type {string} * @type {*}
* @memberof AppPanelField * @memberof AppPanelField
*/ */
@Prop() public name!: string; @Prop() public layoutModelDetails!: any;
/** /**
* 面板数据 * 项名称
* *
* @type {any}
* @memberof AppPanelField * @memberof AppPanelField
*/ */
@Prop() public data!: any; get itemName() {
return this.index ? `${this.name}_${this.index}` : this.name;
}
/** /**
* 编辑器值 * 显示标题
* *
* @type {any}
* @memberof AppPanelField * @memberof AppPanelField
*/ */
@Prop() public value !: any; get showCaption() {
const layoutModel = this.layoutModelDetails[this.itemName];
if (layoutModel) {
return layoutModel.isShowCaption;
}
}
/** /**
* 值规则 * 类名
* *
* @type {string}
* @memberof AppPanelField * @memberof AppPanelField
*/ */
@Prop() public itemRules!: any; get curClassName() {
const layoutModel = this.layoutModelDetails[this.itemName];
if (layoutModel) {
let posClass = "";
switch (layoutModel.labelPos) {
case "TOP":
posClass = "label-top";
break;
case "LEFT":
posClass = "label-left";
break;
case "BOTTOM":
posClass = "label-bottom";
break;
case "RIGHT":
posClass = "label-right";
break;
case "NONE":
posClass = "label-none";
break;
}
return `app-panel-field ${posClass} ${this.itemName} ${layoutModel.sysCss}`;
}
}
/** /**
* 是否必填 * 样式
* *
* @type {boolean}
* @memberof AppPanelField * @memberof AppPanelField
*/ */
public required: boolean = false; get curStyle() {
const layoutModel = this.layoutModelDetails[this.itemName];
if (layoutModel) {
return layoutModel.getElementStyle();
}
}
/** /**
* 值规则数组 * 标签位置
* *
* @type {any[]}
* @memberof AppPanelField * @memberof AppPanelField
*/ */
public rules: any[] = []; get labelPos() {
const layoutModel = this.layoutModelDetails[this.itemName];
if (layoutModel) {
return layoutModel.labelPos || "LEFT";
}
return "LEFT";
}
/** /**
* 值规则监控 * 必填
* *
* @param {*} newVal
* @param {*} oldVal
* @memberof AppPanelField * @memberof AppPanelField
*/ */
@Watch("itemRules", { deep: true }) get required() {
onItemRulesChange(newVal: any, oldVal: any) { const layoutModel = this.layoutModelDetails[this.itemName];
if (newVal) { if (layoutModel) {
try { return layoutModel.required;
this.rules = [];
const _rules: any[] = newVal;
this.rules = [..._rules];
this.rules.some((rule: any) => {
if (rule.hasOwnProperty("required")) {
this.required = rule.required;
return true;
}
return false;
});
} catch (error) {}
} }
} }
/** /**
* 编辑器样式 * 值校验
* *
* @type {boolean} * @type {boolean}
* @memberof AppPanelField * @memberof AppPanelField
...@@ -150,61 +175,11 @@ export default class AppPanelField extends Vue { ...@@ -150,61 +175,11 @@ export default class AppPanelField extends Vue {
* @memberof AppPanelField * @memberof AppPanelField
*/ */
@Watch("value") @Watch("value")
ItemValueRules(newVal: any, oldVal: any) { itemValueRules(newVal: any, oldVal: any) {
if(this.required && !newVal) { if (this.required && !newVal) {
this.valueCheck = false; this.valueCheck = false;
}else{ } else {
this.valueCheck = true; this.valueCheck = true;
}
}
/**
* 计算样式
*
* @readonly
* @type {string []}
* @memberof AppPanelField
*/
get classes(): string[] {
let posClass = "";
switch (this.labelPos) {
case "TOP":
posClass = "label-top";
break;
case "LEFT":
posClass = "label-left";
break;
case "BOTTOM":
posClass = "label-bottom";
break;
case "RIGHT":
posClass = "label-right";
break;
case "NONE":
posClass = "label-none";
break;
}
return [ "app-panel-field", posClass ];
}
/**
* vue 生命周期
*
* @memberof AppPanelField
*/
public mounted() {
if (this.itemRules) {
try {
const _rules: any[] = this.itemRules;
this.rules = [..._rules];
this.rules.some((rule: any) => {
if (rule.hasOwnProperty("required")) {
this.required = rule.required;
return true;
}
return false;
});
} catch (error) {}
} }
} }
} }
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册