app-panel-field.vue 4.2 KB
Newer Older
1
<template>
Shine-zwj's avatar
Shine-zwj committed
2 3
  <div :class="curClassName" :style="curStyle">
    <div v-if="Object.is(labelPos, 'NONE') || !labelPos" class="editor">
Shine-zwj's avatar
Shine-zwj committed
4
      <div :class="{ 'check-error': !valueCheck }">
Shine-zwj's avatar
Shine-zwj committed
5
        <slot></slot>
Shine-zwj's avatar
Shine-zwj committed
6
        <span v-if="!valueCheck" class="error-info">{{ error }}</span>
Shine-zwj's avatar
Shine-zwj committed
7
      </div>
8
    </div>
Shine-zwj's avatar
Shine-zwj committed
9 10
    <div v-if="!Object.is(labelPos, 'NONE')" class="app-panel-field-label">
      <span v-if="required" style="color: red">* </span>
Shine-zwj's avatar
Shine-zwj committed
11
      <span v-if="showCaption">{{ caption }}</span>
Shine-zwj's avatar
Shine-zwj committed
12 13 14 15 16 17 18 19 20 21
    </div>
    <div
      v-if="
        Object.is(labelPos, 'BOTTOM') ||
        Object.is(labelPos, 'TOP') ||
        Object.is(labelPos, 'LEFT') ||
        Object.is(labelPos, 'RIGHT')
      "
      class="editor"
    >
Shine-zwj's avatar
Shine-zwj committed
22
      <div :class="{ 'check-error': !valueCheck }">
Shine-zwj's avatar
Shine-zwj committed
23
        <slot></slot>
Shine-zwj's avatar
Shine-zwj committed
24
        <span v-if="!valueCheck" class="error-info">{{ error }}</span>
Shine-zwj's avatar
Shine-zwj committed
25 26 27
      </div>
    </div>
  </div>
28 29 30 31 32
</template>
<script lang="ts">
import { Vue, Component, Prop, Watch } from "vue-property-decorator";

@Component({})
Shine-zwj's avatar
Shine-zwj committed
33
export default class AppPanelField extends Vue {
34 35 36 37
  /**
   * 名称
   *
   * @type {string}
Shine-zwj's avatar
Shine-zwj committed
38
   * @memberof AppPanelField
39
   */
Shine-zwj's avatar
Shine-zwj committed
40
  @Prop() public name!: string;
41 42

  /**
Shine-zwj's avatar
Shine-zwj committed
43
   * 下标
44
   *
Shine-zwj's avatar
Shine-zwj committed
45
   * @type {string}
Shine-zwj's avatar
Shine-zwj committed
46
   * @memberof AppPanelField
47
   */
Shine-zwj's avatar
Shine-zwj committed
48
  @Prop({ default: 0 }) public index?: number;
49 50

  /**
Shine-zwj's avatar
Shine-zwj committed
51
   * 编辑器值
52
   *
Shine-zwj's avatar
Shine-zwj committed
53
   * @type {any}
Shine-zwj's avatar
Shine-zwj committed
54
   * @memberof AppPanelField
55
   */
Shine-zwj's avatar
Shine-zwj committed
56
  @Prop() public value!: any;
57 58

  /**
Shine-zwj's avatar
Shine-zwj committed
59
   * 布局模型详情
60
   *
Shine-zwj's avatar
Shine-zwj committed
61
   * @type {*}
Shine-zwj's avatar
Shine-zwj committed
62
   * @memberof AppPanelField
63
   */
Shine-zwj's avatar
Shine-zwj committed
64
  @Prop() public layoutModelDetails!: any;
65 66

