ListUtil.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* eslint-disable prefer-destructuring */
  2. /* eslint-disable no-underscore-dangle */
  3. export default class ListUtil {
  4. constructor(list) {
  5. let _list = [];
  6. if (list && list.constructor === String) {
  7. _list = list.split(",");
  8. } else {
  9. _list = list || [];
  10. }
  11. _list = [...new Set(_list)];
  12. _list = _list.filter(item => {
  13. return item !== "" && item != null;
  14. });
  15. this.list = _list;
  16. }
  17. getLength() {
  18. return this.list.length;
  19. }
  20. // 获取正反面照片
  21. getOneTow(one, tow) {
  22. const _list = [...this.list];
  23. let oneVal = "";
  24. let towVal = "";
  25. if (_list.length > 0) {
  26. oneVal = _list[0];
  27. }
  28. if (_list.length > 1) {
  29. towVal = _list[1];
  30. }
  31. if (one) {
  32. one(oneVal);
  33. }
  34. if (tow) {
  35. tow(towVal);
  36. }
  37. }
  38. setImgVal(list) {
  39. const _list = [...this.list];
  40. _list.forEach((item, index) => {
  41. if (list[index]) {
  42. list[index](item);
  43. }
  44. });
  45. }
  46. getKey(key) {
  47. const _list = [...this.list];
  48. if (_list.length > 0) {
  49. return _list.pop()[key];
  50. }
  51. return "";
  52. }
  53. getListValue(key) {
  54. let _list = [...this.list];
  55. if (key) {
  56. _list = _list.map(item => {
  57. return item[key];
  58. });
  59. }
  60. return _list.join(",");
  61. }
  62. }