AssistantSetView.ets 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. import CommonConstants from '../common/constants/CommonConstants'
  2. import AssistantSet from '../model/AssistantSet'
  3. import AssistantSetModel from '../model/database/AssistantSetModel'
  4. @Component
  5. export struct AssistantSetView {
  6. @State assistantSet: AssistantSet = null
  7. editTimbreDialogController: CustomDialogController = new CustomDialogController({
  8. builder: EditTimbreDialog({
  9. assistantSet: this.assistantSet
  10. }),
  11. alignment: DialogAlignment.Center,
  12. customStyle: true,
  13. autoCancel: true,
  14. })
  15. async aboutToAppear() {
  16. this.assistantSet = await AssistantSetModel.getByUserId(CommonConstants.USER_ID)
  17. console.log('testTag', JSON.stringify(this.assistantSet))
  18. }
  19. build() {
  20. Column() {
  21. Text('智汇助手')
  22. .fontColor($r('app.color.general_font_color'))
  23. .fontSize($r('app.float.set_card_font_size'))
  24. .fontWeight(FontWeight.Medium)
  25. .opacity(0.9)
  26. Row() {
  27. Row() {
  28. Column() {
  29. Text('语音唤醒')
  30. .fontColor($r('app.color.general_font_color'))
  31. .fontSize($r('app.float.set_card_font_size'))
  32. .fontWeight(FontWeight.Medium)
  33. .opacity(0.9)
  34. Text('说”小晶,小晶”唤醒智汇助手')
  35. .fontSize($r('app.float.robot_state_font_size'))
  36. .fontColor($r('app.color.general_font_color'))
  37. .fontWeight(FontWeight.Medium)
  38. .opacity(0.6)
  39. }
  40. .alignItems(HorizontalAlign.Start)
  41. Toggle({ type: ToggleType.Switch, isOn: this.assistantSet && this.assistantSet.voiceWakeUp === 1 ? true : false})
  42. .selectedColor('#007DFF')
  43. .switchPointColor('#FFFFFF')
  44. .onChange((isOn: boolean) => {
  45. if (isOn) {
  46. this.assistantSet.voiceWakeUp = 1
  47. } else {
  48. this.assistantSet.voiceWakeUp = 2
  49. }
  50. AssistantSetModel.updateAssistantSet(this.assistantSet)
  51. })
  52. }
  53. .borderRadius($r('app.float.general_border_radius'))
  54. .backgroundColor($r('app.color.general_card_background_color'))
  55. .width('32%')
  56. .height('17%')
  57. .justifyContent(FlexAlign.SpaceBetween)
  58. .padding({ left: '2%', right: '2%' })
  59. Row() {
  60. Column() {
  61. Text('音色')
  62. .fontColor($r('app.color.general_font_color'))
  63. .fontSize($r('app.float.set_card_font_size'))
  64. .fontWeight(FontWeight.Medium)
  65. .opacity(0.9)
  66. Text(this.assistantSet && this.assistantSet.timbre === 1 ? "男声" : "女声")
  67. .fontSize($r('app.float.robot_state_font_size'))
  68. .fontColor($r('app.color.general_font_color'))
  69. .fontWeight(FontWeight.Medium)
  70. .opacity(0.6)
  71. }
  72. .alignItems(HorizontalAlign.Start)
  73. Row() {
  74. Image($r('app.media.subscript'))
  75. .height($r('app.float.card_subscript_size'))
  76. .width($r('app.float.card_subscript_size'))
  77. }
  78. .alignItems(VerticalAlign.Center)
  79. .justifyContent(FlexAlign.End)
  80. .padding({ right: '4.5%', top: '25%' })
  81. .width('97%')
  82. }
  83. .onClick(() => {
  84. try {
  85. this.editTimbreDialogController.open()
  86. } catch (err) {
  87. this.editTimbreDialogController.close()
  88. }
  89. })
  90. .borderRadius($r('app.float.general_border_radius'))
  91. .backgroundColor($r('app.color.general_card_background_color'))
  92. .width('32%')
  93. .height('17%')
  94. .justifyContent(FlexAlign.Center)
  95. .padding({ left: '2%', right: '2%' })
  96. Row() {
  97. Column() {
  98. Text('免唤醒')
  99. .fontColor($r('app.color.general_font_color'))
  100. .fontSize($r('app.float.set_card_font_size'))
  101. .fontWeight(FontWeight.Medium)
  102. .opacity(0.9)
  103. Text('无需唤醒,可直接对话小晶')
  104. .fontSize($r('app.float.robot_state_font_size'))
  105. .fontColor($r('app.color.general_font_color'))
  106. .fontWeight(FontWeight.Medium)
  107. .opacity(0.6)
  108. }
  109. .alignItems(HorizontalAlign.Start)
  110. Toggle({ type: ToggleType.Switch, isOn: this.assistantSet && this.assistantSet.wakeFree === 1 ? true : false})
  111. .selectedColor('#007DFF')
  112. .switchPointColor('#FFFFFF')
  113. .onChange((isOn: boolean) => {
  114. if (isOn) {
  115. this.assistantSet.wakeFree = 1
  116. } else {
  117. this.assistantSet.wakeFree = 2
  118. }
  119. AssistantSetModel.updateAssistantSet(this.assistantSet)
  120. })
  121. }
  122. .borderRadius($r('app.float.general_border_radius'))
  123. .backgroundColor($r('app.color.general_card_background_color'))
  124. .width('32%')
  125. .height('17%')
  126. .justifyContent(FlexAlign.SpaceBetween)
  127. .padding({ left: '2%', right: '2%' })
  128. }
  129. .justifyContent(FlexAlign.SpaceBetween)
  130. .width('100%')
  131. Row()
  132. .height('2%')
  133. Row() {
  134. Row() {
  135. Column() {
  136. Text('提示播报')
  137. .fontColor($r('app.color.general_font_color'))
  138. .fontSize($r('app.float.set_card_font_size'))
  139. .fontWeight(FontWeight.Medium)
  140. .opacity(0.9)
  141. Text('回馈信息同步进行语音播报')
  142. .fontSize($r('app.float.robot_state_font_size'))
  143. .fontColor($r('app.color.general_font_color'))
  144. .fontWeight(FontWeight.Medium)
  145. .opacity(0.6)
  146. }
  147. .alignItems(HorizontalAlign.Start)
  148. Toggle({ type: ToggleType.Switch, isOn: this.assistantSet && this.assistantSet.promptBroadcast === 1 ?true : false})
  149. .selectedColor('#007DFF')
  150. .switchPointColor('#FFFFFF')
  151. .onChange((isOn: boolean) => {
  152. if (isOn) {
  153. this.assistantSet.promptBroadcast = 1
  154. } else {
  155. this.assistantSet.promptBroadcast = 2
  156. }
  157. AssistantSetModel.updateAssistantSet(this.assistantSet)
  158. })
  159. }
  160. .borderRadius($r('app.float.general_border_radius'))
  161. .backgroundColor($r('app.color.general_card_background_color'))
  162. .width('32%')
  163. .height('17%')
  164. .justifyContent(FlexAlign.SpaceBetween)
  165. .padding({ left: '2%', right: '2%' })
  166. Row() {
  167. Column() {
  168. Row() {
  169. Text('语音音量')
  170. .fontColor($r('app.color.general_font_color'))
  171. .fontSize($r('app.float.set_card_font_size'))
  172. .fontWeight(FontWeight.Medium)
  173. .opacity(0.9)
  174. }
  175. .width('100%')
  176. .height('40%')
  177. .padding({ top: '4%' })
  178. Row() {
  179. Image($r('app.media.volume'))
  180. .width($r('app.float.volume_image_size'))
  181. .height($r('app.float.volume_image_size'))
  182. Text()
  183. .width('3%')
  184. Slider({value: this.assistantSet ? this.assistantSet.voiceVolume : 0, min: 0, max: 30, step: 1 })
  185. .layoutWeight(1)
  186. .onChange((value: number)=>{
  187. this.assistantSet.voiceVolume = value
  188. AssistantSetModel.updateAssistantSet(this.assistantSet)
  189. })
  190. }
  191. .justifyContent(FlexAlign.SpaceBetween)
  192. .layoutWeight(1)
  193. }
  194. .borderRadius($r('app.float.general_border_radius'))
  195. .backgroundColor($r('app.color.general_card_background_color'))
  196. .width('66%')
  197. .height('17%')
  198. .alignItems(HorizontalAlign.Start)
  199. .padding({ left: '2%', right: '2%' })
  200. }
  201. }
  202. .justifyContent(FlexAlign.SpaceBetween)
  203. .width('100%')
  204. }
  205. .alignItems(HorizontalAlign.Start)
  206. .width('100%')
  207. }
  208. }
  209. //弹窗组件
  210. @CustomDialog
  211. struct EditTimbreDialog {
  212. @Link assistantSet: AssistantSet
  213. controller: CustomDialogController
  214. cancel: () => void = () => { }
  215. confirm: () => void = () => { }
  216. build() {
  217. Column() {
  218. Row() {
  219. Text("音色")
  220. .margin(3)
  221. .fontSize(20)
  222. .textAlign(TextAlign.Center)
  223. }
  224. .height('17%')
  225. Scroll() {
  226. Row() {
  227. Row() {}
  228. .width('15%')
  229. Stack() {
  230. Image($r('app.media.female_voice'))
  231. .borderRadius($r('app.float.general_border_radius'))
  232. .objectFit(ImageFit.Fill)
  233. .onClick(() => {
  234. this.assistantSet.timbre = 2
  235. AssistantSetModel.updateAssistantSet(this.assistantSet)
  236. this.controller.close()
  237. })
  238. Radio({ value: 'radio0', group: 'voiceRadio' })
  239. .checked(this.assistantSet && this.assistantSet.timbre === 1 ? false : true)
  240. .width($r('app.float.general_icon_size'))
  241. .height($r('app.float.general_icon_size'))
  242. .margin(10)
  243. .onChange((isChecked: boolean) => {
  244. if (isChecked) {
  245. this.assistantSet.timbre = 2
  246. AssistantSetModel.updateAssistantSet(this.assistantSet)
  247. this.controller.close()
  248. }
  249. })
  250. }
  251. .alignContent(Alignment.BottomEnd)
  252. .width('67%')
  253. .height('100%')
  254. Row() {}
  255. .width('5%')
  256. Stack() {
  257. Image($r('app.media.male_voice'))
  258. .borderRadius($r('app.float.general_border_radius'))
  259. .objectFit(ImageFit.Fill)
  260. .onClick(() => {
  261. this.assistantSet.timbre = 1
  262. AssistantSetModel.updateAssistantSet(this.assistantSet)
  263. this.controller.close()
  264. })
  265. Radio({ value: 'radio1', group: 'voiceRadio' })
  266. .checked(this.assistantSet && this.assistantSet.timbre === 1 ? true : false)
  267. .width($r('app.float.general_icon_size'))
  268. .height($r('app.float.general_icon_size'))
  269. .margin(10)
  270. .onChange((isChecked: boolean) => {
  271. if (isChecked) {
  272. this.assistantSet.timbre = 1
  273. AssistantSetModel.updateAssistantSet(this.assistantSet)
  274. this.controller.close()
  275. }
  276. })
  277. }
  278. .alignContent(Alignment.BottomEnd)
  279. .width('67%')
  280. .height('100%')
  281. Row() {}
  282. .width('15%')
  283. }
  284. .alignItems(VerticalAlign.Top)
  285. .justifyContent(FlexAlign.SpaceEvenly)
  286. .height('100%')
  287. }
  288. .scrollable(ScrollDirection.Horizontal)
  289. .scrollBar(BarState.Off)
  290. .height('67%')
  291. }
  292. .width('48%')
  293. .height('62%')
  294. .backgroundColor($r('app.color.page_general_background'))
  295. .borderRadius($r('app.float.general_border_radius'))
  296. }
  297. }