Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
陈剑华
2024-08-27 17:25:23 +0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
4413b27d24dfc69e54ea96c37761321c08811190
4413b27d
2 parents
77ec7508
26c3e3e3
Merge remote-tracking branch 'origin/main'
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
386 additions
and
168 deletions
sight_harmony/features/wdComponent/src/main/ets/components/ImageDownloadComponent.ets
sight_harmony/features/wdComponent/src/main/ets/components/MultiPictureDetailItemComponent.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/model/CommentModel.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentComponent.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentListDialog.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/viewmodel/CommentViewModel.ets
sight_harmony/features/wdComponent/src/main/ets/utils/httpRequest.ets
sight_harmony/features/wdDetailPlayShortVideo/src/main/ets/view/PlayerTitleView.ets
sight_harmony/features/wdDetailPlayShortVideo/src/main/resources/base/media/comment_unfold_svg.svg
sight_harmony/features/wdComponent/src/main/ets/components/ImageDownloadComponent.ets
View file @
4413b27
...
...
@@ -11,6 +11,8 @@ import { TrackConstants, TrackingButton } from 'wdTracking';
import { faceDetector } from '@kit.CoreVisionKit';
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import fileIo from '@ohos.file.fs';
import { httpRequest } from '../utils/httpRequest';
import { taskpool } from '@kit.ArkTS';
const PERMISSIONS: Array<Permissions> = [
'ohos.permission.READ_IMAGEVIDEO',
...
...
@@ -21,6 +23,23 @@ const PERMISSIONS: Array<Permissions> = [
* saveButton参考文档
* https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/savebutton-0000001820999677
* */
@Concurrent
async function getPicture(imageUrl: string): Promise<ArrayBuffer> {
let ret: ArrayBuffer = await new Promise((resolve, reject) => {
httpRequest.httpRequestInStream(imageUrl, (res: ArrayBuffer) => {
resolve(res); // 成功时解析Promise
}, () => {
// 下载失败时弹窗提示检查网络
promptAction.showToast({
message: $r('app.string.image_request_fail'),
duration: 2000
});
reject(new Error('Image download failed')); // 失败时拒绝Promise
});
});
return ret
}
@Component
export struct ImageDownloadComponent {
@State image: PixelMap | undefined = undefined;
...
...
@@ -79,61 +98,12 @@ export struct ImageDownloadComponent {
const context = getContext(this) as common.UIAbilityContext;
const atManager = abilityAccessCtrl.createAtManager();
await atManager.requestPermissionsFromUser(context, PERMISSIONS);
this.getPicture();
}
/**
* 通过http的request方法从网络下载图片资源
*/
async getPicture() {
// 每一个httpRequest对应一个HTTP请求任务,不可复用
let httpRequest = http.createHttp();
// 用于订阅HTTP响应头事件
httpRequest.on('headersReceive', (header: Object) => {
//console.info('header: ' + JSON.stringify(header));
});
// 用于订阅HTTP流式响应数据接收事件
let res = new ArrayBuffer(0);
httpRequest.on('dataReceive', (data: ArrayBuffer) => {
const newRes = new ArrayBuffer(res.byteLength + data.byteLength);
const resView = new Uint8Array(newRes);
resView.set(new Uint8Array(res));
resView.set(new Uint8Array(data), res.byteLength);
res = newRes;
// //console.info('dataReceive res length: ' + res.byteLength);
});
// 用于订阅HTTP流式响应数据接收完毕事件
httpRequest.on('dataEnd', () => {
this.transcodePixelMap(res);
// 判断网络获取到的资源是否为ArrayBuffer类型
//console.info(`dataEnd getPicture ${res}`)
if (res instanceof ArrayBuffer) {
//console.info(`dataEnd getPicture`)
this.imageBuffer = res as ArrayBuffer;
}
//console.info('No more data in response, data receive end');
});
httpRequest.requestInStream(this.url,
(error: BusinessError, data: number) => {
if (error) {
// 下载失败时弹窗提示检查网络,不执行后续逻辑
promptAction.showToast({
message: $r('app.string.image_request_fail'),
duration: 2000
// 通过任务池(taskpool)从网络下载图片资源
taskpool.execute(getPicture, this.url).then((res) => {
const imgBuffer = res as ArrayBuffer
this.imageBuffer = imgBuffer;
this.transcodePixelMap(imgBuffer);
})
//console.error(`http reqeust failed with. Code: ${error.code}, message: ${error.message}`);
return;
}
// 取消订阅HTTP响应头事件
httpRequest.off('headersReceive');
// 取消订阅HTTP流式响应数据接收事件
httpRequest.off('dataReceive');
// 取消订阅HTTP流式响应数据接收完毕事件
httpRequest.off('dataEnd');
// 当该请求使用完毕时,调用destroy方法主动销毁
httpRequest.destroy();
}
)
}
/**
...
...
sight_harmony/features/wdComponent/src/main/ets/components/MultiPictureDetailItemComponent.ets
View file @
4413b27
...
...
@@ -6,11 +6,29 @@ import { OffsetModel } from '../model/OffsetModel';
import { WindowSizeManager } from '../utils/Managers';
import { runWithAnimation } from '../utils/FuncUtils';
import { PhotoListBean } from 'wdBean/Index';
import { http } from '@kit.NetworkKit';
import { router } from '@kit.ArkUI';
import { taskpool } from '@kit.ArkTS';
import { httpRequest } from '../utils/httpRequest';
const TAG = 'MultiPictureDetailItemComponent';
@Concurrent
async function getPicture(imageUrl: string): Promise<ArrayBuffer> {
let ret: ArrayBuffer = await new Promise((resolve, reject) => {
httpRequest.httpRequestInStream(imageUrl, (res: ArrayBuffer) => {
resolve(res); // 成功时解析Promise
}, () => {
// 下载失败时弹窗提示检查网络
promptAction.showToast({
message: $r('app.string.image_request_fail'),
duration: 2000
});
reject(new Error('Image download failed')); // 失败时拒绝Promise
});
});
return ret
}
@Reusable
@Component
export struct MultiPictureDetailItemComponent {
...
...
@@ -34,65 +52,17 @@ export struct MultiPictureDetailItemComponent {
windowSizeManager: WindowSizeManager = new WindowSizeManager();
a
sync a
boutToAppear() {
aboutToAppear() {
this.imageUri = this.MultiPictureDetailItem.picPath
this.getPicture()
}
/**
* 通过http的request方法从网络下载图片资源
*/
async getPicture() {
// 每一个httpRequest对应一个HTTP请求任务,不可复用
let httpRequest = http.createHttp();
// 用于订阅HTTP响应头事件
httpRequest.on('headersReceive', (header: Object) => {
console.info('header: ' + JSON.stringify(header));
});
// 用于订阅HTTP流式响应数据接收事件
let res = new ArrayBuffer(0);
httpRequest.on('dataReceive', (data: ArrayBuffer) => {
const newRes = new ArrayBuffer(res.byteLength + data.byteLength);
const resView = new Uint8Array(newRes);
resView.set(new Uint8Array(res));
resView.set(new Uint8Array(data), res.byteLength);
res = newRes;
// console.info('dataReceive res length: ' + res.byteLength);
});
// 用于订阅HTTP流式响应数据接收完毕事件
httpRequest.on('dataEnd', () => {
this.transcodePixelMap(res);
// 判断网络获取到的资源是否为ArrayBuffer类型
console.info(`dataEnd getPicture ${res}`)
if (res instanceof ArrayBuffer) {
console.info(`dataEnd getPicture`)
this.imageBuffer = res as ArrayBuffer;
}
console.info('No more data in response, data receive end');
});
httpRequest.requestInStream(this.imageUri,
(error: BusinessError, data: number) => {
if (error) {
// 下载失败时弹窗提示检查网络,不执行后续逻辑
promptAction.showToast({
message: $r('app.string.image_request_fail'),
duration: 2000
// 通过任务池(taskpool)从网络下载图片资源
taskpool.execute(getPicture, this.imageUri).then((res) => {
const imgBuffer = res as ArrayBuffer
this.imageBuffer = imgBuffer;
this.transcodePixelMap(imgBuffer);
})
console.error(`http reqeust failed with. Code: ${error.code}, message: ${error.message}`);
return;
}
// 取消订阅HTTP响应头事件
httpRequest.off('headersReceive');
// 取消订阅HTTP流式响应数据接收事件
httpRequest.off('dataReceive');
// 取消订阅HTTP流式响应数据接收完毕事件
httpRequest.off('dataEnd');
// 当该请求使用完毕时,调用destroy方法主动销毁
httpRequest.destroy();
}
)
}
/**
* 使用createPixelMap将ArrayBuffer类型的图片装换为PixelMap类型
* @param data:网络获取到的资源
...
...
sight_harmony/features/wdComponent/src/main/ets/components/comment/model/CommentModel.ets
View file @
4413b27
...
...
@@ -35,6 +35,8 @@ export class commentListModel extends PageModel {
totalCommentNum: string = '0'
hasNext: number = 0
list: commentItemModel[] = []
hotList: commentItemModel[] = [] // 仅第一页存在
hotIds: string[] = [] // 仅第一页存在
// constructor(pageNum:number, pageSize:number, totalCount: number, hasNext: number, list: commentItemModel[]) {
// super()
// this.pageNum = pageNum
...
...
@@ -45,9 +47,16 @@ export class commentListModel extends PageModel {
// }
}
export enum CommentItemCustomType {
comment = 0,
newTitle = 1, // 最新评论标题
hotTitle = 2, // 热门评论标题
hotComment = 3,
}
@Observed
export class commentItemModel {
api_customType: CommentItemCustomType = CommentItemCustomType.comment
authorLike: string = ''
avatarFrame: string = ''
checkStatus: string = ''
...
...
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentComponent.ets
View file @
4413b27
import { DateTimeUtils, EmitterEventId, EmitterUtils, LazyDataSource,
PublicDialogManager,
StringUtils } from 'wdKit/Index';
import { commentItemModel, WDPublicUserType } from '../model/CommentModel';
import {
CommentItemCustomType,
commentItemModel, WDPublicUserType } from '../model/CommentModel';
import commentViewModel from '../viewmodel/CommentViewModel';
import { CommentText } from './CommentText';
import { CommentCustomDialog } from './CommentCustomDialog';
...
...
@@ -37,6 +37,7 @@ export struct CommentComponent {
listScroller: ListScroller = new ListScroller(); // scroller控制器
historyOffset: number = 0; // 上次浏览到列表距离顶端的偏移量offset
@State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource();
firstPageHotIds: string = ''
@State dialogController: CustomDialogController | null = null;
// @State private browSingModel: commentListModel = new commentListModel()
...
...
@@ -49,6 +50,7 @@ export struct CommentComponent {
// 是否在弹框中
@Provide inDialog: boolean = false
private dialogBeforeJumpOtherPageAction: () => void = () => {}
private dialogUpdateTitle: (title: string) => void = () => {}
// 在自定义组件即将析构销毁时将dialogControlle置空
aboutToDisappear() {
...
...
@@ -99,7 +101,16 @@ export struct CommentComponent {
/*一级评论*/
// if (this.publishCommentModel.lastCommentModel)
if (this.publishCommentModel.lastCommentModel.parentId == '-1') {
this.allDatas.addFirstItem(model)
let newCommentHeaderIndex = this.indexOfNewCommentHeaderTitle()
if (newCommentHeaderIndex === -1) {
let newCommentTitle = new commentItemModel()
newCommentTitle.api_customType = CommentItemCustomType.newTitle
this.allDatas.addItems([newCommentTitle, model])
} else {
this.allDatas.addItem(model, newCommentHeaderIndex + 1)
}
} else {
//二级评论
this.allDatas.getDataArray().forEach(element => {
...
...
@@ -116,14 +127,19 @@ export struct CommentComponent {
/*标题:全部评论*/
@Builder
titleHeader() {
titleHeader(title: string = "最新评论", showGapLine: boolean = false) {
Column() {
if (showGapLine) {
Divider().strokeWidth(6).color('#f5f5f5')
}
Row() {
Row() {
Image($r('app.media.redLine'))
.height(16)
.width(3)
Text('全部评论'
)
Text(title
)
.fontSize(16)// .fontColor('#222222')
.fontColor($r('app.color.color_222222'))
.fontWeight(FontWeight.Medium)
...
...
@@ -145,12 +161,7 @@ export struct CommentComponent {
.height(44)
.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
.onClick(() => {
// this.allDatas.push(new commentItemModel())
// this.allDatas.addFirstItem(new commentItemModel())
// this.allDatas.reloadData();
})
}
}
/*1级评论作为titleHeader*/
...
...
@@ -177,16 +188,29 @@ export struct CommentComponent {
build() {
Column() {
List({ scroller: this.listScroller }) {
if (!this.isComments) {
if (this.showTitleComponent) {
ListItemGroup({ header: this.titleHeader() })
}
if (!this.isComments) {
EmptyComponent({ emptyType: 17 })
.height(300)
} else {
LazyForEach(this.allDatas, (item: commentItemModel, index: number) => {
if (item.hasMore) {
if (item.api_customType === CommentItemCustomType.newTitle) {
if (this.inDialog && index === 0) {
ListItemGroup()
} else {
ListItemGroup({ header: this.titleHeader("最新评论", index !== 0) })
}
}
else if (item.api_customType === CommentItemCustomType.hotTitle) {
if (this.inDialog && index === 0) {
ListItemGroup()
} else {
ListItemGroup({ header: this.titleHeader("热门评论") })
}
}
else if (item.hasMore) {
ListItemGroup({
header: this.CommentHeaderItem(item, index),
footer: this.GroupFooterView(item, index)
...
...
@@ -234,6 +258,9 @@ export struct CommentComponent {
}
.scrollBar(BarState.Off)
.margin({ bottom: 10 })
.onScrollIndex((start) => {
this.updateDialogTitleWithStartIndex(start)
})
.onReachEnd(() => {
if (!this.fixedHeightMode) {
return
...
...
@@ -252,6 +279,30 @@ export struct CommentComponent {
}
updateDialogTitleWithStartIndex(start: number) {
if (!this.inDialog) {
return
}
if (this.allDatas.size() === 0) {
this.dialogUpdateTitle("评论")
return
}
if (this.allDatas.getFirst().api_customType !== CommentItemCustomType.hotTitle) {
this.dialogUpdateTitle("最新评论")
return
}
let newCommentHeaderIndex = this.indexOfNewCommentHeaderTitle()
if (newCommentHeaderIndex == -1) {
this.dialogUpdateTitle("热门评论")
return
}
if (start < newCommentHeaderIndex + 1) {
this.dialogUpdateTitle("热门评论")
} else {
this.dialogUpdateTitle("最新评论")
}
}
parentOnReachEnd() {
if (this.fixedHeightMode) {
return
...
...
@@ -268,11 +319,41 @@ export struct CommentComponent {
//获取数据
async getData() {
let pageIndex = this.currentPage
commentViewModel.fetchContentCommentList(pageIndex + '', this.publishCommentModel.targetId,
this.publishCommentModel.targetType)
commentViewModel.fetchContentCommentList(pageIndex + ''
,this.publishCommentModel.targetId
,this.publishCommentModel.targetType
,this.firstPageHotIds)
.then(commentListModel => {
console.log('评论:', JSON.stringify(commentListModel.list))
if (pageIndex == 1) {
// 保存第一页热门评论ids
if (commentListModel.hotIds.length > 0) {
this.firstPageHotIds = commentListModel.hotIds.join(",")
}
if (commentListModel.list.length > 0) { // 热门评论增加头部
let newCommentTitle = new commentItemModel()
newCommentTitle.api_customType = CommentItemCustomType.newTitle
let newArray = [newCommentTitle]
commentListModel.list = newArray.concat(commentListModel.list)
}
if (commentListModel.hotList.length > 0) { // 最新评论增加头部
let hotCommentTitle = new commentItemModel()
hotCommentTitle.api_customType = CommentItemCustomType.hotTitle
let newArray = [hotCommentTitle]
commentListModel.hotList = newArray.concat(commentListModel.hotList)
commentListModel.list = commentListModel.hotList.concat(commentListModel.list)
}
} else { // 非首页数据
if (commentListModel.list.length > 0 && !this.hasNewCommentHeaderTitle()) { // 如果之前仅存在热门评论,这里需要补下数据
let newCommentTitle = new commentItemModel()
newCommentTitle.api_customType = CommentItemCustomType.newTitle
let newArray = [newCommentTitle]
commentListModel.list = newArray.concat(commentListModel.list)
}
}
// 这里需要先赋值,否则下次UI刷新可能重复进入第1页两次
this.currentPage = pageIndex + 1
...
...
@@ -313,6 +394,29 @@ export struct CommentComponent {
}
})
}
hasNewCommentHeaderTitle() {
let hasNewCommentHeader = false
this.allDatas.getDataArray().forEach((comment) => {
if (comment.api_customType === CommentItemCustomType.newTitle) {
hasNewCommentHeader = true
}
})
return hasNewCommentHeader
}
indexOfNewCommentHeaderTitle() {
let resultIndex = -1;
const array = this.allDatas.getDataArray()
for (let index = 0; index < array.length; index++) {
if (array[index].api_customType === CommentItemCustomType.newTitle) {
resultIndex = index;
break
}
}
return resultIndex
}
}
...
...
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentListDialog.ets
View file @
4413b27
...
...
@@ -74,6 +74,7 @@ struct CommentListDialog {
/// 内部使用
@Link publishCommentModel: publishCommentModel
@State private operationButtonList: string[] = []
@State title: string = "评论"
/// 外部初始化
@Link contentDetailData: ContentDetailDTO // 详情页传
...
...
@@ -122,6 +123,9 @@ struct CommentListDialog {
if (this.onClose) {
this.onClose()
}
},
dialogUpdateTitle: (title) => {
this.title = title
}
}).layoutWeight(1)
...
...
@@ -153,7 +157,7 @@ struct CommentListDialog {
Image($r('app.media.redLine'))
.height(16)
.width(3)
Text(
'全部评论'
)
Text(
this.title
)
.fontSize(16)// .fontColor('#222222')
.fontColor($r('app.color.color_222222'))
.fontWeight(FontWeight.Medium)
...
...
sight_harmony/features/wdComponent/src/main/ets/components/comment/viewmodel/CommentViewModel.ets
View file @
4413b27
...
...
@@ -8,6 +8,7 @@ import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest';
import { ProcessUtils, WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import { TrackConstants, TrackingContent } from 'wdTracking/Index';
import {
CommentItemCustomType,
commentItemModel,
commentListModel,
commentStatusListModel,
...
...
@@ -33,9 +34,13 @@ class CommentViewModel {
}
/*获取所有评论*/
fetchContentCommentList(pageNum: string, contentId: string, contentType: string): Promise<commentListModel> {
fetchContentCommentList(pageNum: string, contentId: string, contentType: string
, firstPageHotIds: string = ''
): Promise<commentListModel> {
let url = HttpUrlUtils.getContentCommentListDataUrl() + `?&pageSize=${10}&pageNum=${pageNum}&contentId=${contentId}&contentType=${contentType}&deviceId=${HttpUtils.getDeviceId()}&userId=${HttpUtils.getUserId()}&userType=${HttpUtils.getUserType()}&time=${DateTimeUtils.getCurTime(DateTimeUtils.PATTERN_DATE_TIME_HYPHEN)}`
url = url + "&hotComment=1"
if (pageNum !== "1" && firstPageHotIds.length > 0) {
url = url + `&hotIds=` + firstPageHotIds
}
url = url.replace(' ', '%20')
return new Promise<commentListModel>((success, fail) => {
...
...
@@ -49,10 +54,24 @@ class CommentViewModel {
return
}
let listData = data.data as commentListModel
this.fetchCommentStatusAndConfigAuthIcon(listData).then((commentListModel) => {
this.fetchCommentStatusAndConfigAuthIcon(listData
, false
).then((commentListModel) => {
console.log(TAG, 'fetchCommentStatusAndConfigAuthIcon完成')
if (pageNum !== "1") {
success(commentListModel)
return
}
// 热门评论批查
this.fetchCommentStatusAndConfigAuthIcon(listData, true).then((commentListModel) => {
console.log(TAG, 'hot comment fetchCommentStatusAndConfigAuthIcon完成')
listData.hotList.forEach((item) => {
item.api_customType = CommentItemCustomType.hotComment
})
success(commentListModel)
})
})
}, (error: Error) => {
fail(error.message)
...
...
@@ -213,7 +232,7 @@ class CommentViewModel {
}
/*多接口批查*/
fetchCommentStatusAndConfigAuthIcon(model: commentListModel): Promise<commentListModel> {
fetchCommentStatusAndConfigAuthIcon(model: commentListModel
, hot: boolean = false
): Promise<commentListModel> {
let commentIDs: string[] = [];
...
...
@@ -222,7 +241,7 @@ class CommentViewModel {
let creatorIDs: string[] = [];
//主评论
for (const element of
model.list
) {
for (const element of
(hot ? model.hotList : model.list)
) {
if ((element.id + '').length > 0) {
commentIDs.push(element.id + '')
}
...
...
@@ -277,7 +296,7 @@ class CommentViewModel {
let listData = data.data as commentStatusModel[]
//点赞
for (const element of listData) {
for (const commentModel of
model.list
) {
for (const commentModel of
(hot ? model.hotList : model.list)
) {
if (element.commentId == commentModel.id) {
commentModel.api_status = element.status
}
...
...
@@ -319,7 +338,7 @@ class CommentViewModel {
let listData = data.data as commentStatusModel[]
for (const element of listData) {
for (const commentModel of
model.list
) {
for (const commentModel of
(hot ? model.hotList : model.list)
) {
if (element.userId == commentModel.fromUserId) {
commentModel.api_levelHead = element.levelHead
}
...
...
@@ -364,7 +383,7 @@ class CommentViewModel {
let listData = data.data as commentStatusModel[]
for (const element of listData) {
for (const commentModel of
model.list
) {
for (const commentModel of
(hot ? model.hotList : model.list)
) {
if (element.creatorId == commentModel.fromCreatorId) {
commentModel.api_authIcon = element.authIcon
}
...
...
@@ -400,6 +419,7 @@ class CommentViewModel {
deepCopyCommentItemModel(model: commentItemModel) {
let newModel = new commentItemModel()
newModel.api_customType = model.api_customType
newModel.authorLike = model.authorLike
newModel.avatarFrame = model.avatarFrame
newModel.checkStatus = model.checkStatus
...
...
sight_harmony/features/wdComponent/src/main/ets/utils/httpRequest.ets
0 → 100644
View file @
4413b27
import { http } from '@kit.NetworkKit';
const TAG = 'httpRequestInStream'
export class httpRequest {
// 大于5M的下载请求,使用流下载
/**
* 发起HTTP请求以下载图片资源
* @param {string} imageUrl 图片的URL
* @param {Function} onSuccess 成功回调函数
* @param {Function} onError 失败回调函数
*/
public static httpRequestInStream(imageUrl:string, onSuccess:Function, onError:Function) {
// 每一个httpRequest对应一个HTTP请求任务,不可复用
const httpRequest = http.createHttp();
// 订阅HTTP响应头事件
httpRequest.on('headersReceive', (header) => {
// console.info('header: ' + JSON.stringify(header));
});
// 用于订阅HTTP流式响应数据接收事件
let res = new ArrayBuffer(0);
httpRequest.on('dataReceive', (data) => {
const newRes = new ArrayBuffer(res.byteLength + data.byteLength);
const resView = new Uint8Array(newRes);
resView.set(new Uint8Array(res));
resView.set(new Uint8Array(data), res.byteLength);
res = newRes;
// console.info(TAG, 'dataReceive res length: ' + res.byteLength);
});
// 用于订阅HTTP流式响应数据接收完毕事件
httpRequest.on('dataEnd', () => {
if (res instanceof ArrayBuffer) {
// 如果成功,调用onSuccess回调
// console.info(TAG, 'Success in response, data receive end');
onSuccess(res);
} else {
// 如果数据不是ArrayBuffer类型,可以在这里处理异常
// console.error(TAG, 'Unexpected data type:', res);
onError(new Error('Data is not an ArrayBuffer'));
}
// console.info(TAG, 'No more data in response, data receive end');
});
httpRequest.requestInStream(imageUrl, (error, data) => {
if (error) {
// 如果发生错误,取消订阅事件并销毁请求对象
httpRequest.off('headersReceive');
httpRequest.off('dataReceive');
httpRequest.off('dataEnd');
httpRequest.destroy();
// console.error(`http request failed with. Code: ${error.code}, message: ${error.message}`);
// 调用onError回调
onError(error);
return;
}
// 取消订阅事件
httpRequest.off('headersReceive');
httpRequest.off('dataReceive');
httpRequest.off('dataEnd');
// 销毁请求对象
httpRequest.destroy();
});
}
}
\ No newline at end of file
...
...
sight_harmony/features/wdDetailPlayShortVideo/src/main/ets/view/PlayerTitleView.ets
View file @
4413b27
...
...
@@ -94,7 +94,8 @@ export struct PlayerTitleView {
}
clipStr += strArr[i]
}
console.log(TAG, 'clipStr:', clipStr)
clipStr += this.isOverLines ? '...' : '';
console.log(TAG, 'clipStr2:', clipStr)
return clipStr
}
...
...
@@ -130,7 +131,8 @@ export struct PlayerTitleView {
}
clipStr += strArr[i]
}
console.log(TAG, 'clipTitleText clipStr:', clipStr)
console.log(TAG, 'clipTitleText clipStr1:', clipStr)
clipStr += this.isTitleOverLines ? '...' : '';
return clipStr
}
...
...
@@ -217,7 +219,54 @@ export struct PlayerTitleView {
// })
// }
// } else {
this.detailDesc()
// }
Text(DateTimeUtils.formatDate(new Date(this.contentDetailData?.publishTime).getTime(),
DateTimeUtils.PATTERN_DATE_TIME_HYPHEN_MM))
.fontSize(12)
.fontColor(Color.White)
.opacity(0.7)
.lineHeight(16)
.fontWeight(400)
.fontFamily('PingFang SC-Regular')
.margin({ top: 8, bottom: 8 })
}
.width(this.windowWidth - 150 + 'px')
.padding({ left: 16, right: 22 })
.alignItems(HorizontalAlign.Start)
.visibility(this.isOpenDetail || this.isDragging ? Visibility.None : Visibility.Visible)
}
@Builder
detailDesc() {
/**
* 标题大于三行或存在简介显示查看详情按钮
*/
// if (this.rmhPlatform == 1) {
// if (this.titleHeight > 200 || this.summary) {
// Text('查看详情 > ')
// .padding({
// left: 6,
// right: 6,
// top: 4,
// bottom: 4
// })
// .borderRadius(2)
// .backgroundColor('#99636363')
// .fontFamily('PingFang SC-Regular')
// .fontColor(Color.White)
// .fontSize(12)
// .lineHeight(14)
// .fontWeight(400)
// .onClick(() => {
// this.isOpenDetail = true
// this.dialogController?.open()
// })
// }
// } else {
if (this.summary && this.titleLines < 4) {
Stack({ alignContent: Alignment.TopStart }) {
Text() {
Span(this.clipText(this.summary, 14, this.summaryLines, this.windowWidth - 150 - vp2px(50)))
.fontSize(14)
...
...
@@ -229,9 +278,18 @@ export struct PlayerTitleView {
this.isOpenDetail = true
this.dialogController?.open()
})
}
// .position({ x: 0, y: 0 })
.padding({
left: 0,
right: 6,
top: 0,
bottom: 8
})
if (this.isOverLines) {
Span('... 全文')
.fontColor('#888888')
Text() {
Span('全文')
.fontColor('#99FFFFFF')
.fontWeight(400)
.fontFamily('PingFang SC-Regular')
.fontSize(12)
...
...
@@ -251,37 +309,31 @@ export struct PlayerTitleView {
this.isOpenDetail = true
this.dialogController?.open()
})
}
}
.textAlign(TextAlign.Center)
// .width('100%')
.position({ x: '100%', y: this.summaryLines*23 }) //行高+margin
.translate({ x: '-100%', y: '-100%' })
// .markAnchor({ x: '100%', y: '100%' })
.padding({
left: 0, //6
left: 0,
right: 6,
top: 0, //4
bottom: 8
top: 0,
bottom: 6
})
}
// }
Text(DateTimeUtils.formatDate(new Date(this.contentDetailData?.publishTime).getTime(),
DateTimeUtils.PATTERN_DATE_TIME_HYPHEN_MM))
.fontSize(12)
.fontColor(Color.White)
.opacity(0.7)
.lineHeight(16)
.fontWeight(400)
.fontFamily('PingFang SC-Regular')
.margin({ top: 8, bottom: 8 })
}
.width(this.windowWidth - 150 + 'px')
.padding({ left: 16, right: 22 })
.alignItems(HorizontalAlign.Start)
.visibility(this.isOpenDetail || this.isDragging ? Visibility.None : Visibility.Visible)
.width('100%')
}
}
/**
* 标题
* */
@Builder
titleBuilder() {
// Stack({ alignContent: this.isTitleOverLines ? Alignment.BottomEnd : Alignment.Start }) {
Stack({ alignContent: Alignment.TopStart }) {
Text() {
Span(this.clipTitleText(this.getTitle(), 16, 4, this.windowWidth - 234 - vp2px(50)))
.fontSize(16)
...
...
@@ -289,9 +341,28 @@ export struct PlayerTitleView {
.lineHeight(22)
.fontWeight(600)
.fontFamily('PingFang SC-Regular')
}
// .position({ x: 0, y: 0 })
.onAreaChange((oldArea: Area, newArea: Area) => {
//console.info(`cj2024 titleLines = ${newArea.height as number} line = ${(newArea.height as number) / 20}`)
this.titleLines = Math.floor((newArea.height as number) / 22) // 22是行高
//console.info(`cj2024 titleLines = ${this.titleLines}`)
this.updateSummaryLines()
})
.maxLines(4)
.textOverflow({ overflow: TextOverflow.Ellipsis })
.padding({
left: 0, //6
right: 6,
top: 0, //4
bottom: 8
})
Text() {
if (this.isTitleOverLines) {
Span('... 全文')
.fontColor(Color.White)
Span('全文')
.fontColor('#99FFFFFF')
.fontWeight(600)
.fontFamily('PingFang SC-Regular')
.fontSize(12)
...
...
@@ -311,15 +382,14 @@ export struct PlayerTitleView {
this.isOpenDetail = true
this.dialogController?.open()
})
}
}
.onAreaChange((oldArea: Area, newArea: Area) => {
//console.info(`cj2024 titleLines = ${newArea.height as number} line = ${(newArea.height as number) / 20}`)
this.titleLines = Math.floor((newArea.height as number) / 22) // 22是行高
//console.info(`cj2024 titleLines = ${this.titleLines}`)
this.updateSummaryLines()
})
.textAlign(TextAlign.Center)
// .width('100%')
.position({ x: '100%', y: this.titleLines*23 }) //行高+margin
.translate({ x: '-100%', y: '-100%' })
// .position({ x: '100%', y: '100%' })
// .markAnchor({ x: '100%', y: '100%' })
.padding({
left: 0, //6
right: 6,
...
...
@@ -327,4 +397,6 @@ export struct PlayerTitleView {
bottom: 8
})
}
.width('100%')
}
}
...
...
sight_harmony/features/wdDetailPlayShortVideo/src/main/resources/base/media/comment_unfold_svg.svg
View file @
4413b27
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="none" version="1.1" width="16" height="16" viewBox="0 0 16 16"><g transform="matrix(0,-1,1,0,-16,16)"><g><path d="M10.303455641479491,17.960819560243227L4.363755241479492,23.900515460243227Q4.324434578479492,23.939835460243224,4.324704443879492,23.995445460243225Q4.324434578479492,24.051055460243226,4.363755241479492,24.090375460243223L10.303455641479491,30.030075460243225Q10.342505641479491,30.069075460243226,10.397735641479493,30.069075460243226Q10.452965641479492,30.069075460243226,10.492015641479492,30.030075460243225L11.387685641479493,29.134375460243227Q11.406435641479492,29.115675460243224,11.416585641479493,29.091175460243225Q11.426735641479493,29.066675460243225,11.426735641479493,29.040075460243223Q11.426735641479493,29.013575460243224,11.416585641479493,28.989075460243225Q11.406435641479492,28.964575460243225,11.387685641479493,28.945875460243226L6.437285641479493,23.995445460243225L11.387685641479493,19.045045460243227Q11.406435641479492,19.026295460243226,11.416585641479493,19.001795460243226Q11.426735641479493,18.977295460243226,11.426735641479493,18.950765460243225Q11.426735641479493,18.924245460243224,11.416585641479493,18.899744460243227Q11.406435641479492,18.875241460243224,11.387685641479493,18.856488460243224L10.492015641479492,17.960819560243227Q10.452965641479492,17.921767119783226,10.397735641479493,17.921767119783226Q10.342505641479491,17.921767119783226,10.303455641479491,17.960819560243227Z" fill-rule="evenodd" fill="#888888" fill-opacity="1"/></g></g></svg>
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="none" version="1.1" width="16" height="16" viewBox="0 0 16 16"><g transform="matrix(0,-1,1,0,-16,16)"><g><path d="M10.303455641479491,17.960819560243227L4.363755241479492,23.900515460243227Q4.324434578479492,23.939835460243224,4.324704443879492,23.995445460243225Q4.324434578479492,24.051055460243226,4.363755241479492,24.090375460243223L10.303455641479491,30.030075460243225Q10.342505641479491,30.069075460243226,10.397735641479493,30.069075460243226Q10.452965641479492,30.069075460243226,10.492015641479492,30.030075460243225L11.387685641479493,29.134375460243227Q11.406435641479492,29.115675460243224,11.416585641479493,29.091175460243225Q11.426735641479493,29.066675460243225,11.426735641479493,29.040075460243223Q11.426735641479493,29.013575460243224,11.416585641479493,28.989075460243225Q11.406435641479492,28.964575460243225,11.387685641479493,28.945875460243226L6.437285641479493,23.995445460243225L11.387685641479493,19.045045460243227Q11.406435641479492,19.026295460243226,11.416585641479493,19.001795460243226Q11.426735641479493,18.977295460243226,11.426735641479493,18.950765460243225Q11.426735641479493,18.924245460243224,11.416585641479493,18.899744460243227Q11.406435641479492,18.875241460243224,11.387685641479493,18.856488460243224L10.492015641479492,17.960819560243227Q10.452965641479492,17.921767119783226,10.397735641479493,17.921767119783226Q10.342505641479491,17.921767119783226,10.303455641479491,17.960819560243227Z" fill-rule="evenodd" fill="#FFFFFF" fill-opacity="0.6"/></g></g></svg>
\ No newline at end of file
...
...
Please
register
or
login
to post a comment