  /**
Shine-zwj's avatar
Shine-zwj committed
67
   * 项名称
68
   *
Shine-zwj's avatar
Shine-zwj committed
69
   * @memberof AppPanelField
70
   */
Shine-zwj's avatar
Shine-zwj committed
71
  get itemName() {
Shine-zwj's avatar
Shine-zwj committed
72
    return (this.index || this.index === 0) ? `${this.name}_${this.index}` : this.name;
Shine-zwj's avatar
Shine-zwj committed
73
  }
74

Shine-zwj's avatar
Shine-zwj committed
75 76 77 78 79 80 81 82 83 84 85 86
  /**
   * 标题
   *
   * @memberof AppLoginButton
   */
  get caption() {
    const layoutModel = this.layoutModelDetails[this.itemName];
    if (layoutModel) {
      return layoutModel.caption;
    }
  }

87
  /**
Shine-zwj's avatar
Shine-zwj committed
88
   * 显示标题
89
   *
Shine-zwj's avatar
Shine-zwj committed
90
   * @memberof AppPanelField
91
   */
Shine-zwj's avatar
Shine-zwj committed
92 93 94 95 96 97
  get showCaption() {
    const layoutModel = this.layoutModelDetails[this.itemName];
    if (layoutModel) {
      return layoutModel.isShowCaption;
    }
  }
98 99

  /**
Shine-zwj's avatar
Shine-zwj committed
100
   * 类名
101
   *
Shine-zwj's avatar
Shine-zwj committed
102
   * @memberof AppPanelField
103
   */
Shine-zwj's avatar
Shine-zwj committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
  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}`;
    }
  }

129
  /**
Shine-zwj's avatar
Shine-zwj committed
130
   * 样式
131
   *
Shine-zwj's avatar
Shine-zwj committed
132
   * @memberof AppPanelField
133
   */
Shine-zwj's avatar
Shine-zwj committed
134 135 136 137 138 139
  get curStyle() {
    const layoutModel = this.layoutModelDetails[this.itemName];
    if (layoutModel) {
      return layoutModel.getElementStyle();
    }
  }
140 141

  /**
Shine-zwj's avatar
Shine-zwj committed
142
   * 标签位置
143
   *
Shine-zwj's avatar
Shine-zwj committed
144
   * @memberof AppPanelField
145
   */
Shine-zwj's avatar
Shine-zwj committed
146 147 148 149 150 151 152
  get labelPos() {
    const layoutModel = this.layoutModelDetails[this.itemName];
    if (layoutModel) {
      return layoutModel.labelPos || "LEFT";
    }
    return "LEFT";
  }
153 154

  /**
Shine-zwj's avatar
Shine-zwj committed
155
   * 必填
156
   *
Shine-zwj's avatar
Shine-zwj committed
157
   * @memberof AppPanelField
158
   */
Shine-zwj's avatar
Shine-zwj committed
159 160 161 162
  get required() {
    const layoutModel = this.layoutModelDetails[this.itemName];
    if (layoutModel) {
      return layoutModel.required;
163 164 165
    }
  }

Shine-zwj's avatar
Shine-zwj committed
166 167 168 169 170 171 172 173 174 175 176 177
  /**
   * 错误信息
   *
   * @memberof AppPanelField
   */
  get error() {
    const layoutModel = this.layoutModelDetails[this.itemName];
    if (layoutModel) {
      return layoutModel.error || `${this.caption} 值不能为空!`;
    }
  }

178
  /**
Shine-zwj's avatar
Shine-zwj committed
179
   * 值校验
180
   *
Shine-zwj's avatar
Shine-zwj committed
181
   * @memberof AppPanelField
182
   */
Shine-zwj's avatar
Shine-zwj committed
183 184 185 186 187 188 189
  get valueCheck() {
    let valueCheck = true;
    if (this.required && !this.value && this.valueChange) {
      valueCheck = false;
    }
    return valueCheck;
  }
190 191

  /**
Shine-zwj's avatar
Shine-zwj committed
192
   * 值改变
193
   *
Shine-zwj's avatar
Shine-zwj committed
194
   * @memberof AppPanelField
195
   */
Shine-zwj's avatar
Shine-zwj committed
196 197
  public valueChange: boolean = false;

198
  @Watch("value")
Shine-zwj's avatar
Shine-zwj committed
199
  itemValueRules(newVal: any, oldVal: any) {
Shine-zwj's avatar
Shine-zwj committed
200
    this.valueChange = true;
201 202 203
  }
}
</script>
204 205
<style lang='scss'>
@import "./app-panel-field.scss";
206
</style>