BottomOperateComp.ets 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. import router from '@ohos.router'
  2. import NoticeInfo from '../../model/NoticeInfo'
  3. import common from '@ohos.app.ability.common';
  4. import { KvStoreModel } from '../../model/KvStoreModel';
  5. import deviceManager from '@ohos.distributedDeviceManager';
  6. import { RemoteDeviceModel, BUNDLE_NAME } from '../../model/RemoteDeviceModel'
  7. import { DeviceDialog } from '../../common/DeviceDialog';
  8. import Want from '@ohos.app.ability.Want';
  9. import { class1 } from '../../pages/Storage';
  10. const TAG: string = 'testTag'
  11. const DATA_CHANGE: string = 'dataChange'
  12. const DATA_CHANGE1: number = 0
  13. const EXIT: string = 'exit'
  14. /*
  15. * 底部操作栏
  16. * */
  17. @Component
  18. export struct BottomOperateComp {
  19. // @Link SmartFactoryCardDelete:number
  20. private isHomePage?: boolean = false
  21. @State isClick:boolean = false
  22. //弹窗
  23. dialogController1: CustomDialogController= new CustomDialogController({
  24. builder: NoticeDialog({}),
  25. alignment: DialogAlignment.Center,
  26. customStyle:true,
  27. cancel:()=>{
  28. this.isClick =! this.isClick
  29. }
  30. })
  31. @State Page:number=1
  32. @State deviceDialogWidth: number = 0
  33. @State @Watch('dataChange') click: number = 0;
  34. @State click1: number = 0;
  35. @State @Watch('dataChange') message: string = 'Hello World';
  36. @State inputMsg: string = '';
  37. @State isDistributed: boolean = false
  38. @StorageLink('deviceList') deviceList: Array<deviceManager.DeviceBasicInfo> = []
  39. @State selectedIndex: number | undefined = -1
  40. private remoteDeviceModel: RemoteDeviceModel = new RemoteDeviceModel()
  41. private kvStoreModel: KvStoreModel = new KvStoreModel()
  42. private dialogController: CustomDialogController | null = null
  43. onSelectedIndexChange = async (index: number | undefined) => {
  44. console.info(TAG, `selectedIndexChange`)
  45. this.selectedIndex = index
  46. this.selectDevice()
  47. }
  48. // aboutToAppear(){
  49. // this.showDeviceDialog()
  50. // }
  51. aboutToDisappear() {
  52. console.info(TAG, `index disappear`)
  53. this.kvStoreModel.deleteKvStore()
  54. }
  55. startAbilityCallBack = (key: string) => {
  56. console.info(TAG, `startAbilityCallBack ${key}`)
  57. if (DATA_CHANGE === key) {
  58. this.kvStoreModel.put(DATA_CHANGE, this.message)
  59. }
  60. if (EXIT === key) {
  61. this.kvStoreModel.put(DATA_CHANGE, EXIT)
  62. }
  63. }
  64. selectDevice() {
  65. console.info(TAG, `start ability ......`)
  66. this.isDistributed = true
  67. if (this.selectedIndex !== undefined && (this.remoteDeviceModel === null || this.remoteDeviceModel.discoverList.length <= 0)) {
  68. console.info(TAG, `continue unauthed device: ${JSON.stringify(this.deviceList)}`)
  69. this.startAbility(this.deviceList[this.selectedIndex].networkId as string)
  70. this.clearSelectState()
  71. return
  72. }
  73. console.info(TAG, `start ability1, needAuth:`)
  74. if (this.selectedIndex !== undefined) {
  75. console.log(TAG, '------------' + JSON.stringify(this.deviceList[this.selectedIndex]));
  76. this.remoteDeviceModel.authenticateDevice(this.deviceList[this.selectedIndex], () => {
  77. console.info(TAG, `auth and online finished`);
  78. if (this.remoteDeviceModel !== null && this.remoteDeviceModel.deviceList !== null && this.selectedIndex !== undefined) {
  79. for (let i = 0; i < this.remoteDeviceModel.deviceList!.length; i++) {
  80. if (this.remoteDeviceModel.deviceList![i].deviceName === this.deviceList[this.selectedIndex].deviceName) {
  81. this.startAbility(this.remoteDeviceModel.deviceList![i].networkId);
  82. }
  83. }
  84. }
  85. })
  86. }
  87. console.info(TAG, `start ability2 ......`)
  88. this.clearSelectState()
  89. }
  90. clearSelectState() {
  91. this.deviceList = []
  92. if (this.dialogController !== null) {
  93. this.dialogController.close()
  94. }
  95. console.info(TAG, `cancelDialog`)
  96. if (this.remoteDeviceModel === undefined) {
  97. return
  98. }
  99. this.remoteDeviceModel.unregisterDeviceListCallback()
  100. }
  101. async startAbility(deviceId: string | undefined) {
  102. console.debug(TAG, `startAbility deviceId: ${deviceId}`)
  103. let context = getContext(this) as common.UIAbilityContext
  104. let choicePages:class1={}
  105. // console.log("获取当前页面"+choicePages.choicePages?.toString())
  106. let want: Want = {
  107. bundleName: BUNDLE_NAME,
  108. abilityName: 'EntryAbility',
  109. // abilityName: choicePages.choicePages===2?'':'firstAbility',
  110. deviceId: deviceId,
  111. parameters: {
  112. isRemote: 'isRemote'
  113. }
  114. }
  115. context.startAbility(want).then((data) => {
  116. console.info(TAG, `start ability finished: ${JSON.stringify(data)}`)
  117. this.startAbilityCallBack(DATA_CHANGE)
  118. })
  119. }
  120. dataChange() {
  121. console.info(TAG, `dataChange, message = ${this.message},`)
  122. this.kvStoreModel.put(DATA_CHANGE1.toString(), this.click.toString())
  123. this.kvStoreModel.put(DATA_CHANGE, this.message,)
  124. }
  125. showDeviceDialog() {
  126. this.deviceList = []
  127. // 注册监听回调,发现设备或查找到已认证设备会弹窗显示
  128. this.remoteDeviceModel.registerDeviceListCallback(() => {
  129. this.deviceList = []
  130. let deviceTempList = this.remoteDeviceModel.discoverList.length > 0 ? this.remoteDeviceModel.discoverList : this.remoteDeviceModel.deviceList;
  131. if (deviceTempList !== null) {
  132. for (let i = 0; i < deviceTempList!.length; i++) {
  133. console.debug(TAG, `device ${i}/${deviceTempList!.length} deviceId= ${deviceTempList![i].deviceId},
  134. deviceName= ${deviceTempList![i].deviceName}, deviceType= ${deviceTempList![i].deviceType}`);
  135. if (deviceTempList !== null) {
  136. this.deviceList.push({
  137. deviceId: deviceTempList![i].deviceId,
  138. deviceName: deviceTempList![i].deviceName,
  139. deviceType: deviceTempList![i].deviceType,
  140. networkId: deviceTempList![i].networkId,
  141. })
  142. AppStorage.set('deviceList', this.deviceList)
  143. }
  144. }
  145. }
  146. })
  147. if (this.dialogController === null) {
  148. this.dialogController = new CustomDialogController({
  149. builder: DeviceDialog({
  150. selectedIndex: this.selectedIndex,
  151. onSelectedIndexChange: this.onSelectedIndexChange
  152. }),
  153. cancel: () => {
  154. this.clearSelectState()
  155. },
  156. autoCancel: true,
  157. alignment: DialogAlignment.Center,
  158. customStyle: false
  159. })
  160. }
  161. if (this.dialogController !== null) {
  162. this.dialogController.open()
  163. }
  164. }
  165. build() {
  166. Stack() {
  167. Text()
  168. .width('100%')
  169. .height('100%')
  170. .backgroundColor($r('app.color.bottom_bar_background'))
  171. .opacity(this.isHomePage ? $r('app.float.bottom_bar_home_page_opacity') : $r('app.float.bottom_bar_general_opacity'))
  172. .backdropBlur(this.isHomePage ? 13 : 0)
  173. Row() {
  174. Row () {
  175. Image($r('app.media.home_page'))
  176. .height($r('app.float.robot_image_select_size'))
  177. .width($r('app.float.robot_image_select_size'))
  178. }
  179. .height('100%')
  180. .width('7%')
  181. .justifyContent(FlexAlign.Center)
  182. .onClick(()=>{
  183. router.pushUrl({
  184. url:'pages/Index'
  185. })
  186. })
  187. Row(){
  188. Image($r('app.media.notice'))
  189. .height($r('app.float.robot_image_select_size'))
  190. .width($r('app.float.robot_image_select_size'))
  191. }
  192. .height('100%')
  193. .width('7%')
  194. .justifyContent(FlexAlign.Center)
  195. .onClick(()=>{
  196. this.dialogController1.open()
  197. })
  198. Row(){
  199. Image($r('app.media.jg_circular_icon'))
  200. .height($r('app.float.storage_space_set_size'))
  201. .width($r('app.float.storage_space_set_size'))
  202. }
  203. .height('100%')
  204. .width('7%')
  205. .justifyContent(FlexAlign.Center)
  206. .onClick(()=>{
  207. router.pushUrl({
  208. url:'pages/SmartFactory'
  209. })
  210. })
  211. .gesture(
  212. LongPressGesture({ repeat: false })
  213. .onActionEnd(() => {
  214. })
  215. )
  216. Row(){
  217. Image($r('app.media.page_flow'))
  218. .height($r('app.float.robot_image_select_size'))
  219. .width($r('app.float.robot_image_select_size'))
  220. .onClick(() => {
  221. this.showDeviceDialog()
  222. // router.pushUrl({
  223. // url:'pages/DistributedPage'
  224. // })
  225. })
  226. }
  227. .height('100%')
  228. .width('7%')
  229. .justifyContent(FlexAlign.Center)
  230. Row(){
  231. Image($r('app.media.camera'))
  232. .height($r('app.float.robot_image_select_size'))
  233. .width($r('app.float.robot_image_select_size'))
  234. }
  235. .height('100%')
  236. .width('7%')
  237. .justifyContent(FlexAlign.Center)
  238. // Image($r('app.media.volume'))
  239. // .height($r('app.float.general_icon_size'))
  240. // .width($r('app.float.general_icon_size'))
  241. }
  242. .width('100%')
  243. .height('100%')
  244. .justifyContent(FlexAlign.Center)
  245. }
  246. .width('100%')
  247. .height('8%')
  248. }
  249. }
  250. //弹窗组件
  251. @CustomDialog
  252. struct NoticeDialog {
  253. controller: CustomDialogController
  254. Notices: NoticeInfo[]=[]
  255. build() {
  256. Column({space: 10}) {
  257. Row() {
  258. Text('通知')
  259. .fontSize($r('app.float.fontSize_24'))
  260. .fontWeight(FontWeight.Medium)
  261. .fontColor($r('app.color.general_font_color'))
  262. .opacity($r('app.float.general_font_opacity'))
  263. }
  264. Row(){
  265. List(){
  266. ForEach(this.Notices, (item:NoticeInfo) => {
  267. ListItem(){
  268. Row(){
  269. Text(item.Notice)
  270. .fontSize($r('app.float.fontSize_24'))
  271. .fontColor($r('app.color.general_font_color'))
  272. .opacity($r('app.float.general_font_opacity'))
  273. Text(item.NoticeDate)
  274. .fontSize($r('app.float.fontSize_24'))
  275. .fontColor($r('app.color.general_font_color'))
  276. .opacity($r('app.float.card_font_default_opacity'))
  277. }
  278. .justifyContent(FlexAlign.SpaceBetween)
  279. .width('100%')
  280. }
  281. })
  282. }
  283. }
  284. .width('90%')
  285. .height('80%')
  286. .alignItems(VerticalAlign.Top)
  287. .borderRadius($r('app.float.notice_size'))
  288. .borderWidth($r('app.float.general_border_width'))
  289. .borderColor($r('app.color.general_border_color'))
  290. }
  291. .width('45%')
  292. .height('70%')
  293. .justifyContent(FlexAlign.Center)
  294. .backgroundColor($r('app.color.page_general_background'))
  295. .borderRadius($r('app.float.notice_size'))
  296. }
  297. }