| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- /* eslint-disable prefer-destructuring */
- /* eslint-disable no-underscore-dangle */
- export default class ListUtil {
- constructor(list) {
- let _list = [];
- if (list && list.constructor === String) {
- _list = list.split(",");
- } else {
- _list = list || [];
- }
- _list = [...new Set(_list)];
- _list = _list.filter(item => {
- return item !== "" && item != null;
- });
- this.list = _list;
- }
- getLength() {
- return this.list.length;
- }
- // 获取正反面照片
- getOneTow(one, tow) {
- const _list = [...this.list];
- let oneVal = "";
- let towVal = "";
- if (_list.length > 0) {
- oneVal = _list[0];
- }
- if (_list.length > 1) {
- towVal = _list[1];
- }
- if (one) {
- one(oneVal);
- }
- if (tow) {
- tow(towVal);
- }
- }
- setImgVal(list) {
- const _list = [...this.list];
- _list.forEach((item, index) => {
- if (list[index]) {
- list[index](item);
- }
- });
- }
- getKey(key) {
- const _list = [...this.list];
- if (_list.length > 0) {
- return _list.pop()[key];
- }
- return "";
- }
- getListValue(key) {
- let _list = [...this.list];
- if (key) {
- _list = _list.map(item => {
- return item[key];
- });
- }
- return _list.join(",");
- }
- }
|