公共数据字典选择组件SelectCommonDict


基础字典维护

引用:

Markup 全选
import SelectCommonDict from '@components/SelectCommonDict/index.vue'
...
components: {
    SelectCommonDict
}

使用例子

HTML 全选
<SelectCommonDict :disabled="isView" v-model="data.deliveryType" dict-type="送货方式" :only-label="true"></SelectCommonDict>

公共数据字典选择组件SelectCommonDict

属性说明

属性类型说明
disabledboolean组件可用状态
dict-type
string基础数据类型,对应数据字典中的类别,类别名称
only-label
boolean是否只设置描述文本,默认:false,默认value值为code,如果该值设置为true,则value会设置为描述文本值,如果该值为true,则按道理不需要再去多余的设置options
optionsobject配置,当用户选择数据的时候,会根据配置自动设置附加数据字段,当 ony-label为false时,可以通过该配置来自动给描述文本字段设置文本描述值
options.dataSourceobject数据源
options.codeFildNamestring数据源中ID对应的字段名称,当选择数据的时候,会自动设置该属性值
options.descriptionFileNamestring数据源中描述文本对应的字段名称,当选择数据的时候,会自动设置该属性值

 

组件源码

JavaScript 全选
<template>
  <el-select style="width:100%;" v-model="currentValue" :disabled="disabled" placeholder="请选择">
    <el-option v-for="item in data" :key="item.dictID" :label="item.dictDescription" :value="item[valueMember]"></el-option>
  </el-select>

</template>

<script>
import { ajax } from 'yesweb-libs'

const request = {
  getCommonData(context, dictType) {
    return ajax.get(context, '/microapps/CommonDict/GetCommonData', {
      dictType,
    })
  },
}

export default {
  data() {
    return {
      currentValue: this.value,
      data: [],
    }
  },
  props: {
    value: {
      type: String,
      default: '',
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    dictType: {
      type: String,
      default: '',
    },
    onlyLabel: {
      type: Boolean,
      default: false,
    },
    options: {
      type: Object,
      default: function () {
        return {
          dataSource: null, // 对象数据
          codeFildName: null, // code值绑定字段
          descriptionFildName: null, // description说明绑定字段
        }
      },
    },
  },
  computed: {
    valueMember() {
      if (this.onlyLabel) {
        return 'dictDescription'
      } else {
        return 'dictID'
      }
    },
  },
  created() {
    request
      .getCommonData(this, this.dictType)
      .then((res) => {
        this.data = res.data
      })
      .catch((err) => {
        this.data = []
      })
  },
  watch: {
    value(val) {
      if (this.currentValue !== val) {
        this.currentValue = val
      }
    },
    currentValue(val) {
      if (this.value != val) {
        var obj = this.data.find((item) => item[this.valueMember] == val)
        if (this.options.dataSource) {
          if (this.options.codeFildName)
            this.options.dataSource[this.options.codeFildName] = obj.dictID
          if (this.options.descriptionFildName)
            this.options.dataSource[this.options.descriptionFildName] =
              obj.dictDescription
        }

        this.$emit('input', val)
        // if (this.bindObject != null && this.displayMember)
        //   this.bindObject[this.displayMember] = obj.dictDescription
        this.$emit('on-changed', val, obj)
      }
    },
  },
}
</script>

 

 

版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
张国生
上一篇:添加公共字典
评论列表

发表评论

评论内容
昵称:
关联文章

公共数据字典选择组件SelectCommonDict
添加公共字典
公共字典扩展
省市区选择组件SelectArea
省市区选择组件
单表演练之产品资料,辅助组件ViewDataBinding模式
Element-UI省市区选择组件city-picker
基础字典管理功能开发-表结构设计,模型更新和数据库迁移脚本生成
.Net 下高性能分表分库组件-连接模式原理
基础字典管理功能开发-API接口设计
.NET6中一些常用组件的配置及使用记录,持续更新中。。。
Excel文件数据导入和导出功能实现
数据绑定模式
C# winform选择dll文件
C# Winform选择文件夹目录
vue自定义组件props中设置object属性的默认值:
Winform窗体设置组件可用状态
JS清除Input File 的选择文件 javascript清除Input File选择文件
WPF_15_格式化绑定的数据
EF并发处理,防止并发修改数据