王士厅

直播详情页点赞优化,增加点赞手机震动逻辑,module.json5 sync一下ohos.permission.VIBRATE 权限

@@ -9,6 +9,8 @@ import { @@ -9,6 +9,8 @@ import {
9 } from 'wdBean'; 9 } from 'wdBean';
10 import { LiveModel } from '../../viewmodel/LiveModel'; 10 import { LiveModel } from '../../viewmodel/LiveModel';
11 import { HttpUtils } from 'wdNetwork/Index'; 11 import { HttpUtils } from 'wdNetwork/Index';
  12 +import vibrator from '@ohos.vibrator';
  13 +import { BusinessError } from '@ohos.base';
12 14
13 const TAG = 'LiveLikeComponent'; 15 const TAG = 'LiveLikeComponent';
14 16
@@ -106,38 +108,63 @@ export struct LiveLikeComponent { @@ -106,38 +108,63 @@ export struct LiveLikeComponent {
106 108
107 @Builder 109 @Builder
108 likeCompStyle() { 110 likeCompStyle() {
109 - Stack({ alignContent: Alignment.Bottom }) { 111 + Stack({ alignContent: Alignment.TopEnd }) {
110 Column() { 112 Column() {
111 Image(this.transLikeStyle().url) 113 Image(this.transLikeStyle().url)
112 .width(24) 114 .width(24)
113 .height(24) 115 .height(24)
114 - .onClick(() => {  
115 - this.clickButtonEvent()  
116 - })  
117 } 116 }
118 .justifyContent(FlexAlign.Center) 117 .justifyContent(FlexAlign.Center)
119 .width(36) 118 .width(36)
120 .height(36) 119 .height(36)
121 .borderRadius(18) 120 .borderRadius(18)
122 .backgroundColor((this.pageComponentType === 4 || this.pageComponentType === 2) ? '#4D000000' : this.pageComponentType === 8 ? Color.Transparent : '#FFF5F5F5') 121 .backgroundColor((this.pageComponentType === 4 || this.pageComponentType === 2) ? '#4D000000' : this.pageComponentType === 8 ? Color.Transparent : '#FFF5F5F5')
123 - Row() {  
124 - Text(NumberFormatterUtils.formatNumberWithWan(this.likeCount || ''))  
125 - .fontSize(8)  
126 - .fontColor(Color.White)  
127 - .padding({ left: 8, right: 2 }) 122 + if (this.likeCount != 0) {
  123 + RelativeContainer() {
  124 + Image(this.styleType == 1 ? $r('app.media.comment_icon_number_bg') : $r('app.media.ic_like_back_Select'))
  125 + .objectFit(ImageFit.Fill)
  126 + .resizable({
  127 + slice: {
  128 + top: 1,
  129 + left: 20,
  130 + right: 1,
  131 + bottom: 1
128 } 132 }
  133 + })
  134 + .alignRules({
  135 + top: { anchor: "Text", align: VerticalAlign.Top },
  136 + left: { anchor: "Text", align: HorizontalAlign.Start },
  137 + right: { anchor: "Text", align: HorizontalAlign.End },
  138 + bottom: { anchor: "Text", align: VerticalAlign.Bottom },
  139 + })
  140 + .id("Image")
  141 +
  142 + Text(NumberFormatterUtils.formatNumberWithWan(this.likeCount || ''))// Text("44444444")
  143 + .fontSize(8)
  144 + .fontColor('#ffffff')// .backgroundColor('#ED2800')
129 .height(12) 145 .height(12)
130 - .alignItems(VerticalAlign.Center)  
131 - .position({ x: '100%', y: 10 })  
132 - .markAnchor({ x: '100%' })  
133 - .backgroundImage($r('app.media.ic_like_back'))  
134 - .backgroundImageSize({height: 13}) 146 + .textAlign(TextAlign.Center)
  147 + .alignRules({
  148 + top: { anchor: "__container__", align: VerticalAlign.Top },
  149 + left: { anchor: "__container__", align: HorizontalAlign.Start }
  150 + })// .margin({left: 4,right:4
  151 + // })
  152 + /*动态计算文字宽度*/
135 .width(this.getMeasureText(NumberFormatterUtils.formatNumberWithWan(this.likeCount || '')) + 153 .width(this.getMeasureText(NumberFormatterUtils.formatNumberWithWan(this.likeCount || '')) +
136 - 12) 154 + 12)// .backgroundColor(Color.Green)
  155 + .id("Text")
137 .visibility(this.likeCount > 0 ? Visibility.Visible : Visibility.Hidden) 156 .visibility(this.likeCount > 0 ? Visibility.Visible : Visibility.Hidden)
138 } 157 }
  158 + .offset({
  159 + x: 18
  160 + })
  161 + }
  162 + }
139 .width(36) 163 .width(36)
140 - .height(42) 164 + .height(36)
  165 + .onClick(() => {
  166 + this.clickButtonEvent()
  167 + })
141 .visibility(this.likesStyle == 'empty' || !this.openLikes ? Visibility.None : Visibility.Visible) 168 .visibility(this.likesStyle == 'empty' || !this.openLikes ? Visibility.None : Visibility.Visible)
142 169
143 } 170 }
@@ -164,6 +191,25 @@ export struct LiveLikeComponent { @@ -164,6 +191,25 @@ export struct LiveLikeComponent {
164 this.LiveModel.getLiveRoomNumberLike(this.likeBean['contentId'], 1, HttpUtils.getDeviceId()).then((data) => { 191 this.LiveModel.getLiveRoomNumberLike(this.likeBean['contentId'], 1, HttpUtils.getDeviceId()).then((data) => {
165 192
166 console.log(TAG, '点赞接口调用成功', JSON.stringify(data)) 193 console.log(TAG, '点赞接口调用成功', JSON.stringify(data))
  194 + try {
  195 + // 触发马达振动
  196 + vibrator.startVibration({
  197 + type: 'time',
  198 + duration: 100,
  199 + }, {
  200 + id: 0,
  201 + usage: 'alarm'
  202 + }, (error: BusinessError) => {
  203 + if (error) {
  204 + console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`);
  205 + return;
  206 + }
  207 + console.info('Succeed in starting vibration');
  208 + });
  209 + } catch (err) {
  210 + let e: BusinessError = err as BusinessError;
  211 + console.error(`An unexpected error occurred. Code: ${e.code}, message: ${e.message}`);
  212 + }
167 this.likeCount++ 213 this.likeCount++
168 214
169 }).catch(() => { 215 }).catch(() => {
@@ -12,6 +12,9 @@ @@ -12,6 +12,9 @@
12 "requestPermissions": [ 12 "requestPermissions": [
13 { 13 {
14 "name": "ohos.permission.INTERNET" 14 "name": "ohos.permission.INTERNET"
  15 + },
  16 + {
  17 + "name": "ohos.permission.VIBRATE"
15 } 18 }
16 ], 19 ],
17 "pages": "$profile:main_pages" 20 "pages": "$profile:main_pages"