wuyanan

ref |> 搜索集成语音输入

... ... @@ -107,4 +107,6 @@ export { MorningEveningViewModel } from './src/main/ets/viewmodel/MorningEvening
export { GrayManageModel } from './src/main/ets/viewmodel/GrayManageModel'
export { VoiceInputView } from './src/main/ets/components/comment/view/VoiceInputView'
\ No newline at end of file
export { VoiceInputView } from './src/main/ets/components/comment/view/VoiceInputView'
// export {voicese}
\ No newline at end of file
... ...
import router from '@ohos.router'
import { VoiceRecoginizer } from 'wdHwAbility'
import { BreakpointSystem, DateTimeUtils, NetworkUtil, StringUtils, ToastUtils } from 'wdKit'
import { ParamType, TrackConstants, Tracking } from 'wdTracking/Index'
import SearcherAboutDataModel from '../../model/SearcherAboutDataModel'
... ... @@ -8,6 +9,8 @@ import { SearchHistoryComponent } from './SearchHistoryComponent'
import { SearchHotsComponent } from './SearchHotsComponent'
import { SearchRelatedComponent } from './SearchRelatedComponent'
import { SearchResultComponent } from './SearchResultComponent'
import { VoiceSearchCustomDialog } from './VoiceSearchCustomDialog'
import { common } from '@kit.AbilityKit'
const TAG = "SearchComponent"
... ... @@ -37,6 +40,7 @@ export struct SearchComponent {
@StorageProp('currentBreakpoint') @Watch("currentChanged") currentBreakpoint: string = 'sm';
private breakpointSystem = new BreakpointSystem();
@State percent: number = 1
private commentInputDialogController?: CustomDialogController
currentChanged() {
if (this.currentBreakpoint == "md" || this.currentBreakpoint == "lg") {
... ... @@ -366,17 +370,22 @@ export struct SearchComponent {
}
})
Image($r('app.media.search_input_del_icon'))
Image($r(StringUtils.isEmpty(this.searchText) ? 'app.media.search_voice_icon' : 'app.media.search_input_del_icon'))
.width(`${this.calcHeight(31)}lpx`)
.height(`${this.calcHeight(31)}lpx`)
.objectFit(ImageFit.Auto)
.interpolation(ImageInterpolation.Medium)
.onClick(() => {
this.searchText = ""
if (StringUtils.isEmpty(this.searchText)) { ///唤起语音搜索
this.stopInput()
this.voiceSearchDialog()
}else { ///清除输入内容
this.searchText = ""
}
})
.offset({ x: 10 })
.enabled(true)
.visibility(StringUtils.isEmpty(this.searchText) ? Visibility.Hidden : Visibility.Visible)
// .visibility(StringUtils.isEmpty(this.searchText) ? Visibility.Hidden : Visibility.Visible)
}.padding({ right: `${this.calcHeight(70)}lpx` })
.layoutWeight(1)
... ... @@ -406,6 +415,31 @@ export struct SearchComponent {
.alignItems(VerticalAlign.Center)
}
private voiceSearchDialog() {
VoiceRecoginizer.checkPemmission(getContext(this) as common.UIAbilityContext)
this.commentInputDialogController = new CustomDialogController({
builder: VoiceSearchCustomDialog (
{ onSearchBtnClick:((content:string) => {
this.commentInputDialogController?.close()
this.searchText = content
if (StringUtils.isNotEmpty(this.searchText)) {
SearcherAboutDataModel.putSearchHistoryData(this.searchText)
this.getSearchHistoryData()
this.getSearchInputResData(this.searchText)
}
})
}
),
autoCancel: true,
alignment: DialogAlignment.Bottom,
customStyle: true,
backgroundColor: "#50000000",
}).open()
}
getSearchResultCountData() {
SearcherAboutDataModel.getSearchResultCountData(encodeURI(this.searchText), getContext(this)).then((value) => {
if (value != null) {
... ...
import { VoiceRecoginizer } from 'wdHwAbility'
import { common, UIAbility } from '@kit.AbilityKit'
import { VoiceInputView } from '../comment/view/VoiceInputView'
@Preview
@CustomDialog
export struct VoiceSearchCustomDialog {
controller?: CustomDialogController
onSearchBtnClick?: (content: string) => void
@State voiceContent: string = ""
build() {
Column() {
Row() {
TextArea({
placeholder: '我来说两句',
text: this.voiceContent
})
.placeholderColor("#999999")
.id("textAreaId")
.defaultFocus(false) // 获取默认焦点
.enableKeyboardOnFocus(true)
.height('100%')
.width('100%')
.backgroundColor($r('app.color.color_transparent'))
.caretColor("#ED2800")
.onFocus(() => {
this.controller?.close()
})
}
.backgroundColor('#F9F9F9')
.margin({ top: 12, right: 12, left: 12, bottom:10})
.height(80)
.borderRadius(4)
Row() {
Image($r('app.media.WDInput_keyboardImage'))
.width(30)
.height(30)
.onClick(() => {
this.controller?.close()
})
Text('搜索')
.backgroundColor("#ED2800")
.width(80)
.height(30)
.fontSize(15)
.fontColor(Color.White)
.textAlign(TextAlign.Center)
.borderRadius(4)
.opacity(this.voiceContent.length > 0 ? 1.0 : 0.5)
.enabled(this.voiceContent.length > 0)
.onClick(() => {
if (this.onSearchBtnClick) {
this.onSearchBtnClick(this.voiceContent)
}
})
}
.padding({ left: 12, right: 12 })
.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
VoiceInputView({voiceRecoginizerResult:(result: string) => {
this.voiceContent = result
}}).height(150)
}.backgroundColor(Color.White)
.width('100%')
}
}
\ No newline at end of file
... ...