UNPKG

tfp

Version:

A Web UI framework for TaskBuilder

375 lines (313 loc) 11.7 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _controller = require("../controller.js"); function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } /** * 弹出列表组件 * @param {[type]} dataModel [description] */ var List = /*#__PURE__*/function (_FormInput) { (0, _inherits2["default"])(List, _FormInput); var _super = _createSuper(List); function List(__tfp, dataModel, parent) { (0, _classCallCheck2["default"])(this, List); return _super.call(this, __tfp, "List", dataModel, parent); } (0, _createClass2["default"])(List, [{ key: "value", get: function get() { if (!this.dataModel.value) return ""; return this.dataModel.value; }, set: function set(value) { var val = value; if (isNull(value)) { val = ""; this.dataModel.value = null; } else { this.dataModel.value = val; //this.options = this.dataModel.options; } if (this._jqObj) { this.reRender(); } if (!this._tfp.isDesigning) { this.valueOnChange(); this.exeEventHandler("onChange", val); } } }, { key: "options", get: function get() { return this.dataModel.options; }, set: function set(options) { if (this._jqObj && options && Array.isArray(options)) { this.dataModel.options = options; if (this._jqObj) { this.reRender(); } } } }, { key: "orderType", get: function get() { return this.dataModel.orderType; }, set: function set(value) { this.dataModel.orderType = value; //this.options = this.dataModel.options; if (this._jqObj) { this.reRender(); } } }, { key: "icon", get: function get() { return this.dataModel.icon; }, set: function set(value) { this.dataModel.icon = value; //this.options = this.dataModel.options; if (this._jqObj) { this.reRender(); } } }, { key: "color", get: function get() { return this.dataModel.color; }, set: function set(value) { this.dataModel.color = value; if (this._jqObj) { this.reRender(); } } }, { key: "bgColor", get: function get() { return this.dataModel.bgColor; }, set: function set(value) { this.dataModel.bgColor = value; if (this._jqObj) { this.reRender(); } } }, { key: "loadDataListService", get: function get() { return this.dataModel.loadDataListService; }, set: function set(value) { this.dataModel.loadDataListService = value; } }, { key: "dataListBindingMember", get: function get() { return this.dataModel.dataListBindingMember; }, set: function set(value) { this.dataModel.dataListBindingMember = value; } }, { key: "dataListValueFormat", get: function get() { return this.dataModel.dataListValueFormat; }, set: function set(value) { this.dataModel.dataListValueFormat = value; } }, { key: "dataListTextFormat", get: function get() { return this.dataModel.dataListTextFormat; }, set: function set(value) { this.dataModel.dataListTextFormat = value; } }, { key: "reRender", value: function reRender() { this._jqObj.empty(); this._jqObj.append(this.getBodyHtml()); if (!this._tfp.isDesigning) this.bindItemEvent(); } }, { key: "getBodyHtml", value: function getBodyHtml(getComponentsHtml) { var indent = this.getHtmlIndent(); var html = "\r\n"; var bgColor = '#dddddd'; var color = '#666666'; if (this.dataModel.bgColor) bgColor = this.dataModel.bgColor; if (this.dataModel.color) color = this.dataModel.color; if (this.dataModel.options) { for (var i = 0; i < this.dataModel.options.length; i++) { var option = this.dataModel.options[i]; html += indent + "\t<div data-value=\"" + option.value + "\""; if (option.value + "" == this.dataModel.value + "") { html += " style=\"background-color:" + bgColor + ";"; if (!option.href) { html += "color:" + color + ";"; } html += "\""; } if (!this._tfp.isDesigning && option.onClick) html += " onclick=\"" + option.onClick + "\""; var dot = "●"; if (this.dataModel.orderType == "order") dot = i + 1 + "."; if (this.dataModel.icon) { var imgUrl = ''; if (this.dataModel.icon[0] == '/') { imgUrl = this._tfp.rootPath + "" + this.dataModel.icon + ""; } else { imgUrl = this.dataModel.icon; } dot = "<img width=\"16\" height=\"16\" align=\"absmiddle\" src=\"" + imgUrl + "\" />"; } html += ">"; if (option.href) { html += "<a "; if (option.value + "" == this.dataModel.value + "") html += " style=\"color:" + color + ";\""; if (!this._tfp.isDesigning) { if (option.target == "self") { html += " href=\"" + option.href + "\""; } else { html += " href=\"javascript:void(0)\" onclick=\""; var title = "Tasgine - 任擎"; if (option.targetTitle) title = option.targetTitle; if (option.target == "page") { html += "tfp.openPage('" + title + "', '" + option.href + "')"; } else if (option.target == "dialog") { var width = option.dialogWidth; if (!width) width = "480px"; if ((width + "").indexOf("px") < 0) width += "px"; var height = option.dialogHeight; if (!height) height = "480px"; if ((height + "").indexOf("px") < 0) height += "px"; html += "tfp.openDialog('" + title + "', '" + option.href + "'" + ", '" + width + "', '" + height + "')"; } else if (option.target == "window") { html += "window.open('" + option.href + "', '" + title + "')"; } html += "\""; } } html += ">"; } html += "" + dot + " " + (option.text ? option.text : option.value) + ""; if (option.href) { html += "</a>"; } html += "</div>\r\n"; } } return html + "\t"; } }, { key: "bindItemEvent", value: function bindItemEvent() { var that = this; this._jqObj.children("div").click(function () { var bgColor = "#dddddd"; var color = "#666666"; if (that.dataModel.bgColor) bgColor = that.dataModel.bgColor; if (that.dataModel.color) color = that.dataModel.color; that._jqObj.find("div").css("color", "#666666"); that._jqObj.find("a").css("color", "#666666"); $(this).css("background-color", bgColor).siblings("div").css("background-color", ""); if ($(this).find("a").length > 0) { $(this).find("a").css("color", color); } else { $(this).css("color", color); } var index = $(this).index(); var option = that.dataModel.options[index]; var value = option.value; if (option.onClick) eval(option.onClick); if (that.dataModel.onClickOption) eval(that.dataModel.onClickOption); }); } }, { key: "bindData", value: function bindData(data) { if (isNull(data) || !Array.isArray(data)) return; var options = []; for (var i = 0; i < data.length; i++) { var row = data[i]; var option = {}; try { var valueFormat = this.dataModel.dataListValueFormat; if (valueFormat.indexOf("{") < 0 && valueFormat.indexOf("#[") < 0) valueFormat = "{" + valueFormat + "}"; option.value = this._tfp.replaceDataField(row, valueFormat); if (option.value) option.value = this._tfp.exeExpress(option.value); } catch (e) { console.log(e); return; } if (isNull(option.value)) continue; option.text = option.value; if (this.dataModel.dataListTextFormat) { try { var textFormat = this.dataModel.dataListTextFormat; if (textFormat.indexOf("{") < 0 && textFormat.indexOf("#[") < 0) textFormat = "{" + textFormat + "}"; option.text = this._tfp.replaceDataField(row, textFormat); if (option.text) option.text = this._tfp.exeExpress(option.text); } catch (e) { console.log(e); return; } } if (isNull(option.text)) continue; options.push(option); } this.options = options; } }, { key: "loadData", value: function loadData() { if (!this.dataModel.loadDataListService) { alert("请为[" + this.id + "]设置加载数据服务!"); return; } var serviceCpt = this._tfp.get(this.dataModel.loadDataListService); if (!serviceCpt) { alert("ID为[" + this.dataModel.loadDataListService + "]的组件不存在!"); return; } if (!this.dataModel.dataListBindingMember) { alert("请为[" + this.id + "]设置数据绑定成员!"); return; } if (!this.dataModel.dataListValueFormat) { alert("请为[" + this.id + "]设置选项值数据格式!"); return; } var that = this; //与服务组件建立绑定 if (!serviceCpt.bindCpts) serviceCpt.bindCpts = []; if (!serviceCpt.bindCpts.contains(this.id)) serviceCpt.bindCpts.push(this.id); serviceCpt.request(null, function (req, res) { var data = res[that.dataModel.dataListBindingMember]; that.bindData(data); }); } }, { key: "initRuntime", value: function initRuntime() { //如果设置了加载数据列表的服务 if (this.dataModel.loadDataListService) { this.loadData(); } this.bindItemEvent(); } }]); return List; }(_controller.FormInput); exports["default"] = List;