2022-11-16 14:53:22 +08:00
|
|
|
|
$(function () {
|
|
|
|
|
$(".dropdown-menu.dropdown-select-menu").each((index, value) => {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
setDropdownItem(value);
|
|
|
|
|
});
|
|
|
|
|
});
|
2022-11-16 14:53:22 +08:00
|
|
|
|
|
2023-02-14 15:16:11 +08:00
|
|
|
|
/**
|
2023-04-24 11:55:46 +08:00
|
|
|
|
* fn 定義 | 手動初始化 Bootstrap dropdown select
|
|
|
|
|
*/
|
2022-11-16 14:53:22 +08:00
|
|
|
|
$.fn.droSetItem = function () {
|
|
|
|
|
setDropdownItem(this);
|
|
|
|
|
return this;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2023-02-14 15:16:11 +08:00
|
|
|
|
/**
|
2023-04-24 11:55:46 +08:00
|
|
|
|
* fn 定義 | 輸出含原元素 html
|
|
|
|
|
*/
|
2022-11-18 17:12:45 +08:00
|
|
|
|
$.fn.outerHtml = function () {
|
|
|
|
|
return $(this).prop("outerHTML");
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-11-16 14:53:22 +08:00
|
|
|
|
|
2022-12-02 15:46:37 +08:00
|
|
|
|
/**
|
2023-04-24 11:55:46 +08:00
|
|
|
|
* fn 定義 | Loading 操作
|
|
|
|
|
* @param {any} type - close / start / exceed , exceed => 繼續執行並可切換文字
|
|
|
|
|
* @param {any} text - 右下角 Alert 文字
|
|
|
|
|
*/
|
2023-01-03 16:47:23 +08:00
|
|
|
|
$.fn.Loading = function (type = "close", text) {
|
2022-12-02 15:46:37 +08:00
|
|
|
|
let ele = this;
|
|
|
|
|
let aleObj = $(this)[0]._aleObj;
|
2023-01-16 18:35:01 +08:00
|
|
|
|
let showStatus = $(ele).data("loading-show-status");
|
2022-12-02 15:46:37 +08:00
|
|
|
|
|
|
|
|
|
function closeLoading() {
|
2023-01-16 18:35:01 +08:00
|
|
|
|
$(ele).data("loading-show-status", "close");
|
2022-12-02 15:46:37 +08:00
|
|
|
|
$("body").css("overflow", "auto");
|
|
|
|
|
$(aleObj.ele).YTAlert().hide();
|
|
|
|
|
$(ele).animate({ opacity: 0 }, 300, () => {
|
2023-02-14 15:16:11 +08:00
|
|
|
|
if ($(ele).data("loading-show-status") == "close") {
|
2023-01-16 18:35:01 +08:00
|
|
|
|
$(ele).hide();
|
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2022-12-02 15:46:37 +08:00
|
|
|
|
}
|
|
|
|
|
function showLoading() {
|
2023-01-16 18:35:01 +08:00
|
|
|
|
$(ele).data("loading-show-status", "show");
|
2022-12-02 15:46:37 +08:00
|
|
|
|
$("body").css("overflow", "hidden");
|
|
|
|
|
let aleObj = YT.Alert.Tip(text || "讀取中,請稍後", "show");
|
|
|
|
|
$(ele)[0]._aleObj = aleObj;
|
|
|
|
|
$(ele).show();
|
2023-01-03 16:47:23 +08:00
|
|
|
|
$(ele).animate({ opacity: 1 }, 300);
|
|
|
|
|
|
2022-12-02 15:46:37 +08:00
|
|
|
|
$(aleObj.ele).YTAlert().text(text);
|
|
|
|
|
}
|
|
|
|
|
if (type == "close") {
|
|
|
|
|
closeLoading();
|
|
|
|
|
} else if (type == "exceed") {
|
|
|
|
|
$(aleObj.ele).YTAlert().text(text);
|
|
|
|
|
} else if (type == "start") {
|
|
|
|
|
showLoading();
|
|
|
|
|
}
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
2022-12-02 15:46:37 +08:00
|
|
|
|
return $(this);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-12-02 15:46:37 +08:00
|
|
|
|
|
|
|
|
|
$.fn.YTAlert = function () {
|
|
|
|
|
let th = { element: this };
|
|
|
|
|
th.hide = function (delay = 0) {
|
|
|
|
|
let obj = this;
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
$(obj.element).fadeOut(300);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
alertIdArray.splice(
|
|
|
|
|
$.inArray($(obj.element).prop("id"), alertIdArray),
|
|
|
|
|
1
|
|
|
|
|
);
|
2022-12-02 15:46:37 +08:00
|
|
|
|
setTimeout(function () {
|
|
|
|
|
$(obj.element).remove();
|
|
|
|
|
}, 1000);
|
|
|
|
|
}, delay);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-12-02 15:46:37 +08:00
|
|
|
|
|
|
|
|
|
th.text = function (text) {
|
|
|
|
|
let obj = this;
|
|
|
|
|
let id = $(obj.element).prop("id").split("tip-alert-")[1];
|
|
|
|
|
$(`#alert-text-${id}`).text(text);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-12-02 15:46:37 +08:00
|
|
|
|
return th;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-12-02 15:46:37 +08:00
|
|
|
|
|
2022-11-16 17:23:00 +08:00
|
|
|
|
/**
|
2023-04-24 11:55:46 +08:00
|
|
|
|
* 設置 bootstrap dropdown 為下拉選單
|
|
|
|
|
* @param {any} menuEle - .dropdown-menu element
|
|
|
|
|
*/
|
2022-11-16 14:53:22 +08:00
|
|
|
|
function setDropdownItem(menuEle) {
|
|
|
|
|
if ($(menuEle).find(".dropdown-item.active").length == 0) {
|
|
|
|
|
$(menuEle).find(".dropdown-item").first().addClass("active");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let actText = $(menuEle).find(".dropdown-item.active").first().text();
|
|
|
|
|
let actEleId = $(menuEle).prop("id");
|
|
|
|
|
$(`.dropdown-toggle[data-target=${actEleId}]`).text(actText);
|
2022-11-22 13:33:49 +08:00
|
|
|
|
|
|
|
|
|
/*actChaCallback($(menuEle).find(".dropdown-item.active"))*/
|
2022-11-16 14:53:22 +08:00
|
|
|
|
$(menuEle).trigger("active:change", $(menuEle).find(".dropdown-item.active"));
|
|
|
|
|
|
2022-11-16 17:23:00 +08:00
|
|
|
|
//點選選項 add active class
|
2023-04-24 11:55:46 +08:00
|
|
|
|
onEvent(
|
|
|
|
|
"click",
|
|
|
|
|
".dropdown-menu.dropdown-select-menu .dropdown-item",
|
|
|
|
|
function () {
|
|
|
|
|
$(this)
|
|
|
|
|
.parent(".dropdown-menu.dropdown-select-menu")
|
|
|
|
|
.find(".dropdown-item")
|
|
|
|
|
.removeClass("active");
|
|
|
|
|
$(this).addClass("active");
|
|
|
|
|
setDropdownItem($(this).parent(".dropdown-menu.dropdown-select-menu"));
|
|
|
|
|
}
|
|
|
|
|
);
|
2022-11-16 17:23:00 +08:00
|
|
|
|
}
|
2022-11-16 14:53:22 +08:00
|
|
|
|
|
2022-11-16 17:23:00 +08:00
|
|
|
|
/**
|
2023-04-24 11:55:46 +08:00
|
|
|
|
* 預設設備圖像
|
|
|
|
|
* @param {any} obj
|
|
|
|
|
*/
|
2022-11-16 14:53:22 +08:00
|
|
|
|
function defDev(obj) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let defSrc = "img/defdev.png";
|
2022-11-16 14:53:22 +08:00
|
|
|
|
obj.src = defSrc;
|
|
|
|
|
}
|
2022-11-17 10:49:49 +08:00
|
|
|
|
|
2022-12-02 15:46:37 +08:00
|
|
|
|
/**
|
2023-04-24 11:55:46 +08:00
|
|
|
|
* jquery datatable - ajax send data reset
|
|
|
|
|
* @param {any} table
|
|
|
|
|
* @param {any} sendData
|
|
|
|
|
*/
|
2023-01-03 16:47:23 +08:00
|
|
|
|
function dtAjaxResetSendData(table, sendData) {
|
2022-11-18 17:12:45 +08:00
|
|
|
|
table.context[0].ajax.data = function (d) {
|
|
|
|
|
d = sendData;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
return JSON.stringify(d);
|
|
|
|
|
};
|
2022-11-18 17:12:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-04-24 11:55:46 +08:00
|
|
|
|
* element 建造
|
|
|
|
|
* @param {any} text
|
|
|
|
|
* @param {any} id
|
|
|
|
|
* @param {any} name
|
|
|
|
|
* @param {any} cls
|
|
|
|
|
* @param {any} data
|
|
|
|
|
* @param {any} attr
|
|
|
|
|
*/
|
|
|
|
|
function eleBuild(
|
|
|
|
|
text = null,
|
|
|
|
|
id = null,
|
|
|
|
|
name = null,
|
|
|
|
|
cls = [],
|
|
|
|
|
data = {},
|
|
|
|
|
attr = {}
|
|
|
|
|
) {
|
|
|
|
|
(cls = cls ?? []), (data = data ?? {}), (attr = attr ?? {});
|
2022-11-18 17:12:45 +08:00
|
|
|
|
id = id ? `id="${id}"` : "";
|
|
|
|
|
name = name ? `name="${name}"` : "";
|
2023-04-24 11:55:46 +08:00
|
|
|
|
cls = cls.length != 0 ? `class="${cls.join(" ")}"` : "";
|
|
|
|
|
data =
|
|
|
|
|
data.length != 0
|
|
|
|
|
? `${Object.keys(data)
|
|
|
|
|
.map((x) => `data-${x}="${data[x]}"`)
|
|
|
|
|
.join(" ")}`
|
|
|
|
|
: "";
|
|
|
|
|
attr = attr
|
|
|
|
|
? `${Object.keys(attr)
|
|
|
|
|
.map((x) => `${x}="${attr[x]}"`)
|
|
|
|
|
.join(" ")}`
|
|
|
|
|
: "";
|
|
|
|
|
let attrArr = [],
|
|
|
|
|
attrText = "";
|
2022-11-18 17:12:45 +08:00
|
|
|
|
attrArr = [id, name, cls, data, attr];
|
2023-04-24 11:55:46 +08:00
|
|
|
|
attrText = attrArr.filter((x) => x != "").join(" ");
|
2022-11-18 17:12:45 +08:00
|
|
|
|
text = text === null ? "" : text;
|
|
|
|
|
return { attrText: attrText, text: text };
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function creEle(
|
|
|
|
|
ele,
|
|
|
|
|
text = null,
|
|
|
|
|
id = null,
|
|
|
|
|
name = null,
|
|
|
|
|
cls = [],
|
|
|
|
|
data = {},
|
|
|
|
|
attr = {}
|
|
|
|
|
) {
|
2022-11-18 17:12:45 +08:00
|
|
|
|
let comp = eleBuild(text, id, name, cls, data, attr);
|
|
|
|
|
return $(`<${ele} ${comp.attrText}>${comp.text}</${ele}>`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function creDiv(
|
|
|
|
|
cls = [],
|
|
|
|
|
attr = {},
|
|
|
|
|
id = null,
|
|
|
|
|
name = null,
|
|
|
|
|
data = {},
|
|
|
|
|
text = null
|
|
|
|
|
) {
|
2022-11-18 17:12:45 +08:00
|
|
|
|
return creEle("div", text, id, name, cls, data, attr);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function creBtn(
|
|
|
|
|
text = null,
|
|
|
|
|
id = null,
|
|
|
|
|
name = null,
|
|
|
|
|
cls = [],
|
|
|
|
|
data = {},
|
|
|
|
|
attr = {}
|
|
|
|
|
) {
|
2022-11-18 17:12:45 +08:00
|
|
|
|
return creEle("button", text, id, name, cls, data, attr);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function creBtnHtml(
|
|
|
|
|
text = null,
|
|
|
|
|
id = null,
|
|
|
|
|
name = null,
|
|
|
|
|
cls = [],
|
|
|
|
|
data = {},
|
|
|
|
|
attr = {}
|
|
|
|
|
) {
|
2022-11-18 17:12:45 +08:00
|
|
|
|
return creEle("button", text, id, name, cls, data, attr).prop("outerHTML");
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function creSelect(
|
|
|
|
|
id = null,
|
|
|
|
|
cls = [],
|
|
|
|
|
name = null,
|
|
|
|
|
data = {},
|
|
|
|
|
attr = {},
|
|
|
|
|
text = null
|
|
|
|
|
) {
|
2022-11-18 17:12:45 +08:00
|
|
|
|
return creEle("select", text, id, name, cls, data, attr);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function creOption(
|
|
|
|
|
text = null,
|
|
|
|
|
value = null,
|
|
|
|
|
data = {},
|
|
|
|
|
attr = {},
|
|
|
|
|
cls = [],
|
|
|
|
|
name = null,
|
|
|
|
|
id = null
|
|
|
|
|
) {
|
|
|
|
|
value != null ? (attr.value = value) : attr;
|
2022-11-18 17:12:45 +08:00
|
|
|
|
return creEle("option", text, id, name, cls, data, attr);
|
2022-11-28 12:38:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function creImg(
|
|
|
|
|
ele,
|
|
|
|
|
text = null,
|
|
|
|
|
id = null,
|
|
|
|
|
name = null,
|
|
|
|
|
cls = [],
|
|
|
|
|
data = {},
|
|
|
|
|
attr = {}
|
|
|
|
|
) {
|
2022-12-09 18:20:41 +08:00
|
|
|
|
let comp = eleBuild(text, id, name, cls, data, attr);
|
|
|
|
|
return $(`<${ele} ${comp.attrText}>${comp.text}`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function creI(
|
|
|
|
|
cls = [],
|
|
|
|
|
data = {},
|
|
|
|
|
attr = {},
|
|
|
|
|
id = null,
|
|
|
|
|
name = null,
|
|
|
|
|
text = null
|
|
|
|
|
) {
|
2022-12-26 18:32:21 +08:00
|
|
|
|
return creEle("i", text, id, name, cls, data, attr);
|
|
|
|
|
}
|
2023-01-04 17:31:34 +08:00
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function creA(
|
|
|
|
|
text = null,
|
|
|
|
|
attr = {},
|
|
|
|
|
cls = [],
|
|
|
|
|
id = null,
|
|
|
|
|
data = {},
|
|
|
|
|
name = null
|
|
|
|
|
) {
|
2023-01-04 17:31:34 +08:00
|
|
|
|
return creEle("a", text, id, name, cls, data, attr);
|
|
|
|
|
}
|
2023-01-18 17:49:25 +08:00
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function creSpan(
|
|
|
|
|
text = null,
|
|
|
|
|
cls = [],
|
|
|
|
|
id = null,
|
|
|
|
|
attr = {},
|
|
|
|
|
data = {},
|
|
|
|
|
name = null
|
|
|
|
|
) {
|
2023-01-18 17:49:25 +08:00
|
|
|
|
return creEle("span", text, id, name, cls, data, attr);
|
|
|
|
|
}
|
2022-12-02 15:46:37 +08:00
|
|
|
|
/**
|
2023-04-24 11:55:46 +08:00
|
|
|
|
* 根據該棟建築底下的'所有'電梯執行緒物件
|
|
|
|
|
* */
|
2022-11-28 12:38:19 +08:00
|
|
|
|
class ElevatorHandler {
|
|
|
|
|
constructor(ele, option = {}) {
|
|
|
|
|
this.ele = ele;
|
|
|
|
|
this.eleId = "";
|
|
|
|
|
this.eleWra = $("<div></div>");
|
2022-11-28 18:08:50 +08:00
|
|
|
|
this.speed = 0.3;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.movStatus = {}; // {id:elevator01,value:0} 0=no 1=up 2=down
|
|
|
|
|
this.floorHeight =
|
|
|
|
|
typeof option.fHeight == "undefined" ? 60 : option.fHeight;
|
2022-11-28 12:38:19 +08:00
|
|
|
|
this.floorWidth = typeof option.fWidth == "undefined" ? 45 : option.fWidth;
|
|
|
|
|
this.floors = typeof option.floors == "undefined" ? [{}] : option.floors;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.elevators =
|
|
|
|
|
typeof option.elevators == "undefined" ? [{}] : option.elevators; // {id:elevator01}
|
|
|
|
|
this.curElevFloor =
|
|
|
|
|
typeof option.curElevFloor == "undefined" ? {} : option.curElevFloor;
|
2022-11-28 18:08:50 +08:00
|
|
|
|
this.setTimeout = null;
|
2022-11-28 12:38:19 +08:00
|
|
|
|
this.init();
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-02 15:46:37 +08:00
|
|
|
|
// 所有電梯初始化
|
2022-11-28 12:38:19 +08:00
|
|
|
|
init = function () {
|
|
|
|
|
this.setTabWra();
|
|
|
|
|
this.setTabFloor();
|
2022-12-02 15:46:37 +08:00
|
|
|
|
// 若已有每個設備的所在樓層,則預設到該樓層位置
|
2023-01-03 16:47:23 +08:00
|
|
|
|
if (Object.keys(this.curElevFloor).length != 0) {
|
2022-11-28 18:08:50 +08:00
|
|
|
|
$.each(Object.keys(this.curElevFloor), (idx, elevKey) => {
|
2023-01-03 16:47:23 +08:00
|
|
|
|
this.setElevFloor(elevKey, this.curElevFloor[elevKey]);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2022-11-28 18:08:50 +08:00
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-11-28 12:38:19 +08:00
|
|
|
|
|
|
|
|
|
// 設置 wrapper
|
|
|
|
|
setTabWra = function () {
|
|
|
|
|
let id = $(this.ele).prop("id");
|
|
|
|
|
this.eleId = id;
|
|
|
|
|
if ($(this.ele).parent(".elevator-table-wrapper").length != 0) {
|
|
|
|
|
$(this.ele).unwrap(".elevator-table-wrapper");
|
|
|
|
|
}
|
|
|
|
|
let wrapper = creDiv(["elevator-table-wrapper"], null, `${id}_wrapper`);
|
|
|
|
|
$(this.ele).wrap(wrapper);
|
|
|
|
|
this.eleWra = wrapper;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-11-28 12:38:19 +08:00
|
|
|
|
|
|
|
|
|
// 設置 table 樓層
|
|
|
|
|
setTabFloor = function () {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let _w = this.floorWidth,
|
|
|
|
|
_h = this.floorHeight;
|
|
|
|
|
let thead = creEle("thead"),
|
|
|
|
|
tbody = creEle("tbody");
|
|
|
|
|
let _floors = this.floors,
|
|
|
|
|
_ele = this.ele,
|
|
|
|
|
_elevators = this.elevators;
|
2022-11-28 12:38:19 +08:00
|
|
|
|
//樓層從小到大
|
2023-04-24 11:55:46 +08:00
|
|
|
|
_floors = _floors
|
|
|
|
|
.oSort("sort")
|
|
|
|
|
.reverse()
|
|
|
|
|
.map((x) => x.name);
|
2022-11-28 12:38:19 +08:00
|
|
|
|
|
|
|
|
|
let theadTr = creEle("tr");
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
2022-11-28 18:08:50 +08:00
|
|
|
|
for (let e = 1; e <= _elevators.length + 2; e++) {
|
2022-11-28 12:38:19 +08:00
|
|
|
|
let th = creEle("th");
|
2023-04-24 11:55:46 +08:00
|
|
|
|
th.css({ width: `${_w}px`, height: `${_h}px`, position: "relative" });
|
2022-11-28 18:08:50 +08:00
|
|
|
|
if (e != 1 && e != _elevators.length + 2) {
|
2022-11-29 12:46:19 +08:00
|
|
|
|
let elevId = _elevators[e - 2]?.id;
|
2022-11-28 12:38:19 +08:00
|
|
|
|
// 電梯方框
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let span = creEle("span", null, "elevator-item-" + elevId, null, [
|
|
|
|
|
"elevator-item",
|
|
|
|
|
]);
|
2022-11-29 12:46:19 +08:00
|
|
|
|
let spanUp = creEle("span", null, null, null, ["elevator-item-toup"]);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let spanDown = creEle("span", null, null, null, [
|
|
|
|
|
"elevator-item-todown",
|
|
|
|
|
]);
|
|
|
|
|
span.css({
|
|
|
|
|
width: `${_w - 3}px`,
|
|
|
|
|
height: `${_h - 3}px`,
|
|
|
|
|
top: `1.5px`,
|
|
|
|
|
left: "1.5px",
|
|
|
|
|
transition: `transform ${1 / this.speed
|
|
|
|
|
}s cubic-bezier(0.43, 0.05, 0.62, 1) 0s`,
|
|
|
|
|
});
|
|
|
|
|
spanUp.css({
|
|
|
|
|
width: `${_w - 3}px`,
|
|
|
|
|
height: `${(_h - 3) / 2}px`,
|
|
|
|
|
top: `1.5px`,
|
|
|
|
|
left: "1.5px",
|
|
|
|
|
transition: `transform ${1 / this.speed
|
|
|
|
|
}s cubic-bezier(0.43, 0.05, 0.62, 1) 0s`,
|
|
|
|
|
});
|
|
|
|
|
spanDown.css({
|
|
|
|
|
width: `${_w - 3}px`,
|
|
|
|
|
height: `${(_h - 3) / 2}px`,
|
|
|
|
|
top: `1.5px`,
|
|
|
|
|
left: "1.5px",
|
|
|
|
|
transition: `transform ${1 / this.speed
|
|
|
|
|
}s cubic-bezier(0.43, 0.05, 0.62, 1) 0s`,
|
|
|
|
|
top: `${1.5 + (_h - 3) / 2}px`,
|
|
|
|
|
});
|
2022-11-29 12:46:19 +08:00
|
|
|
|
th.append(spanUp);
|
2022-11-28 12:38:19 +08:00
|
|
|
|
th.append(span);
|
2022-11-29 12:46:19 +08:00
|
|
|
|
th.append(spanDown);
|
2022-11-28 12:38:19 +08:00
|
|
|
|
}
|
|
|
|
|
theadTr.append(th);
|
|
|
|
|
}
|
|
|
|
|
thead.css("position", "absolute");
|
|
|
|
|
thead.append(theadTr);
|
|
|
|
|
|
|
|
|
|
//樓層表格建置 tbody
|
|
|
|
|
for (let f = 1; f <= _floors.length; f++) {
|
|
|
|
|
let tr = creEle("tr");
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
2022-11-28 18:08:50 +08:00
|
|
|
|
for (let e = 1; e <= _elevators.length + 2; e++) {
|
2022-11-28 12:38:19 +08:00
|
|
|
|
let td = creEle("td");
|
2023-04-24 11:55:46 +08:00
|
|
|
|
td.css({ width: `${_w}px`, height: `${_h}px` });
|
2022-11-28 12:38:19 +08:00
|
|
|
|
if (e == 1) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
td.addClass("t-black");
|
2022-11-28 12:38:19 +08:00
|
|
|
|
td.text(_floors[f - 1]);
|
2022-11-28 18:08:50 +08:00
|
|
|
|
} else if (e == _elevators.length + 2) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
} else {
|
|
|
|
|
let div = creDiv([
|
|
|
|
|
"d-flex",
|
|
|
|
|
"justify-content-center",
|
|
|
|
|
"align-items-end",
|
|
|
|
|
"h-100",
|
|
|
|
|
]);
|
|
|
|
|
div.append(`<i class="fal fa-door-open fs-1-2"></i>`);
|
|
|
|
|
td.append(div);
|
2022-11-28 12:38:19 +08:00
|
|
|
|
}
|
|
|
|
|
tr.append(td);
|
|
|
|
|
}
|
|
|
|
|
tbody.append(tr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(_ele).append(thead);
|
|
|
|
|
$(_ele).append(tbody);
|
|
|
|
|
|
|
|
|
|
//表格外圍無框線
|
2023-04-24 11:55:46 +08:00
|
|
|
|
$(_ele)
|
|
|
|
|
.find("tbody tr")
|
|
|
|
|
.each((index, tr) => {
|
|
|
|
|
$(tr).find("td:eq(0)").css("border-left", "0");
|
|
|
|
|
$(tr).find("td:eq(-1)").css("border-right", "0");
|
|
|
|
|
|
|
|
|
|
if (index == 0) {
|
|
|
|
|
$(tr)
|
|
|
|
|
.find("td")
|
|
|
|
|
.each((index, td) => {
|
|
|
|
|
$(td).css("border-top", "0");
|
|
|
|
|
});
|
|
|
|
|
} else if (index == $("#floorTable tbody tr").length - 1) {
|
|
|
|
|
$(tr)
|
|
|
|
|
.find("td")
|
|
|
|
|
.each((index, td) => {
|
|
|
|
|
$(td).css("border-bottom", "0");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2022-11-28 12:38:19 +08:00
|
|
|
|
|
2022-12-02 15:46:37 +08:00
|
|
|
|
// 設置某個電梯到某個樓層
|
2022-11-28 18:08:50 +08:00
|
|
|
|
setElevFloor = function (elevId, floId) {
|
|
|
|
|
let curFloId = this.curElevFloor[elevId];
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let curSort = this.floors
|
|
|
|
|
.filter((x) => x.id == curFloId)
|
|
|
|
|
.map((x) => x.sort)[0];
|
|
|
|
|
let tarSort = this.floors
|
|
|
|
|
.filter((x) => x.id == floId)
|
|
|
|
|
.map((x) => x.sort)[0];
|
2022-11-28 18:08:50 +08:00
|
|
|
|
let gapFloor = tarSort - curSort;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let cssEle = [
|
|
|
|
|
$(`#elevator-item-${elevId}`)[0],
|
|
|
|
|
$(`#elevator-item-${elevId}`).prev("span.elevator-item-toup")[0],
|
|
|
|
|
$(`#elevator-item-${elevId}`).next("span.elevator-item-todown")[0],
|
|
|
|
|
];
|
2023-01-03 16:47:23 +08:00
|
|
|
|
if (this.movStatus[elevId] != 0) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
$(cssEle).css(
|
|
|
|
|
"transition",
|
|
|
|
|
`transform ${(1 / this.speed) * Math.abs(gapFloor)
|
|
|
|
|
}s cubic-bezier(0, 0, 0.62, 1) 0s`
|
|
|
|
|
);
|
2022-11-28 18:08:50 +08:00
|
|
|
|
}
|
2022-12-02 15:46:37 +08:00
|
|
|
|
clearTimeout(this.setTimeout);
|
2022-11-28 18:08:50 +08:00
|
|
|
|
this.setTimeout = setTimeout(() => {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
$(cssEle).css(
|
|
|
|
|
"transition",
|
|
|
|
|
`transform ${(1 / this.speed) * Math.abs(gapFloor)
|
|
|
|
|
}s cubic-bezier(0.43, 0.05, 0.62, 1) 0s`
|
|
|
|
|
);
|
2022-11-29 12:46:19 +08:00
|
|
|
|
this.setEleUpDownStyle(elevId);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
}, (1 / this.speed) * Math.abs(gapFloor) * 1000);
|
2022-11-29 12:46:19 +08:00
|
|
|
|
this.setEleUpDownStyle(elevId);
|
|
|
|
|
this.curElevFloor[elevId] = floId;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
$(cssEle).css(
|
|
|
|
|
"transition",
|
|
|
|
|
`transform ${(1 / this.speed) * Math.abs(gapFloor)
|
|
|
|
|
}s cubic-bezier(0.43, 0.05, 0.62, 1) 0s`
|
|
|
|
|
);
|
|
|
|
|
$(cssEle).css(
|
|
|
|
|
"transform",
|
|
|
|
|
`translateY(${this.floorHeight * (this.floors.length - tarSort)}px)`
|
|
|
|
|
);
|
|
|
|
|
};
|
2022-11-29 12:46:19 +08:00
|
|
|
|
|
2022-12-02 15:46:37 +08:00
|
|
|
|
// 設定現在電梯狀態 (往上/往下/停止)
|
2023-01-03 16:47:23 +08:00
|
|
|
|
setEleMovStatus = function (elevId, status) {
|
2022-11-29 12:46:19 +08:00
|
|
|
|
this.movStatus[elevId] = status;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-11-28 18:08:50 +08:00
|
|
|
|
|
2022-12-02 15:46:37 +08:00
|
|
|
|
// 電梯方框 往上或往下閃爍
|
2022-11-29 12:46:19 +08:00
|
|
|
|
setEleUpDownStyle = function (elevId) {
|
|
|
|
|
if (this.movStatus[elevId] == 1) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
$(`#elevator-item-${elevId}`)
|
|
|
|
|
.next("span.elevator-item-todown")
|
|
|
|
|
.removeClass("light-flash-c-bd");
|
|
|
|
|
$(`#elevator-item-${elevId}`)
|
|
|
|
|
.prev("span.elevator-item-toup")
|
|
|
|
|
.addClass("light-flash-c-bd")
|
|
|
|
|
.css("--flash-color-1", "#44ea8e")
|
|
|
|
|
.css("--flash-color-2", "rgba(255,255,255,0)");
|
2022-11-29 12:46:19 +08:00
|
|
|
|
} else if (this.movStatus[elevId] == 2) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
$(`#elevator-item-${elevId}`)
|
|
|
|
|
.prev("span.elevator-item-toup")
|
|
|
|
|
.removeClass("light-flash-c-bd");
|
|
|
|
|
$(`#elevator-item-${elevId}`)
|
|
|
|
|
.next("span.elevator-item-todown")
|
|
|
|
|
.addClass("light-flash-c-bd")
|
|
|
|
|
.css("--flash-color-1", "#44ea8e")
|
|
|
|
|
.css("--flash-color-2", "rgba(255,255,255,0)");
|
2022-11-29 12:46:19 +08:00
|
|
|
|
} else {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
$(`#elevator-item-${elevId}`)
|
|
|
|
|
.prev("span.elevator-item-toup")
|
|
|
|
|
.removeClass("light-flash-c-bd");
|
|
|
|
|
$(`#elevator-item-${elevId}`)
|
|
|
|
|
.next("span.elevator-item-todown")
|
|
|
|
|
.removeClass("light-flash-c-bd");
|
2022-11-29 12:46:19 +08:00
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-11-28 18:08:50 +08:00
|
|
|
|
|
2022-12-02 15:46:37 +08:00
|
|
|
|
// 設定現在某個電梯所在樓層
|
2023-01-03 16:47:23 +08:00
|
|
|
|
setCurElevFloor = function (elevId, floId) {
|
2022-11-28 18:08:50 +08:00
|
|
|
|
this.curElevFloor[elevId] = floId;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-11-28 12:38:19 +08:00
|
|
|
|
|
2022-12-02 15:46:37 +08:00
|
|
|
|
// 重新繪製
|
2022-11-28 18:08:50 +08:00
|
|
|
|
redraw = function () {
|
|
|
|
|
$(this.ele).empty();
|
|
|
|
|
this.setTabFloor();
|
2022-11-29 12:46:19 +08:00
|
|
|
|
if (Object.keys(this.curElevFloor).length != 0) {
|
|
|
|
|
$.each(Object.keys(this.curElevFloor), (idx, elevKey) => {
|
|
|
|
|
this.setElevFloor(elevKey, this.curElevFloor[elevKey]);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2022-11-29 12:46:19 +08:00
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-12-03 16:45:20 +08:00
|
|
|
|
}
|
2022-12-09 18:20:41 +08:00
|
|
|
|
|
|
|
|
|
// 從數字週數轉為中文週數
|
|
|
|
|
function dayToChiDay(num) {
|
|
|
|
|
let chiDay = ["週日", "週一", "週二", "週三", "週四", "週五", "週六"];
|
|
|
|
|
return chiDay[num];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 取得現在或前後時間,輸出單位依據 type
|
2023-01-09 19:15:27 +08:00
|
|
|
|
function getTimeByType(type = null, cal = 0, unit = "d") {
|
2022-12-09 18:20:41 +08:00
|
|
|
|
let now = new Date();
|
2023-01-09 19:15:27 +08:00
|
|
|
|
return strToDate(now, type, cal, unit);
|
2022-12-09 18:20:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 取得某當下時間或前後時間,輸出單位依據 type
|
2023-01-09 19:15:27 +08:00
|
|
|
|
function strToDate(text, type = null, cal = 0, unit = "d") {
|
|
|
|
|
let dec = 24 * 60 * 60 * 1000;
|
|
|
|
|
|
|
|
|
|
if (unit == "d") {
|
|
|
|
|
dec = 24 * 60 * 60 * 1000;
|
|
|
|
|
} else if (unit == "h") {
|
|
|
|
|
dec = 60 * 60 * 1000;
|
|
|
|
|
} else if (unit == "m") {
|
|
|
|
|
dec = 60 * 1000;
|
|
|
|
|
} else if (unit == "s") {
|
|
|
|
|
dec = 1000;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-09 18:20:41 +08:00
|
|
|
|
let calDay = function (_d, _cal) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
return new Date(_d.getTime() + cal * dec);
|
|
|
|
|
};
|
2023-01-09 19:15:27 +08:00
|
|
|
|
|
2022-12-09 18:20:41 +08:00
|
|
|
|
let tarDate = new Date(text);
|
|
|
|
|
let result = 0;
|
|
|
|
|
if (type == "year") {
|
|
|
|
|
result = calDay(tarDate, cal).getFullYear();
|
|
|
|
|
} else if (type == "month") {
|
|
|
|
|
result = calDay(tarDate, cal).getMonth();
|
|
|
|
|
} else if (type == "date") {
|
|
|
|
|
result = calDay(tarDate, cal).getDate();
|
|
|
|
|
} else if (type == "day") {
|
|
|
|
|
result = calDay(tarDate, cal).getDay();
|
|
|
|
|
} else {
|
|
|
|
|
result = calDay(tarDate, cal);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2022-12-27 18:44:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-10 18:39:07 +08:00
|
|
|
|
// 將只有時間(Hms) 格式轉換為當日的時間
|
|
|
|
|
function fullTime(time) {
|
|
|
|
|
let nowDate = displayDate(new Date(), "date");
|
|
|
|
|
return new Date(nowDate + " " + time);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-09 19:15:27 +08:00
|
|
|
|
function dateRanCutPart(start, end, cutNum) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let sTime = new Date(start).getTime();
|
|
|
|
|
let eTime = new Date(end).getTime();
|
2023-01-09 19:15:27 +08:00
|
|
|
|
let cutTimeArr = [];
|
|
|
|
|
if (sTime < eTime) return [];
|
|
|
|
|
|
|
|
|
|
let partNum = (sTime - eTime) / cutNum;
|
|
|
|
|
for (let i = eTime; i <= sTime; i = i + partNum) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
cutTimeArr.push(i);
|
2023-01-09 19:15:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
cutTimeArr.forEach((x) => new Date(x));
|
2023-01-09 19:15:27 +08:00
|
|
|
|
|
|
|
|
|
return cutTimeArr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-27 18:44:22 +08:00
|
|
|
|
function isJSON(str) {
|
|
|
|
|
try {
|
|
|
|
|
JSON.parse(str);
|
|
|
|
|
return true;
|
|
|
|
|
} catch {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-01-03 16:47:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function addBsToast(
|
|
|
|
|
container,
|
|
|
|
|
type = "warning",
|
|
|
|
|
title = "",
|
|
|
|
|
content = "",
|
|
|
|
|
id,
|
|
|
|
|
datas = {},
|
|
|
|
|
option = {}
|
|
|
|
|
) {
|
|
|
|
|
datas =
|
|
|
|
|
Object.keys(datas).length != 0
|
|
|
|
|
? `${Object.keys(datas)
|
|
|
|
|
.map((x) => `data-${x}="${datas[x]}"`)
|
|
|
|
|
.join(" ")}`
|
|
|
|
|
: "";
|
2023-01-11 18:37:58 +08:00
|
|
|
|
let iconClass = option.iconHtml ?? `fas fa-exclamation-triangle`;
|
2023-02-14 15:16:11 +08:00
|
|
|
|
let strHtml = `<div class="toast" role="alert" aria-live="assertive" aria-atomic="true" data-autohide="false" ${datas}>
|
2023-04-24 11:55:46 +08:00
|
|
|
|
<div class="toast-header ${warning ? `bg-` + warning : ""
|
|
|
|
|
}">
|
2023-02-14 15:16:11 +08:00
|
|
|
|
<i class="${iconClass}"></i>
|
|
|
|
|
<strong class="mr-auto">${title}</strong>
|
|
|
|
|
<small class="text-muted">just now</small>
|
|
|
|
|
<button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
|
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="toast-body">
|
|
|
|
|
${content}
|
|
|
|
|
</div>
|
2023-04-24 11:55:46 +08:00
|
|
|
|
</div>`;
|
2023-01-11 18:37:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 16:47:23 +08:00
|
|
|
|
/**
|
2023-04-24 11:55:46 +08:00
|
|
|
|
* 取得資料庫電梯設備,根據 baja 訂閱移動 3D 電梯
|
|
|
|
|
* */
|
2023-01-03 16:47:23 +08:00
|
|
|
|
class Forge3DElevFull {
|
|
|
|
|
constructor(option = {}) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.allElevDevList = []; //全電梯設備清單
|
|
|
|
|
this.subSeviceData = []; //每個設備訂閱點位值
|
2023-01-03 16:47:23 +08:00
|
|
|
|
this.floList = [];
|
|
|
|
|
this.elev3DBind = {};
|
|
|
|
|
this.elev3DOption = {};
|
|
|
|
|
this.elev3DObj = [];
|
|
|
|
|
this.viewer = option.viewer ?? null;
|
|
|
|
|
this.ordPath = option.ordPath ?? {};
|
|
|
|
|
this.sysMainTag = option.system_tag ?? "ELEV";
|
|
|
|
|
this.sysSubTag = option.name_tag ?? "EL";
|
|
|
|
|
this.selector = option.selector ?? "#forgeViewer";
|
|
|
|
|
this.bajaChaCallback = option.bajaChaCallback ?? null;
|
|
|
|
|
this.bajaEndCallback = option.bajaEndCallback ?? null;
|
2023-02-14 15:16:11 +08:00
|
|
|
|
this.sensorObjs = option.sensorObjs ?? null;
|
2023-01-03 16:47:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-14 15:16:11 +08:00
|
|
|
|
init = function () {
|
2023-01-03 16:47:23 +08:00
|
|
|
|
// 系統大類、小類固定
|
|
|
|
|
this.ordPath.system_tag = this.sysMainTag;
|
|
|
|
|
this.ordPath.name_tag = this.sysSubTag;
|
2023-02-14 15:16:11 +08:00
|
|
|
|
|
|
|
|
|
// if (pageAct.sysSubTag === "M12") {
|
|
|
|
|
// console.log("@@",pageAct, pageAct.sysSubTag)
|
|
|
|
|
// this.getSensorDevList();
|
|
|
|
|
// }
|
2023-01-03 16:47:23 +08:00
|
|
|
|
this.getElevDevList();
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
|
|
|
|
// 訂閱電梯設備
|
|
|
|
|
subElevDevice = function () {
|
|
|
|
|
let myBaja = new subscriptionDevices();
|
|
|
|
|
let ordPath = this.ordPath;
|
|
|
|
|
|
|
|
|
|
myBaja.setSubscribeDevicesByBql(ordPath);
|
|
|
|
|
myBaja.setSubscribeDevicesCallBack((data) => {
|
|
|
|
|
this.bajaChaCallback ? this.bajaChaCallback(data) : "";
|
|
|
|
|
if (this.allElevDevList.length == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
data.device_number = data.device_number_full;
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let matchDevice = this.allElevDevList.filter(
|
|
|
|
|
(x) => x.device_number == data.device_number
|
|
|
|
|
)[0];
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
|
|
|
|
if (!matchDevice) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//將訂閱值塞入 subSeviceData
|
2023-04-24 11:55:46 +08:00
|
|
|
|
if (
|
|
|
|
|
this.subSeviceData.findIndex(
|
|
|
|
|
(x) => x.device_number == matchDevice.device_number
|
|
|
|
|
) == -1
|
|
|
|
|
) {
|
2023-01-03 16:47:23 +08:00
|
|
|
|
let obj = {};
|
|
|
|
|
obj.device_number = matchDevice.device_number;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.subSeviceData.push(obj);
|
2023-01-03 16:47:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let subData = this.subSeviceData.filter(
|
|
|
|
|
(x) => x.device_number == matchDevice.device_number
|
|
|
|
|
)[0];
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
|
|
|
|
if (subData) {
|
|
|
|
|
subData[data.point_name] = data.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.point_name == "CP") {
|
|
|
|
|
if (this.elev3DObj.length != 0) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let elevObj = this.elev3DObj.filter(
|
|
|
|
|
(x) => x.nodeId == this.elev3DBind[matchDevice.device_number]
|
|
|
|
|
)[0];
|
2023-01-03 16:47:23 +08:00
|
|
|
|
if (elevObj && elevObj.id) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
elevObj.obj.setElevatorFloor(data.value);
|
2023-01-03 16:47:23 +08:00
|
|
|
|
elevObj.obj.movElevator();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
myBaja.setSubscribeDeviceEndCallBack((data) => {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.floList = data
|
|
|
|
|
.filter((x) => x.point_name.startsWith("SP_FLS_"))
|
|
|
|
|
.map((x) => x?.point_name?.split("SP_FLS_")[1])
|
|
|
|
|
.Distinct();
|
2023-01-03 16:47:23 +08:00
|
|
|
|
this.set3DElevOpt(data);
|
|
|
|
|
this.bajaEndCallback != null ? this.bajaEndCallback() : "";
|
|
|
|
|
});
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
|
|
|
|
// 電梯 3D Option 設置
|
|
|
|
|
set3DElevOpt = function (data) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let devNumArr = data
|
|
|
|
|
.map((x) => {
|
|
|
|
|
return {
|
|
|
|
|
devNum: x.device_number_full,
|
|
|
|
|
priority: this.allElevDevList.filter(
|
|
|
|
|
(y) => y.device_number == x.device_number_full
|
|
|
|
|
)[0]?.priority,
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
.DistinctBy("devNum");
|
2023-01-03 16:47:23 +08:00
|
|
|
|
devNumArr = devNumArr.oSort("priority");
|
|
|
|
|
$.each(devNumArr, (idx, devObj) => {
|
|
|
|
|
let devNum = devObj.devNum;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let subData = this.subSeviceData.filter(
|
|
|
|
|
(x) => x.device_number == devNum
|
|
|
|
|
)[0];
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
|
|
|
|
if (subData) {
|
|
|
|
|
//// 左側 3D 電梯 nodeID 與 device_number match
|
|
|
|
|
//if (Object.keys(elev3DBind).indexOf(devNum) == -1 && viewer3DNodeIds.length != 0) {
|
|
|
|
|
// elev3DBind[devNum] = viewer3DNodeIds[Object.keys(elev3DBind).length];
|
|
|
|
|
//}
|
|
|
|
|
// 左側 3D 電梯 Viewer Option 設置
|
|
|
|
|
/*elev3DOption.nodes = Object.keys(elev3DBind).map(x => elev3DBind[x]);*/
|
|
|
|
|
this.elev3DOption.nodeId = this.elev3DBind[devNum];
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.elev3DOption.floorHeight = this.floList.map((x) => {
|
|
|
|
|
return { floor: x };
|
|
|
|
|
});
|
2023-01-03 16:47:23 +08:00
|
|
|
|
this.elev3DOption.floorHeight.forEach((floObj, idx) => {
|
|
|
|
|
if (floObj.floor.startsWith("B")) {
|
|
|
|
|
let floor = parseInt(floObj.floor.split("B")[1].split("F")[0]);
|
|
|
|
|
floObj.height = floor * -13;
|
|
|
|
|
} else {
|
|
|
|
|
let floor = parseInt(floObj.floor.split("F")[0]);
|
|
|
|
|
if (floor == 1) {
|
|
|
|
|
floObj.height = 0;
|
|
|
|
|
} else if (floor == 2) {
|
|
|
|
|
floObj.height = 14.75;
|
|
|
|
|
} else {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
floObj.height = 14.75 + (floor - 2) * 9.75;
|
2023-01-03 16:47:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
|
|
|
|
if (this.elev3DObj.length != 0) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let elevObj = this.elev3DObj.filter(
|
|
|
|
|
(x) => x.nodeId == this.elev3DBind[devNum]
|
|
|
|
|
)[0];
|
2023-01-03 16:47:23 +08:00
|
|
|
|
if (!elevObj.id) {
|
|
|
|
|
elevObj.id = devNum;
|
|
|
|
|
}
|
|
|
|
|
elevObj.obj = Object.assign(elevObj.obj, this.elev3DOption);
|
|
|
|
|
elevObj.obj.init(() => {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let frags = elevObj.obj.fragProxys.filter(
|
|
|
|
|
(x) => x.nodeId == this.elev3DBind[devNum]
|
|
|
|
|
);
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
|
|
|
|
frags.forEach((fragProxy) => {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
fragProxy.frag.position.z =
|
|
|
|
|
this.elev3DOption.floorHeight.filter(
|
|
|
|
|
(x) => x.floor == subData["CP"]
|
|
|
|
|
)[0]?.height ?? 0;
|
2023-02-14 15:16:11 +08:00
|
|
|
|
let start = 0;
|
2023-03-06 11:37:01 +08:00
|
|
|
|
// 改變感測器熱點位置
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.sensorObjs &&
|
|
|
|
|
this.sensorObjs[0]?.changePos(
|
|
|
|
|
node + 2,
|
|
|
|
|
fragProxy.frag.position.z
|
|
|
|
|
);
|
2023-03-06 11:37:01 +08:00
|
|
|
|
// if (node === 15200 && start == 0) {
|
|
|
|
|
// start = 1;
|
|
|
|
|
// }
|
2023-01-03 16:47:23 +08:00
|
|
|
|
fragProxy.frag.updateAnimTransform();
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2023-01-03 16:47:23 +08:00
|
|
|
|
elevObj.obj.viewer.impl.sceneUpdated(true);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2023-01-03 16:47:23 +08:00
|
|
|
|
this.set3DElevPos();
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
|
|
|
|
// 電梯 3D 位置呈現
|
|
|
|
|
set3DElevPos = function () {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let nodeIds = this.allElevDevList
|
|
|
|
|
.filter((x) => !isNaN(parseInt(x.forge_dbid)))
|
|
|
|
|
.map((x) => {
|
|
|
|
|
return { devNum: x.device_number, nodeId: parseInt(x.forge_dbid) };
|
|
|
|
|
});
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
|
|
|
|
$.each(nodeIds, (idx, item) => {
|
|
|
|
|
this.elev3DBind[item.devNum] = item.nodeId;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
|
|
|
|
nodeIds = nodeIds.map((x) => x.nodeId);
|
2023-01-03 16:47:23 +08:00
|
|
|
|
$.each(nodeIds, (idx, node) => {
|
|
|
|
|
let options = {
|
|
|
|
|
element: $(this.selector),
|
|
|
|
|
viewer: this.viewer,
|
|
|
|
|
nodeId: node,
|
|
|
|
|
floorHeight: this.elev3DOption.floorHeight ?? [],
|
2023-02-14 15:16:11 +08:00
|
|
|
|
sensorObjs: this.sensorObjs,
|
2023-04-24 11:55:46 +08:00
|
|
|
|
inited: function () { },
|
|
|
|
|
};
|
2023-01-03 16:47:23 +08:00
|
|
|
|
let elevator3DObj = new elevator3D(options);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let devNum = Object.keys(this.elev3DBind).filter(
|
|
|
|
|
(x) => this.elev3DBind[x] == node
|
|
|
|
|
)[0];
|
|
|
|
|
let subData = this.subSeviceData.filter(
|
|
|
|
|
(x) => x.device_number == devNum
|
|
|
|
|
)[0];
|
|
|
|
|
|
|
|
|
|
if (this.elev3DObj.filter((x) => x.nodeId == node).length == 0) {
|
2023-01-03 16:47:23 +08:00
|
|
|
|
this.elev3DObj.push({ id: devNum, nodeId: node, obj: elevator3DObj });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (subData) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let elevObj = this.elev3DObj.filter((x) => x.nodeId == node)[0];
|
2023-01-03 16:47:23 +08:00
|
|
|
|
if (!elevObj.id) {
|
|
|
|
|
elevObj.id = devNum;
|
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
elevObj.obj = Object.assign(elevObj, elevator3DObj ?? {});
|
2023-01-03 16:47:23 +08:00
|
|
|
|
elevObj.obj.init(() => {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let frags = elevObj.obj.fragProxys.filter((x) => x.nodeId == node);
|
2023-01-03 16:47:23 +08:00
|
|
|
|
frags.forEach((fragProxy) => {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
fragProxy.frag.position.z =
|
|
|
|
|
this.elev3DOption.floorHeight.filter(
|
|
|
|
|
(x) => x.floor == subData["CP"]
|
|
|
|
|
)[0]?.height ?? 0;
|
2023-02-14 15:16:11 +08:00
|
|
|
|
let start = 0;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.sensorObjs &&
|
|
|
|
|
this.sensorObjs[0]?.changePos(
|
|
|
|
|
node + 2,
|
|
|
|
|
fragProxy.frag.position.z
|
|
|
|
|
);
|
2023-03-06 11:37:01 +08:00
|
|
|
|
// if (node === 15200 && start == 0) {
|
|
|
|
|
// // 改變感測器熱點位置
|
|
|
|
|
// start = 1;
|
|
|
|
|
// }
|
2023-04-24 11:55:46 +08:00
|
|
|
|
fragProxy.frag.updateAnimTransform();
|
|
|
|
|
});
|
2023-01-03 16:47:23 +08:00
|
|
|
|
elevObj.obj.viewer.impl.sceneUpdated(true);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2023-01-03 16:47:23 +08:00
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
|
|
|
|
};
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
|
|
|
|
// 取得設備列表
|
|
|
|
|
getElevDevList = function () {
|
|
|
|
|
let url = baseApiUrl + "/api/Device/GetDeviceList";
|
|
|
|
|
let sendData = {
|
|
|
|
|
sub_system_tag: this.ordPath.name_tag,
|
|
|
|
|
building_tag: this.ordPath.building_tag,
|
|
|
|
|
};
|
|
|
|
|
objSendData.Data = sendData;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
ytAjax = new YourTeam.Ajax(
|
|
|
|
|
url,
|
|
|
|
|
objSendData,
|
|
|
|
|
(res) => {
|
|
|
|
|
if (!res || res.code != "0000" || !res.data) {
|
|
|
|
|
} else {
|
|
|
|
|
$.each(res.data, (index, floObj) => {
|
|
|
|
|
$.each(floObj.device_list, (index2, devObj) => {
|
|
|
|
|
this.allElevDevList.push(devObj);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
this.subElevDevice();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
null,
|
|
|
|
|
"POST"
|
|
|
|
|
).send();
|
|
|
|
|
};
|
2023-01-04 18:49:37 +08:00
|
|
|
|
|
|
|
|
|
getNodeIds = function () {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
return this.elev3DObj.map((x) => x.nodeId);
|
|
|
|
|
};
|
2023-02-02 17:17:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-04-24 11:55:46 +08:00
|
|
|
|
* 取得資料庫溫度感測器
|
|
|
|
|
* 1. baja 取得溫度感測器改變顏色
|
|
|
|
|
* 2. 參數取得要移動到的電梯位置
|
|
|
|
|
* */
|
2023-02-02 17:17:07 +08:00
|
|
|
|
class Forge3DSensor {
|
2023-02-14 15:16:11 +08:00
|
|
|
|
constructor(option = {}) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.subDeviceData = []; //每個設備訂閱點位值
|
2023-02-14 15:16:11 +08:00
|
|
|
|
this.viewer = option.viewer ?? null;
|
|
|
|
|
this.ordPath = option.ordPath; // TPE_B1
|
|
|
|
|
this.sysMainTag = "ME";
|
|
|
|
|
this.sysSubTag = "M12";
|
|
|
|
|
this.selector = "#forgeViewer";
|
|
|
|
|
this.heatMap = null;
|
|
|
|
|
this.bajaChaCallback = option.bajaChaCallback ?? null;
|
|
|
|
|
this.bajaEndCallback = option.bajaEndCallback ?? null;
|
|
|
|
|
this.floorHeight = 0;
|
|
|
|
|
this.dataVizExtn = null;
|
|
|
|
|
this.DataVizCore = null;
|
|
|
|
|
this.tempVal = 20;
|
|
|
|
|
this.curDevice = option.curDevice ?? null;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.deviceList = option.deviceList ?? null;
|
|
|
|
|
this.selector = option.selector ?? "#forgeViewer";
|
|
|
|
|
this.elevCb = option.elevCb ?? null;
|
2023-02-14 15:16:11 +08:00
|
|
|
|
this.#init();
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
static sensorTimes = 0;
|
|
|
|
|
|
2023-02-14 15:16:11 +08:00
|
|
|
|
#init = async function () {
|
|
|
|
|
// 系統大類、小類固定
|
|
|
|
|
this.ordPath.system_tag = this.sysMainTag;
|
|
|
|
|
this.ordPath.name_tag = this.sysSubTag;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
// this.dataVizExtn = await this.viewer.loadExtension(
|
|
|
|
|
// "Autodesk.DataVisualization"
|
|
|
|
|
// );
|
|
|
|
|
// this.DataVizCore = Autodesk.DataVisualization.Core;
|
|
|
|
|
await this.registerHotPoint();
|
|
|
|
|
this.addSensorHotspotList(this.curDevice.forge_dbid, 35);
|
2023-02-14 15:16:11 +08:00
|
|
|
|
this.subSensorDevice();
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.elevCb && this.elevCb();
|
|
|
|
|
};
|
2023-02-14 15:16:11 +08:00
|
|
|
|
|
2023-03-06 11:37:01 +08:00
|
|
|
|
// // 建立熱點
|
|
|
|
|
// async addHotPoint() {
|
2023-02-14 15:16:11 +08:00
|
|
|
|
|
2023-03-06 11:37:01 +08:00
|
|
|
|
// // this.dataVizExtn.removeAllViewables()
|
|
|
|
|
// await this.registerHotPoint()
|
|
|
|
|
// this.subSensorDevice();
|
|
|
|
|
// // console.log("2",this.dataVizExtn)
|
|
|
|
|
// }
|
2023-02-14 15:16:11 +08:00
|
|
|
|
|
|
|
|
|
async registerHotPoint(color = "") {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
if (Forge3DSensor.sensorTimes === 1) {
|
|
|
|
|
var viewer = this.viewer;
|
|
|
|
|
const dataVizExtn = await viewer.loadExtension(
|
|
|
|
|
"Autodesk.DataVisualization"
|
|
|
|
|
);
|
|
|
|
|
const DataVizCore = Autodesk.DataVisualization.Core;
|
|
|
|
|
const viewableType = DataVizCore.ViewableType.SPRITE; //DataVizCore.ViewableType.SPRITE;
|
|
|
|
|
const spriteColor = new THREE.Color(0xff8c00);
|
|
|
|
|
// const highlightedColor = new THREE.Color(0xe0e0ff);
|
|
|
|
|
let spriteIcon = "/file/img/forge/sensor_circle.svg";
|
|
|
|
|
if (location.href.indexOf("localhost:5966") != -1) {
|
|
|
|
|
spriteIcon = "/img/forge/sensor_circle.svg";
|
|
|
|
|
}
|
|
|
|
|
const style = new DataVizCore.ViewableStyle(
|
|
|
|
|
viewableType,
|
|
|
|
|
spriteColor,
|
|
|
|
|
spriteIcon
|
|
|
|
|
);
|
|
|
|
|
const viewableData = new DataVizCore.ViewableData();
|
|
|
|
|
viewableData.spriteSize = 30; // Sprites as points of size 24 x 24 pixels
|
|
|
|
|
this.deviceList.forEach((myData, index) => {
|
|
|
|
|
// console.log(myData)
|
|
|
|
|
const dbId = myData.forge_dbid;
|
|
|
|
|
const myPosition = myData.position;
|
|
|
|
|
const viewable = new DataVizCore.SpriteViewable(
|
|
|
|
|
myPosition,
|
|
|
|
|
style,
|
|
|
|
|
dbId
|
|
|
|
|
);
|
|
|
|
|
myData._dbId = dbId;
|
|
|
|
|
viewableData.addViewable(viewable);
|
|
|
|
|
});
|
|
|
|
|
await viewableData.finish();
|
|
|
|
|
dataVizExtn.addViewables(viewableData);
|
|
|
|
|
viewer.addEventListener(
|
|
|
|
|
DataVizCore.MOUSE_CLICK,
|
|
|
|
|
this.onSpriteClicked.bind(this)
|
|
|
|
|
); // SPRITE_SELECTED
|
|
|
|
|
// viewer.addEventListener(this.DataVizCore.MOUSE_CLICK_OUT, onSpriteClickedOut.bind(this));
|
2023-02-14 15:16:11 +08:00
|
|
|
|
}
|
2023-02-22 10:33:35 +08:00
|
|
|
|
}
|
|
|
|
|
// ---------------- 熱點點擊事件 --------------------
|
|
|
|
|
onSpriteClicked(event) {
|
|
|
|
|
event.hasStopped = true;
|
|
|
|
|
const dbIdStart = 10;
|
|
|
|
|
if (event != undefined && event != null) {
|
|
|
|
|
if (event.dbId >= dbIdStart) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let myData = this.deviceList.find((x) => x.forge_dbid == event.dbId);
|
|
|
|
|
console.log("site", myData);
|
|
|
|
|
// this.changeColorForSensorHotspot(event.dbId, this.tempVal);
|
|
|
|
|
myData && moveViewToDevice(myData.forge_dbid); //移動視角至該設備
|
|
|
|
|
myData &&
|
|
|
|
|
$(this.selector).trigger("autodesk:click:sprite", { event, myData });
|
2023-02-22 10:33:35 +08:00
|
|
|
|
} else {
|
|
|
|
|
$(this.selector).trigger("autodesk:clickOut:sprite", { event });
|
2023-02-14 15:16:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 改變熱點位置
|
2023-02-22 10:33:35 +08:00
|
|
|
|
async changePos(dbId, positionZ) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
const dataVizExtn = await viewer.loadExtension(
|
|
|
|
|
"Autodesk.DataVisualization"
|
|
|
|
|
);
|
|
|
|
|
dataVizExtn?.invalidateViewables(dbId, (viewable) => {
|
2023-02-14 15:16:11 +08:00
|
|
|
|
// console.log(viewable._position)
|
2023-04-24 11:55:46 +08:00
|
|
|
|
const z = viewable._position.z + positionZ;
|
|
|
|
|
const newPos = { ...viewable._position, z };
|
2023-02-02 17:17:07 +08:00
|
|
|
|
return {
|
2023-02-14 15:16:11 +08:00
|
|
|
|
// Move the viewable to a new location.
|
2023-04-24 11:55:46 +08:00
|
|
|
|
position: newPos,
|
2023-02-02 17:17:07 +08:00
|
|
|
|
};
|
|
|
|
|
});
|
2023-02-14 15:16:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
// 溫度感測器 sprite 隨溫度變化
|
|
|
|
|
static lowerTempForSensor = [];
|
|
|
|
|
static normalTempForSensor = [];
|
|
|
|
|
static highTempForSensor = [];
|
|
|
|
|
static highestTempForSensor = [];
|
|
|
|
|
|
|
|
|
|
async addSensorHotspotList(dbid, temp) {
|
2023-02-14 15:16:11 +08:00
|
|
|
|
let index = Math.floor(temp / 10) - 1 || 0;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
|
|
|
|
|
// 清空資料
|
|
|
|
|
Forge3DSensor.lowerTempForSensor = Forge3DSensor.lowerTempForSensor.filter(
|
|
|
|
|
(point) => point !== dbid
|
|
|
|
|
);
|
|
|
|
|
Forge3DSensor.normalTempForSensor =
|
|
|
|
|
Forge3DSensor.normalTempForSensor.filter((point) => point !== dbid);
|
|
|
|
|
Forge3DSensor.highTempForSensor = Forge3DSensor.highTempForSensor.filter(
|
|
|
|
|
(point) => point !== dbid
|
|
|
|
|
);
|
|
|
|
|
Forge3DSensor.highestTempForSensor =
|
|
|
|
|
Forge3DSensor.highestTempForSensor.filter((point) => point !== dbid);
|
|
|
|
|
|
|
|
|
|
const temps = [
|
|
|
|
|
new THREE.Color(0x00009c),
|
|
|
|
|
new THREE.Color(0xffff31),
|
|
|
|
|
new THREE.Color(0xff8c00),
|
|
|
|
|
new THREE.Color(0xff0000),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
|
case -1:
|
|
|
|
|
Forge3DSensor.lowerTempForSensor.push(dbid);
|
|
|
|
|
break;
|
|
|
|
|
case 0:
|
|
|
|
|
Forge3DSensor.lowerTempForSensor.push(dbid);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
Forge3DSensor.normalTempForSensor.push(dbid);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
Forge3DSensor.highTempForSensor.push(dbid);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
Forge3DSensor.highestTempForSensor.push(dbid);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Forge3DSensor.highTempForSensor.push(dbid);
|
|
|
|
|
break;
|
2023-02-14 15:16:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
await this.changeColorForSensorHotspot(
|
|
|
|
|
Forge3DSensor.lowerTempForSensor,
|
|
|
|
|
temps[0]
|
|
|
|
|
);
|
|
|
|
|
await this.changeColorForSensorHotspot(
|
|
|
|
|
Forge3DSensor.normalTempForSensor,
|
|
|
|
|
temps[1]
|
|
|
|
|
);
|
|
|
|
|
await this.changeColorForSensorHotspot(
|
|
|
|
|
Forge3DSensor.highTempForSensor,
|
|
|
|
|
temps[2]
|
|
|
|
|
);
|
|
|
|
|
await this.changeColorForSensorHotspot(
|
|
|
|
|
Forge3DSensor.highestTempForSensor,
|
|
|
|
|
temps[3]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async changeColorForSensorHotspot(viewablesToUpdate, color) {
|
|
|
|
|
const dataVizExtn = await viewer.loadExtension(
|
|
|
|
|
"Autodesk.DataVisualization"
|
|
|
|
|
);
|
|
|
|
|
dataVizExtn.invalidateViewables(viewablesToUpdate, (viewable) => {
|
2023-02-14 15:16:11 +08:00
|
|
|
|
return {
|
|
|
|
|
color: color,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 訂閱sensor設備
|
|
|
|
|
subSensorDevice() {
|
|
|
|
|
let myBaja = new subscriptionDevices();
|
|
|
|
|
myBaja.setSubscribeDevicesByBql(this.ordPath);
|
|
|
|
|
|
|
|
|
|
myBaja.setSubscribeDevicesCallBack((data) => {
|
|
|
|
|
this.bajaChaCallback ? this.bajaChaCallback(data) : "";
|
|
|
|
|
if (this.curDevice == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.device_number = data.device_number_full; // "TPE_B1_ME_M12_U1F_NA_TH_N1" (forge TPE_B1_ME_M12_R2F_NA_TH_N1)
|
|
|
|
|
|
|
|
|
|
//將訂閱值塞入 subDeviceData
|
|
|
|
|
if (
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.subDeviceData.findIndex(
|
|
|
|
|
(d) => d.device_number == this.curDevice.id
|
|
|
|
|
) == -1
|
2023-02-14 15:16:11 +08:00
|
|
|
|
) {
|
|
|
|
|
let obj = {};
|
|
|
|
|
obj.device_number = this.curDevice.id;
|
|
|
|
|
obj.dbid = this.curDevice.roomDbId;
|
|
|
|
|
this.subDeviceData.push(obj);
|
|
|
|
|
}
|
|
|
|
|
let subData = this.subDeviceData.find(
|
2023-04-24 11:55:46 +08:00
|
|
|
|
(x) => x.device_number == this.curDevice.id
|
2023-02-14 15:16:11 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (subData) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
subData = { ...subData, [data.point_name]: data.value };
|
2023-02-14 15:16:11 +08:00
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
|
2023-02-14 15:16:11 +08:00
|
|
|
|
//let norDevPoiName = matchDevice.device_normal_point_name;
|
|
|
|
|
//let cloDevPoiName = matchDevice.device_close_point_name || "";
|
|
|
|
|
//let errDevPoiName = matchDevice.device_error_point_name;
|
|
|
|
|
|
|
|
|
|
if (data.point_name == "Temp" || data.point_name == "TEMP") {
|
|
|
|
|
this.tempVal = !isNaN(parseInt(data.value)) ? parseInt(data.value) : 0;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.curDevice = {
|
|
|
|
|
...this.curDevice,
|
|
|
|
|
temp: !isNaN(parseInt(data.value)) ? parseInt(data.value) : 0,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (data.device_number_full === this.curDevice.id) {
|
|
|
|
|
this.addSensorHotspotList(
|
|
|
|
|
this.curDevice.forge_dbid,
|
|
|
|
|
this.curDevice.temp
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-02-14 15:16:11 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
myBaja.setSubscribeDeviceEndCallBack((data) => {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
if (
|
|
|
|
|
data.findIndex(
|
|
|
|
|
(x) => x.point_name == "Temp" || x.point_name == "TEMP"
|
|
|
|
|
) != -1
|
|
|
|
|
) {
|
2023-02-14 15:16:11 +08:00
|
|
|
|
// 顯示溫度條
|
|
|
|
|
showHeat("[name=forgeHeatBar]");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// window.x = 28
|
|
|
|
|
// setInterval(()=>{
|
|
|
|
|
// this.changeColorForSensorHotspot(this.curDevice.forge_dbid, x++)
|
|
|
|
|
// }, 2000)
|
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
}
|