@angular-jz/jz
Version:
jim jz
134 lines • 6.09 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var forms_1 = require("@angular/forms");
var array_utility_1 = require("../../../jz/utility/array-utility");
var JZMultipleTreeSelectComponent = /** @class */ (function () {
function JZMultipleTreeSelectComponent() {
var _this = this;
this.idField = 'id';
this.textField = 'text';
this.placeholder = '请选择';
this._value = [];
this.propagateChange = function (_) { };
this.template = function (state) {
if (!state[_this.idField]) {
return state.text;
}
var item = array_utility_1.ArrayUtility.findInArray(_this.items, _this.idField, state.id);
if (!item)
return state.text;
var lineVisibility = "";
if (item.childCount == 0)
lineVisibility = ' style="visibility:hidden;"';
var lineText = "<span style=\"text-indent:" + (item.level - 1) + "em;\"><i class=\"fa fa-caret-down\"" + lineVisibility + "></i> " + state.text + "</span>";
var $state = $(lineText);
return $state;
//<span style="text-indent:2em;"><i class="fa fa-caret-down" style="visibility:hidden;"></i> a1.1</span>
};
}
JZMultipleTreeSelectComponent_1 = JZMultipleTreeSelectComponent;
JZMultipleTreeSelectComponent.prototype.ngOnInit = function () {
var me = this;
$(this.select.nativeElement).on('change', function (e) {
var idType = null;
if (me.items && me.items.length) {
idType = typeof (me.items[0][me.idField]);
}
var newValue = $(me.select.nativeElement).val();
newValue = newValue.map(function (item) {
if (idType == null)
return item;
else if (idType == "number")
return Number(item);
else if (idType == "string")
return String(item);
else if (idType == "object")
return item;
});
me._value = newValue;
me.propagateChange(me.value);
});
};
JZMultipleTreeSelectComponent.prototype.ngOnDestroy = function () {
$(this.select.nativeElement).off('change');
};
JZMultipleTreeSelectComponent.prototype.ngAfterViewInit = function () {
$(this.select.nativeElement).select2({
placeholder: this.placeholder,
templateResult: this.template,
});
};
Object.defineProperty(JZMultipleTreeSelectComponent.prototype, "value", {
get: function () {
return this._value;
},
set: function (value) {
if (this._value != value) {
this._value = value;
this.propagateChange(this.value);
$(this.select.nativeElement).val(this._value);
$(this.select.nativeElement).trigger('change');
}
},
enumerable: true,
configurable: true
});
JZMultipleTreeSelectComponent.prototype.writeValue = function (value) {
this.value = value;
};
JZMultipleTreeSelectComponent.prototype.registerOnChange = function (fn) {
this.propagateChange = fn;
};
JZMultipleTreeSelectComponent.prototype.registerOnTouched = function (fn) { };
__decorate([
core_1.ViewChild('select'),
__metadata("design:type", core_1.ElementRef)
], JZMultipleTreeSelectComponent.prototype, "select", void 0);
__decorate([
core_1.Input(),
__metadata("design:type", Array)
], JZMultipleTreeSelectComponent.prototype, "items", void 0);
__decorate([
core_1.Input(),
__metadata("design:type", String)
], JZMultipleTreeSelectComponent.prototype, "idField", void 0);
__decorate([
core_1.Input(),
__metadata("design:type", String)
], JZMultipleTreeSelectComponent.prototype, "textField", void 0);
__decorate([
core_1.Input(),
__metadata("design:type", String)
], JZMultipleTreeSelectComponent.prototype, "placeholder", void 0);
__decorate([
core_1.Input(),
__metadata("design:type", Array)
], JZMultipleTreeSelectComponent.prototype, "_value", void 0);
JZMultipleTreeSelectComponent = JZMultipleTreeSelectComponent_1 = __decorate([
core_1.Component({
selector: 'jz-multiple-tree-select',
templateUrl: './jz-multiple-tree-select.component.html',
providers: [{
provide: forms_1.NG_VALUE_ACCESSOR,
/* tslint:disable */
useExisting: core_1.forwardRef(function () { return JZMultipleTreeSelectComponent_1; }),
/* tslint:enable */
multi: true
}],
})
], JZMultipleTreeSelectComponent);
return JZMultipleTreeSelectComponent;
var JZMultipleTreeSelectComponent_1;
}());
exports.JZMultipleTreeSelectComponent = JZMultipleTreeSelectComponent;
//# sourceMappingURL=jz-multiple-tree-select.component.js.map