陈剑华

Merge remote-tracking branch 'origin/main'

1 -import { PhotoListBean } from 'wdBean';  
2 -import { Logger } from 'wdKit'; 1 +import { image } from '@kit.ImageKit';
  2 +import { matrix4, promptAction, window } from '@kit.ArkUI';
  3 +import { BusinessError } from '@kit.BasicServicesKit';
  4 +import { ScaleModel } from '../model/ScaleModel';
  5 +import { OffsetModel } from '../model/OffsetModel';
  6 +import { windowSizeManager } from '../utils/Managers';
  7 +import { runWithAnimation } from '../utils/FuncUtils';
  8 +import { PhotoListBean } from 'wdBean/Index';
  9 +import { http } from '@kit.NetworkKit';
3 10
4 -const TAG = 'MultiPictureDetailPageComponent'; 11 +const TAG = 'MultiPictureDetailItemComponent';
5 12
6 @Reusable 13 @Reusable
7 @Component 14 @Component
8 export struct MultiPictureDetailItemComponent { 15 export struct MultiPictureDetailItemComponent {
  16 + @Link isEnableSwipe: boolean; // TODO:需求:多图切换
  17 + @State isEnableOffset: boolean = false;
  18 + @State imageScaleInfo: ScaleModel = new ScaleModel(1.0, 1.0, 1.5, 0.3);
  19 + @State imageOffsetInfo: OffsetModel = new OffsetModel(0, 0);
  20 + @State matrix: matrix4.Matrix4Transit = matrix4.identity().copy();
  21 + @State imagePixelMap: image.PixelMap | null = null; // 当前图片pixelMap,用于Image组件显示
  22 + @State fitWH: "width" | "height" | undefined = undefined; // 表示当前图片是根据宽度适配还是高度适配
  23 + @State imageDefaultSize: image.Size = { width: 0, height: 0 }; // 图片默认大小,即,与屏幕大小最适配的显示大小
  24 + imageUri: string = ""; // 当前图片uri
  25 + imageWHRatio: number = 0; // 图片原始宽高比
  26 + @State imageBuffer: ArrayBuffer | undefined = undefined; // 图片ArrayBuffer
9 private MultiPictureDetailItem: PhotoListBean = {} as PhotoListBean 27 private MultiPictureDetailItem: PhotoListBean = {} as PhotoListBean
10 //alt app.media.picture_loading 设计稿尺寸 28 //alt app.media.picture_loading 设计稿尺寸
11 @State imageWidth:string | number = 167 29 @State imageWidth:string | number = 167
12 30
13 31
14 async aboutToAppear() { 32 async aboutToAppear() {
15 - // Logger.info(TAG, 'pictures preview' 33 + this.imageUri = this.MultiPictureDetailItem.picPath
  34 + this.getPicture()
  35 + }
  36 +
  37 + /**
  38 + * 通过http的request方法从网络下载图片资源
  39 + */
  40 + async getPicture() {
  41 + console.info(`cj2024 getPicture`)
  42 + http.createHttp()
  43 + .request(this.imageUri,
  44 + (error: BusinessError, data: http.HttpResponse) => {
  45 + if (error) {
  46 + // 下载失败时弹窗提示检查网络,不执行后续逻辑
  47 + promptAction.showToast({
  48 + message: $r('app.string.image_request_fail'),
  49 + duration: 2000
  50 + })
  51 + return;
  52 + }
  53 + this.transcodePixelMap(data);
  54 + // 判断网络获取到的资源是否为ArrayBuffer类型
  55 + console.info(`cj2024 getPicture ${data.result}`)
  56 + if (data.result instanceof ArrayBuffer) {
  57 + console.info(`cj2024 getPicture 222`)
  58 + this.imageBuffer = data.result as ArrayBuffer;
  59 + }
  60 + }
  61 + )
  62 + }
  63 +
  64 + /**
  65 + * 使用createPixelMap将ArrayBuffer类型的图片装换为PixelMap类型
  66 + * @param data:网络获取到的资源
  67 + */
  68 + transcodePixelMap(data: http.HttpResponse) {
  69 + console.info(`cj2024 transcodePixelMap ${data.responseCode}`)
  70 + if (http.ResponseCode.OK === data.responseCode) {
  71 + const imageData: ArrayBuffer = data.result as ArrayBuffer;
  72 + // 通过ArrayBuffer创建图片源实例。
  73 + const imageSource: image.ImageSource = image.createImageSource(imageData);
  74 + this.initCurrentImageInfo(imageSource);
  75 + }
  76 + }
  77 +
  78 + /**
  79 + * 设置当前图片的相关信息:uri、whRatio、pixelMap、fitWH、defaultSize、maxScaleValue
  80 + * TODO:知识点:提前获取图片的信息,以进行Image组件的尺寸设置及后续的相关计算
  81 + */
  82 + initCurrentImageInfo(imageSource: image.ImageSource): void {
  83 + this.matrix = matrix4.identity().copy();
  84 + // const imageSource: image.ImageSource = image.createImageSource(this.imageUri);
  85 + imageSource.getImageInfo(0).then((data: image.ImageInfo) => {
  86 + this.imageWHRatio = data.size.width / data.size.height;
  87 + this.imageDefaultSize = this.calcImageDefaultSize(this.imageWHRatio, windowSizeManager.get());
  88 + if (this.imageDefaultSize.width === windowSizeManager.get().width) {
  89 + this.fitWH = "width";
  90 + } else {
  91 + this.fitWH = "height";
  92 + }
  93 + this.imageScaleInfo.maxScaleValue += this.fitWH === "width" ?
  94 + (windowSizeManager.get().height / this.imageDefaultSize.height) :
  95 + (windowSizeManager.get().width / this.imageDefaultSize.width);
  96 + }).catch((err: BusinessError) => {
  97 + console.error(`[error][getImageInfo]${err.message}`);
  98 + });
  99 + imageSource.createPixelMap().then((data: image.PixelMap) => {
  100 + this.imagePixelMap = data;
  101 + }).catch((err: BusinessError) => {
  102 + console.error(`[error][createPixelMap]${err.message}`);
  103 + });
  104 + this.isEnableOffset = false;
  105 + this.imageScaleInfo.reset();
  106 + this.imageOffsetInfo.reset();
  107 + }
  108 +
  109 + /**
  110 + * 根据图片宽高比及窗口大小计算图片的默认宽高,即,图片最适配屏幕的大小
  111 + * @param imageWHRatio:图片原始宽高比
  112 + * @param size:窗口大小{with:number,height:number}
  113 + * @returns image.Size
  114 + */
  115 + calcImageDefaultSize(imageWHRatio: number, size: window.Size): image.Size {
  116 + let width = 0
  117 + let height = 0;
  118 + width = size.width;
  119 + height = size.width / imageWHRatio;
  120 + return { width: width, height: height };
  121 + }
  122 +
  123 + /**
  124 + * TODO:知识点:根据图片大小(宽高<=屏幕宽高)和屏幕大小计算图片放大适配屏幕进行显示的缩放倍率
  125 + * @param imageSize:图片当前大小
  126 + * @param windowSize:窗口大小
  127 + * @returns:缩放倍率
  128 + */
  129 + calcFitScaleRatio(imageSize: image.Size, windowSize: window.Size): number {
  130 + let ratio: number = 1.0;
  131 + if (windowSize.width > imageSize.width) {
  132 + ratio = windowSize.width / imageSize.width;
  133 + } else {
  134 + ratio = windowSize.height / imageSize.height;
  135 + }
  136 + return ratio;
  137 + }
  138 +
  139 + /**
  140 + * 在图片消失时,将当前图片的信息设置为默认值
  141 + */
  142 + resetCurrentImageInfo(): void {
  143 + this.imageScaleInfo.reset();
  144 + this.imageOffsetInfo.reset();
  145 + this.matrix = matrix4.identity().copy();
  146 + }
  147 +
  148 + /**
  149 + * TODO:需求:在偏移时评估是否到达边界,以便进行位移限制与图片的切换
  150 + * @returns:长度为4的boolean数组,表示上下左右是否到达边界
  151 + */
  152 + evaluateBound(): boolean[] {
  153 + return [false, false, false, false];
16 } 154 }
17 155
18 build() { 156 build() {
19 Row() { 157 Row() {
20 - Image(this.MultiPictureDetailItem.picPath)  
21 - .alt($r('app.media.datail_imageLoading_w'))  
22 -  
23 - .width(this.imageWidth)  
24 - .objectFit(ImageFit.Auto)  
25 - .interpolation(ImageInterpolation.High)  
26 - .onComplete(event => {  
27 - this.imageWidth = '100%'  
28 - }) 158 + if(this.imageUri != null && (this.imageUri.includes('.gif') || this.imageUri.includes('.GIF'))){
  159 + Image(this.imageUri)// TODO:知识点:宽高只根据其尺寸设置一个,通过保持宽高比来设置另一个属性
  160 + .alt($r('app.media.datail_imageLoading_w'))
  161 + .width(this.imageWidth)
  162 + .objectFit(ImageFit.Auto)// TODO:知识点:保持宽高比进行缩放,可以超出父组件,以便实现多图切换的增强功能
  163 + .interpolation(ImageInterpolation.High)
  164 + .autoResize(false)
  165 + .transform(this.matrix)// TODO:知识点:通过matrix控制图片的缩放
  166 + .defaultFocus(true)
  167 + .offset({
  168 + // TODO:知识点:通过offset控制图片的偏移
  169 + x: this.imageOffsetInfo.currentX,
  170 + y: this.imageOffsetInfo.currentY
  171 + })
  172 + .onComplete(event => {
  173 + this.imageWidth = '100%'
  174 + })
  175 + }else{
  176 + Image(this.imagePixelMap)// TODO:知识点:宽高只根据其尺寸设置一个,通过保持宽高比来设置另一个属性
  177 + .alt($r('app.media.datail_imageLoading_w'))
  178 + .width(this.imageWidth)
  179 + .objectFit(ImageFit.Auto)// TODO:知识点:保持宽高比进行缩放,可以超出父组件,以便实现多图切换的增强功能
  180 + .interpolation(ImageInterpolation.High)
  181 + .autoResize(false)
  182 + .transform(this.matrix)// TODO:知识点:通过matrix控制图片的缩放
  183 + .defaultFocus(true)
  184 + .offset({
  185 + // TODO:知识点:通过offset控制图片的偏移
  186 + x: this.imageOffsetInfo.currentX,
  187 + y: this.imageOffsetInfo.currentY
  188 + })
  189 + .onComplete(event => {
  190 + this.imageWidth = '100%'
  191 + })
  192 + }
29 } 193 }
  194 + .onBlur(() => {
  195 + this.resetCurrentImageInfo();
  196 + })
30 .height('100%') 197 .height('100%')
31 .width('100%') 198 .width('100%')
32 .backgroundColor(Color.Black) 199 .backgroundColor(Color.Black)
33 .justifyContent(FlexAlign.Center) 200 .justifyContent(FlexAlign.Center)
  201 + .gesture(
  202 + GestureGroup(
  203 + GestureMode.Exclusive,
  204 + // TODO:知识点:双击切换图片大小
  205 + TapGesture({ count: 2 })
  206 + .onAction(() => {
  207 + let fn: Function;
  208 + // 已经是放大状态下,双击缩小
  209 + if (this.imageScaleInfo.scaleValue > this.imageScaleInfo.defaultScaleValue) {
  210 + fn = () => {
  211 + this.isEnableSwipe = true;
  212 + this.imageScaleInfo.reset();
  213 + this.imageOffsetInfo.reset();
  214 + this.matrix = matrix4.identity().copy();
  215 + };
  216 + } else {
  217 + // 已经是缩小状态,双击放大
  218 + fn = () => {
  219 + this.isEnableSwipe = false;
  220 + const ratio: number = this.calcFitScaleRatio(this.imageDefaultSize, windowSizeManager.get());
  221 + this.imageScaleInfo.scaleValue = ratio;
  222 + this.imageOffsetInfo.reset();
  223 + this.matrix = matrix4.identity().scale({
  224 + x: ratio,
  225 + y: ratio,
  226 + }).copy();
  227 + this.imageScaleInfo.stash();
  228 + }
  229 + }
  230 + runWithAnimation(fn);
  231 + }),
  232 + // 单击切换背景色
  233 + // TapGesture({ count: 1 }).onAction(() => {
  234 + // runWithAnimation(() => {
  235 + // this.bgc = this.bgc === Color.White ? Color.Black : Color.White;
  236 + // });
  237 + // }),
  238 + // TODO:知识点:双指捏合缩放图片
  239 + PinchGesture({ fingers: 2, distance: 1 })
  240 + .onActionUpdate((event: GestureEvent) => {
  241 + this.imageScaleInfo.scaleValue = this.imageScaleInfo.lastValue * event.scale;
  242 + // TODO:知识点:缩放时不允许大于最大缩放因子+额外缩放因子,不允许小于默认大小-额外缩放因子,额外缩放因子用于提升用户体验
  243 + if (this.imageScaleInfo.scaleValue > this.imageScaleInfo.maxScaleValue *
  244 + (1 + this.imageScaleInfo.extraScaleValue)
  245 + ) {
  246 + this.imageScaleInfo.scaleValue = this.imageScaleInfo.maxScaleValue *
  247 + (1 + this.imageScaleInfo.extraScaleValue);
  248 + }
  249 + if (this.imageScaleInfo.scaleValue < this.imageScaleInfo.defaultScaleValue *
  250 + (1 - this.imageScaleInfo.extraScaleValue)) {
  251 + this.imageScaleInfo.scaleValue = this.imageScaleInfo.defaultScaleValue *
  252 + (1 - this.imageScaleInfo.extraScaleValue);
  253 + }
  254 + // TODO:知识点:matrix默认缩放中心为组件中心
  255 + this.matrix = matrix4.identity().scale({
  256 + x: this.imageScaleInfo.scaleValue,
  257 + y: this.imageScaleInfo.scaleValue,
  258 + }).copy();
  259 + console.debug(this.imageScaleInfo.toString());
  260 + })
  261 + .onActionEnd((event: GestureEvent) => {
  262 + /**
  263 + * TODO:知识点:当小于默认大小时,恢复为默认大小
  264 + */
  265 + if (this.imageScaleInfo.scaleValue < this.imageScaleInfo.defaultScaleValue) {
  266 + runWithAnimation(() => {
  267 + this.imageScaleInfo.reset();
  268 + this.imageOffsetInfo.reset();
  269 + this.matrix = matrix4.identity().copy();
  270 + })
  271 + }
  272 + // TODO:知识点:当大于最大缩放因子时,恢复到最大
  273 + if (this.imageScaleInfo.scaleValue > this.imageScaleInfo.maxScaleValue) {
  274 + runWithAnimation(() => {
  275 + this.imageScaleInfo.scaleValue = this.imageScaleInfo.maxScaleValue;
  276 + this.matrix = matrix4.identity()
  277 + .scale({
  278 + x: this.imageScaleInfo.maxScaleValue,
  279 + y: this.imageScaleInfo.maxScaleValue
  280 + });
  281 + })
  282 + }
  283 + this.imageScaleInfo.stash();
  284 + }),
  285 + // // TODO:知识点:滑动图片
  286 + // PanGesture({ fingers: 1 })// TODO:需求:默认大小下左右滑动应当是切换图片
  287 + // .onActionUpdate((event: GestureEvent) => {
  288 + // if (this.imageScaleInfo.scaleValue === this.imageScaleInfo.defaultScaleValue) {
  289 + // // 默认大小下不允许移动
  290 + // return;
  291 + // }
  292 + // this.imageOffsetInfo.currentX = this.imageOffsetInfo.lastX + event.offsetX;
  293 + // this.imageOffsetInfo.currentY = this.imageOffsetInfo.lastY + event.offsetY;
  294 + // })
  295 + // .onActionEnd((event: GestureEvent) => {
  296 + // this.imageOffsetInfo.stash();
  297 + // })
  298 + ),
  299 + )
34 } 300 }
35 } 301 }
@@ -25,6 +25,9 @@ export struct ImageItemView { @@ -25,6 +25,9 @@ export struct ImageItemView {
25 imageWHRatio: number = 0; // 图片原始宽高比 25 imageWHRatio: number = 0; // 图片原始宽高比
26 private MultiPictureDetailItem: PhotoListBean = {} as PhotoListBean 26 private MultiPictureDetailItem: PhotoListBean = {} as PhotoListBean
27 @State imageBuffer: ArrayBuffer | undefined = undefined; // 图片ArrayBuffer 27 @State imageBuffer: ArrayBuffer | undefined = undefined; // 图片ArrayBuffer
  28 + //alt app.media.picture_loading 设计稿尺寸
  29 + @State imageWidth:string | number = 167
  30 + private scroller: Scroller = new Scroller()
28 31
29 aboutToAppear(): void { 32 aboutToAppear(): void {
30 this.imageUri = this.MultiPictureDetailItem.picPath 33 this.imageUri = this.MultiPictureDetailItem.picPath
@@ -81,14 +84,8 @@ export struct ImageItemView { @@ -81,14 +84,8 @@ export struct ImageItemView {
81 calcImageDefaultSize(imageWHRatio: number, size: window.Size): image.Size { 84 calcImageDefaultSize(imageWHRatio: number, size: window.Size): image.Size {
82 let width = 0 85 let width = 0
83 let height = 0; 86 let height = 0;
84 - if (imageWHRatio > size.width / size.height) {  
85 - // 图片宽高比大于屏幕宽高比,图片默认以屏幕宽度进行显示  
86 - width = size.width;  
87 - height = size.width / imageWHRatio;  
88 - } else {  
89 - height = size.height;  
90 - width = size.height * imageWHRatio;  
91 - } 87 + width = size.width;
  88 + height = size.width / imageWHRatio;
92 return { width: width, height: height }; 89 return { width: width, height: height };
93 } 90 }
94 91
@@ -117,7 +114,12 @@ export struct ImageItemView { @@ -117,7 +114,12 @@ export struct ImageItemView {
117 // const imageSource: image.ImageSource = image.createImageSource(this.imageUri); 114 // const imageSource: image.ImageSource = image.createImageSource(this.imageUri);
118 imageSource.getImageInfo(0).then((data: image.ImageInfo) => { 115 imageSource.getImageInfo(0).then((data: image.ImageInfo) => {
119 this.imageWHRatio = data.size.width / data.size.height; 116 this.imageWHRatio = data.size.width / data.size.height;
  117 + console.error(`this.imageDefaultSize this.imageWHRatio = ${this.imageWHRatio}`);
  118 + console.error(`this.imageDefaultSize width = ${data.size.width}`);
  119 + console.error(`this.imageDefaultSize height = ${data.size.height}`);
120 this.imageDefaultSize = this.calcImageDefaultSize(this.imageWHRatio, windowSizeManager.get()); 120 this.imageDefaultSize = this.calcImageDefaultSize(this.imageWHRatio, windowSizeManager.get());
  121 + console.error(`this.imageDefaultSize = ${JSON.stringify(windowSizeManager.get())}`);
  122 + console.error(`this.imageDefaultSize = ${JSON.stringify(this.imageDefaultSize)}`);
121 if (this.imageDefaultSize.width === windowSizeManager.get().width) { 123 if (this.imageDefaultSize.width === windowSizeManager.get().width) {
122 this.fitWH = "width"; 124 this.fitWH = "width";
123 } else { 125 } else {
@@ -158,47 +160,57 @@ export struct ImageItemView { @@ -158,47 +160,57 @@ export struct ImageItemView {
158 160
159 build() { 161 build() {
160 Stack() { 162 Stack() {
161 - if(this.imageUri != null && (this.imageUri.includes('.gif') || this.imageUri.includes('.GIF'))){  
162 - Image(this.imageUri)// TODO:知识点:宽高只根据其尺寸设置一个,通过保持宽高比来设置另一个属性  
163 - .width(this.fitWH === "width" ? "100%" : undefined)  
164 - .height(this.fitWH === "height" ? "100%" : undefined)  
165 - .aspectRatio(this.imageWHRatio)  
166 - .objectFit(ImageFit.Cover)// TODO:知识点:保持宽高比进行缩放,可以超出父组件,以便实现多图切换的增强功能  
167 - .autoResize(false)  
168 - .transform(this.matrix)// TODO:知识点:通过matrix控制图片的缩放  
169 - .defaultFocus(true)  
170 - .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])  
171 - .offset({  
172 - // TODO:知识点:通过offset控制图片的偏移  
173 - x: this.imageOffsetInfo.currentX,  
174 - y: this.imageOffsetInfo.currentY  
175 - })  
176 - }else{  
177 - Image(this.imagePixelMap)// TODO:知识点:宽高只根据其尺寸设置一个,通过保持宽高比来设置另一个属性  
178 - .width(this.fitWH === "width" ? "100%" : undefined)  
179 - .height(this.fitWH === "height" ? "100%" : undefined)  
180 - .aspectRatio(this.imageWHRatio)  
181 - .objectFit(ImageFit.Cover)// TODO:知识点:保持宽高比进行缩放,可以超出父组件,以便实现多图切换的增强功能  
182 - .autoResize(false)  
183 - .transform(this.matrix)// TODO:知识点:通过matrix控制图片的缩放  
184 - .defaultFocus(true)  
185 - .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])  
186 - .offset({  
187 - // TODO:知识点:通过offset控制图片的偏移  
188 - x: this.imageOffsetInfo.currentX,  
189 - y: this.imageOffsetInfo.currentY  
190 - }) 163 + Scroll(this.scroller) {
  164 + if(this.imageUri != null && (this.imageUri.includes('.gif') || this.imageUri.includes('.GIF'))){
  165 + Image(this.imageUri)// TODO:知识点:宽高只根据其尺寸设置一个,通过保持宽高比来设置另一个属性
  166 + .alt($r('app.media.datail_imageLoading_w'))
  167 + .width(this.imageWidth)
  168 + .objectFit(ImageFit.Auto)// TODO:知识点:保持宽高比进行缩放,可以超出父组件,以便实现多图切换的增强功能
  169 + .interpolation(ImageInterpolation.High)
  170 + .autoResize(false)
  171 + .transform(this.matrix)// TODO:知识点:通过matrix控制图片的缩放
  172 + .defaultFocus(true)
  173 + .offset({
  174 + // TODO:知识点:通过offset控制图片的偏移
  175 + x: this.imageOffsetInfo.currentX,
  176 + y: this.imageOffsetInfo.currentY
  177 + })
  178 + .onComplete(event => {
  179 + this.imageWidth = '100%'
  180 + })
  181 + } else {
  182 + Image(this.imagePixelMap)// TODO:知识点:宽高只根据其尺寸设置一个,通过保持宽高比来设置另一个属性
  183 + .alt($r('app.media.datail_imageLoading_w'))
  184 + .width(this.imageWidth)
  185 + .objectFit(ImageFit.Auto)// TODO:知识点:保持宽高比进行缩放,可以超出父组件,以便实现多图切换的增强功能
  186 + .interpolation(ImageInterpolation.High)
  187 + .autoResize(false)
  188 + .transform(this.matrix)// TODO:知识点:通过matrix控制图片的缩放
  189 + .defaultFocus(true)
  190 + .offset({
  191 + // TODO:知识点:通过offset控制图片的偏移
  192 + x: this.imageOffsetInfo.currentX,
  193 + y: this.imageOffsetInfo.currentY
  194 + })
  195 + .onComplete(event => {
  196 + this.imageWidth = '100%'
  197 + })
  198 + }
191 } 199 }
192 - 200 + .scrollable(ScrollDirection.Vertical)
  201 + .scrollBarWidth(0)
  202 + .constraintSize({
  203 + maxHeight: this.imageDefaultSize.height
  204 + })
193 } 205 }
194 .onBlur(() => { 206 .onBlur(() => {
195 this.resetCurrentImageInfo(); 207 this.resetCurrentImageInfo();
196 }) 208 })
197 // .backgroundColor(this.bgc) 209 // .backgroundColor(this.bgc)
198 .alignContent(Alignment.Center) 210 .alignContent(Alignment.Center)
199 - .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])  
200 .width("100%") 211 .width("100%")
201 .height("100%") 212 .height("100%")
  213 + .backgroundColor(Color.Black)
202 .gesture( 214 .gesture(
203 GestureGroup( 215 GestureGroup(
204 GestureMode.Exclusive, 216 GestureMode.Exclusive,
@@ -3,6 +3,7 @@ import { display, router } from '@kit.ArkUI'; @@ -3,6 +3,7 @@ import { display, router } from '@kit.ArkUI';
3 import { ImageItemView } from '../components/view/ImageItemView'; 3 import { ImageItemView } from '../components/view/ImageItemView';
4 import { ImageDownloadComponent } from '../components/ImageDownloadComponent'; 4 import { ImageDownloadComponent } from '../components/ImageDownloadComponent';
5 import { Action } from 'wdBean'; 5 import { Action } from 'wdBean';
  6 +import { WindowModel } from 'wdKit/Index';
6 7
7 const TAG = 'MultiPictureListPage'; 8 const TAG = 'MultiPictureListPage';
8 9
@@ -36,22 +37,37 @@ export struct MultiPictureListPage { @@ -36,22 +37,37 @@ export struct MultiPictureListPage {
36 this.currentUrl = this.photoList[this.swiperIndex]?.picPath 37 this.currentUrl = this.photoList[this.swiperIndex]?.picPath
37 } 38 }
38 39
  40 + onPageShow(): void {
  41 + console.log(TAG, 'onPageShow')
  42 + WindowModel.shared.setWindowSystemBarProperties({ statusBarContentColor: '#ffffff'})
  43 + }
  44 +
  45 + onPageHide(): void {
  46 + console.log(TAG, 'onPageHide')
  47 + WindowModel.shared.setWindowSystemBarProperties({ statusBarContentColor: '#000000'})
  48 + }
  49 +
39 build() { 50 build() {
40 RelativeContainer() { 51 RelativeContainer() {
41 - Image($r('app.media.icon_arrow_left_white'))  
42 - .width(24)  
43 - .height(24)  
44 - .aspectRatio(1)  
45 - .interpolation(ImageInterpolation.High)  
46 - .alignRules({  
47 - top: { anchor: "__container__", align: VerticalAlign.Top },  
48 - left: { anchor: "__container__", align: HorizontalAlign.Start }  
49 - })  
50 - .onClick(() => {  
51 - this.onBack();  
52 - router.back();  
53 - })  
54 - .id("backImg") 52 + Row(){
  53 + Image($r('app.media.icon_arrow_left_white'))
  54 + .width(24)
  55 + .height(24)
  56 + .aspectRatio(1)
  57 + .interpolation(ImageInterpolation.High)
  58 + }
  59 + .zIndex(10)
  60 + .margin({ top: `${this.topSafeHeight}px` })
  61 + .alignRules({
  62 + top: { anchor: "__container__", align: VerticalAlign.Top },
  63 + left: { anchor: "__container__", align: HorizontalAlign.Start }
  64 + })
  65 + .onClick(() => {
  66 + this.onBack();
  67 + router.back();
  68 + })
  69 + .id("backImg")
  70 +
55 71
56 if (this.photoList && this.photoList?.length > 0) { 72 if (this.photoList && this.photoList?.length > 0) {
57 Swiper(this.swiperController) { 73 Swiper(this.swiperController) {
@@ -61,7 +77,7 @@ export struct MultiPictureListPage { @@ -61,7 +77,7 @@ export struct MultiPictureListPage {
61 } 77 }
62 .index(this.swiperIndex) 78 .index(this.swiperIndex)
63 .width('100%') 79 .width('100%')
64 - .height(px2vp(this.picHeight) + 32) 80 + .height('100%')
65 .vertical(false) 81 .vertical(false)
66 .autoPlay(false) 82 .autoPlay(false)
67 .loop(false) 83 .loop(false)
@@ -83,8 +99,8 @@ export struct MultiPictureListPage { @@ -83,8 +99,8 @@ export struct MultiPictureListPage {
83 Scroll(this.scroller) { 99 Scroll(this.scroller) {
84 Row() { 100 Row() {
85 Flex({ 101 Flex({
86 - direction: FlexDirection.Column,  
87 - justifyContent: FlexAlign.Start 102 + direction: FlexDirection.Row,
  103 + justifyContent: FlexAlign.SpaceBetween
88 }) { 104 }) {
89 Text() { 105 Text() {
90 Span(`${this.swiperIndex + 1}`) 106 Span(`${this.swiperIndex + 1}`)
@@ -97,7 +113,9 @@ export struct MultiPictureListPage { @@ -97,7 +113,9 @@ export struct MultiPictureListPage {
97 .fontFamily('PingFang SC-Medium') 113 .fontFamily('PingFang SC-Medium')
98 .fontWeight(500) 114 .fontWeight(500)
99 .lineHeight(19) 115 .lineHeight(19)
100 - }.fontColor(Color.White).margin(4) 116 + }
  117 + .fontColor(Color.White)
  118 + .margin(4)
101 } 119 }
102 } 120 }
103 .width('100%') 121 .width('100%')
@@ -133,8 +151,6 @@ export struct MultiPictureListPage { @@ -133,8 +151,6 @@ export struct MultiPictureListPage {
133 } 151 }
134 .width('100%') 152 .width('100%')
135 .height('100%') 153 .height('100%')
136 - .padding({top: `${this.topSafeHeight}px`,bottom:`${this.bottomSafeHeight}px`})  
137 - .backgroundColor(Color.Black)  
138 .id('e_picture_container') 154 .id('e_picture_container')
139 } 155 }
140 156
@@ -36,9 +36,6 @@ export struct MultiPictureDetailPageComponent { @@ -36,9 +36,6 @@ export struct MultiPictureDetailPageComponent {
36 private contentId: string = '' 36 private contentId: string = ''
37 private relType: string = '' 37 private relType: string = ''
38 private displayTool = display.getDefaultDisplaySync() 38 private displayTool = display.getDefaultDisplaySync()
39 - private screenWidth: number = 0  
40 - private picWidth: number = 0  
41 - @State picHeight: number = 0  
42 @State titleHeight: number = 0 39 @State titleHeight: number = 0
43 @State index: number = 0 40 @State index: number = 0
44 @State currentIndex: number = 0 41 @State currentIndex: number = 0
@@ -65,6 +62,7 @@ export struct MultiPictureDetailPageComponent { @@ -65,6 +62,7 @@ export struct MultiPictureDetailPageComponent {
65 pageParam: ParamType = {} 62 pageParam: ParamType = {}
66 followUserId: string = '' 63 followUserId: string = ''
67 followUserName: string = '' 64 followUserName: string = ''
  65 + @State isEnableSwipe: boolean = true;
68 66
69 //watch监听页码回调 67 //watch监听页码回调
70 onCurrentPageNumUpdated(): void { 68 onCurrentPageNumUpdated(): void {
@@ -76,11 +74,7 @@ export struct MultiPictureDetailPageComponent { @@ -76,11 +74,7 @@ export struct MultiPictureDetailPageComponent {
76 74
77 async aboutToAppear() { 75 async aboutToAppear() {
78 //获取宽高尺寸 76 //获取宽高尺寸
79 - this.screenWidth = this.displayTool.width  
80 - // this.picWidth = this.screenWidth - vp2px(52)  
81 - this.picWidth = this.screenWidth  
82 - this.picHeight = this.picWidth * 578 / 375  
83 - this.titleHeight = this.screenWidth * 178 / 375 77 + this.titleHeight = this.displayTool.width * 178 / 375
84 //注册字体 78 //注册字体
85 // font.registerFont({ 79 // font.registerFont({
86 // familyName: 'BebasNeueBold', 80 // familyName: 'BebasNeueBold',
@@ -306,7 +300,7 @@ export struct MultiPictureDetailPageComponent { @@ -306,7 +300,7 @@ export struct MultiPictureDetailPageComponent {
306 Swiper(this.swiperController) { 300 Swiper(this.swiperController) {
307 ForEach(this.contentDetailData.photoList, (item: PhotoListBean) => { 301 ForEach(this.contentDetailData.photoList, (item: PhotoListBean) => {
308 Swiper(this.swiperControllerItem) { 302 Swiper(this.swiperControllerItem) {
309 - MultiPictureDetailItemComponent({ MultiPictureDetailItem: item }) 303 + MultiPictureDetailItemComponent({ MultiPictureDetailItem: item, isEnableSwipe: this.isEnableSwipe })
310 } 304 }
311 .width('100%') 305 .width('100%')
312 .height('100%') 306 .height('100%')