From c7134f4332625b75fe3bd6bfb51c6d4505871131 Mon Sep 17 00:00:00 2001 From: zty Date: Fri, 10 Jul 2026 04:25:07 -0400 Subject: [PATCH] =?UTF-8?q?fix(web):=20=E6=89=8B=E5=8A=A8=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E6=A8=A1=E5=BC=8F=E6=89=8D=E5=85=81=E8=AE=B8=E8=B0=83?= =?UTF-8?q?=20sort=5Forder,=20=E6=96=B0=E6=8E=92=E5=BA=8F=E4=BE=9D?= =?UTF-8?q?=E6=8D=AE=E4=B8=8B=E6=8B=89=E4=B8=BA=E5=87=86,=20=E9=98=B2?= =?UTF-8?q?=E8=A6=86=E7=9B=96=E7=AD=96=E5=B1=95=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01VCShKevM5prWZhp1kk1iGh --- .../src/components/material-card/index.tsx | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/空气质量预测/源码/用户端/iapip-web/src/components/material-card/index.tsx b/空气质量预测/源码/用户端/iapip-web/src/components/material-card/index.tsx index 6dfe4ec..a1644e6 100644 --- a/空气质量预测/源码/用户端/iapip-web/src/components/material-card/index.tsx +++ b/空气质量预测/源码/用户端/iapip-web/src/components/material-card/index.tsx @@ -46,8 +46,17 @@ const MaterialCard: React.FC<{ (cert?.type === ADMIN_TYPE.SUPER_ADMIN || (cert?.type === ADMIN_TYPE.ADMIN && cert?.authz_mtrl_mgmt === 1)) const pageDataRef = useRef([]) - // 仅在「手动排序」视图下启用排序控件(避免在按其他字段排序时破坏 sort_order 语义) - const canSort = !modal && tab === DATA_TYPE.PUBLIC && isAdmin && (!filterConditions?.sort || filterConditions?.sort === 'sort_order') + // 仅在「手动排序」视图下启用排序控件(避免在按其他字段排序时破坏 sort_order 语义)。 + // 顶部「排序依据」Select 才是实际决定请求排序字段的来源(见下方 request), + // 因此这里额外要求 sortKey === 'sort_order' 且未开启分组,避免在 Ypt/污染物排序或分组视图下 + // 误开放拖动排序、把当前展示顺序(非 sort_order 顺序)误当成 sort_order 持久化覆盖策展顺序 + const canSort = + !modal && + tab === DATA_TYPE.PUBLIC && + isAdmin && + (!filterConditions?.sort || filterConditions?.sort === 'sort_order') && + sortKey === 'sort_order' && + !groupByTier // pageDataRef.current 为全部材料(按 sort_order 升序)。输入目标全局序号(1-based)直接定位: // 把材料移到目标位置后,对全部材料按新顺序连续重编号(0,1,2,...),保证全局顺序一致、不跨页错乱 const moveSortTo = async (material_id: string, targetPos: number) => { @@ -261,6 +270,7 @@ const MaterialCard: React.FC<{ tableRef.current?.reload() }} options={[ + { value: 'sort_order', label: '手动排序' }, { value: 'ypt', label: '综合 Ypt' }, { value: 'methanal_be_area', label: '甲醛 Yp' }, { value: 'tvoc_be_area', label: 'TVOC Yp' }, @@ -544,6 +554,10 @@ const MaterialCard: React.FC<{ request={async ({ type, conditions, sortKey: skParam, groupByTier: gbtParam, ...other }) => { // 弹窗与独立页面统一:都按当前 tab(type) 分别查公共库或自建库 try { + // 旧筛选区「排序」下拉已被顶部「排序依据」Select 取代: + // 从 conditions 里剔除 sort,不让它随 otherConditions 传给后端, + // 也不再把它转成 searchParams() 的第三个参数(那会覆盖 query.sort_key/sort_val, + // 导致新 Select 选的排序字段被静默忽略)。'category' 仍保留为纯前端排序(见下方 data.sort)。 const { sort, ...otherConditions } = conditions ?? {} const sortByCategory = sort === 'category' const data = await api.material.search( @@ -554,18 +568,12 @@ const MaterialCard: React.FC<{ ...other, display: 1, with_cltrs: 1, - // 顶部「排序依据」控件的默认值(如 ypt 升序);若下方筛选区的「排序」被管理员显式选中, - // 下面的第三个参数会覆盖此处的 sort_key/sort_val + // 顶部「排序依据」Select 始终是排序字段的唯一来源,不会被旧筛选区排序覆盖 sort_key: skParam, sort_val: 'asc', group_by_tier: gbtParam ? 1 : 0 }, - false, - !sortByCategory && sort - ? { - [sort]: sort !== 'updated_at' ? 'ascend' : 'descend' - } - : undefined + false ) ) pageDataRef.current = data