257 lines
5.3 KiB
JavaScript
257 lines
5.3 KiB
JavaScript
|
|
/*******************************************************************************
|
|
*
|
|
* 代理: 视图
|
|
*
|
|
*
|
|
*
|
|
* 2021.12.10
|
|
******************************************************************************/
|
|
|
|
// 功能安装
|
|
const install = function( _inst ) {
|
|
|
|
// 对象非法
|
|
if( nx.dt.objEmpty( _inst ) ) {
|
|
nx.error( "[视图插件]安装失败,对象非法!" );
|
|
return false;
|
|
}
|
|
|
|
// 重复安装
|
|
if( nx.dt.arrGood( _inst.vv_binders ) ) {
|
|
nx.error( "[视图插件]安装失败,重复安装!" );
|
|
return false;
|
|
}
|
|
|
|
// 安装
|
|
_inst.vid = "";
|
|
_inst.vv_binders = [];
|
|
_inst.vv_configs = null;
|
|
|
|
// 视图创建
|
|
nx.dt.fnEmptyError( _inst.vbuild );
|
|
_inst.vbuild = function( _ifos ) {
|
|
|
|
// 重复初始化
|
|
if( nx.dt.strNEmpty( _inst.vid ) ) {
|
|
nx.error( "[视图插件]重复创建:" + _inst.vid );
|
|
return false;
|
|
}
|
|
|
|
// 视图注册
|
|
if( !nx.views.queryModel( _ifos.Name, false ) ) {
|
|
nx.views.regModel( _ifos.Name, _ifos.Model, _ifos.Single );
|
|
}
|
|
|
|
// 视图创建
|
|
_inst.vid = nx.views.buildView( _ifos.Name, _ifos.Model );
|
|
|
|
// VBD关联
|
|
if( _ifos.VBD ) {
|
|
nx.views.regBindTarget( _ifos.Name, _inst );
|
|
}
|
|
|
|
_inst.vv_configs = _ifos;
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
// 附着
|
|
nx.dt.fnEmptyError( _inst.vattach );
|
|
_inst.vattach = function( _vname ) {
|
|
|
|
// 查询视图
|
|
let view = nx.views.queryView( _vname );
|
|
if( !view ) {
|
|
return false;
|
|
}
|
|
|
|
_inst.vid = view.vid;
|
|
_inst.vv_configs = null;
|
|
return true;
|
|
};
|
|
|
|
// 重置
|
|
nx.dt.fnEmptyError( _inst.vreset );
|
|
_inst.vreset = function( _vmodel, _clean ) {
|
|
return nx.views.resetView( _inst.vid, _vmodel, _clean );
|
|
};
|
|
|
|
// 获取
|
|
nx.dt.fnEmptyError( _inst.vget );
|
|
_inst.vget = function( _vk, _def ) {
|
|
return nx.views.getData( _inst.vid, _vk, _def );
|
|
};
|
|
|
|
// 获取老值
|
|
nx.dt.fnEmptyError( _inst.vgetOld );
|
|
_inst.vgetOld = function( _vk, _def ) {
|
|
return nx.views.getOldData( _inst.vid, _vk, _def );
|
|
};
|
|
|
|
// 设置
|
|
nx.dt.fnEmptyError( _inst.vset );
|
|
_inst.vset = function( _vk, _value, _notify ) {
|
|
return nx.views.setData( _inst.vid, _vk, _value, _notify );
|
|
};
|
|
|
|
// 批量设置
|
|
nx.dt.fnEmptyError( _inst.vsetBatch );
|
|
_inst.vsetBatch = function( _vpairs ) {
|
|
return nx.views.setDataBatch( _inst.vid, _vpairs );
|
|
};
|
|
|
|
// 批量更新
|
|
nx.dt.fnEmptyError( _inst.vupdBatch );
|
|
_inst.vupdBatch = function( _data, _notify ) {
|
|
|
|
for( let k in _data ) {
|
|
_inst.vset( k, _data[ k ], _notify );
|
|
}
|
|
};
|
|
|
|
// 通知
|
|
nx.dt.fnEmptyError( _inst.vnotify );
|
|
_inst.vnotify = function( _vk ) {
|
|
|
|
var v = nx.views.queryView( _inst.vid );
|
|
if( v ) {
|
|
v.vnotify( _vk );
|
|
}
|
|
};
|
|
|
|
// 绑定
|
|
nx.dt.fnEmptyError( _inst.vbind );
|
|
_inst.vbind = function( _binder, _lst ) {
|
|
|
|
// 无效编号
|
|
if( nx.dt.strEmpty( _inst.vid ) ) {
|
|
nx.error( "[视图插件]无效的视图编号!" );
|
|
return false;
|
|
}
|
|
|
|
var uuid = nx.factory.getUUID( _binder, true );
|
|
if( !nx.dt.arrMember( _inst.vv_binders, uuid ) ) {
|
|
_inst.vv_binders.push( uuid );
|
|
}
|
|
|
|
return nx.views.bindView( _inst.vid, uuid, _lst );
|
|
|
|
};
|
|
|
|
// 解绑
|
|
nx.dt.fnEmptyError( _inst.vunbind );
|
|
_inst.vunbind = function( _binder ) {
|
|
|
|
if( window.nx ){
|
|
// 无效编号
|
|
if( nx.dt.strEmpty( _inst.vid ) ) {
|
|
nx.error( "[视图插件]无效的视图编号!" );
|
|
return false;
|
|
}
|
|
|
|
var uuid = nx.factory.getUUID( _binder, true );
|
|
for( let i in _inst.vv_binders ) {
|
|
if( _inst.vv_binders[ i ] == uuid ) {
|
|
_inst.vv_binders.splice( i, 1 );
|
|
break;
|
|
}
|
|
}
|
|
|
|
return nx.views.unbindView( _inst.vid, uuid );
|
|
}
|
|
|
|
|
|
};
|
|
|
|
// 视图销毁
|
|
nx.dt.fnEmptyError( _inst.vclean );
|
|
_inst.vclean = function() {
|
|
|
|
// 单例视图解除通过该代理尚未解绑的监听者
|
|
for( let i in _inst.vv_binders ) {
|
|
var bdname = _inst.vv_binders[ i ];
|
|
nx.views.unbindView( _inst.vid, bdname );
|
|
cc.warn( "[代理]视图代理:残留未解绑驱动器清理: %d %s", _inst.vid, bdname );
|
|
}
|
|
|
|
// 只是附着,简单解除即可
|
|
if( !_inst.vv_configs ) {
|
|
_inst.vid = "";
|
|
return;
|
|
}
|
|
|
|
// 负责收尾
|
|
|
|
// VBD关联解除
|
|
if( _inst.vv_configs.VBD ) {
|
|
nx.views.unregBindTarget( _inst.vv_configs.Name );
|
|
}
|
|
|
|
// 视图删除 && 注销
|
|
nx.views.delView( _inst.vid );
|
|
nx.views.unregModel( _inst.vv_configs.Name );
|
|
|
|
_inst.vv_configs = null;
|
|
|
|
};
|
|
|
|
// 视图对象化
|
|
nx.dt.fnEmptyError( _inst.vtoObject );
|
|
_inst.vtoObject = function() {
|
|
return nx.views.toObject( _inst.vid );
|
|
};
|
|
|
|
// 视图对象化更新
|
|
nx.dt.fnEmptyError( _inst.vfromObject );
|
|
_inst.vfromObject = function( _obj ) {
|
|
return nx.views.fromObject( _inst.vid, _obj );
|
|
};
|
|
|
|
// 视图打印
|
|
nx.dt.fnEmptyError( _inst.vdump );
|
|
_inst.vdump = function( _tform ) {
|
|
return nx.views.dumpView( _inst.vid, _tform );
|
|
};
|
|
|
|
return true;
|
|
};
|
|
|
|
// 功能卸载
|
|
const uninstall = function( _inst ) {
|
|
|
|
// 对象非法
|
|
if( nx.dt.objEmpty( _inst ) ) {
|
|
nx.error( "[视图插件]安装视图插件失败,对象非法!" );
|
|
return false;
|
|
}
|
|
|
|
// 视图清理
|
|
_inst.vclean();
|
|
|
|
// 卸载
|
|
delete _inst.vbuild;
|
|
delete _inst.vattach;
|
|
delete _inst.vreset;
|
|
delete _inst.vget;
|
|
delete _inst.vset;
|
|
delete _inst.vsetBatch;
|
|
delete _inst.vupdBatch;
|
|
delete _inst.vnotify;
|
|
delete _inst.vbind;
|
|
delete _inst.vunbind;
|
|
delete _inst.vclean;
|
|
delete _inst.vtoObject;
|
|
delete _inst.vfromObject;
|
|
delete _inst.vdump;
|
|
delete _inst.vv_binders;
|
|
delete _inst.vv_configs;
|
|
delete _inst.vid;
|
|
|
|
return true;
|
|
};
|
|
|
|
|
|
module.exports = { install, uninstall };
|