WXL (wul)
4 天以前 d0c13711e4a03409c28d7a01716218689e52c11c
src/views/sfstatistics/percentage/index.vue
@@ -1511,43 +1511,97 @@
      getSfStatistics(params).then((response) => {
        this.loading = false;
        // this.total = response.total;
        this.total = response.total;
        // this.userList = response.data;
        this.userList = this.customSort(response.data);
      });
    },
    sortChineseNumber(a, b) {
      // 提取中文数字
      const chineseNumbers = [
        "一",
        "二",
        "三",
        "四",
        "五",
        "六",
        "七",
        "八",
        "九",
        "十",
        "十一",
        "十二",
      ];
    sortChineseNumber(aRow, bRow) {
      const a = aRow.leavehospitaldistrictname;
      const b = bRow.leavehospitaldistrictname;
      // 从字符串中提取病区数字,如"四病区" -> "四"
      // 中文数字到阿拉伯数字的映射(扩展到45)
      const chineseNumMap = {
        一: 1,
        二: 2,
        三: 3,
        四: 4,
        五: 5,
        六: 6,
        七: 7,
        八: 8,
        九: 9,
        十: 10,
        十一: 11,
        十二: 12,
        十三: 13,
        十四: 14,
        十五: 15,
        十六: 16,
        十七: 17,
        十八: 18,
        十九: 19,
        二十: 20,
        二十一: 21,
        二十二: 22,
        二十三: 23,
        二十四: 24,
        二十五: 25,
        二十六: 26,
        二十七: 27,
        二十八: 28,
        二十九: 29,
        三十: 30,
        三十一: 31,
        三十二: 32,
        三十三: 33,
        三十四: 34,
        三十五: 35,
        三十六: 36,
        三十七: 37,
        三十八: 38,
        三十九: 39,
        四十: 40,
        四十一: 41,
        四十二: 42,
        四十三: 43,
        四十四: 44,
        四十五: 45,
      };
      // 提取中文数字
      const getNumberFromText = (text) => {
        if (!text) return -1;
        if (!text || typeof text !== "string") return -1;
        // 匹配中文数字,支持一到四十五
        const match = text.match(/^([一二三四五六七八九十]+)/);
        if (match && match[1]) {
          return chineseNumbers.indexOf(match[1]);
          const chineseNum = match[1];
          return chineseNumMap[chineseNum] !== undefined
            ? chineseNumMap[chineseNum]
            : -1;
        }
        // 如果没有匹配到中文数字,尝试匹配阿拉伯数字
        const arabicMatch = text.match(/^(\d+)/);
        if (arabicMatch && arabicMatch[1]) {
          const num = parseInt(arabicMatch[1], 10);
          return num >= 1 && num <= 45 ? num : -1;
        }
        return -1;
      };
      const numA = getNumberFromText(a);
      const numB = getNumberFromText(b);
      if (numA === -1 && numB === -1) return 0;
      if (numA === -1) return 1; // 无法解析的放到后面
      if (numB === -1) return -1; // 无法解析的放到后面
      // 处理无法解析的情况
      if (numA === -1 && numB === -1) {
        return (a || "").localeCompare(b || "");
      }
      if (numA === -1) return 1;
      if (numB === -1) return -1;
      return numA - numB;
    },
@@ -1565,8 +1619,9 @@
      }
    },
    customSort(data) {
      // 定义您期望的病区顺序(扩展到三十)
      // 定义您期望的病区顺序(扩展到四十五)
      const order = [
        "一",
        "二",
        "三",
        "四",
@@ -1596,21 +1651,55 @@
        "二十八",
        "二十九",
        "三十",
        "三十一",
        "三十二",
        "三十三",
        "三十四",
        "三十五",
        "三十六",
        "三十七",
        "三十八",
        "三十九",
        "四十",
        "四十一",
        "四十二",
        "四十三",
        "四十四",
        "四十五",
      ];
      return data.sort((a, b) => {
        // 提取病区名称中的中文数字部分[6](@ref)
        // 提取病区名称中的中文数字部分
        const getIndex = (name) => {
          const numStr = name.match(
            /^(二|三|四|五|六|七|八|九|十|十一|十二|十三|十四|十五|十六|十七|十八|十九|二十|二十一|二十二|二十三|二十四|二十五|二十六|二十七|二十八|二十九|三十)/
          )?.[1];
          return order.indexOf(numStr);
          if (!name || typeof name !== "string") return -1;
          // 匹配中文数字
          const chineseMatch = name.match(/^([一二三四五六七八九十]+)/);
          if (chineseMatch && chineseMatch[1]) {
            return order.indexOf(chineseMatch[1]);
          }
          // 匹配阿拉伯数字
          const arabicMatch = name.match(/^(\d+)/);
          if (arabicMatch && arabicMatch[1]) {
            const num = parseInt(arabicMatch[1], 10);
            if (num >= 1 && num <= 45) {
              return num - 1; // 因为数组索引从0开始
            }
          }
          return -1;
        };
        const indexA = getIndex(a.leavehospitaldistrictname);
        const indexB = getIndex(b.leavehospitaldistrictname);
        // 如果都在定义的顺序中,按定义顺序排;否则,未定义的排在后面[2](@ref)
        // 排序逻辑
        if (indexA === -1 && indexB === -1) {
          return (a.leavehospitaldistrictname || "").localeCompare(
            b.leavehospitaldistrictname || ""
          );
        }
        if (indexA === -1) return 1;
        if (indexB === -1) return -1;
        return indexA - indexB;