nimble-ui
Version:
61 lines (58 loc) • 1.96 kB
JavaScript
import { ClassProxy, callFn } from 'nimble-lib';
import Service from '../services';
/**
* 代理Picker
*
* @export
* @param {*} Vue Vue
* @param {*} options 配置参数
* @returns {Picker}
*/
function pickerFactory (Vue, options) {
let _classProxy = new ClassProxy();
class PickerProxy extends Service {
name = 'Picker';
constructor(vue, opts) {
super(vue, opts);
let _that = this;
_classProxy.proxyHook(_that, () => {
return _that.preload();
}, ['cityPicker', 'picker', 'closePopup', 'close']);
}
preload() {
let _that = this;
let res = _classProxy.initProxy(() => {
return new Promise((resolve, reject) => {
import(/* webpackChunkName: "_picker_" */ './picker').then((back) => {
let Picker = back && back.default;
let _res = Picker(Vue, options);
if (_that._callInstall instanceof Function) {
_that._callInstall((...args) => {
_res._getParent = () => {
return _that._getParent();
};
_res.install(...args);
});
}
resolve(_res);
}, reject);
});
}, 'preload')();
_that.preload = () => {
return res;
};
return res;
}
install(vue, opts) {
super.install(vue, opts);
this._callInstall = function(cb) {
callFn(cb, [vue, opts]);
};
}
}
return new PickerProxy(Vue, options);
}
pickerFactory.install = (Vue, options) => {
Vue.use(pickerFactory(Vue, options), options);
};
export default pickerFactory;