Showing
1 changed file
with
58 additions
and
3 deletions
| @@ -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,6 +239,7 @@ export struct CardSourceInfo { | @@ -192,6 +239,7 @@ export struct CardSourceInfo { | ||
| 192 | .textOverflow({ overflow: TextOverflow.Ellipsis }) | 239 | .textOverflow({ overflow: TextOverflow.Ellipsis }) |
| 193 | } | 240 | } |
| 194 | 241 | ||
| 242 | + if (!this.onlyShowCornerAndSource) { | ||
| 195 | // 点 | 243 | // 点 |
| 196 | if (this.showDot()) { | 244 | if (this.showDot()) { |
| 197 | 245 | ||
| @@ -232,6 +280,8 @@ export struct CardSourceInfo { | @@ -232,6 +280,8 @@ export struct CardSourceInfo { | ||
| 232 | 280 | ||
| 233 | } | 281 | } |
| 234 | } | 282 | } |
| 283 | + } | ||
| 284 | + | ||
| 235 | 285 | ||
| 236 | } | 286 | } |
| 237 | .width(CommonConstants.FULL_WIDTH) | 287 | .width(CommonConstants.FULL_WIDTH) |
| @@ -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 | /** |
-
Please register or login to post a comment