@nbxx/nb-input
Version:
Angular - nbinput
96 lines • 4.07 kB
JavaScript
import { Component, forwardRef, Input } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { DescriptionStrategy, Image as GalleryImage } from '@ks89/angular-modal-gallery';
import { NbinputConfig } from './nbinput.entity';
export class NbinputGalleryComponent {
constructor() {
this.rid = 'nbg-' + Math.random() * 10000000;
this.imgConf = {
downloadable: false,
description: {
strategy: DescriptionStrategy.ALWAYS_VISIBLE,
style: { marginBottom: '0px' }
}
};
this.config = new NbinputConfig();
}
registerOnChange(fn) { }
registerOnTouched(fn) { }
setDisabledState(isDisabled) { }
writeValue(obj) {
setTimeout(() => {
this.data = obj;
}, 0);
}
set data(val) {
this.imgs = [];
this._data = val;
// 1. 如果 val 不是 array
// 1.1 如果 val 是 string of URL
// 1.2 如果 val 是 Attachment
if (!!val) {
if (typeof val == 'object' && typeof val.length == 'number') {
this.imgs = val.filter(e => !!e && (((typeof e == 'string') && e.length > 0) || e.url && e.url.length > 0)).map((e, i) => (typeof e == 'string') ?
new GalleryImage(i + 1, {
img: '' + (e.startsWith('http:') || e.startsWith('https:') ? '' : this.config.downloadAPI) +
e + (this.config.token && this.config.token.length > 0 ? '' : '?token=' + this.config.token)
})
: new GalleryImage(i + 1, {
img: (e.url.startsWith('http:') || e.url.startsWith('https:') ? '' : this.config.downloadAPI) +
e.url + (this.config.token && this.config.token.length > 0 ? '' : '?token=' + this.config.token),
title: e.name,
alt: e.name
}));
}
else if (typeof val == 'string' && val.length > 0) {
this.imgs = [
new GalleryImage(1, {
img: '' + (val.startsWith('http:') || val.startsWith('https:') ? '' : this.config.downloadAPI) +
val + (this.config.token && this.config.token.length > 0 ? '' : '?token=' + this.config.token)
})
];
}
else if (val.url && val.url.length > 0) {
this.imgs = [
new GalleryImage(1, {
img: (val.url.startsWith('http:') || val.url.startsWith('https:') ? '' : this.config.downloadAPI) +
val.url + (this.config.token && this.config.token.length > 0 ? '' : '?token=' + this.config.token),
title: val.name,
alt: val.name
})
];
}
}
}
get data() {
return this._data;
}
}
NbinputGalleryComponent.decorators = [
{ type: Component, args: [{
selector: 'nbinput-gallery',
template: `
<ks-modal-gallery *ngIf="imgs&&imgs.length>0"
[id]="rid"
[modalImages]="imgs"
[slideConfig]="{infinite: false}"
[currentImageConfig]="imgConf"
></ks-modal-gallery>
<span *ngIf="!imgs||imgs.length<=0">无</span>
`,
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => NbinputGalleryComponent),
multi: true
}
]
},] },
];
/** @nocollapse */
NbinputGalleryComponent.ctorParameters = () => [];
NbinputGalleryComponent.propDecorators = {
config: [{ type: Input }],
data: [{ type: Input }]
};
//# sourceMappingURL=nbinput-gallery.component.js.map