UNPKG

nimble-ui

Version:
85 lines (82 loc) 2.52 kB
import { callFn, extend, getBackData } from 'nimble-lib'; import { PopupBase } from '../popup/PopupBase'; import Service from '../services'; export class Datepicker extends Service { name = 'Datepicker'; defaultOption={ /** * 过滤选中的数据 * @param {Object} back 选择的数据 * @returns {String} */ filterData(back) { let _data = back.data; return _data || ''; } } constructor(Vue, options) { super(options); let _that = this; _that.setDefaultOptions(options); _that._popup = new PopupBase(Vue, _that.defaultOption); _that._popup._getParent = () => { return _that._getParent && _that._getParent(); }; } /** * 模态框 * @param {Objec} props 组件参数 * @param {Objec} options 弹框选项 * @returns {*} */ datepicker(props, options) { let _that = this; let _options = _that.getOptions({ key: 'datepicker', wrapCla: '', // 最外层追加的Class名 alignCla: 'bottom', // ''|'bottom'|'top'|'fullScreen'|'centerMiddle', transitionCls: 'toUp', // ''|toUp|scale|toBottom|toLeft; maskCloseFlag: 0, maskFlag: 1 }, options); if (props) { _options.props = extend(false, _options.props || {}, props); } _options.wrapCla = (_options.wrapCla || '') + ' nus_datepicker-popup'; return new Promise((resolve, reject) => { _that._popup.popupData(() => { return callFn(_options.getComponent, [_options.type || 'datepicker']); }, _options).then((res) => { if (res.type === 'confirm') { getBackData(_options.filterData || res.data, [res.data]) .then(resolve, reject); } }, reject); }); } /** * 安装 * * @param {Vue} Vue Vue * @param {Object} options 选项 * @memberof Service * @returns {Object} */ install(Vue, options) { let _that = this; super.install(Vue, options); _that._popup && _that._popup._setSPopup(Vue); return _that; } } /** * * 实例化工厂方法 * @export * @param {Vue} Vue vue * @param {any} options 配置选项 * @returns {Dialog} */ export default function datepickerFactory(Vue, options) { return new Datepicker(Vue, options); }