Преглед изворни кода

admin: 用户列表展示与搜索支持邮箱

wenhongquan пре 1 месец
родитељ
комит
256ae82d51
2 измењених фајлова са 8 додато и 4 уклоњено
  1. 3 2
      assets/js/admin.js
  2. 5 2
      server/routes_admin.py

+ 3 - 2
assets/js/admin.js

@@ -693,7 +693,8 @@
   function UsersView() {
     const userCols = [
       { title: 'ID', dataIndex: 'id', width: 60 },
-      { title: '手机号', dataIndex: 'phone', width: 130 },
+      { title: '邮箱', dataIndex: 'email', width: 180, render: function (v) { return v || '—'; } },
+      { title: '手机号(旧)', dataIndex: 'phone', width: 120, render: function (v) { return v || '—'; } },
       { title: '昵称', dataIndex: 'name', width: 120 },
       { title: '订单数', dataIndex: 'orderCount', width: 80 },
       { title: '消费额', dataIndex: 'paidTotal', width: 100, render: fmtMoney },
@@ -740,7 +741,7 @@
         { key: 'users', label: '注册用户', children:
           h('div', null,
             h('div', { style: { display: 'flex', gap: 10, marginBottom: 14 } },
-              h(A.Input.Search, { value: state.users.query, style: { width: 260 }, placeholder: '搜索手机号 / 昵称',
+              h(A.Input.Search, { value: state.users.query, style: { width: 260 }, placeholder: '搜索手机号 / 邮箱 / 昵称',
                 allowClear: true,
                 onChange: function (e) { state.users.query = e.target.value; render(); },
                 onSearch: function () { state.users.page = 1; loadUsers(); } })),

+ 5 - 2
server/routes_admin.py

@@ -207,8 +207,11 @@ def users(request: Request, query: str = "", page: int = 1, page_size: int = 10)
     auth.require_admin(request)
     page = max(1, page)
     page_size = min(50, max(1, page_size))
-    where = "WHERE role = 'user' AND (phone LIKE %s OR name LIKE %s)" if query.strip() else "WHERE role = 'user'"
-    args = ("%" + query.strip() + "%", "%" + query.strip() + "%") if query.strip() else ()
+    where = (
+        "WHERE role = 'user' AND (phone LIKE %s OR name LIKE %s OR email LIKE %s)"
+        if query.strip() else "WHERE role = 'user'"
+    )
+    args = ("%" + query.strip() + "%",) * 3 if query.strip() else ()
     with db() as cur:
         cur.execute("SELECT COUNT(*) AS c FROM users %s" % where, args)
         total = cur.fetchone()["c"]