陈剑华

fix: 19347 卡片来源显示规则-来源过长时,不符合省略优先级

@@ -3,6 +3,8 @@ import { CommonConstants, CompStyle } from 'wdConstant/Index'; @@ -3,6 +3,8 @@ import { CommonConstants, CompStyle } from 'wdConstant/Index';
3 import { DateTimeUtils, Logger } from 'wdKit/Index'; 3 import { DateTimeUtils, Logger } from 'wdKit/Index';
4 import router from '@ohos.router' 4 import router from '@ohos.router'
5 import { SearchShowRed, textItem, titleInitRes } from '../../utils/searchShowRed'; 5 import { SearchShowRed, textItem, titleInitRes } from '../../utils/searchShowRed';
  6 +import measure from '@ohos.measure'
  7 +import display from '@ohos.display';
6 8
7 @Reusable 9 @Reusable
8 @Component 10 @Component
@@ -20,10 +22,13 @@ export struct CardSourceInfo { @@ -20,10 +22,13 @@ export struct CardSourceInfo {
20 @State authorMarked: boolean = false; 22 @State authorMarked: boolean = false;
21 @State authorArr: textItem[] = [] 23 @State authorArr: textItem[] = []
22 24
  25 + @State onlyShowCornerAndSource: boolean = false;
  26 +
23 aboutToAppear(): void { 27 aboutToAppear(): void {
24 this.processText(); 28 this.processText();
25 29
26 this.titleInit(); 30 this.titleInit();
  31 + this.calcContentSpace();
27 } 32 }
28 33
29 titleInit() { 34 titleInit() {
@@ -171,6 +176,48 @@ export struct CardSourceInfo { @@ -171,6 +176,48 @@ export struct CardSourceInfo {
171 return flag; 176 return flag;
172 } 177 }
173 178
  179 + getContentSize(textContent: string, fontSize: number ) {
  180 + return px2vp(Number(measure.measureTextSize({
  181 + textContent,
  182 + fontSize
  183 + }).width))
  184 + }
  185 +
  186 + calcContentSpace() {
  187 + if (this.isLimited()) return;
  188 +
  189 + const screenWidth = px2vp(display.getDefaultDisplaySync().width)
  190 + let leftSpace = screenWidth;
  191 +
  192 + const souceSize = this.getContentSize(this.displayText, 12);
  193 + const cornerSize = this.getContentSize(this.contentDTO.cornerMark || this.contentDTO.corner, 12);
  194 + const dotSize = 11;
  195 + const timeSize = this.getContentSize(this.handleTimeStr(), 12);
  196 +
  197 + const commentNum = this.getContentDtoBean()?.interactData?.commentNum
  198 + let commentSize = 0;
  199 + if (commentNum) {
  200 + commentSize = this.getContentSize(`${this.handlerNum(commentNum.toString())}评`, 12);
  201 + }
  202 +
  203 + if (this.contentDTO.cornerMark || this.contentDTO.corner) {
  204 + leftSpace = leftSpace - cornerSize
  205 + }
  206 +
  207 + if (this.showTime()) {
  208 + leftSpace = leftSpace - dotSize - timeSize
  209 + }
  210 +
  211 + if (!this.isEllipsisActive) {
  212 + leftSpace = leftSpace - dotSize - commentSize
  213 + }
  214 +
  215 + if (leftSpace < souceSize) {
  216 + this.onlyShowCornerAndSource = true;
  217 + }
  218 +
  219 + }
  220 +
174 build() { 221 build() {
175 Column(){ 222 Column(){
176 Flex({ justifyContent: FlexAlign.Start, direction: FlexDirection.Row }) { 223 Flex({ justifyContent: FlexAlign.Start, direction: FlexDirection.Row }) {
@@ -192,47 +239,50 @@ export struct CardSourceInfo { @@ -192,47 +239,50 @@ export struct CardSourceInfo {
192 .textOverflow({ overflow: TextOverflow.Ellipsis }) 239 .textOverflow({ overflow: TextOverflow.Ellipsis })
193 } 240 }
194 241
195 - // 点  
196 - if (this.showDot()) {  
197 -  
198 - Image($r("app.media.point"))  
199 - .width(11)  
200 - .height(11)  
201 - .visibility(!this.isEllipsisActive ? Visibility.Visible : Visibility.Hidden) 242 + if (!this.onlyShowCornerAndSource) {
  243 + // 点
  244 + if (this.showDot()) {
202 245
203 - } 246 + Image($r("app.media.point"))
  247 + .width(11)
  248 + .height(11)
  249 + .visibility(!this.isEllipsisActive ? Visibility.Visible : Visibility.Hidden)
204 250
205 - // 发布日期  
206 - if (this.showTime()) {  
207 - Text(this.handleTimeStr())  
208 - .fontSize(12)  
209 - .fontColor($r("app.color.color_B0B0B0"))  
210 - .flexShrink(0)  
211 - .margin({ right: 4 })  
212 - .visibility(!this.isEllipsisActive ? Visibility.Visible : Visibility.Hidden)  
213 - } 251 + }
214 252
215 - // 评论数  
216 - // if (!this.contentDTO.cornerMark && !this.contentDTO.corner && !this.isEllipsisActive) {  
217 - if (!this.isEllipsisActive) {  
218 - if (this.contentDTO.objectType !=='2' && !this.isCompInnerSource && Number(this.getContentDtoBean()?.interactData?.commentNum) > 0 &&  
219 - this.showCommentNum()) {  
220 - Text(`${this.handlerNum(this.getContentDtoBean()?.interactData?.commentNum.toString())}评`) 253 + // 发布日期
  254 + if (this.showTime()) {
  255 + Text(this.handleTimeStr())
221 .fontSize(12) 256 .fontSize(12)
222 .fontColor($r("app.color.color_B0B0B0")) 257 .fontColor($r("app.color.color_B0B0B0"))
223 .flexShrink(0) 258 .flexShrink(0)
224 - } else { 259 + .margin({ right: 4 })
  260 + .visibility(!this.isEllipsisActive ? Visibility.Visible : Visibility.Hidden)
  261 + }
225 262
226 - if (this.contentDTO.objectType !=='2' && this.isCompInnerSource && this.contentDTO.interactData && this.contentDTO.interactData?.commentNum > 0) {  
227 - Text(`${this.handlerNum(this.contentDTO.interactData?.commentNum.toString())}评`) 263 + // 评论数
  264 + // if (!this.contentDTO.cornerMark && !this.contentDTO.corner && !this.isEllipsisActive) {
  265 + if (!this.isEllipsisActive) {
  266 + if (this.contentDTO.objectType !=='2' && !this.isCompInnerSource && Number(this.getContentDtoBean()?.interactData?.commentNum) > 0 &&
  267 + this.showCommentNum()) {
  268 + Text(`${this.handlerNum(this.getContentDtoBean()?.interactData?.commentNum.toString())}评`)
228 .fontSize(12) 269 .fontSize(12)
229 .fontColor($r("app.color.color_B0B0B0")) 270 .fontColor($r("app.color.color_B0B0B0"))
230 .flexShrink(0) 271 .flexShrink(0)
231 - } 272 + } else {
232 273
  274 + if (this.contentDTO.objectType !=='2' && this.isCompInnerSource && this.contentDTO.interactData && this.contentDTO.interactData?.commentNum > 0) {
  275 + Text(`${this.handlerNum(this.contentDTO.interactData?.commentNum.toString())}评`)
  276 + .fontSize(12)
  277 + .fontColor($r("app.color.color_B0B0B0"))
  278 + .flexShrink(0)
  279 + }
  280 +
  281 + }
233 } 282 }
234 } 283 }
235 284
  285 +
236 } 286 }
237 .width(CommonConstants.FULL_WIDTH) 287 .width(CommonConstants.FULL_WIDTH)
238 288
@@ -260,6 +310,7 @@ export struct CardSourceInfo { @@ -260,6 +310,7 @@ export struct CardSourceInfo {
260 } 310 }
261 .width(CommonConstants.FULL_WIDTH) 311 .width(CommonConstants.FULL_WIDTH)
262 .margin({ top: this.viewShowData ? 8 : 0 }) 312 .margin({ top: this.viewShowData ? 8 : 0 })
  313 + .clip(true)
263 314
264 } 315 }
265 316
@@ -268,13 +319,17 @@ export struct CardSourceInfo { @@ -268,13 +319,17 @@ export struct CardSourceInfo {
268 * @returns 319 * @returns
269 */ 320 */
270 private getContentDtoBean(): ContentDTO { 321 private getContentDtoBean(): ContentDTO {
  322 + let content = new ContentDTO
271 if (this.compDTO == undefined) { 323 if (this.compDTO == undefined) {
272 - return this.contentDTO 324 + content = this.contentDTO
273 } 325 }
274 if (this.compDTO.operDataList.length == 0) { 326 if (this.compDTO.operDataList.length == 0) {
275 - return this.contentDTO 327 + content = this.contentDTO
  328 + }
  329 + if (!content) {
  330 + content = this.compDTO.operDataList[0]
276 } 331 }
277 - return this.compDTO.operDataList[0] 332 + return content;
278 } 333 }
279 334
280 /** 335 /**