Skip to content

Commit 4eefa10

Browse files
authored
feat(ImageViewer): support display by index (#2411)
* make ImageViewer surport view at index(js file) make ImageViewer surport view at index(js file) Signed-off-by: zhouqi <[email protected]> * make ImageViewer surport view at index(cs file) make ImageViewer surport view at index(cs file) Signed-off-by: zhouqi <[email protected]> --------- Signed-off-by: zhouqi <[email protected]>
1 parent 2d478f7 commit 4eefa10

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/BootstrapBlazor/Components/ImageViewer/ImageViewer.razor.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ public partial class ImageViewer
8585
/// </summary>
8686
[Parameter]
8787
public List<string>? PreviewList { get; set; }
88+
89+
/// <summary>
90+
/// 获得/设置 预览大图当前链接集合点开的索引 默认为 0
91+
/// </summary>
92+
[Parameter]
93+
public int PreviewIndex { get; set; } = 0;
8894

8995
/// <summary>
9096
/// 获得/设置 图片加载失败时回调方法
@@ -138,15 +144,15 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
138144

139145
if (!firstRender)
140146
{
141-
await InvokeVoidAsync("update", Id, PreviewList);
147+
await InvokeVoidAsync("update", Id, PreviewList, PreviewIndex);
142148
}
143149
}
144150

145151
/// <summary>
146152
/// <inheritdoc/>
147153
/// </summary>
148154
/// <returns></returns>
149-
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Url, PreviewList);
155+
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Url, PreviewList, PreviewIndex);
150156

151157
private RenderFragment RenderChildContent() => builder =>
152158
{

src/BootstrapBlazor/Components/ImageViewer/ImageViewer.razor.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import Data from "../../modules/data.js?v=$version"
22
import EventHandler from "../../modules/event-handler.js?v=$version"
33

4-
const setListeners = viewer => {
4+
const setListeners = (viewer, index) => {
55
if (viewer.prevList && viewer.prevList.length > 0) {
66
EventHandler.on(viewer.img, 'click', () => {
77
if (!viewer.previewer) {
88
viewer.previewer = Data.get(viewer.previewerId)
99
}
1010
if (viewer.previewer) {
11-
viewer.previewer.viewer.show()
11+
viewer.previewer.viewer.show(index)
1212
}
1313
})
1414
}
1515
}
1616

17-
export function init(id, url, preList) {
17+
export function init(id, url, preList, index) {
1818
const el = document.getElementById(id)
1919
if (el === null) {
2020
return
@@ -35,17 +35,17 @@ export function init(id, url, preList) {
3535
viewer.img.setAttribute('src', url)
3636
}
3737

38-
setListeners(viewer)
38+
setListeners(viewer, index)
3939
}
4040

41-
export function update(id, prevList) {
41+
export function update(id, prevList, index) {
4242
const viewer = Data.get(id)
4343
if (viewer.img) {
4444
EventHandler.off(viewer.img, 'click')
4545
}
4646

4747
viewer.prevList = prevList
48-
setListeners(viewer)
48+
setListeners(viewer,index)
4949
}
5050

5151
export function dispose(id) {

0 commit comments

Comments
 (0)