MaiXinRong 5 лет назад
Родитель
Сommit
b3b6379f16
1 измененных файлов с 20 добавлено и 2 удалено
  1. 20 2
      app/public/js/shares/tender_list_order.js

+ 20 - 2
app/public/js/shares/tender_list_order.js

@@ -11,6 +11,21 @@
 const tenderListOrder = (function () {
     let orderSetting = getLocalCache('zh-calc-tender-list-order');
     if (!orderSetting) orderSetting = 'name|up';
+    function CompareStr (x, y) {
+        // 根据mysql的GBK
+        const regASC = /^[\x00-\x7F]/;
+        if (regASC.test(x) || regASC.test(y)) {
+            if (x > y) {
+                return 1
+            } else if (x < y) {
+                return -1
+            } else {
+                return 0;
+            }
+        } else {
+            return x.localeCompare(y, 'zh-CN');
+        }
+    }
     function reOrderTenders (orderStr) {
         if (orderStr) {
             orderSetting = orderStr;
@@ -19,9 +34,12 @@ const tenderListOrder = (function () {
         const orders = orderSetting.split('|');
         if (orders[0] === 'name') {
             tenders.sort(function (a, b) {
+                // return orders[1] === 'up'
+                //     ? a[orders[0]].localeCompare(b[orders[0]], 'zh')
+                //     : -a[orders[0]].localeCompare(b[orders[0]], 'zh');
                 return orders[1] === 'up'
-                    ? a[orders[0]].localeCompare(b[orders[0]], 'zh-CN')
-                    : -a[orders[0]].localeCompare(b[orders[0]], 'zh-CN')
+                    ? CompareStr(a[orders[0]], b[orders[0]])
+                    : CompareStr(b[orders[0]], a[orders[0]]);
             });
         } else if (orders[0] === 'create_time') {
             tenders.sort(function (a, b){