Skip to content

Commit 2065bef

Browse files
Altermoemikezhuang2022
authored andcommitted
fix: 修改地区、物品类型、物品的排序逻辑
1 parent bb7bbd3 commit 2065bef

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/hooks/useAreaList.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ export const useAreaList = (options: AreaListHookOptions = {}) => {
4343
onRequest: () => Api.area.listArea({}, { isTraverse: true, parentId: -1 }),
4444
})
4545

46-
onSuccess((res) => {
47-
areaList.value = res.data ?? []
46+
onSuccess(({ data = [] }) => {
47+
areaList.value = data.sort(({ sortIndex: ia }, { sortIndex: ib }) => {
48+
if (ia === undefined || ib === undefined)
49+
return 0
50+
return ib - ia
51+
})
4852
})
4953

5054
return { areaList, areaTree, areaMap, selectedArea, updateAreaList: refresh, onSuccess, ...rest }

src/hooks/useItemList.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ export const useItemList = (options: ItemListHookOptions = {}) => {
3131
},
3232
})
3333

34-
onSuccess((res) => {
35-
itemList.value = (res?.data?.record ?? []).sort((a, b) => Number(a.sortIndex) - Number(b.sortIndex))
34+
onSuccess(({ data: { record = [] } = {} }) => {
35+
itemList.value = record.sort(({ sortIndex: ia }, { sortIndex: ib }) => {
36+
if (ia === undefined || ib === undefined)
37+
return 0
38+
return ib - ia
39+
})
3640
})
3741

3842
const { pause, resume } = pausableWatch(fetchParams, updateItemList, { deep: true })

src/hooks/useTypeList.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ export const useTypeList = (options: FetchHookOptions<API.RPageListVoItemTypeVo>
2222
})
2323

2424
onSuccess(({ data = [] }) => {
25-
typeList.value = data
25+
typeList.value = data.sort(({ sortIndex: ia }, { sortIndex: ib }) => {
26+
if (ia === undefined || ib === undefined)
27+
return 0
28+
return ib - ia
29+
})
2630
})
2731

2832
return { typeList, typeTree, updateTypeList, onSuccess, ...rest }

0 commit comments

Comments
 (0)