yangsunyue_wd

desc:评论相关

@@ -15,7 +15,7 @@ export class publishCommentModel { @@ -15,7 +15,7 @@ export class publishCommentModel {
15 /*【迭代二新增】关联的频道id/专题id; 页面必传*/ 15 /*【迭代二新增】关联的频道id/专题id; 页面必传*/
16 targetRelObjectId: string = "" 16 targetRelObjectId: string = ""
17 /*【迭代二新增】是否是重点稿件 1是 0否 页面必传*/ 17 /*【迭代二新增】是否是重点稿件 1是 0否 页面必传*/
18 - keyArticle: string = '' 18 + keyArticle: string = '0'
19 /*内容类别, 1:点播,2:直播,3:活动,4:广告,5:专题,6:链接,7:榜单,8:图文,9:组图,10:H5新闻,11:频道,12:组件,13:音频,14:动态(13和14为中文版新增) 页面必传*/ 19 /*内容类别, 1:点播,2:直播,3:活动,4:广告,5:专题,6:链接,7:榜单,8:图文,9:组图,10:H5新闻,11:频道,12:组件,13:音频,14:动态(13和14为中文版新增) 页面必传*/
20 targetType: string = '' 20 targetType: string = ''
21 /*评论总数*/ 21 /*评论总数*/
@@ -9,8 +9,9 @@ import measure from '@ohos.measure' @@ -9,8 +9,9 @@ import measure from '@ohos.measure'
9 import { CommentCustomDialog } from './CommentCustomDialog' 9 import { CommentCustomDialog } from './CommentCustomDialog'
10 import { publishCommentModel } from '../model/PublishCommentModel'; 10 import { publishCommentModel } from '../model/PublishCommentModel';
11 import { ifaa } from '@kit.OnlineAuthenticationKit'; 11 import { ifaa } from '@kit.OnlineAuthenticationKit';
12 -import { HttpUrlUtils } from 'wdNetwork/Index'; 12 +import { HttpUrlUtils, HttpUtils } from 'wdNetwork/Index';
13 import NoMoreLayout from '../../page/NoMoreLayout'; 13 import NoMoreLayout from '../../page/NoMoreLayout';
  14 +import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
14 15
15 const TAG = 'CommentComponent'; 16 const TAG = 'CommentComponent';
16 17
@@ -559,6 +560,12 @@ struct commentFooterView { @@ -559,6 +560,12 @@ struct commentFooterView {
559 560
560 } 561 }
561 .onClick(() => { 562 .onClick(() => {
  563 + // 未登录,跳转登录
  564 + const user_id = HttpUtils.getUserId()
  565 + if (!user_id) {
  566 + WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
  567 + return
  568 + }
562 commentLikeChange(this.item) 569 commentLikeChange(this.item)
563 commentViewModel.commentLike(this.item).then(() => { 570 commentViewModel.commentLike(this.item).then(() => {
564 }).catch(() => { 571 }).catch(() => {
@@ -7,17 +7,17 @@ import commentViewModel from '../viewmodel/CommentViewModel' @@ -7,17 +7,17 @@ import commentViewModel from '../viewmodel/CommentViewModel'
7 @Preview 7 @Preview
8 @CustomDialog 8 @CustomDialog
9 export struct CommentCustomDialog { 9 export struct CommentCustomDialog {
10 -  
11 @ObjectLink publishCommentModel: publishCommentModel 10 @ObjectLink publishCommentModel: publishCommentModel
12 controller?: CustomDialogController 11 controller?: CustomDialogController
13 confirm: (value: Record<string, string>) => void = () => { 12 confirm: (value: Record<string, string>) => void = () => {
14 } 13 }
15 @State private emojiSwitch: boolean = false 14 @State private emojiSwitch: boolean = false
16 textInputController: TextAreaController = new TextAreaController() 15 textInputController: TextAreaController = new TextAreaController()
  16 + @State positionInfo: CaretOffset = { index: 0, x: 0, y: 0 }
17 17
18 aboutToAppear(): void { 18 aboutToAppear(): void {
19 19
20 - 20 + // this.textInputController.caretPosition(0)
21 } 21 }
22 22
23 publishCommentRequest() { 23 publishCommentRequest() {
@@ -25,7 +25,7 @@ export struct CommentCustomDialog { @@ -25,7 +25,7 @@ export struct CommentCustomDialog {
25 // this.publishCommentModel.commentContent = this.commentText 25 // this.publishCommentModel.commentContent = this.commentText
26 //TODO 判断类型 26 //TODO 判断类型
27 this.publishCommentModel.commentType = '2' 27 this.publishCommentModel.commentType = '2'
28 - commentViewModel.publishComment(this.publishCommentModel).then((model:commentItemModel) => { 28 + commentViewModel.publishComment(this.publishCommentModel).then((model: commentItemModel) => {
29 this.publishCommentModel.commentContent = '' 29 this.publishCommentModel.commentContent = ''
30 // 30 //
31 31
@@ -74,12 +74,13 @@ export struct CommentCustomDialog { @@ -74,12 +74,13 @@ export struct CommentCustomDialog {
74 .height(30) 74 .height(30)
75 .onClick(() => { 75 .onClick(() => {
76 76
77 - // this.commentText = this.commentText + '神鼎' 77 + this.positionInfo = this.textInputController.getCaretOffset()
  78 +
78 this.emojiSwitch = !this.emojiSwitch 79 this.emojiSwitch = !this.emojiSwitch
79 if (this.emojiSwitch) { 80 if (this.emojiSwitch) {
80 this.textInputController.stopEditing() 81 this.textInputController.stopEditing()
81 } else { 82 } else {
82 - this.textInputController.caretPosition(this.textInputController.getTextContentRect().x) 83 + // this.textInputController.caretPosition(this.textInputController.getTextContentRect().x)
83 } 84 }
84 85
85 }) 86 })
@@ -116,7 +117,7 @@ export struct CommentCustomDialog { @@ -116,7 +117,7 @@ export struct CommentCustomDialog {
116 117
117 //表情view 118 //表情view
118 if (this.emojiSwitch) { 119 if (this.emojiSwitch) {
119 - emojiView() 120 + emojiView({ publishCommentModel: this.publishCommentModel }).height(150)
120 } 121 }
121 122
122 }.backgroundColor(Color.White) 123 }.backgroundColor(Color.White)
@@ -129,8 +130,88 @@ export struct CommentCustomDialog { @@ -129,8 +130,88 @@ export struct CommentCustomDialog {
129 130
130 @Component 131 @Component
131 struct emojiView { 132 struct emojiView {
  133 + @ObjectLink publishCommentModel: publishCommentModel
  134 + /*没找到获取系统emoji的方案*/
  135 + private emojiString = '😀,😁,😂,😃,😄,😅,😆,😇,😈,😉,😊,😋,😌,😍,😎,😏,😐,😑,😒,😓,😔,😕,😖,😗,😘,😙,😚,😛,😜,😝,😞,😟,😠,😡,😢,😣,😤,😥,😦,😧,😨,😩,😪,😫,😬,😭,😮,😯,😰,😱,😲,😳,😴,😵,😶,😷,😸,😹,😺,😻,😼,😽,😾,😿,🙀,🙅,🙆,🙇,🙈,🙉,🙊,🙋,🙌,🙍,🙎,🙏'
  136 + private displayArray: string[][] = []
  137 + private swiperController: SwiperController = new SwiperController()
  138 +
  139 + aboutToAppear(): void {
  140 +
  141 +
  142 +
  143 + this.displayArray = chunk(this.emojiString.split(','), 20)
  144 +
  145 + //补上删除按钮以及空白占位
  146 + let lastElement = this.displayArray.slice(-1)[0];
  147 + if (lastElement.length < 20) {
  148 + let needLength = (20 - lastElement.length)
  149 + for (let index = 0; index < needLength; index++) {
  150 + lastElement.push('')
  151 + }
  152 + }
  153 +
  154 + this.displayArray.forEach(element => {
  155 + element.push('删除')
  156 + });
  157 +
  158 + }
  159 +
132 build() { 160 build() {
  161 +
  162 + // String.fromCodePoint()
  163 + Swiper(this.swiperController) {
  164 +
  165 + ForEach(this.displayArray, (array: [], index) => {
  166 + Column() {
  167 + Grid() {
  168 + ForEach(array, (emoji: string, subIndex: number) => {
  169 + GridItem() {
  170 + Text() {
  171 + if (emoji == '删除') {
  172 + ImageSpan($r('app.media.wdInput_delete'))
  173 + } else {
  174 + Span(emoji)
  175 + }
  176 +
  177 + }.textAlign(TextAlign.Center).width(30).height(30)
  178 +
  179 + // .backgroundColor(Color.Orange)
  180 + }.onClick(() => {
  181 + if (emoji == '删除') {
  182 + this.publishCommentModel.commentContent = this.publishCommentModel.commentContent.substring(0, this.publishCommentModel.commentContent.length -1)
  183 + } else if (emoji == '') {
  184 +
  185 + } else {
  186 + this.publishCommentModel.commentContent = this.publishCommentModel.commentContent + emoji
  187 + }
  188 +
  189 + })
  190 + })
  191 + }
  192 + .maxCount(6)
  193 + .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr')
  194 + .rowsGap(10)
  195 + .layoutDirection(GridDirection.Row)
  196 +
  197 + Row().height(40)
  198 + }
  199 + })
  200 + }
  201 + .indicator(true)
  202 + .vertical(false)
  203 + .height(140)
  204 + }
  205 +}
  206 +
  207 +function chunk<T>(array: T[], size: number): T[][] {
  208 + const result: T[][] = [];
  209 +
  210 + for (let i = 0; i < array.length; i += size) {
  211 + result.push(array.slice(i, i + size));
133 } 212 }
  213 +
  214 + return result;
134 } 215 }
135 216
136 217
@@ -5,12 +5,16 @@ import commentViewModel from '../viewmodel/CommentViewModel' @@ -5,12 +5,16 @@ import commentViewModel from '../viewmodel/CommentViewModel'
5 import { router, window } from '@kit.ArkUI' 5 import { router, window } from '@kit.ArkUI'
6 import { CustomTitleUI } from '../../reusable/CustomTitleUI' 6 import { CustomTitleUI } from '../../reusable/CustomTitleUI'
7 import { MyCommentDataSource } from '../model/MyCommentDataSource' 7 import { MyCommentDataSource } from '../model/MyCommentDataSource'
8 -import { HttpUrlUtils } from 'wdNetwork/Index' 8 +import { HttpUrlUtils, HttpUtils } from 'wdNetwork/Index'
9 import PageModel from '../../../viewmodel/PageModel' 9 import PageModel from '../../../viewmodel/PageModel'
10 import { ErrorComponent } from '../../view/ErrorComponent' 10 import { ErrorComponent } from '../../view/ErrorComponent'
11 import { EmptyComponent , WDViewDefaultType} from '../../view/EmptyComponent' 11 import { EmptyComponent , WDViewDefaultType} from '../../view/EmptyComponent'
12 import { CustomPullToRefresh } from '../../reusable/CustomPullToRefresh' 12 import { CustomPullToRefresh } from '../../reusable/CustomPullToRefresh'
13 import NoMoreLayout from '../../page/NoMoreLayout' 13 import NoMoreLayout from '../../page/NoMoreLayout'
  14 +import { CommentCustomDialog } from './CommentCustomDialog'
  15 +import { publishCommentModel } from '../model/PublishCommentModel'
  16 +import { ifaa } from '@kit.OnlineAuthenticationKit'
  17 +import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'
14 18
15 const TAG = 'QualityCommentsComponent'; 19 const TAG = 'QualityCommentsComponent';
16 20
@@ -24,9 +28,6 @@ export struct QualityCommentsComponent { @@ -24,9 +28,6 @@ export struct QualityCommentsComponent {
24 @State hasMore: boolean = true; 28 @State hasMore: boolean = true;
25 @State currentPage: number = 1; 29 @State currentPage: number = 1;
26 private scroller: Scroller = new Scroller(); 30 private scroller: Scroller = new Scroller();
27 -  
28 -  
29 -  
30 @State tileOpacity: number = 0; 31 @State tileOpacity: number = 0;
31 firstPositionY: number = 0; 32 firstPositionY: number = 0;
32 bottomSafeHeight: string = AppStorage.get<number>('bottomSafeHeight') + 'px'; 33 bottomSafeHeight: string = AppStorage.get<number>('bottomSafeHeight') + 'px';
@@ -34,6 +35,11 @@ export struct QualityCommentsComponent { @@ -34,6 +35,11 @@ export struct QualityCommentsComponent {
34 lastWindowColor: string = '#ffffff' 35 lastWindowColor: string = '#ffffff'
35 currentWindowColor: string = '#FF4202' 36 currentWindowColor: string = '#FF4202'
36 @State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource(); 37 @State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource();
  38 + @State dialogController: CustomDialogController | null = null;
  39 +
  40 + /*必传*/
  41 + @State publishCommentModel: publishCommentModel = new publishCommentModel()
  42 +
37 43
38 aboutToDisappear(): void { 44 aboutToDisappear(): void {
39 45
@@ -43,13 +49,33 @@ export struct QualityCommentsComponent { @@ -43,13 +49,33 @@ export struct QualityCommentsComponent {
43 windowClass.setWindowLayoutFullScreen(false) 49 windowClass.setWindowLayoutFullScreen(false)
44 // windowClass.setWindowSystemBarProperties({ statusBarColor: '#000' }) 50 // windowClass.setWindowSystemBarProperties({ statusBarColor: '#000' })
45 51
  52 + this.dialogController = null // 将dialogController置空
  53 +
46 } 54 }
47 55
48 aboutToAppear(): void { 56 aboutToAppear(): void {
49 57
50 this.fullScreen(); 58 this.fullScreen();
51 this.getData(); 59 this.getData();
  60 + this.showAlert()
  61 + }
52 62
  63 + showAlert(){
  64 + this.dialogController = new CustomDialogController({
  65 + builder: CommentCustomDialog({
  66 + confirm: (value: Record<string, string>) => {
  67 +
  68 + },
  69 + publishCommentModel: this.publishCommentModel
  70 + }),
  71 + autoCancel: true,
  72 + alignment: DialogAlignment.Bottom,
  73 + customStyle: true,
  74 + offset: {
  75 + dx: 0,
  76 + dy: -20
  77 + },
  78 + })
53 } 79 }
54 80
55 getData(resolve?: (value: string | PromiseLike<string>) => void){ 81 getData(resolve?: (value: string | PromiseLike<string>) => void){
@@ -217,7 +243,7 @@ export struct QualityCommentsComponent { @@ -217,7 +243,7 @@ export struct QualityCommentsComponent {
217 // ListItemGroup({ header: this.titleHeader() }) 243 // ListItemGroup({ header: this.titleHeader() })
218 LazyForEach(this.allDatas, (item: commentItemModel, index: number) => { 244 LazyForEach(this.allDatas, (item: commentItemModel, index: number) => {
219 ListItem() { 245 ListItem() {
220 - QualityCommentItem({ item: item, index: index }).margin({ left: 12, right: 12 }) 246 + QualityCommentItem({ item: item, index: index , dialogController:this.dialogController, publishCommentModel:this.publishCommentModel}).margin({ left: 12, right: 12 })
221 } 247 }
222 }) 248 })
223 // 加载更多 249 // 加载更多
@@ -243,16 +269,6 @@ export struct QualityCommentsComponent { @@ -243,16 +269,6 @@ export struct QualityCommentsComponent {
243 } 269 }
244 270
245 271
246 - @Builder  
247 - testLayout(){  
248 - List({ space: 12, scroller:this.scroller }){  
249 - LazyForEach(this.allDatas, (item: commentItemModel, index: number) => {  
250 - ListItem() {  
251 - QualityCommentItem({ item: item, index: index }).margin({ left: 12, right: 12 })  
252 - }  
253 - })  
254 - }  
255 - }  
256 272
257 } 273 }
258 274
@@ -261,6 +277,8 @@ export struct QualityCommentsComponent { @@ -261,6 +277,8 @@ export struct QualityCommentsComponent {
261 277
262 @Component 278 @Component
263 struct QualityCommentItem { 279 struct QualityCommentItem {
  280 + @ObjectLink publishCommentModel: publishCommentModel
  281 + dialogController: CustomDialogController | null = null;
264 @ObjectLink item: commentItemModel 282 @ObjectLink item: commentItemModel
265 index: number = 0 283 index: number = 0
266 284
@@ -360,7 +378,20 @@ struct QualityCommentItem { @@ -360,7 +378,20 @@ struct QualityCommentItem {
360 Row({ space: 16 }) { 378 Row({ space: 16 }) {
361 Row() { 379 Row() {
362 Image($r('app.media.comment_icon_pinglun')).width(16).height(16) 380 Image($r('app.media.comment_icon_pinglun')).width(16).height(16)
363 - } 381 + }.onClick(()=>{
  382 + this.publishCommentModel.targetId = this.item.targetId
  383 + this.publishCommentModel.targetRelId = this.item.targetRelId
  384 + this.publishCommentModel.targetTitle = this.item.targetTitle
  385 + this.publishCommentModel.targetRelType = this.item.targetRelType
  386 + this.publishCommentModel.targetRelObjectId = this.item.targetRelObjectId
  387 + this.publishCommentModel.targetType = this.item.targetType
  388 + // this.publishCommentModel.keyArticle = this.item.keyArticle
  389 +
  390 + this.publishCommentModel.rootCommentId = this.item.rootCommentId
  391 + this.publishCommentModel.parentId = this.item.id
  392 +
  393 + this.dialogController?.open()
  394 + })
364 395
365 Row() { 396 Row() {
366 Image($r(this.item.api_status ? 'app.media.comment_like_select' : 'app.media.comment_like_normal')) 397 Image($r(this.item.api_status ? 'app.media.comment_like_select' : 'app.media.comment_like_normal'))
@@ -373,6 +404,12 @@ struct QualityCommentItem { @@ -373,6 +404,12 @@ struct QualityCommentItem {
373 .margin({ left: 3 }) 404 .margin({ left: 3 })
374 } 405 }
375 }.onClick(() => { 406 }.onClick(() => {
  407 + // 未登录,跳转登录
  408 + const user_id = HttpUtils.getUserId()
  409 + if (!user_id) {
  410 + WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
  411 + return
  412 + }
376 commentLikeChange(this.item) 413 commentLikeChange(this.item)
377 commentViewModel.commentLike(this.item).then(() => { 414 commentViewModel.commentLike(this.item).then(() => {
378 }).catch(() => { 415 }).catch(() => {