list-utlis.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import XEUtils from "xe-utils";
  2. export function ArrayIsEqual(arr1: any[], arr2: any[]) {
  3. return JSON.stringify(arr1) === JSON.stringify(arr2);
  4. }
  5. const isEnglish = (str: string) => {
  6. return /^[a-zA-Z]+$/.test(str);
  7. }
  8. export const notNullAndLike = (data: any, likeValue: string, keyName: string[] = ['pyCode', 'dcode', 'code', 'name', 'value', 'label']) => {
  9. for (let i = 0; i < keyName.length; i++) {
  10. let itemKey = keyName[i];
  11. let tempVal = data[itemKey]
  12. if (isEnglish(likeValue)) {
  13. likeValue = likeValue.toUpperCase();
  14. }
  15. if (tempVal) {
  16. try {
  17. // 去除前后空格
  18. tempVal = XEUtils.trim(tempVal)
  19. if (tempVal.indexOf(likeValue) > -1) {
  20. return true
  21. }
  22. } catch {
  23. }
  24. }
  25. }
  26. return false
  27. }
  28. export function listFilter(data: any[], likeValue: string, keyName: string[] = ['pyCode', 'dcode', 'code', 'name', 'value', 'label']) {
  29. return XEUtils.filter(data, (item) => {
  30. return notNullAndLike(item, likeValue, keyName)
  31. });
  32. }