568 lines
27 KiB
JavaScript
568 lines
27 KiB
JavaScript
/**
|
|
* 历史数据变化记录组态
|
|
* Auther: Eddy
|
|
* Date: 2022/09/13
|
|
*/
|
|
|
|
angular.module("nurseApp.directives")
|
|
.directive('newdatachange',['$modal', '$compile', '$timeout', 'historyDataChangeService', 'balert', 'baseTypeService', 'equipmentTemplateService', 'TemplateService',
|
|
function($modal, $compile, $timeout, historyDataChangeService, balert, baseTypeService, equipmentTemplateService, TemplateService){
|
|
return {
|
|
restrict: 'A',
|
|
link: function(scope, element) {
|
|
var setDlg = undefined;
|
|
element.bind('click',function(){
|
|
initFunction();
|
|
scope.newpart = getNewPart("datachange");
|
|
setDlg = $modal({
|
|
scope:scope,
|
|
templateUrl:'partials/directive/newdatachange.html',
|
|
show:false
|
|
});
|
|
setDlg.$promise.then(setDlg.show);
|
|
// 声明函数(防止重命冲突)
|
|
scope.save = function(){
|
|
if(scope.DataChangeDisplay == undefined || scope.DataChange.displayId == undefined){
|
|
balert.show('danger', scope.languageJson.DataChange.Prompt.PleaseSelectRule,3000);
|
|
return;
|
|
}
|
|
// 1.修改数据库
|
|
var prompt = scope.languageJson.DataChange.Prompt;
|
|
historyDataChangeService.modifyDataChangeDisplay(scope.DataChange).then(function(result){
|
|
if(result === 'Succeed'){
|
|
// 2.添加组态
|
|
scope.Style.Title = scope.DataChange.displayName;
|
|
|
|
var cofg ={};
|
|
cofg.id= scope.newpart.id;
|
|
cofg.type= "datachangepart";
|
|
cofg.left= "5";
|
|
cofg.top= "80";
|
|
cofg.width= "240";
|
|
cofg.height= "500";
|
|
cofg.zindex= "1";
|
|
cofg.binding= scope.DataChange.displayId+"|"+scope.Style.dataCount;
|
|
cofg.options= angular.toJson(scope.Style);
|
|
scope.diagram.parts.push(cofg);
|
|
scope.resetParts();
|
|
|
|
setDlg.hide();
|
|
}else{
|
|
balert.show('danger', prompt.Failed,3000);
|
|
}
|
|
});
|
|
};
|
|
});
|
|
|
|
function initFunction(){
|
|
scope.DataChange = {};
|
|
scope.Style = {
|
|
titleFontSize: 20,
|
|
dataFontSize: 14,
|
|
dataCount: 15
|
|
};
|
|
// 加载所有 数据变化 配置
|
|
historyDataChangeService.getAllDataChangeDisplay().then(function(data){
|
|
scope.DataChangeDisplay = data;
|
|
if(data.length > 0) {
|
|
scope.DataChange = data[0];
|
|
scope.displayId = data[0].displayId;
|
|
}
|
|
});
|
|
// 加载所有 设备模板 配置
|
|
equipmentTemplateService.getAllEquipmentTemplate().then(function (data) {
|
|
scope.EquipmentTemplates = data;
|
|
});
|
|
// 选择不同规则,加载规则数据
|
|
scope.changeDisplay = function(id){
|
|
if(scope.DataChangeDisplay){
|
|
var item = _.findWhere(scope.DataChangeDisplay, {displayId: id});
|
|
if(item){
|
|
scope.DataChange = item;
|
|
}
|
|
}
|
|
};
|
|
// 新增规则
|
|
scope.addedClk = function(){
|
|
var prompt = scope.languageJson.DataChange.Prompt;
|
|
historyDataChangeService.addedDataChangeDisplay().then(function(dataChange){
|
|
if(dataChange != undefined){
|
|
if(scope.DataChangeDisplay == undefined) scope.DataChangeDisplay = [];
|
|
scope.DataChangeDisplay.push(dataChange);
|
|
scope.DataChange = dataChange;
|
|
scope.displayId = dataChange.displayId;
|
|
balert.show('success', prompt.Succeed,3000);
|
|
}else{
|
|
balert.show('danger', prompt.Failed,3000);
|
|
}
|
|
});
|
|
};
|
|
// 删除规则
|
|
scope.removeClk = function(displayId){
|
|
var prompt = scope.languageJson.DataChange.Prompt;
|
|
historyDataChangeService.removeDataChangeDisplay(displayId).then(function(result){
|
|
if(result === 'Succeed'){
|
|
historyDataChangeService.getAllDataChangeDisplay().then(function(data){
|
|
scope.DataChangeDisplay = data;
|
|
if(data.length > 0) {
|
|
scope.DataChange = data[data.length-1];
|
|
scope.displayId = data[data.length-1].displayId;
|
|
}else{
|
|
scope.DataChange = {};
|
|
scope.displayId = undefined;
|
|
}
|
|
});
|
|
balert.show('success', prompt.Succeed,3000);
|
|
}else{
|
|
balert.show('danger', prompt.Failed,3000);
|
|
}
|
|
});
|
|
};
|
|
// 选择规则提示
|
|
scope.notSelectRule = function(){
|
|
if(scope.DataChangeDisplay == undefined || scope.DataChange.displayId == undefined){
|
|
balert.show('danger', scope.languageJson.DataChange.Prompt.PleaseSelectRule,3000);
|
|
}
|
|
};
|
|
// 过滤器
|
|
scope.Equipments = undefined,BaseTypes = undefined, Signals = undefined;
|
|
var filterDlg = $modal({
|
|
scope:scope,
|
|
templateUrl:'partials/directive/dataFilter.html',
|
|
show:false
|
|
});
|
|
scope.dataFilterClk = function(type, values){
|
|
scope.showTemplate = false;
|
|
scope.filterType = type;
|
|
scope.filterList = [];// 过滤列表
|
|
scope.filterSelect = values ? angular.fromJson(values) : [];// 选中集合
|
|
var language = scope.languageJson.DataChange;
|
|
// 设备 黑白 名单
|
|
if(type.indexOf('Equipment_') > -1){
|
|
if(scope.Equipments == undefined){
|
|
baseTypeService.getDeviceList().then(function(data){
|
|
scope.Equipments = equipmentToFilters(data);
|
|
scope.filterList = scope.Equipments;
|
|
});
|
|
}else{
|
|
scope.filterList = scope.Equipments;
|
|
}
|
|
if(type == 'Equipment_Whitelist')
|
|
scope.filterTitle = language.EquipmentWhitelist;
|
|
else
|
|
scope.filterTitle = language.EquipmentBlacklist;
|
|
filterDlg.$promise.then(filterDlg.show);
|
|
}else if(type.indexOf('BaseType_') > -1){// 基类 黑白 名单
|
|
if(type == 'BaseType_Whitelist')
|
|
scope.filterTitle = language.BaseTypeWhitelist;
|
|
else
|
|
scope.filterTitle = language.BaseTypeBlacklist;
|
|
scope.showTemplate = true;// 显示设备模板列表
|
|
filterDlg.$promise.then(filterDlg.show);
|
|
}
|
|
|
|
// 声明函数(防止重命冲突)
|
|
scope.confirm = function(){
|
|
if(scope.filterType == 'Equipment_Whitelist')
|
|
scope.DataChange.equipmentWhitelist = angular.toJson(scope.filterSelect);
|
|
else if(scope.filterType == 'Equipment_Blacklist')
|
|
scope.DataChange.equipmentBlacklist = angular.toJson(scope.filterSelect);
|
|
else if(scope.filterType == 'BaseType_Whitelist')
|
|
scope.DataChange.baseTypeWhitelist = angular.toJson(scope.filterSelect);
|
|
else if(scope.filterType == 'BaseType_Blacklist')
|
|
scope.DataChange.baseTypeBlacklist = angular.toJson(scope.filterSelect);
|
|
filterDlg.hide();
|
|
};
|
|
};
|
|
function equipmentToFilters(data){
|
|
var filters = [];
|
|
if(data){
|
|
_.find(data,function(item){
|
|
filters.push({
|
|
id: item.EquipmentId,
|
|
value: item.EquipmentName
|
|
});
|
|
});
|
|
}
|
|
return filters;
|
|
}
|
|
function baseTypeToFilters(data){
|
|
var filters = [];
|
|
if(data){
|
|
_.find(data,function(item){
|
|
filters.push({
|
|
id: item.BaseTypeId,
|
|
value: item.BaseEquipmentId+"-"+item.BaseTypeName
|
|
});
|
|
});
|
|
}
|
|
return filters;
|
|
}
|
|
scope.addFilter = function(row){
|
|
if(scope.filterSelect == undefined) scope.filterSelect = [];
|
|
var isExist = false;
|
|
_.find(scope.filterSelect, function(item){
|
|
if(item[0] == row.id){
|
|
isExist = true;
|
|
}
|
|
});
|
|
if(!isExist){
|
|
scope.filterSelect.push([row.id,row.value]);
|
|
addedTab(row);
|
|
}
|
|
};
|
|
function addedTab(row){
|
|
var tab = "<e-tab name=\""+row.value+"\" ng-click=\"delFilter('"+row.id+"')\"/>";
|
|
var $tab = $compile(tab)(scope);
|
|
$("#tab-list").append($tab);
|
|
}
|
|
scope.initTab = function(list){
|
|
$timeout(function () {
|
|
_.find(list, function(item){
|
|
addedTab({id:item[0],value:item[1]});
|
|
});
|
|
},300);
|
|
}
|
|
scope.delFilter = function(id){
|
|
var index = -1;
|
|
_.find(scope.filterSelect, function(item){
|
|
if(id === item[0]){
|
|
index = scope.filterSelect.indexOf(item);
|
|
}
|
|
});
|
|
if(index > -1) scope.filterSelect.splice(index,1);
|
|
};
|
|
scope.changeTemplate = function(equipmentBaseType){
|
|
if(scope.filterType.indexOf('BaseType_') > -1){
|
|
TemplateService.GetBaseDicByBaseType("SignalBaseDic", equipmentBaseType).then(function (data) {
|
|
scope.filterList = baseTypeToFilters(data);
|
|
});
|
|
}
|
|
};
|
|
|
|
// 失去焦点获得光标位置
|
|
scope.CheckExpression = function(id){
|
|
var textDom = document.getElementById(id);
|
|
if (textDom.selectionStart || textDom.selectionStart == '0') {
|
|
scope.startPos = textDom.selectionStart;
|
|
scope.endPos = textDom.selectionEnd;
|
|
scope.scrollTop = textDom.scrollTop;
|
|
}
|
|
};
|
|
// 根据光标位置将字符串插入到表达式中
|
|
scope.InsterExpression = function(id,symbol){
|
|
var textDom = document.getElementById(id);
|
|
var addStr = symbol;
|
|
|
|
if ((textDom.selectionStart || textDom.selectionStart == '0') && scope.startPos) {
|
|
scope.DataChange.dataFormat = scope.DataChange.dataFormat.substring(0,scope.startPos)+addStr+
|
|
scope.DataChange.dataFormat.substring(scope.endPos);
|
|
textDom.focus();
|
|
textDom.selectionStart = scope.startPos + addStr.length;
|
|
textDom.selectionEnd = scope.startPos + addStr.length;
|
|
textDom.scrollTop = scope.scrollTop;
|
|
}else {
|
|
scope.DataChange.dataFormat += addStr;
|
|
textDom.focus();
|
|
}
|
|
};
|
|
}
|
|
|
|
function getNewPart(type){
|
|
var num = 1;
|
|
var cparts = scope.diagram.parts;
|
|
if(cparts == undefined){
|
|
scope.diagram.parts = [];
|
|
return 1;
|
|
}
|
|
for(var i=0;i<cparts.length;i++) {
|
|
if(cparts[i].id.indexOf(type)==-1)continue;
|
|
var partnum = parseInt(cparts[i].id.replace(type,''));
|
|
if(partnum >= num) num = partnum + 1;
|
|
}
|
|
|
|
var part={};
|
|
part.id=type+num;
|
|
part.url="/#";
|
|
part.target="";
|
|
return part;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
])
|
|
.directive('datachangepart',['$compile', 'diagramService',
|
|
function($compile, diagramService){
|
|
return {
|
|
restrict: "AE",
|
|
replace: true,
|
|
scope: true,
|
|
templateUrl: "partials/directive/datachangepart.html",
|
|
link: function(scope, elem, attrs) {
|
|
var cfg = diagramService.initPart(scope, elem, attrs);
|
|
scope.partid = attrs.partid;
|
|
scope.Style = angular.fromJson(cfg.options);
|
|
|
|
// 限制高度
|
|
var titleHeight = parseInt(scope.Style.titleFontSize) + 34;
|
|
var height = elem.find(".data_change_root")[0].clientHeight;
|
|
elem.find(".data_change .data_change_body").css("height",(height - titleHeight)+"px");
|
|
|
|
// 监听组态数据
|
|
scope.$watch('binddata', function(newValue, oldValue, scope) {
|
|
var data = _.findWhere(newValue, {partId: scope.partid});
|
|
if(data){
|
|
//console.log("data change:",data);
|
|
var lines = angular.fromJson(data.currentValue);
|
|
if(lines && lines.length > 0){
|
|
$("#data_change_body").children().remove();
|
|
_.find(lines,function(line){
|
|
var div = "<div class=\"content\" ng-style=\"{'font-size': Style.dataFontSize+'px'}\">"+line+"</div>";
|
|
var $div = $compile(div)(scope);
|
|
$("#data_change_body").append($div);
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
scope.$watch('diagram.edit', function (newValue, oldValue, scope) {
|
|
diagramService.updateEditStatus(elem, newValue);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
])
|
|
.directive('datachangesetter',['$modal', '$compile', '$timeout', 'historyDataChangeService', 'balert', 'baseTypeService', 'equipmentTemplateService', 'TemplateService',
|
|
function($modal, $compile, $timeout, historyDataChangeService, balert, baseTypeService, equipmentTemplateService, TemplateService){
|
|
return {
|
|
restrict: 'A',
|
|
link: function(scope,element){
|
|
var setDlg = undefined;
|
|
element.bind('click',function(){
|
|
initFunction();
|
|
setDlg = $modal({
|
|
scope:scope,
|
|
templateUrl:'partials/directive/datachangesetter.html',
|
|
show:false
|
|
});
|
|
setDlg.$promise.then(setDlg.show);
|
|
// 声明函数(防止重命冲突)
|
|
scope.save = function(){
|
|
if(scope.DataChange.displayId == undefined){
|
|
balert.show('danger', scope.languageJson.DataChange.Prompt.PleaseSelectRule,3000);
|
|
return;
|
|
}
|
|
// 1.修改数据库
|
|
var prompt = scope.languageJson.DataChange.Prompt;
|
|
historyDataChangeService.modifyDataChangeDisplay(scope.DataChange).then(function(result){
|
|
if(result === 'Succeed'){
|
|
// 2.添加组态
|
|
scope.Style.Title = scope.DataChange.displayName;
|
|
|
|
var cofg = getPartConfig(scope.diagram, scope.partid);
|
|
cofg.binding= scope.DataChange.displayId+"|"+scope.Style.dataCount;
|
|
cofg.options= angular.toJson(scope.Style);
|
|
scope.resetParts();
|
|
|
|
setDlg.hide();
|
|
}else{
|
|
balert.show('danger', prompt.Failed,3000);
|
|
}
|
|
});
|
|
};
|
|
});
|
|
|
|
function initFunction(){
|
|
scope.partid = element.parent().parent().attr("partid");
|
|
var cfg = getPartConfig(scope.diagram, scope.partid);
|
|
if(cfg){
|
|
var id = cfg.binding.split("|")[0];
|
|
// 加载所有 数据变化 配置
|
|
historyDataChangeService.getAllDataChangeDisplay().then(function(data){
|
|
if(data.length > 0) {
|
|
scope.DataChange = _.findWhere(data, {displayId: id});
|
|
}
|
|
});
|
|
scope.Style = angular.fromJson(cfg.options);
|
|
}
|
|
// 加载所有 设备模板 配置
|
|
equipmentTemplateService.getAllEquipmentTemplate().then(function (data) {
|
|
scope.EquipmentTemplates = data;
|
|
});
|
|
|
|
// 失去焦点获得光标位置
|
|
scope.CheckExpression = function(id){
|
|
var textDom = document.getElementById(id);
|
|
if (textDom.selectionStart || textDom.selectionStart == '0') {
|
|
scope.startPos = textDom.selectionStart;
|
|
scope.endPos = textDom.selectionEnd;
|
|
scope.scrollTop = textDom.scrollTop;
|
|
}
|
|
};
|
|
// 根据光标位置将字符串插入到表达式中
|
|
scope.InsterExpression = function(id,symbol){
|
|
var textDom = document.getElementById(id);
|
|
var addStr = symbol;
|
|
|
|
if ((textDom.selectionStart || textDom.selectionStart == '0') && scope.startPos) {
|
|
scope.DataChange.dataFormat = scope.DataChange.dataFormat.substring(0,scope.startPos)+addStr+
|
|
scope.DataChange.dataFormat.substring(scope.endPos);
|
|
textDom.focus();
|
|
textDom.selectionStart = scope.startPos + addStr.length;
|
|
textDom.selectionEnd = scope.startPos + addStr.length;
|
|
textDom.scrollTop = scope.scrollTop;
|
|
}else {
|
|
scope.DataChange.dataFormat += addStr;
|
|
textDom.focus();
|
|
}
|
|
};
|
|
|
|
// 过滤器
|
|
scope.Equipments = undefined,BaseTypes = undefined, Signals = undefined;
|
|
var filterDlg = $modal({
|
|
scope:scope,
|
|
templateUrl:'partials/directive/dataFilter.html',
|
|
show:false
|
|
});
|
|
scope.dataFilterClk = function(type, values){
|
|
scope.showTemplate = false;
|
|
scope.filterType = type;
|
|
scope.filterList = [];// 过滤列表
|
|
scope.filterSelect = values ? angular.fromJson(values) : [];// 选中集合
|
|
var language = scope.languageJson.DataChange;
|
|
// 设备 黑白 名单
|
|
if(type.indexOf('Equipment_') > -1){
|
|
if(scope.Equipments == undefined){
|
|
baseTypeService.getDeviceList().then(function(data){
|
|
scope.Equipments = equipmentToFilters(data);
|
|
scope.filterList = scope.Equipments;
|
|
});
|
|
}else{
|
|
scope.filterList = scope.Equipments;
|
|
}
|
|
if(type == 'Equipment_Whitelist')
|
|
scope.filterTitle = language.EquipmentWhitelist;
|
|
else
|
|
scope.filterTitle = language.EquipmentBlacklist;
|
|
filterDlg.$promise.then(filterDlg.show);
|
|
}else if(type.indexOf('BaseType_') > -1){// 基类 黑白 名单
|
|
if(type == 'BaseType_Whitelist')
|
|
scope.filterTitle = language.BaseTypeWhitelist;
|
|
else
|
|
scope.filterTitle = language.BaseTypeBlacklist;
|
|
scope.showTemplate = true;// 显示设备模板列表
|
|
filterDlg.$promise.then(filterDlg.show);
|
|
}
|
|
|
|
// 声明函数(防止重命冲突)
|
|
scope.confirm = function(){
|
|
if(scope.filterType == 'Equipment_Whitelist')
|
|
scope.DataChange.equipmentWhitelist = angular.toJson(scope.filterSelect);
|
|
else if(scope.filterType == 'Equipment_Blacklist')
|
|
scope.DataChange.equipmentBlacklist = angular.toJson(scope.filterSelect);
|
|
else if(scope.filterType == 'BaseType_Whitelist')
|
|
scope.DataChange.baseTypeWhitelist = angular.toJson(scope.filterSelect);
|
|
else if(scope.filterType == 'BaseType_Blacklist')
|
|
scope.DataChange.baseTypeBlacklist = angular.toJson(scope.filterSelect);
|
|
filterDlg.hide();
|
|
};
|
|
};
|
|
function equipmentToFilters(data){
|
|
var filters = [];
|
|
if(data){
|
|
_.find(data,function(item){
|
|
filters.push({
|
|
id: item.EquipmentId,
|
|
value: item.EquipmentName
|
|
});
|
|
});
|
|
}
|
|
return filters;
|
|
}
|
|
function baseTypeToFilters(data){
|
|
var filters = [];
|
|
if(data){
|
|
_.find(data,function(item){
|
|
filters.push({
|
|
id: item.BaseTypeId,
|
|
value: item.BaseEquipmentId+"-"+item.BaseTypeName
|
|
});
|
|
});
|
|
}
|
|
return filters;
|
|
}
|
|
scope.addFilter = function(row){
|
|
if(scope.filterSelect == undefined) scope.filterSelect = [];
|
|
var isExist = false;
|
|
_.find(scope.filterSelect, function(item){
|
|
if(item[0] == row.id){
|
|
isExist = true;
|
|
}
|
|
});
|
|
if(!isExist){
|
|
scope.filterSelect.push([row.id,row.value]);
|
|
addedTab(row);
|
|
}
|
|
};
|
|
function addedTab(row){
|
|
var tab = "<e-tab name=\""+row.value+"\" ng-click=\"delFilter('"+row.id+"')\"/>";
|
|
var $tab = $compile(tab)(scope);
|
|
$("#tab-list").append($tab);
|
|
}
|
|
scope.initTab = function(list){
|
|
$timeout(function () {
|
|
_.find(list, function(item){
|
|
addedTab({id:item[0],value:item[1]});
|
|
});
|
|
},300);
|
|
}
|
|
scope.delFilter = function(id){
|
|
var index = -1;
|
|
_.find(scope.filterSelect, function(item){
|
|
if(id === item[0]){
|
|
index = scope.filterSelect.indexOf(item);
|
|
}
|
|
});
|
|
if(index > -1) scope.filterSelect.splice(index,1);
|
|
};
|
|
scope.changeTemplate = function(equipmentBaseType){
|
|
if(scope.filterType.indexOf('BaseType_') > -1){
|
|
TemplateService.GetBaseDicByBaseType("SignalBaseDic", equipmentBaseType).then(function (data) {
|
|
scope.filterList = baseTypeToFilters(data);
|
|
});
|
|
}
|
|
};
|
|
}
|
|
|
|
function getPartConfig(diagram, id) {
|
|
var found = _.find(diagram.parts, function(part) {
|
|
return part.id === id;
|
|
});
|
|
return found;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
])
|
|
// 自定义 可移除标签
|
|
// 使用方法: <e-tab ng-click="removeTab('100001')" name="设备"/>
|
|
.directive('eTab',[
|
|
function(){
|
|
return {
|
|
restrict: 'AE',
|
|
replace: true,
|
|
scope:{
|
|
name : "@"
|
|
},
|
|
template: "<div class='e_tab' ng-click=';remove2()'>" +
|
|
" <sapn>{{name}}</sapn>"+
|
|
" <i class='fa fa-times'/>"+
|
|
"</div>",
|
|
link: function(scope, element) {
|
|
scope.remove2 = function(){
|
|
element.remove();
|
|
};
|
|
}
|
|
}
|
|
}
|
|
]); |