|
1 | 1 | import flow from '@scripts/flow' |
2 | | -import { defineComponent, onMounted, readonly, ref, unref, watch } from '@scripts/gm-vue' |
| 2 | +import { onMounted, readonly, ref, unref, watch } from '@scripts/gm-vue' |
3 | 3 | import Image from '../component/Image' |
4 | 4 | import WhitePage from '../component/WhitePage' |
5 | 5 | import { DirectionMode, PageType } from '../constant' |
6 | 6 | import useDirectionMode from './useDirectionMode' |
7 | 7 | import useImageInfoMap from './useImageInfoMap' |
8 | 8 | import useRawImageList from './useRawImageList' |
9 | 9 | import useWhitePage from './useWhitePage' |
10 | | - |
11 | | -type ImageItem = { |
12 | | - component: ReturnType<typeof defineComponent> | string |
13 | | - props: { key: string; pageType: PageType } & Record<string, any> |
14 | | -} |
| 10 | +import { injectDataIndexInternal } from './utils/injectDataIndex' |
| 11 | +import { ImageItem } from './utils/types' |
15 | 12 |
|
16 | 13 | export default function useImageList() { |
17 | 14 | const rawImageListRef = useRawImageList() |
@@ -116,36 +113,7 @@ export default function useImageList() { |
116 | 113 | return tempList.flat() |
117 | 114 | } |
118 | 115 | const injectDataIndex = (list: ImageItem[]): ImageItem[] => { |
119 | | - let portraitCount = 0 |
120 | | - return list.map((item, index) => { |
121 | | - let targetIndex = index + 1 |
122 | | - let side = 'A' |
123 | | - if (item.props.pageType === PageType.LANDSCAPE) { |
124 | | - portraitCount = 0 |
125 | | - side = 'A' |
126 | | - } else { |
127 | | - portraitCount++ |
128 | | - if (DirectionMode.RTL === unref(directionModeRef)) { |
129 | | - if (portraitCount % 2 === 0) { |
130 | | - targetIndex -= 1 |
131 | | - } else { |
132 | | - targetIndex += 1 |
133 | | - } |
134 | | - side = portraitCount % 2 === 1 ? 'R' : 'L' |
135 | | - } |
136 | | - if (DirectionMode.LTR === unref(directionModeRef)) { |
137 | | - side = portraitCount % 2 === 1 ? 'L' : 'R' |
138 | | - } |
139 | | - } |
140 | | - return { |
141 | | - ...item, |
142 | | - props: { |
143 | | - ...item.props, |
144 | | - 'data-index': targetIndex, |
145 | | - 'data-side': side, |
146 | | - }, |
147 | | - } |
148 | | - }) |
| 116 | + return injectDataIndexInternal(list, unref(directionModeRef)) |
149 | 117 | } |
150 | 118 | const imagesRef = ref<ImageItem[]>([]) |
151 | 119 | function refresh() { |
|
0 commit comments