nimble-ui
Version:
111 lines (103 loc) • 2.87 kB
JavaScript
import { callFn, extend } from 'nimble-lib';
import { PopupBase } from '../popup/PopupBase';
import Service from '../services';
export class Loading extends Service {
name = 'Loading';
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();
};
}
/**
* loading框
* @param {Objec} options 弹框内容
* @returns {*}
*/
loading (options) {
let _that = this;
let _options = _that.getOptions({
key: 'loading',
wrapCla: '', // 最外层追加的Class名
alignCla: 'centerMiddle', // ''|'bottom'|'top'|'fullScreen'|'centerMiddle',
transitionCls: '', // ''|'bottom'|'top'|'fullScreen'|'centerMiddle',
maskCloseFlag: 0,
maskFlag: -1
}, options);
_options.wrapCla = (_options.wrapCla || '') + ' nu_loading-popup';
return _that._popup.popupData(() => {
return callFn(_options.getComponent);
}, _options);
}
/**
* 打开普通的loading框
* @param {Object} param 参数
* @param {Objec} options 弹框内容
* @returns {*}
*/
loadingc (param, options) {
const _that = this;
return _that.loading(extend(true, {
props: {
type: 'loadingc'
},
wrapCla: 'nu_loadingc-popup'
}, options, {
props: param || {}
}));
}
/**
* 打开logo的loading框
* @param {Object} param 参数
* @param {Objec} options 弹框内容
* @returns {*}
*/
loadingl (param, options) {
const _that = this;
return _that.loading(extend(true, {
props: {
type: 'loadingl'
},
wrapCla: 'nu_loadingl-popup'
}, options, {
props: param || {}
}));
}
/**
* 关闭loading框
* @param {String} key 关闭的key
*/
close (key) {
let _popup = this._popup;
callFn(_popup && _popup.closePopup, [key || 'loading'], _popup);
}
/**
* 安装
*
* @param {Vue} Vue Vue
* @param {Object} options 选项
* @memberof Service
* @returns {Object}
*/
install(Vue, options) {
let _that = this;
let _popup = _that._popup;
super.install(Vue, options);
_popup && _popup._setSPopup(Vue);
return _that;
}
}
/**
*
* 实例化工厂方法
* @export
* @param {Vue} Vue vue
* @param {any} options 配置选项
* @returns {Photo}
*/
export default function loadingFactory(Vue, options) {
return new Loading(Vue, options);
}