UNPKG

vue-ant-patterns

Version:

vue-ant-patterns

172 lines (157 loc) 4.79 kB
/* * @Description: 常数代码 * @Autor: liuyanxin * @Date: 2020-05-12 15:37:04 * @LastEditors: liuyanxin * @LastEditTime: 2020-07-27 17:39:15 */ import PropTypes from 'ant-design-vue/es/_util/vue-types'; import cx from 'classnames'; var DConstant = { name: 'DConstant', props: { prefixCls: PropTypes.string.def('depot-layout-constant'), dataSource: PropTypes.object, allowClear: PropTypes.bool.def(false), // 支持清除 defaultValue: PropTypes.oneOfType([String, PropTypes.arrayOf(String)]), value: PropTypes.oneOfType([String, PropTypes.arrayOf(String)]), // 组件值 placeholder: PropTypes.string.def(''), // 选择框默认文字 multiple: PropTypes.bool.def(false) }, data: function data() { var value = this.value || this.defaultValue || (this.multiple ? [] : ''); return { selectValue: value }; }, watch: { value: function value() { var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; this.selectValue = val; } }, methods: { /** * @description: 构建 LIST COMBOBOx 下拉框 * @param {type} * @return: */ rander_LIST_COMBOBOX: function rander_LIST_COMBOBOX() { var _this = this; var h = this.$createElement; var prefixCls = this.prefixCls, dataSource = this.dataSource, allowClear = this.allowClear, placeholder = this.placeholder, multiple = this.multiple; var COMBOBOX_Props = { props: { allowClear: allowClear, placeholder: placeholder, value: this.selectValue, mode: multiple ? 'multiple' : 'default' }, on: { change: function change(e) { _this.selectValue = e; _this.$emit('change', e); _this.$emit('input', e); // v-model } } }; return h( 'a-select', COMBOBOX_Props, [dataSource ? dataSource.codeList.map(function (dataitem) { return h( 'a-select-option', { attrs: { value: dataitem.code } }, [dataitem.name] ); }) : ''] ); }, /** * @description: LIST SELECTBOX Radio组件 * @param {type} * @return: */ rander_LIST_SELECTBOX: function rander_LIST_SELECTBOX() { var _this2 = this; var h = this.$createElement; var prefixCls = this.prefixCls, dataSource = this.dataSource, allowClear = this.allowClear, multiple = this.multiple; var options = dataSource.codeList.map(function (dataitem) { return { label: dataitem.name, value: dataitem.code }; }); var SELECTBOX_Props = { props: { options: options, value: this.selectValue }, on: { change: function change(e) { var _v = multiple ? e : e.target.value; _this2.selectValue = _v; _this2.$emit('change', _v); _this2.$emit('input', _v); // v-model } } }; return multiple ? h('a-checkbox-group', SELECTBOX_Props) : h('a-radio-group', SELECTBOX_Props); }, /** * @description:TREE 组件 * @param {type} * @return: */ rander_TREE_POPUP: function rander_TREE_POPUP() { var _this3 = this; var h = this.$createElement; var prefixCls = this.prefixCls, dataSource = this.dataSource, allowClear = this.allowClear, placeholder = this.placeholder, multiple = this.multiple; var formatData1 = dataSource ? dataSource.codeList.map(function (_item) { _item.id = _item.code; _item.pId = _item.parentCode; _item.label = _item.name; _item.value = _item.code; return _item; }) : []; var TREE_POPUP_Props = { props: { treeDataSimpleMode: true, treeData: formatData1, placeholder: placeholder, allowClear: allowClear, value: this.selectValue, multiple: multiple }, on: { change: function change(e) { _this3.selectValue = e; _this3.$emit('change', e); _this3.$emit('input', e); } } }; return h('a-tree-select', TREE_POPUP_Props); } }, render: function render() { var prefixCls = this.prefixCls, dataSource = this.dataSource, allowClear = this.allowClear; return dataSource ? this['rander_' + dataSource.dataStructure + '_' + dataSource.controlType]() : ''; } }; DConstant.install = function (Vue) { Vue.component(DConstant.name, DConstant); }; export default DConstant;