From fc801e13456aaf2f31d3008daa30dbb3f5711431 Mon Sep 17 00:00:00 2001 From: xiaoxiao Date: Thu, 29 May 2025 17:13:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E9=A2=91=E8=AF=A6=E6=83=85=E8=AF=84?= =?UTF-8?q?=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-profile.json5 | 16 +- commons/basic/Index.ets | 4 + .../src/main/ets/constants/BasicConstant.ets | 5 +- .../main/ets/models/Huanzhelast444Model.ets | 82 ++++++++ .../src/main/ets/utils/HuanzhelasDbHelper.ets | 153 +++++++++++++++ commons/basic/src/main/ets/utils/request.ets | 2 +- features/Home/Index.ets | 4 + .../main/ets/components/CommentChildView.ets | 37 ++++ .../src/main/ets/components/ItemCompVideo.ets | 3 +- .../ets/components/VideoDetailsComment.ets | 138 ++++++++++++++ .../src/main/ets/model/VideoCommentModel.ets | 22 +++ .../Home/src/main/ets/pages/PastVideo.ets | 3 + features/Home/src/main/ets/pages/PlayBack.ets | 2 +- .../register/src/main/ets/view/LoginComp.ets | 2 +- oh-package-lock.json5 | 22 ++- oh-package.json5 | 3 +- .../ets/common/utils/PLVOrientationManager.ts | 5 +- .../src/main/ets/models/Huanzhelast444Dao.ets | 177 ++++++++++++++++++ .../src/main/ets/pages/MinePage/MyPage.ets | 1 - .../ets/pages/VideoPage/CommentReplyPage.ets | 76 ++++++++ .../PLVMediaPlayerSingleVideoPage.ets | 167 +++++++++++++++-- .../resources/base/profile/main_pages.json | 3 +- .../PLVMediaPlayerSingleVideoLayout.ets | 5 + 23 files changed, 899 insertions(+), 33 deletions(-) create mode 100644 commons/basic/src/main/ets/models/Huanzhelast444Model.ets create mode 100644 commons/basic/src/main/ets/utils/HuanzhelasDbHelper.ets create mode 100644 features/Home/src/main/ets/components/CommentChildView.ets create mode 100644 features/Home/src/main/ets/components/VideoDetailsComment.ets create mode 100644 features/Home/src/main/ets/model/VideoCommentModel.ets create mode 100644 products/expert/src/main/ets/models/Huanzhelast444Dao.ets create mode 100644 products/expert/src/main/ets/pages/VideoPage/CommentReplyPage.ets diff --git a/build-profile.json5 b/build-profile.json5 index d2c0f71..7dc7b4e 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -1,6 +1,20 @@ { "app": { - "signingConfigs": [], + "signingConfigs": [ + { + "name": "default", + "type": "HarmonyOS", + "material": { + "certpath": "/Users/gandanxiangzhao/.ohos/config/default_harmony_0p9qf45UN48IqoSyKhLtcLhTMwMj81GJRnBkhg7Axm4=.cer", + "keyAlias": "debugKey", + "keyPassword": "0000001AA50378305356D7D7EEDE463DB4E4B1B23C35A2615C29ED413C2E2DC30778DFE346C51C100F7D", + "profile": "/Users/gandanxiangzhao/.ohos/config/default_harmony_0p9qf45UN48IqoSyKhLtcLhTMwMj81GJRnBkhg7Axm4=.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "/Users/gandanxiangzhao/.ohos/config/default_harmony_0p9qf45UN48IqoSyKhLtcLhTMwMj81GJRnBkhg7Axm4=.p12", + "storePassword": "0000001A29D969B0C08E79F7AC25E39AEB74F09540DED4C7BEF6ABF0671F85B598C8F911C2943D3B741C" + } + } + ], "products": [ { "name": "default", diff --git a/commons/basic/Index.ets b/commons/basic/Index.ets index 652da84..891ba00 100644 --- a/commons/basic/Index.ets +++ b/commons/basic/Index.ets @@ -49,3 +49,7 @@ export { EmptyViewComp } from './src/main/ets/Views/EmptyViewComp' export { HdLoadingDialog } from './src/main/ets/components/HdLoadingDialog' export { EditUserDataItem } from './src/main/ets/Views/EditUserDataItem' + +export { Huanzhelast444Model } from './src/main/ets/models/Huanzhelast444Model' + +export { huanzheDb } from './src/main/ets/utils/HuanzhelasDbHelper' \ No newline at end of file diff --git a/commons/basic/src/main/ets/constants/BasicConstant.ets b/commons/basic/src/main/ets/constants/BasicConstant.ets index 3e14cf4..acfb42b 100644 --- a/commons/basic/src/main/ets/constants/BasicConstant.ets +++ b/commons/basic/src/main/ets/constants/BasicConstant.ets @@ -7,7 +7,7 @@ export class BasicConstant { //测试环境 static readonly urlExpertAPI = "https://dev-app.igandan.com/app/expertAPI/"; - static readonly urlExpertApp = "https://dev-app.igandan.com//app/expertApp/" + static readonly urlExpertApp = "https://dev-app.igandan.com/app/expertApp/" static readonly urlHtml = "http://dev-doc.igandan.com/app/" static readonly urlImage = "https://dev-doc.igandan.com/app/" static readonly urlExpert = "https://dev-app.igandan.com/app/expert/" @@ -29,6 +29,9 @@ export class BasicConstant { static readonly zhibourl = BasicConstant.wxUrl+"hcp/setInfo"; static readonly videoByTypeNew = BasicConstant.urlExpertApp + 'videoByTypeNew' static readonly videoDetail = BasicConstant.urlExpertAPI + "videoDetail"; + static readonly videoCommentListV2 = BasicConstant.urlExpertAPI + "videoCommentListV2";//视频详情评价列表 + static readonly addCommentV2 = BasicConstant.urlExpertAPI+'addCommentV2';//评论回复 + static readonly deleteComment = BasicConstant.urlExpertApp+'deleteComment';//删除评论 static readonly meetingHistoryList = BasicConstant.urlExpertAPI + "meetingHistoryList"; static readonly videoRoll = BasicConstant.urlExpertAPI + "videoRoll"; static readonly expertVideoTypeList = BasicConstant.urlExpertAPI + "expertVideoTypeList"; diff --git a/commons/basic/src/main/ets/models/Huanzhelast444Model.ets b/commons/basic/src/main/ets/models/Huanzhelast444Model.ets new file mode 100644 index 0000000..eb01851 --- /dev/null +++ b/commons/basic/src/main/ets/models/Huanzhelast444Model.ets @@ -0,0 +1,82 @@ +import { Entity, Columns, Id, ColumnType } from '@ohos/dataorm'; + +// 表名需与sqlite一致 +@Entity('t_huanzhelast444') +export class Huanzhelast444Model { + @Id() + @Columns({ columnName: '_id', types: ColumnType.num }) // 主键字段映射 + _id: number = 0; + + @Columns({ columnName: 'id', types: ColumnType.num }) + id: number = 0; + + @Columns({ columnName: 'fullname', types: ColumnType.str }) + fullname: string = ''; + + @Columns({ columnName: 'name', types: ColumnType.str }) + name: string = ''; + + @Columns({ columnName: 'parent', types: ColumnType.num }) + parent: number = 0; + + @Columns({ columnName: 'treePath', types: ColumnType.str }) + treePath: string = ''; + + // 必须包含所有非静态变量的构造函数 + constructor( + _id: number = 0, + id: number = 0, + fullname: string = '', + name: string = '', + parent: number = 0, + treePath: string = '' + ) { + this._id = _id; + this.id = id; + this.fullname = fullname; + this.name = name; + this.parent = parent; + this.treePath = treePath; + } + + setTreePath(treePath:string) { + this.treePath = treePath; + } + + getTreePath():string { + return this.treePath; + } + + setParent(parent:number) { + this.parent = parent; + } + + getParent():number { + return this.parent; + } + + setName(name:string) { + this.name = name; + } + + getName():string { + return this.name; + } + + setFullname(fullname:string) { + this.fullname = fullname; + } + + getFullname():string { + return this.fullname; + } + + getId():number { + return this.id; + } + + setId(id:number) { + this.id = id; + } + +} \ No newline at end of file diff --git a/commons/basic/src/main/ets/utils/HuanzhelasDbHelper.ets b/commons/basic/src/main/ets/utils/HuanzhelasDbHelper.ets new file mode 100644 index 0000000..1f586e6 --- /dev/null +++ b/commons/basic/src/main/ets/utils/HuanzhelasDbHelper.ets @@ -0,0 +1,153 @@ +import fs from '@ohos.file.fs'; +import common from '@ohos.app.ability.common'; +import relationalStore from '@ohos.data.relationalStore'; +import util from '@ohos.util'; +import { Huanzhelast444Model } from '../models/Huanzhelast444Model' + +const huanzhelastFile: string = 'huanzhelas.sqlite'; + +// 步骤1:将rawfile数据库文件复制到应用沙箱 +async function copyDatabase(context: common.Context): Promise { + try { + const resourceMgr = context.resourceManager; + const rawFile = await resourceMgr.getRawFileContent(huanzhelastFile); + + // 将Uint8Array转为ArrayBuffer + const arrayBuffer = rawFile.buffer; + + // 创建沙箱路径 + const dbPath = context.filesDir + '/' + huanzhelastFile; + console.info(`[DB] context.filesDir: ${context.filesDir}`); + console.info(`[DB] dbPath: ${dbPath}`); + // 确保目录存在 + try { + fs.accessSync(context.filesDir); + } catch (e) { + fs.mkdirSync(context.filesDir); + } + + // 写入文件 + const file = fs.openSync(dbPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); + fs.writeSync(file.fd, arrayBuffer); + fs.closeSync(file); + + // 检查文件是否存在 + try { + fs.accessSync(dbPath); + console.info(`[DB] DB file exists after copy: ${dbPath}`); + } catch (e) { + console.error(`[DB] DB file does not exist after copy: ${dbPath}`); + } + } catch (error) { + console.error(`Copy database failed: ${error}`); + } +} + +// 步骤2:数据库操作封装类 +class HuanzhelasDbHelper { + private rdbStore: relationalStore.RdbStore | null = null; + + // 初始化数据库连接 + async initDatabase(context: common.Context): Promise { + await copyDatabase(context); + const storeConfig: relationalStore.StoreConfig = { + name: huanzhelastFile, + securityLevel: relationalStore.SecurityLevel.S1 + }; + + try { + this.rdbStore = await relationalStore.getRdbStore(context, storeConfig); + console.info('Database connection established'); + } catch (error) { + console.error(`Init database failed: ${error}`); + } + } + + async queryHuanzhelastData():Promise> { + if (!this.rdbStore) { + console.error('Database not initialized'); + throw new Error('Database not initialized'); + } + // const resultSet = await this.rdbStore.querySql('SELECT * FROM t_huanzhelast444', []); + // if (resultSet.rowCount > 0) { + // resultSet.goToFirstRow(); + // do { + // console.info('[DB] Table:', resultSet.getString(0)); + // } while (resultSet.goToNextRow()); + // } + // resultSet.close(); + // try { + // const predicates = new relationalStore.RdbPredicates('t_huanzhelast444'); + // console.info('[DB] Querying table: t_huanzhelast444'); + // const resultSet = await this.rdbStore.query(predicates); + // + // if (resultSet.isClosed) { + // console.error('[DB] ResultSet is closed immediately after query!'); + // return; + // } + // console.info('[DB] ResultSet columnNames:', resultSet.columnNames); + // console.info('[DB] Query finished, rowCount:', resultSet.rowCount); + // + // if (resultSet.rowCount > 0) { + // resultSet.goToFirstRow(); + // do { + // // // 打印每一行 + // // let row: Required = {}; + // // for (let i = 0; i < resultSet.columnNames.length; i++) { + // // row[resultSet.columnNames[i]] = resultSet.getString(i); + // // } + // // console.info('[DB] Row:', JSON.stringify(row)); + // console.info('[DB] Row:'); + // } while (resultSet.goToNextRow()); + // } else { + // console.warn('[DB] No data found, please check table name and data!'); + // } + // resultSet.close(); + // } catch (e) { + // console.error('[DB] Query error:', e); + // throw new Error('Database query error'); + // } + try {///data/app/el2/100/base/com.example.expert/haps/default/files/databases/huanzhelas.sqlite + const predicates = new relationalStore.RdbPredicates('cn_shangyu_gdxzExpert_bean_City'); + const resultSet = await this.rdbStore.query(predicates); + + const dataList: Array = []; + if (resultSet.rowCount > 0) { + resultSet.goToFirstRow(); + do { + dataList.push(this.parseResultSet(resultSet)); + } while (resultSet.goToNextRow()); + } else { + console.error(`Query failed: ${predicates}`); + } + resultSet.close(); + return dataList; + } catch (error) { + console.error(`Query failed: ${error}`); + throw new Error('Database query error'); + } + } + + private parseResultSet(resultSet: relationalStore.ResultSet): HuanzhelastEntity { + return { + _id: resultSet.getDouble(resultSet.getColumnIndex('_id')), + id: resultSet.getDouble(resultSet.getColumnIndex('id')), + fullname: resultSet.getString(resultSet.getColumnIndex('fullname')), + name: resultSet.getString(resultSet.getColumnIndex('name')), + parent: resultSet.getDouble(resultSet.getColumnIndex('parent')), + treePath: resultSet.getString(resultSet.getColumnIndex('treePath')) + }; + } +} + +// 实体类型定义 +interface HuanzhelastEntity { + _id: number; + id: number; + fullname: string; + name: string; + parent: number; + treePath: string; +} + +export const huanzheDb = new HuanzhelasDbHelper() diff --git a/commons/basic/src/main/ets/utils/request.ets b/commons/basic/src/main/ets/utils/request.ets index cca61bf..a491b67 100644 --- a/commons/basic/src/main/ets/utils/request.ets +++ b/commons/basic/src/main/ets/utils/request.ets @@ -151,7 +151,7 @@ class HdHttp { logger.info('Response httpReq:' + data.result); let json:TimestampBean = JSON.parse(data.result.toString()) as TimestampBean; let tp = json.timestamp; - datas.set("user_uuid", authStore.getUser().uuid?authStore.getUser().uuid:'5kO57cuAL8seXQpxgtc'); + datas.set("user_uuid", authStore.getUser().uuid?authStore.getUser().uuid:''); datas.set("client_type", 'A'); datas.set("version",'4.0.0' ); datas.set('timestamp',tp+''); diff --git a/features/Home/Index.ets b/features/Home/Index.ets index 5b49321..ea33337 100644 --- a/features/Home/Index.ets +++ b/features/Home/Index.ets @@ -8,8 +8,12 @@ export { VideoMore } from './src/main/ets/pages/VideoMore' export { VideoDetailModel } from './src/main/ets/model/VideoDetailModel' +export { VideoCommentModel,commentModel } from './src/main/ets/model/VideoCommentModel' + export { PastVideo } from './src/main/ets/pages/PastVideo'; export { VideoGandan } from './src/main/ets/pages/VideoGandan'; export { PLVMockMediaResourceData } from './src/main/ets/polyv/PLVMockMediaResourceData' + +export { VideoDetailsComment } from './src/main/ets/components/VideoDetailsComment' diff --git a/features/Home/src/main/ets/components/CommentChildView.ets b/features/Home/src/main/ets/components/CommentChildView.ets new file mode 100644 index 0000000..5294b24 --- /dev/null +++ b/features/Home/src/main/ets/components/CommentChildView.ets @@ -0,0 +1,37 @@ +import { BasicConstant, authStore } from '@itcast/basic' +import { commentModel } from '../model/VideoCommentModel' + +@Preview +@Component +export struct CommentChildView { + @Prop model:commentModel; + @State isShowMoreComment:boolean = false; + + build() { + Column() { + Row() { + Row({ space: 10 }) { + Image(BasicConstant.urlHtml + this.model.photo) + .alt($r('app.media.userPhoto_default')) + .width(34).height(34) + .borderRadius(3.4) + Text(this.model.user_status == 1 ? this.model.name : '账号已注销') + .fontSize(16).fontColor('#333333') + .height('100%') + .alignSelf(ItemAlign.Start) + } + .margin({ left: 10, right: authStore.getUser().uuid == this.model.user_uuid ? 35 : 65 }) + .layoutWeight(1)//权重自定义 + .justifyContent(FlexAlign.Start) + }.width('100%').height(40).margin({top:15}).alignItems(VerticalAlign.Center) + Column() { + Text(this.model.content) + .fontSize(15).fontColor('#666666') + Text(this.model.create_date) + .margin({top:5}) + .fontSize(14) + .fontColor('#999999') + }.margin({left:50}).alignItems(HorizontalAlign.Start).width('calc(100% - 70vp)') + } + } +} diff --git a/features/Home/src/main/ets/components/ItemCompVideo.ets b/features/Home/src/main/ets/components/ItemCompVideo.ets index 50a7479..c0f1f6d 100644 --- a/features/Home/src/main/ets/components/ItemCompVideo.ets +++ b/features/Home/src/main/ets/components/ItemCompVideo.ets @@ -66,8 +66,7 @@ export struct ItemCompVideo { this.goPLVMediaPlayerSingleVideoPage(json.video.polyv_uuid,video_uuid) }).catch((err: BusinessError) => { - - + this.goPLVMediaPlayerSingleVideoPage('','') }) } diff --git a/features/Home/src/main/ets/components/VideoDetailsComment.ets b/features/Home/src/main/ets/components/VideoDetailsComment.ets new file mode 100644 index 0000000..1388a03 --- /dev/null +++ b/features/Home/src/main/ets/components/VideoDetailsComment.ets @@ -0,0 +1,138 @@ +import { BasicConstant, authStore } from '@itcast/basic' +import { commentModel } from '../model/VideoCommentModel' +import { CommentChildView } from '../components/CommentChildView' +import { router,promptAction } from '@kit.ArkUI'; +import { hdHttp, HdResponse ,logger} from '@itcast/basic/Index' +import HashMap from '@ohos.util.HashMap'; +import { BusinessError,emitter } from '@kit.BasicServicesKit'; +import { rcp } from '@kit.RemoteCommunicationKit'; + +@Preview +@Component +export struct VideoDetailsComment { + @Prop model:commentModel; + @Prop videoCommentUuid:string; + @State isShowMoreComment:boolean = false; + + deleteComment() { + const updateDataUrl:string = BasicConstant.deleteComment; + const postContent = new rcp.MultipartForm({ + 'uuid': this.model.comment_uuid + }) + const session = rcp.createSession(); + session.post(updateDataUrl, postContent) + .then((response) => { + if (response.statusCode == 200) { + emitter.emit({ + eventId: 250529, + priority: emitter.EventPriority.HIGH + }) + promptAction.showToast({ message: '删除评论成功', duration: 1000 }) + } + }) + .catch((err: BusinessError) => { + console.error(`Response err: Code is ${JSON.stringify(err.code)}, message is ${JSON.stringify(err)}`); + }) + } + + build() { + Column() { + Row() { + Row({ space: 10 }) { + Image(BasicConstant.urlHtml + this.model.photo) + .alt($r('app.media.userPhoto_default')) + .width(40).height(40) + .borderRadius(4) + Text(this.model.user_status == 1 ? this.model.name : '账号已注销') + .fontSize(16).fontColor('#333333') + .height('100%') + .alignSelf(ItemAlign.Start) + } + .margin({ left: 10, right: authStore.getUser().uuid == this.model.user_uuid ? 35 : 65 }) + .layoutWeight(1)//权重自定义 + .justifyContent(FlexAlign.Start) + + if (authStore.getUser().uuid == this.model.user_uuid) { + Image($r('app.media.video_comment_delete')) + .width(20).height(20).margin({right:15}) + .onClick(()=>{ + promptAction.showDialog({ title: '温馨提示', message: '确定要删除评论?', + buttons: [{ text: '取消', color: '#666666' }, { text: '确定', color: $r('app.color.main_color') }], + }) + .then(data => { + if (data.index == 1) { + this.deleteComment(); + } + }) + }) + } else { + Text('回复') + .textAlign(TextAlign.Center) + .width(50).height(25).margin({right:15}) + .borderRadius(10) + .backgroundColor('#f4f4f4') + .borderWidth(1).borderColor($r('app.color.main_color')) + .fontSize(16).fontColor($r('app.color.main_color')) + .onClick(() => { + if (this.model.user_status === 1) { + router.pushUrl({ + params:{'replyName':this.model.name,'comment_id':this.videoCommentUuid,'comment':this.model.content}, + url: 'pages/VideoPage/CommentReplyPage' + }) + } else { + promptAction.showToast({ message: '该评论无法回复', duration: 1000 }) + } + }) + } + }.width('100%').height(40).margin({top:15}).alignItems(VerticalAlign.Center) + Column() { + Text(this.model.content) + .fontSize(15).fontColor('#666666') + Text(this.model.create_date) + .margin({top:5}) + .fontSize(14) + .fontColor('#999999') + }.margin({left:50}).alignItems(HorizontalAlign.Start).width('calc(100% - 70vp)') + + Column() { + if (this.model.childs.length > 3) { + ForEach(this.model.childs.slice(0, this.isShowMoreComment ? this.model.childs.length : 3), + (childModels: commentModel) => { + ListItem() { + CommentChildView({model:childModels}); + } + .width('100%') + }) + this.dynamicFooter((isShow: boolean) => { + this.isShowMoreComment = isShow; + }); + } else { + ForEach(this.model.childs, (childModels: commentModel) => { + CommentChildView({model:childModels}); + }) + } + } + .margin({left:50}).alignItems(HorizontalAlign.Start).width('calc(100% - 70vp)') + + Divider() + .color(Color.White) + .width('100%').strokeWidth(1).margin({top:5}) + } + } + + // Footer构建器 + @Builder + dynamicFooter(onClick: (isShow:boolean) => void ) { + Row({space:5}) { + Text(this.isShowMoreComment ? '--收起' : '--展开更多回复') + .fontColor($r('app.color.main_color')) + .fontSize(13) + Image(this.isShowMoreComment?$r('app.media.closePinglun'):$r('app.media.openPinglun')) + .width(15).height(15) + } + .width(200) + .height(30) + .justifyContent(FlexAlign.Start) + .onClick(()=>onClick(!this.isShowMoreComment)) + } +} diff --git a/features/Home/src/main/ets/model/VideoCommentModel.ets b/features/Home/src/main/ets/model/VideoCommentModel.ets new file mode 100644 index 0000000..af08da5 --- /dev/null +++ b/features/Home/src/main/ets/model/VideoCommentModel.ets @@ -0,0 +1,22 @@ +export interface VideoCommentModel{ + code:string; + data:commentModel[]; + message:string; + msg:string +} + +export interface commentModel{ + name:string; + id:number; + create_date:string; + user_uuid:string; + parent_id:string; + comment_uuid:string; + status:number; + content:string; + examine_status:number; + childs:commentModel[]; + is_parent:boolean; + photo:string; + user_status:number; +} \ No newline at end of file diff --git a/features/Home/src/main/ets/pages/PastVideo.ets b/features/Home/src/main/ets/pages/PastVideo.ets index d04c414..c3a156c 100644 --- a/features/Home/src/main/ets/pages/PastVideo.ets +++ b/features/Home/src/main/ets/pages/PastVideo.ets @@ -121,6 +121,7 @@ export struct PastVideo { } }, (item: string) => JSON.stringify(item)) } .width('100%') + .zIndex(2) .height('100%').backgroundColor(Color.White) } if(this.typelistStatus) @@ -162,6 +163,8 @@ export struct PastVideo { } }, (item: string) => JSON.stringify(item)) } .width('100%') + + .zIndex(3) .height('100%').backgroundColor(Color.White) } } diff --git a/features/Home/src/main/ets/pages/PlayBack.ets b/features/Home/src/main/ets/pages/PlayBack.ets index 738dabd..bf0f028 100644 --- a/features/Home/src/main/ets/pages/PlayBack.ets +++ b/features/Home/src/main/ets/pages/PlayBack.ets @@ -170,7 +170,7 @@ export struct PlayBack { .height('100%').backgroundColor(Color.White) } } - + .layoutWeight(1) } .width('100%') .height('100%') diff --git a/features/register/src/main/ets/view/LoginComp.ets b/features/register/src/main/ets/view/LoginComp.ets index 2c1de6c..a423a08 100644 --- a/features/register/src/main/ets/view/LoginComp.ets +++ b/features/register/src/main/ets/view/LoginComp.ets @@ -90,7 +90,7 @@ export struct LoginComp { getSaveUserInfor(type:number,objs:LoginInfo) { let state:number=objs.data.state if(state!=6) { - perfactAuth.initUser(this.mobile) + // perfactAuth.initUser(this.mobile) router.pushUrl({ url: 'pages/LoginPage/LoginSetInfoPage', // 目标url params: { diff --git a/oh-package-lock.json5 b/oh-package-lock.json5 index f18e42c..015f8d4 100644 --- a/oh-package-lock.json5 +++ b/oh-package-lock.json5 @@ -6,8 +6,10 @@ "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "specifiers": { "@ohos/crypto-js@^2.0.4": "@ohos/crypto-js@2.0.4", + "@ohos/dataorm@^2.2.6": "@ohos/dataorm@2.2.6", "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0", - "@ohos/hypium@1.0.21": "@ohos/hypium@1.0.21" + "@ohos/hypium@1.0.21": "@ohos/hypium@1.0.21", + "reflect-metadata@^0.1.13": "reflect-metadata@0.2.1" }, "packages": { "@ohos/crypto-js@2.0.4": { @@ -17,6 +19,16 @@ "resolved": "https://repo.harmonyos.com/ohpm/@ohos/crypto-js/-/crypto-js-2.0.4.har", "registryType": "ohpm" }, + "@ohos/dataorm@2.2.6": { + "name": "@ohos/dataorm", + "version": "2.2.6", + "integrity": "sha512-qwAQnMxfuG5Imsrq3jjikEUCC/FGqddj0YXe40zUELGdhHegEqkDaxtTp9KIq4fg1ZU/c8fxYNfApx3XZ7E6cA==", + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/dataorm/-/dataorm-2.2.6.har", + "registryType": "ohpm", + "dependencies": { + "reflect-metadata": "^0.1.13" + } + }, "@ohos/hamock@1.0.0": { "name": "@ohos/hamock", "version": "1.0.0", @@ -30,6 +42,14 @@ "integrity": "sha512-iyKGMXxE+9PpCkqEwu0VykN/7hNpb+QOeIuHwkmZnxOpI+dFZt6yhPB7k89EgV1MiSK/ieV/hMjr5Z2mWwRfMQ==", "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.21.har", "registryType": "ohpm" + }, + "reflect-metadata@0.2.1": { + "name": "reflect-metadata", + "version": "0.2.1", + "integrity": "sha512-i5lLI6iw9AU3Uu4szRNPPEkomnkjRTaVt9hy/bn5g/oSzekBSMeLZblcjP74AW0vBabqERLLIrz+gR8QYR54Tw==", + "resolved": "https://repo.harmonyos.com/ohpm/reflect-metadata/-/reflect-metadata-0.2.1.tgz", + "shasum": "8d5513c0f5ef2b4b9c3865287f3c0940c1f67f74", + "registryType": "ohpm" } } } \ No newline at end of file diff --git a/oh-package.json5 b/oh-package.json5 index 36b2fe4..737cde9 100644 --- a/oh-package.json5 +++ b/oh-package.json5 @@ -2,7 +2,8 @@ "modelVersion": "5.0.2", "description": "Please describe the basic information.", "dependencies": { - "@ohos/crypto-js": "^2.0.4" + "@ohos/crypto-js": "^2.0.4", + "@ohos/dataorm": "^2.2.6" }, "devDependencies": { "@ohos/hypium": "1.0.21", diff --git a/polyv/src/main/ets/common/utils/PLVOrientationManager.ts b/polyv/src/main/ets/common/utils/PLVOrientationManager.ts index f1e46ee..ca9b314 100644 --- a/polyv/src/main/ets/common/utils/PLVOrientationManager.ts +++ b/polyv/src/main/ets/common/utils/PLVOrientationManager.ts @@ -14,16 +14,17 @@ export class PLVOrientationManager { } readonly isPortrait: MutableState = new MutableState(isPortrait()) - requestOrientation(orientation: 'port' | 'land') { const context = PLVAbilityContexts.getInstance().lastContext() + console.info('requestOrientation', orientation, context) const windowOrientation = orientation === 'port' ? window.Orientation.PORTRAIT : window.Orientation.LANDSCAPE if (!context) { + console.info('No context found') return } window.getLastWindow(context).then((lastWindow) => { + console.info('Got lastWindow', lastWindow) lastWindow.setPreferredOrientation(windowOrientation) }) } - } \ No newline at end of file diff --git a/products/expert/src/main/ets/models/Huanzhelast444Dao.ets b/products/expert/src/main/ets/models/Huanzhelast444Dao.ets new file mode 100644 index 0000000..0e4c5a9 --- /dev/null +++ b/products/expert/src/main/ets/models/Huanzhelast444Dao.ets @@ -0,0 +1,177 @@ +import { huanzheDb } from '@itcast/basic'; +import { Huanzhelast444Model } from '@itcast/basic'; +import common from '@ohos.app.ability.common'; +import fs from '@ohos.file.fs'; +import relationalStore from '@ohos.data.relationalStore'; + +export interface Huanzhelast444Result { + code: number; // 0: 成功, 1: 文件不存在, 2: 表不存在, 3: 其它错误 + msg: string; + data?: Huanzhelast444Model[]; +} + +export class Huanzhelast444Dao { + /** + * 获取所有患者数据,并检查数据库文件和表是否存在。 + * @param context 应用上下文 + * @returns Huanzhelast444Result + */ + // static async getAll(context: common.Context): Promise { + // console.info('getAll called'); + // const dbFileName = 'huanzhelas.sqlite'; + // const dbPath = context.filesDir + '/' + dbFileName; + // // 1. 检查数据库文件是否存在 + // let fileExists = false; + // try { + // fileExists = fs.accessSync(dbPath); + // } catch (e) { + // fileExists = false; + // } + // // 2. 如不存在则尝试复制 + // if (!fileExists) { + // try { + // const resourceMgr = context.resourceManager; + // const rawFile = await resourceMgr.getRawFileContent(dbFileName); + // const arrayBuffer = rawFile.buffer; + // // 确保目录存在 + // try { fs.accessSync(context.filesDir); } catch (e) { fs.mkdirSync(context.filesDir); } + // // 复制前删除旧文件 + // if (fs.accessSync(dbPath)) { + // fs.unlinkSync(dbPath); + // } + // // 复制数据库文件(确保完整写入) + // const file = fs.openSync(dbPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); + // const buffer = new Uint8Array(arrayBuffer); + // fs.writeSync(file.fd, buffer, 0, buffer.length); + // fs.closeSync(file); + // // 复制后校验文件大小 + // const stat = fs.statSync(dbPath); + // console.info('数据库文件大小:', stat.size, '原始大小:', buffer.length); + // fs.accessSync(dbPath); // 再次检查 + // fileExists = true; + // } catch (e) { + // return { code: 1, msg: '数据库文件移动失败: ' + e }; + // } + // } + // // 3. 初始化数据库并查询 + // try { + // await huanzheDb.initDatabase(context); + // // 直接用 helper 的查询方法 + // const rawList = await huanzheDb.queryHuanzhelastData() as Partial[]; + // // 用 Huanzhelast444Model 构造实例数组 + // const dataList: Huanzhelast444Model[] = rawList.map((item) => new Huanzhelast444Model( + // item._id ?? 0, + // item.id ?? 0, + // item.fullname ?? '', + // item.name ?? '', + // item.parent ?? 0, + // item.treePath ?? '' + // )); + // console.info('getAll return:', JSON.stringify({ code: 0, msg: '查询成功', data: dataList })); + // return { code: 0, msg: '查询成功', data: dataList }; + // } catch (e) { + // // 判断表不存在的情况 + // if (typeof e === 'string' && e.indexOf('no such table') !== -1) { + // return { code: 2, msg: '表 t_huanzhelast444 不存在' }; + // } + // return { code: 3, msg: '数据查询失败: ' + e }; + // } + // } + + /** + * 直接独立实现:获取所有患者数据,判断文件移动、表存在、数据查询。 + * @param context 应用上下文 + * @returns Huanzhelast444Result + */ + static async getAllDirect(context: common.Context): Promise { + const dbFileName = 'huanzhelas.sqlite'; + const dbPath = context.databaseDir + '/' + dbFileName; + // 1. 检查数据库文件是否存在 + let fileExists = fs.accessSync(dbPath); + + // 2. 如不存在则尝试复制 + if (!fileExists) { + try { + const resourceMgr = context.resourceManager; + const rawFile = await resourceMgr.getRawFileContent(dbFileName); + const arrayBuffer = rawFile.buffer; + // 确保目录存在 + try { fs.accessSync(context.databaseDir); } catch (e) { fs.mkdirSync(context.databaseDir); } + // 复制前删除旧文件 + if (fs.accessSync(dbPath)) { + fs.unlinkSync(dbPath); + } + // 复制数据库文件(确保完整写入) + const file = fs.openSync(dbPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); + const buffer = new Uint8Array(arrayBuffer); + fs.writeSync(file.fd, buffer); // offset=0, length=buffer.length + fs.closeSync(file); + // 复制后校验文件大小 + const stat = fs.statSync(dbPath); + console.info('数据库文件大小:', stat.size, '原始大小:', buffer.length); + fileExists = true; + } catch (e) { + return { code: 1, msg: '数据库文件移动失败: ' + e } as Huanzhelast444Result; + } + } + // 3. 用 relationalStore 直接操作数据库 + let rdbStore: relationalStore.RdbStore | null = null; + try { + const storeConfig: relationalStore.StoreConfig = { name: dbFileName, securityLevel: relationalStore.SecurityLevel.S1 }; + rdbStore = await relationalStore.getRdbStore(context, storeConfig); + } catch (e) { + return { code: 1, msg: '数据库文件打开失败: ' + e } as Huanzhelast444Result; + } + // 4. 检查表是否存在 + try { + // 复制后,打印所有表名 + const resultSet = await rdbStore.querySql("SELECT name FROM sqlite_master WHERE type='table'", []); + if (resultSet.rowCount > 0) { + resultSet.goToFirstRow(); + do { + console.info('数据库中存在的表:', resultSet.getString(0)); + } while (resultSet.goToNextRow()); + } + resultSet.close(); + // const resultSet = await rdbStore.querySql("SELECT name FROM sqlite_master WHERE type='table' AND name='t_huanzhelast444'", []); + // let hasTable = false; + // if (resultSet.rowCount > 0) { + // resultSet.goToFirstRow(); + // do { + // if (resultSet.getString(0) === 't_huanzhelast444') { + // hasTable = true; + // break; + // } + // } while (resultSet.goToNextRow()); + // } + // resultSet.close(); + // if (!hasTable) { + // return { code: 2, msg: '表 t_huanzhelast444 不存在' } as Huanzhelast444Result; + // } + } catch (e) { + return { code: 3, msg: '表检查失败: ' + e } as Huanzhelast444Result; + } + // 5. 查询所有数据 + try { + const resultSet = await rdbStore.querySql('SELECT _id, id, fullname, name, parent, treePath FROM t_huanzhelast444', []); + const dataList: Huanzhelast444Model[] = []; + if (resultSet.rowCount > 0) { + resultSet.goToFirstRow(); + do { + dataList.push(new Huanzhelast444Model( + resultSet.getDouble(0), + resultSet.getDouble(1), + resultSet.getString(2), + resultSet.getString(3), + resultSet.getDouble(4), + resultSet.getString(5) + )); + } while (resultSet.goToNextRow()); + } + resultSet.close(); + return { code: 0, msg: '查询成功', data: dataList } as Huanzhelast444Result; + } catch (e) { + return { code: 3, msg: '数据查询失败: ' + e } as Huanzhelast444Result; + } + } +} diff --git a/products/expert/src/main/ets/pages/MinePage/MyPage.ets b/products/expert/src/main/ets/pages/MinePage/MyPage.ets index 6f051cd..227f9cf 100644 --- a/products/expert/src/main/ets/pages/MinePage/MyPage.ets +++ b/products/expert/src/main/ets/pages/MinePage/MyPage.ets @@ -1,5 +1,4 @@ import { MyHomePage } from 'mypage' -import { emitter } from '@kit.BasicServicesKit'; @Entry @Component diff --git a/products/expert/src/main/ets/pages/VideoPage/CommentReplyPage.ets b/products/expert/src/main/ets/pages/VideoPage/CommentReplyPage.ets new file mode 100644 index 0000000..62c1404 --- /dev/null +++ b/products/expert/src/main/ets/pages/VideoPage/CommentReplyPage.ets @@ -0,0 +1,76 @@ +import { HdNav,BasicConstant } from '@itcast/basic' +import { emitter } from '@kit.BasicServicesKit' +import { router,promptAction } from '@kit.ArkUI'; +import { hdHttp, HdResponse ,logger} from '@itcast/basic/Index' +import HashMap from '@ohos.util.HashMap'; +import { BusinessError } from '@kit.BasicServicesKit'; +import inputMethod from '@ohos.inputMethod'; + +@Entry +@Component +struct CommentReplyPage { + @State params:Record = router.getParams() as Record; + @State finalContent: string = ''; + hashMap: HashMap = new HashMap(); + + aboutToAppear() { + emitter.on({ eventId: 250516 }, () => { + this.commitAction() + }) + } + + aboutToDisappear() { + emitter.off(250516) + } + + commitAction() { + inputMethod.getController().hideTextInput();//关闭键盘 + if (this.finalContent.length === 0) { + promptAction.showToast({ message: '请输入回复内容', duration: 1000 }) + return; + } + this.hashMap.clear(); + this.hashMap.set('article_uuid', this.params.comment_id) + this.hashMap.set('comment', `${this.finalContent}||${this.params.replyName}:${this.params.comment}`) + this.hashMap.set('type', '8') + hdHttp.httpReq(BasicConstant.addCommentV2,this.hashMap).then(async (res: HdResponse) => { + logger.info('Response replyComment:'+res); + let json:CommentV2Model = JSON.parse(res+'') as CommentV2Model; + if(json.code == 200) { + emitter.emit({ + eventId: 250529, + priority: emitter.EventPriority.HIGH + }) + promptAction.showToast({ message: '回复评论成功', duration: 1000 }) + router.back(); + } else { + promptAction.showToast({ message: json.message, duration: 1000 }) + } + }).catch((err: BusinessError) => { + }) + } + + build() { + Column() { + HdNav({ title: '回复', showRightIcon: false, showLeftIcon: true,showRightText:true,rightText:'确定'}) + TextArea({placeholder:`回复:${this.params.replyName}`}) + .fontSize(14) + .width('100%') + .height('50%') + .backgroundColor(Color.White) + .onChange((value: string) => { + this.finalContent = value; // 实时更新临时内容[3](@ref) + console.info('回复输入框内容:', this.finalContent); + }) + } + .height('100%') + .width('100%') + } +} + +export interface CommentV2Model{ + code:number; + data:Object[]; + message:string; + msg:string +} \ No newline at end of file diff --git a/products/expert/src/main/ets/pages/VideoPage/PLVMediaPlayerSingleVideoPage.ets b/products/expert/src/main/ets/pages/VideoPage/PLVMediaPlayerSingleVideoPage.ets index 002e90e..7d899cb 100644 --- a/products/expert/src/main/ets/pages/VideoPage/PLVMediaPlayerSingleVideoPage.ets +++ b/products/expert/src/main/ets/pages/VideoPage/PLVMediaPlayerSingleVideoPage.ets @@ -10,16 +10,18 @@ import { } from 'media-player-common'; import common from '@ohos.app.ability.common'; import window from '@ohos.window'; -import router from '@ohos.router'; import { createDependScope } from '@polyvharmony/media-player-sdk' import { - commonPageModule, + commonPageModule,getDisplayWindowWidth } from 'media-player-common' import { HdNav,BasicConstant } from '@itcast/basic' import HashMap from '@ohos.util.HashMap'; import { hdHttp, HdResponse ,logger} from '@itcast/basic/Index' -import { BusinessError } from '@kit.BasicServicesKit'; -import { VideoDetailModel } from 'home' +import { emitter,BusinessError } from '@kit.BasicServicesKit'; +import { VideoDetailModel,VideoCommentModel,commentModel,VideoDetailsComment } from 'home' +import { router,promptAction } from '@kit.ArkUI'; +import inputMethod from '@ohos.inputMethod'; + @Entry @Component export struct PLVMediaPlayerSingleVideoPage { @@ -32,7 +34,10 @@ export struct PLVMediaPlayerSingleVideoPage { private pageControlViewModel: PLVMPPageControlViewModel = this.pageDependScope.get(PLVMPPageControlViewModel) private onBackPressDisposable: Disposable | undefined = undefined private readonly plv_media_player_single_video_background: string = createId() - hashMap: HashMap = new HashMap(); + + @State isPortrait: boolean = true;//是否竖屏 + @State commentList:Array = [];//评论列表 + @State commentContent:string = '';//评论内容 @State note:string='' aboutToAppear(): void { @@ -43,7 +48,19 @@ export struct PLVMediaPlayerSingleVideoPage { windowInstance.setWindowKeepScreenOn(true) }) this.getVideoDetail(this.params.video_uuid) + this.getCommentdata(this.params.video_uuid) + + PLVOrientationManager.getInstance().isPortrait.observe((isPortrait) => { + if (typeof isPortrait === 'boolean') { + this.isPortrait = isPortrait + } + }) + + emitter.on({ eventId: 250529 }, () => { + this.getCommentdata(this.params.video_uuid) + }) } + @State currentIndex: number = 0; @Builder tabBuilder(title: string, targetIndex: number) { @@ -61,7 +78,10 @@ export struct PLVMediaPlayerSingleVideoPage { } build() { Column(){ - HdNav({ title: '视频详情', showRightIcon: false, showLeftIcon: true}) + if (this.isPortrait) { + HdNav({ title: '视频详情', showRightIcon: false, showLeftIcon: true }) + } + Stack() { // 背景图 // Image($r('app.media.plv_media_player_video_item_background_portrait')) @@ -78,21 +98,62 @@ export struct PLVMediaPlayerSingleVideoPage { PLVOrientationManagerObserver() } .width('100%') - .height(204) + .height(this.getPlayerAreaHeight()) + Tabs() { TabContent() { Text(this.note).fontSize(14).fontColor(Color.Black) } .align(Alignment.TopStart) .padding(15) - .tabBar(this.tabBuilder('视频简介', 0)) + .customTabbar('视频简介') TabContent() { - Text('推荐的内容').fontSize(30).alignSelf(ItemAlign.Start) - } - .tabBar(this.tabBuilder('评论', 1)) + Column() { + List(){ + ForEach(this.commentList,(model:commentModel)=>{ + ListItem(){ + VideoDetailsComment({model:model,videoCommentUuid:this.params.video_uuid}); + } + }) + }.height('calc(100% - 100vp)').width('100%').backgroundColor('#f4f4f4').scrollBar(BarState.Off) + Row({space:10}) { + Row() { + TextInput({ placeholder: '我也说一句',text:this.commentContent }) + .fontSize(17) + .backgroundColor(Color.White) + .width('95%') + .onChange((value: string) => { + this.commentContent = value; // 实时更新临时内容[3](@ref) + console.info('视频详情评论输入框内容:', this.commentContent); + }) + }.borderRadius(5).borderWidth(1).borderColor('#333333').backgroundColor(Color.White).height(50).width('calc(100% - 100vp)') + .margin({ left: 10,top: 10 }) - }.layoutWeight(1) + Button('发送') + .borderRadius(5) + .type(ButtonType.ROUNDED_RECTANGLE) + .backgroundColor($r('app.color.main_color')) + .fontColor(Color.White) + .fontSize(17) + .width(70).height(50) + .margin({top:10}) + .onClick(()=>{ + this.addComment(); + }) + }.backgroundColor(Color.White).width('100%').height(100).justifyContent(FlexAlign.Start).alignItems(VerticalAlign.Top) + // Button('推荐的内容').fontSize(30).alignSelf(ItemAlign.Start) + } + .justifyContent(FlexAlign.End) + } + .backgroundColor('#f4f4f4') + .customTabbar('评论') + } + .divider( { + strokeWidth: 1, + color: $r('app.color.common_gray_border'), + }) + .layoutWeight(1) .onChange((index: number) => { this.currentIndex = index; }) @@ -100,6 +161,14 @@ export struct PLVMediaPlayerSingleVideoPage { } + getPlayerAreaHeight(): string | number { + if (this.isPortrait) { + return getDisplayWindowWidth().vp / 16 * 9 + } else { + return '100%' + } + } + onBackPress(): boolean { if (!PLVOrientationManager.getInstance().isPortrait.value) { PLVOrientationManager.getInstance().requestOrientation('port'); @@ -114,26 +183,84 @@ export struct PLVMediaPlayerSingleVideoPage { const windowInstance = await window.getLastWindow(this.context) windowInstance.setWindowKeepScreenOn(false) }) + + emitter.off(250529) } - getVideoDetail(video_uuid:string) - { - this.hashMap.clear(); - this.hashMap.set('video_uuid', video_uuid) - hdHttp.httpReq(BasicConstant.videoDetail,this.hashMap).then(async (res: HdResponse) => { + getVideoDetail(video_uuid:string) { + const hashMap: HashMap = new HashMap(); + hashMap.clear(); + hashMap.set('video_uuid', video_uuid) + hdHttp.httpReq(BasicConstant.videoDetail,hashMap).then(async (res: HdResponse) => { logger.info('Response videoDetails'+video_uuid); logger.info('Response videoDetail'+res); let json:VideoDetailModel = JSON.parse(res+'') as VideoDetailModel; this.note=json.video.note - }).catch((err: BusinessError) => { + }) + } + getCommentdata(video_uuid:string) { + const hashMap: HashMap = new HashMap(); + hashMap.clear(); + hashMap.set('uuid', video_uuid) + hdHttp.httpReq(BasicConstant.videoCommentListV2,hashMap).then(async (res: HdResponse) => { + logger.info('Response videoDetails commentList:'+video_uuid); + logger.info('Response videoDetail commentList:'+res); + let json:VideoCommentModel = JSON.parse(res+'') as VideoCommentModel; + if(json.data != null && json.data!) { + this.commentList = json.data; + } + }).catch((err: BusinessError) => { + }) + } + addComment() { + inputMethod.getController().hideTextInput();//关闭键盘 + if (this.commentContent.length == 0) { + promptAction.showToast({ message: '请输入评论内容', duration: 1000 }) + return; + } + + const hashMap: HashMap = new HashMap(); + hashMap.set('article_uuid', this.params.video_uuid) + hashMap.set('comment', this.commentContent) + hashMap.set('type', '8') + hdHttp.httpReq(BasicConstant.addCommentV2,hashMap).then(async (res: HdResponse) => { + logger.info('Response replyComment:'+res); + let json:CommentV2Model = JSON.parse(res+'') as CommentV2Model; + if(json.code == 200) { + promptAction.showToast({ message: '发表评论成功', duration: 1000 }) + this.getCommentdata(this.params.video_uuid); + this.commentContent = ''; + } else { + promptAction.showToast({ message: json.message, duration: 1000 }) + } + }).catch((err: BusinessError) => { }) } } -interface VideoPageParam -{ + +@Extend(TabContent) +function customTabbar(name:string) { + .tabBar(SubTabBarStyle.of(name) + .labelStyle({ unselectedColor: '#848284', selectedColor:'#8D2316' , font: { size: 17 }}) + .indicator({ + color: '#8D2316', //下划线颜色 + height: 1, //下划线高度 + marginTop:16 //下划线与文字间距 + })) + .height('100%') +} + +interface VideoPageParam { video_uuid:string param:PLVMediaPlayerSingleVideoPageParam +} + +export interface CommentV2Model{ + code:number; + data:Object[]; + message:string; + msg:string } \ No newline at end of file diff --git a/products/expert/src/main/resources/base/profile/main_pages.json b/products/expert/src/main/resources/base/profile/main_pages.json index 8e57da9..6467180 100644 --- a/products/expert/src/main/resources/base/profile/main_pages.json +++ b/products/expert/src/main/resources/base/profile/main_pages.json @@ -24,6 +24,7 @@ "pages/VideoPage/PLVMediaPlayerSingleVideoPage", "pages/WebView/LivebroadcastPages", "pages/VideoPage/PastVideoPage", - "pages/VideoPage/VideoGandanPage" + "pages/VideoPage/VideoGandanPage", + "pages/VideoPage/CommentReplyPage" ] } \ No newline at end of file diff --git a/scene_single_video/src/main/ets/scene/single/PLVMediaPlayerSingleVideoLayout.ets b/scene_single_video/src/main/ets/scene/single/PLVMediaPlayerSingleVideoLayout.ets index 289cb64..0b84fea 100644 --- a/scene_single_video/src/main/ets/scene/single/PLVMediaPlayerSingleVideoLayout.ets +++ b/scene_single_video/src/main/ets/scene/single/PLVMediaPlayerSingleVideoLayout.ets @@ -25,6 +25,8 @@ import { import { PLVMediaPlayerAuxiliaryLayout } from './component/PLVMediaPlayerAuxiliaryLayout'; import { PLVMediaPlayerSingleVideoControllerLayout } from './layout/PLVMediaPlayerSingleVideoControllerLayout'; import { PLVMediaPlayerSingleVideoFloatActionLayout } from './layout/PLVMediaPlayerSingleVideoFloatActionLayout'; +import {PLVAbilityContexts} from 'media-player-common'; +import common from '@ohos.app.ability.common'; @Preview @Component @@ -55,6 +57,8 @@ export struct PLVMediaPlayerSingleVideoLayout { aboutToAppear(): void { requireNotNull(this.mediaResource, () => 'mediaResource must not be null') + const context = getContext(this) as common.UIAbilityContext; + PLVAbilityContexts.getInstance().registerContext(context) this.observeMediaViewState() this.observeOrientation() this.downloadItemViewModel.setDownloadActionVisible(!this.enterFromDownloadCenter) @@ -71,6 +75,7 @@ export struct PLVMediaPlayerSingleVideoLayout { this.viewModel.setPlayerOption([ PLVMediaPlayerOptionEnum.ENABLE_ACCURATE_SEEK.value("1"), PLVMediaPlayerOptionEnum.SKIP_ACCURATE_SEEK_AT_START.value("1"), + PLVMediaPlayerOptionEnum.START_ON_PREPARED.value("0"), ]) this.viewModel.setMediaResource(this.mediaResource) }