RobotSetView.ets 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. import CommonConstants from '../common/constants/CommonConstants'
  2. import RobotInfo from '../model/RobotInfo'
  3. import RobotSelfCheck from '../model/RobotSelfCheck'
  4. import RobotSelfCheckModel from '../model/database/RobotSelfCheckModel'
  5. import StorageInfo from '../model/StorageInfo'
  6. import TimeUtil from '../common/util/TimeUtil'
  7. import router from '@ohos.router'
  8. import { RobotPreviewComp } from '../common/component/RobotPreviewComp'
  9. import StorageConfig from '../viewmodel/StorageConfig'
  10. import JGRequest from '../common/util/request/Request'
  11. import StorageModel from '../model/database/StorageModel'
  12. import StorageSpace from '../model/StorageSpace'
  13. import StorageSpaceModel from '../model/database/StorageSpaceModel'
  14. @Component
  15. export struct RobotSetView {
  16. @State list: Resource[] = [$r('app.media.car_preview'),$r('app.media.car_preview'),$r('app.media.car_preview')]
  17. @State selectRobot : number = 1
  18. @State robots: RobotInfo[] = CommonConstants.ROBOTS
  19. @State storages: StorageInfo[] = []
  20. @State robotX: number = 0
  21. @State robotY: number = 0
  22. @State robotStorage: StorageInfo = new StorageInfo()
  23. // 视频播放
  24. @State videoSrc: Resource = $rawfile('robot.mp4')
  25. videoController: VideoController = new VideoController()
  26. async aboutToAppear() {
  27. if (this.robots && this.robots[this.selectRobot] && this.robots[this.selectRobot].x) {
  28. this.robotX = this.robots[this.selectRobot].x
  29. }
  30. if (this.robots && this.robots[this.selectRobot] && this.robots[this.selectRobot].y) {
  31. this.robotY = this.robots[this.selectRobot].y
  32. }
  33. // 查询本地数据库,没有则从后台获取
  34. this.storages = await StorageModel.getStorageList()
  35. if (!this.storages || this.storages.length <= 0) {
  36. // 查询后台数据库的线边库
  37. let config: StorageConfig = await JGRequest.get("/api/v1/wms/position/houseConfigInfo/" + 1, {})
  38. if (!config) {
  39. return
  40. }
  41. let storage = {storageName: config.houseName, xSize: config.xNum, ySize: config.yNum, defaultLayer: config.layer} as StorageInfo
  42. this.storages.push(storage)
  43. let storageId = await StorageModel.addStorage(config.houseName, config.xNum, config.yNum, config.layer)
  44. storage.id = storageId
  45. if (config.xNum && config.xNum > 0 && config.yNum && config.yNum > 0) {
  46. for (let y = 1; y <= config.yNum; y++) {
  47. for (let x = 1; x <= config.xNum; x++) {
  48. let space: StorageSpace = {storageId: storageId, x: x, y: y, enableState: 1, storageType: '', capacity: config.layer, canWay: 1, canPark: 0}
  49. await StorageSpaceModel.addStorageSpace(space)
  50. }
  51. }
  52. }
  53. }
  54. for (const storage of this.storages) {
  55. if (this.robots && this.robots[this.selectRobot] && this.robots[this.selectRobot].storageId && this.robots[this.selectRobot].storageId === storage.id) {
  56. this.robotStorage = storage
  57. }
  58. }
  59. }
  60. // 编辑机器人编码的弹窗控制器
  61. editCodeController: CustomDialogController = new CustomDialogController({
  62. builder: EditCodeDialog({
  63. currentRobot: this.robots && this.robots[this.selectRobot] ? this.robots[this.selectRobot] : null,
  64. selectRobot : this.selectRobot,
  65. robots: this.robots
  66. }),
  67. autoCancel: true,
  68. alignment: DialogAlignment.Center,
  69. // gridCount: 3,
  70. customStyle: true,
  71. })
  72. // 编辑机器人所属仓库的弹窗控制器
  73. editStorageController: CustomDialogController = new CustomDialogController({
  74. builder: EditStorageDialog({
  75. selectRobot : this.selectRobot,
  76. robotStorage : this.robotStorage,
  77. robots: this.robots,
  78. storages: this.storages,
  79. }),
  80. autoCancel: true,
  81. alignment: DialogAlignment.Center,
  82. // gridCount: 3,
  83. customStyle: true,
  84. })
  85. // 编辑机器人朝向弹窗控制器
  86. editTowardController: CustomDialogController = new CustomDialogController({
  87. builder: RobotTowardDialog({
  88. currentRobot: this.robots && this.robots[this.selectRobot] ? this.robots[this.selectRobot] : null,
  89. selectRobot : this.selectRobot,
  90. robots: this.robots
  91. }),
  92. autoCancel: true,
  93. alignment: DialogAlignment.Center,
  94. // gridCount: 3,
  95. customStyle: true,
  96. })
  97. // 编辑机器人坐标的弹窗控制器
  98. editCoordController: CustomDialogController = new CustomDialogController({
  99. builder: EditCoordinateDialog({
  100. x: this.robotX,
  101. y: this.robotY,
  102. xSize: this.robotStorage ? this.robotStorage.xSize : 0,
  103. ySize: this.robotStorage ? this.robotStorage.ySize : 0,
  104. confirm: ()=> {
  105. if (this.robots && this.robots[this.selectRobot]) {
  106. let robot = Object.assign({}, this.robots[this.selectRobot]);
  107. robot.x = this.robotX
  108. robot.y = this.robotY
  109. this.robots[this.selectRobot] = robot
  110. }
  111. }
  112. }),
  113. autoCancel: true,
  114. alignment: DialogAlignment.Center,
  115. // gridCount: 3,
  116. customStyle: true,
  117. })
  118. // 编辑机器人自检的弹窗控制器
  119. selfCheckController: CustomDialogController = new CustomDialogController({
  120. builder: SelfCheckDialog({
  121. currentRobot: this.robots && this.robots[this.selectRobot] ? this.robots[this.selectRobot] : null,
  122. }),
  123. autoCancel: true,
  124. alignment: DialogAlignment.Center,
  125. // gridCount: 3,
  126. customStyle: true,
  127. })
  128. build() {
  129. Column() {
  130. // 机器人预览图片和当前机器人状态
  131. Row() {
  132. RobotPreviewComp({
  133. list: $list,
  134. selectRobot: $selectRobot,
  135. robots: $robots,
  136. robotX: $robotX,
  137. robotY: $robotY,
  138. robotStorage: $robotStorage,
  139. storages: $storages,
  140. })
  141. .width($r('app.float.robot_image_list_size'))
  142. Blank()
  143. Row() {
  144. Image($r('app.media.battery_level'))
  145. .width($r('app.float.card_image_size'))
  146. .height($r('app.float.card_image_size'))
  147. Text('98%')
  148. .fontSize($r('app.float.robot_state_font_size'))
  149. .fontWeight(FontWeight.Medium)
  150. .fontColor($r('app.color.general_font_color'))
  151. .opacity($r('app.float.general_font_opacity'))
  152. }
  153. .width('10%')
  154. .justifyContent(FlexAlign.SpaceEvenly)
  155. Row() {
  156. Image($r('app.media.coordinate'))
  157. .width($r('app.float.card_image_size'))
  158. .height($r('app.float.card_image_size'))
  159. Text('x:' + (this.robots && this.robots[this.selectRobot] && this.robots[this.selectRobot].x ? this.robots[this.selectRobot].x : ' ') + 'y:' + (this.robots && this.robots[this.selectRobot] && this.robots[this.selectRobot].y ? this.robots[this.selectRobot].y : ' '))
  160. .fontSize($r('app.float.robot_state_font_size'))
  161. .fontWeight(FontWeight.Medium)
  162. .fontColor($r('app.color.general_font_color'))
  163. .opacity($r('app.float.general_font_opacity'))
  164. }
  165. .width('10%')
  166. .justifyContent(FlexAlign.SpaceEvenly)
  167. Row() {
  168. Image($r('app.media.robot_auto_mode'))
  169. .width($r('app.float.card_image_size'))
  170. .height($r('app.float.card_image_size'))
  171. Text('自动模式')
  172. .fontSize($r('app.float.robot_state_font_size'))
  173. .fontWeight(FontWeight.Medium)
  174. .fontColor($r('app.color.general_font_color'))
  175. .opacity($r('app.float.general_font_opacity'))
  176. }
  177. .width('10%')
  178. .justifyContent(FlexAlign.SpaceEvenly)
  179. }
  180. .width('100%')
  181. .height('8%')
  182. // 机器人3D播放
  183. Row() {
  184. Video({
  185. src: this.videoSrc,
  186. // previewUri: this.previewUri,
  187. currentProgressRate: PlaybackSpeed.Speed_Forward_1_00_X,
  188. controller: this.videoController
  189. })
  190. .width('100%')
  191. .height('100%')
  192. .autoPlay(true)
  193. .controls(false)
  194. .loop(true)
  195. .backgroundImage($r('app.media.set_robot_unity_background'))
  196. .backgroundImageSize({ width:'100%', height:'100%'})
  197. // Image($r('app.media.robot_set_demo'))
  198. // .objectFit(ImageFit.Contain)
  199. }
  200. .width('100%')
  201. .height('56%')
  202. .justifyContent(FlexAlign.Center)
  203. // .backgroundImage($r('app.media.set_robot_unity_background'))
  204. // .backgroundImageSize(ImageSize.Auto)
  205. // 机器人信息展示
  206. Row() {
  207. this.displayCard({cardName:'机器人', displayInfo: (this.robots && this.robots[this.selectRobot] ? this.robots[this.selectRobot].robotCode : ''), clickEvent: ()=>{
  208. this.editCodeController.open()
  209. }})
  210. this.displayCard({cardName:'所属仓库', displayInfo: (this.robotStorage && this.robotStorage.storageName ? this.robotStorage.storageName : ''), clickEvent: ()=>{
  211. this.editStorageController.open()
  212. }})
  213. this.displayCard({cardName:'机器人朝向', displayInfo: this.robots && this.robots[this.selectRobot] ? (this.robots[this.selectRobot].robotToward === 1 ? '+x轴方向' : (this.robots[this.selectRobot].robotToward === 2 ? '-x轴方向' : (this.robots[this.selectRobot].robotToward === 3 ? '+y轴方向' : '-y轴方向'))) : '', clickEvent: ()=>{
  214. this.editTowardController.open()
  215. }})
  216. }
  217. .width('100%')
  218. .height('18%')
  219. .justifyContent(FlexAlign.SpaceBetween)
  220. Row() {
  221. this.displayCard({cardName: '当前点位', displayInfo: ('x:' + (this.robots && this.robots[this.selectRobot] && this.robots[this.selectRobot].x ? this.robots[this.selectRobot].x : ' ') + 'y:' + (this.robots && this.robots[this.selectRobot] && this.robots[this.selectRobot].y ? this.robots[this.selectRobot].y : ' ')), clickEvent: ()=>{
  222. this.editCoordController.open()
  223. }})
  224. this.displayCard({cardName: '自检', displayInfo: '上次自检:' + (this.robots && this.robots[this.selectRobot] ? this.robots[this.selectRobot].lastSelfCheck : ''), clickEvent: ()=>{
  225. this.selfCheckController.open()
  226. }})
  227. Column() {
  228. Row() {
  229. Text('调试')
  230. .height('30%')
  231. .fontSize($r('app.float.card_title_font_size'))
  232. .fontColor($r('app.color.general_font_color'))
  233. .opacity($r('app.float.general_font_opacity'))
  234. }
  235. .alignItems(VerticalAlign.Center)
  236. .justifyContent(FlexAlign.Start)
  237. .padding({left: '6.6%', right: '4.5%'})
  238. .width('100%')
  239. .onClick(()=>{
  240. router.pushUrl({
  241. url:'pages/RobotDebug'
  242. })
  243. })
  244. }
  245. .height('90%')
  246. .width('32%')
  247. .justifyContent(FlexAlign.Center)
  248. .borderRadius($r('app.float.general_border_radius'))
  249. .backgroundColor($r('app.color.general_card_background_color'))
  250. }
  251. .width('100%')
  252. .height('18%')
  253. .justifyContent(FlexAlign.SpaceBetween)
  254. }
  255. .width('100%')
  256. .width('100%')
  257. }
  258. @Builder
  259. displayCard($$: { cardName: string, displayInfo: string , clickEvent?: Function}) {
  260. Column() {
  261. Row() {
  262. Text($$.cardName)
  263. .height('30%')
  264. .fontSize($r('app.float.card_title_font_size'))
  265. .fontColor($r('app.color.general_font_color'))
  266. .fontWeight(FontWeight.Medium)
  267. .opacity($r('app.float.general_font_opacity'))
  268. }
  269. .alignItems(VerticalAlign.Center)
  270. .justifyContent(FlexAlign.Start)
  271. .padding({left: '6.6%', right: '4.5%'})
  272. .width('100%')
  273. Row() {
  274. Text($$.displayInfo)
  275. .fontSize($r('app.float.card_info_font_size'))
  276. .fontColor($r('app.color.general_font_color'))
  277. .fontWeight(FontWeight.Regular)
  278. .opacity($r('app.float.card_font_default_opacity'))
  279. }
  280. .alignItems(VerticalAlign.Center)
  281. .justifyContent(FlexAlign.Start)
  282. .padding({left: '6.6%', right: '4.5%'})
  283. .width('100%')
  284. Row() {
  285. Image($r('app.media.subscript'))
  286. .height($r('app.float.card_subscript_size'))
  287. .width($r('app.float.card_subscript_size'))
  288. }
  289. .alignItems(VerticalAlign.Center)
  290. .justifyContent(FlexAlign.End)
  291. .padding({right: '4.5%'})
  292. .width('100%')
  293. }
  294. .height('90%')
  295. .width('32%')
  296. .justifyContent(FlexAlign.Center)
  297. .borderRadius($r('app.float.general_border_radius'))
  298. .backgroundColor($r('app.color.general_card_background_color'))
  299. .onClick(()=>{
  300. try {
  301. $$.clickEvent()
  302. } catch (err) {
  303. console.log('testTag', '---------err' + JSON.stringify(err))
  304. }
  305. })
  306. }
  307. }
  308. // 编辑机器人编码弹窗
  309. @CustomDialog
  310. struct EditCodeDialog {
  311. robotCode: string = ''
  312. private currentRobot: RobotInfo
  313. selectRobot : number
  314. @Link robots: RobotInfo[]
  315. controller?: CustomDialogController
  316. cancel: () => void = () => {}
  317. confirm: () => void = () => {}
  318. aboutToAppear() {
  319. if (this.currentRobot && this.currentRobot.robotCode) {
  320. this.robotCode = this.currentRobot.robotCode
  321. }
  322. }
  323. build() {
  324. Column() {
  325. Row() {
  326. Text('机器人')
  327. .fontSize($r('app.float.title_font_size'))
  328. .fontWeight(FontWeight.Medium)
  329. .fontColor($r('app.color.general_font_color'))
  330. .opacity($r('app.float.general_font_opacity'))
  331. }
  332. .height('25%')
  333. .alignItems(VerticalAlign.Center)
  334. Row() {
  335. TextInput({placeholder: '请输入机器人编号' })
  336. .placeholderColor($r('app.color.text_input_placeholder_font_color'))
  337. .placeholderFont({size: $r('app.float.robot_set_font_size'), weight: FontWeight.Regular})
  338. .fontSize($r('app.float.robot_set_font_size'))
  339. .fontWeight(FontWeight.Regular)
  340. .fontColor($r('app.color.general_font_color'))
  341. .borderRadius($r('app.float.robot_set_radius'))
  342. .backgroundColor($r('app.color.general_font_white_color'))
  343. .onChange((value: string) => {
  344. this.robotCode = value
  345. })
  346. }
  347. .height('25%')
  348. .width('80%')
  349. .justifyContent(FlexAlign.SpaceAround)
  350. .alignItems(VerticalAlign.Center)
  351. Blank()
  352. Row() {
  353. Button('取消')
  354. .fontSize($r('app.float.robot_set_font_size'))
  355. .fontWeight(FontWeight.Medium)
  356. .fontColor($r('app.color.robot_set_card_blue'))
  357. .width('32%')
  358. .height('50%')
  359. .borderRadius($r('app.float.robot_set_radius'))
  360. .backgroundColor($r('app.color.robot_set_coord_card_grey'))
  361. .onClick(() => {
  362. this.controller.close()
  363. this.cancel()
  364. })
  365. Row()
  366. .width('2.5%')
  367. Button('确认')
  368. .fontSize($r('app.float.robot_set_font_size'))
  369. .fontWeight(FontWeight.Medium)
  370. .fontColor($r('app.color.general_font_white_color'))
  371. .width('32%')
  372. .height('50%')
  373. .borderRadius($r('app.float.robot_set_radius'))
  374. .backgroundColor($r('app.color.robot_set_card_blue'))
  375. .onClick(() => {
  376. if (this.controller != undefined) {
  377. this.controller.close()
  378. let robot = Object.assign({}, this.robots[this.selectRobot]);
  379. robot.robotCode = this.robotCode
  380. this.robots[this.selectRobot] = robot
  381. console.log('testTag', '---------'+JSON.stringify(robot))
  382. }
  383. })
  384. }
  385. .justifyContent(FlexAlign.Center)
  386. .alignItems(VerticalAlign.Center)
  387. .height('40%')
  388. .width('100%')
  389. }
  390. .width('48%')
  391. .height('37%')
  392. .backgroundColor($r('app.color.page_general_background'))
  393. .justifyContent(FlexAlign.SpaceEvenly)
  394. .borderRadius($r('app.float.general_border_radius'))
  395. }
  396. }
  397. // 编辑机器人所属仓库弹窗
  398. @CustomDialog
  399. struct EditStorageDialog {
  400. selectRobot : number
  401. @Link robotStorage: StorageInfo
  402. @Link robots: RobotInfo[]
  403. storages: StorageInfo[]
  404. controller?: CustomDialogController
  405. cancel: () => void = () => { }
  406. confirm: () => void = () => { }
  407. build() {
  408. Column() {
  409. Row() {
  410. Text('所属仓储')
  411. .fontSize($r('app.float.title_font_size'))
  412. .fontWeight(FontWeight.Medium)
  413. .fontColor($r('app.color.general_font_color'))
  414. .opacity($r('app.float.general_font_opacity'))
  415. }
  416. .height('15%')
  417. .alignItems(VerticalAlign.Center)
  418. List({ space: 20, initialIndex: 0 }) {
  419. ForEach(this.storages, (item: StorageInfo) => {
  420. ListItem() {
  421. Text(item.storageName)
  422. .fontSize($r('app.float.robot_set_font_size'))
  423. .fontWeight(FontWeight.Medium)
  424. .fontColor(this.robotStorage && item.id === this.robotStorage.id ? $r('app.color.general_font_white_color') : $r('app.color.general_font_color'))
  425. .textAlign(TextAlign.Center)
  426. .width('71%')
  427. .height('12.5%')
  428. .borderRadius($r('app.float.general_border_radius'))
  429. .backgroundColor(this.robotStorage && item.id === this.robotStorage.id ? $r('app.color.robot_set_card_blue') : $r('app.color.robot_set_card_white'))
  430. .onClick(()=>{
  431. let robot = Object.assign({}, this.robots[this.selectRobot]);
  432. robot.storageId = item.id
  433. this.robots[this.selectRobot] = robot
  434. this.robotStorage = item
  435. this.controller.close()
  436. })
  437. }
  438. })
  439. }
  440. .listDirection(Axis.Vertical) // 排列方向
  441. // .edgeEffect(EdgeEffect.Spring) // 滑动到边缘无效果
  442. .height('80%')
  443. .width('100%')
  444. .alignListItem(ListItemAlign.Center)
  445. }
  446. .width('48%')
  447. .height('74%')
  448. .backgroundColor($r('app.color.page_general_background'))
  449. .justifyContent(FlexAlign.SpaceEvenly)
  450. .borderRadius($r('app.float.general_border_radius'))
  451. }
  452. }
  453. // 编辑坐标弹窗
  454. @CustomDialog
  455. struct EditCoordinateDialog {
  456. @Link private x : number
  457. @Link private y : number
  458. @State private xSize : number = 0
  459. @State private ySize : number = 0
  460. private xList : string[] = []
  461. private yList : string[] = []
  462. controller?: CustomDialogController
  463. cancel: () => void = () => {}
  464. confirm: () => void = () => {}
  465. aboutToAppear() {
  466. if (this.xSize > 0) {
  467. for (let index = 1; index <= this.xSize; index++) {
  468. this.xList.push(index.toString())
  469. }
  470. } else {
  471. this.xList.push('0')
  472. }
  473. if (this.ySize > 0) {
  474. for (let index = 1; index <= this.ySize; index++) {
  475. this.yList.push(index.toString())
  476. }
  477. } else {
  478. this.yList.push('0')
  479. }
  480. }
  481. build() {
  482. Column() {
  483. Row() {
  484. Text('当前点位')
  485. .fontSize($r('app.float.title_font_size'))
  486. .fontWeight(FontWeight.Medium)
  487. .fontColor($r('app.color.general_font_color'))
  488. .opacity($r('app.float.general_font_opacity'))
  489. }
  490. .height('16%')
  491. .alignItems(VerticalAlign.Center)
  492. Row() {
  493. Text('X轴')
  494. .fontSize($r('app.float.robot_set_font_size'))
  495. .fontWeight(FontWeight.Medium)
  496. .fontColor($r('app.color.general_font_color'))
  497. .opacity($r('app.float.general_font_opacity'))
  498. Text('Y轴')
  499. .fontSize($r('app.float.robot_set_font_size'))
  500. .fontWeight(FontWeight.Medium)
  501. .fontColor($r('app.color.general_font_color'))
  502. .opacity($r('app.float.general_font_opacity'))
  503. }
  504. .height('8%')
  505. .width('80%')
  506. .justifyContent(FlexAlign.SpaceAround)
  507. .alignItems(VerticalAlign.Center)
  508. Row() {
  509. TextPicker({ range: this.xList, selected: this.x && this.x > 0 ? this.x - 1 : 0})
  510. .onChange((value: string, index: number) => {
  511. this.x = Number.parseInt(value)
  512. console.info('textTag', 'Picker item changed, value: ' + value + ', index: ' + index)
  513. })
  514. .width('40%')
  515. .height('100%')
  516. .backgroundColor($r('app.color.bottom_bar_background'))
  517. .borderImage({source:$r('app.media.text_picker_frame'), fill: true})
  518. TextPicker({ range: this.yList, selected: this.y && this.y > 0 ? this.y - 1 : 0})
  519. .onChange((value: string, index: number) => {
  520. this.y = Number.parseInt(value)
  521. console.info('textTag', 'Picker item changed, value: ' + value + ', index: ' + index)
  522. })
  523. .width('40%')
  524. .height('100%')
  525. .backgroundColor($r('app.color.bottom_bar_background'))
  526. .borderImage({source:$r('app.media.text_picker_frame'), fill: true})
  527. }
  528. .height('52%')
  529. .width('100%')
  530. .justifyContent(FlexAlign.Center)
  531. Row() {
  532. Button('取消')
  533. .fontSize($r('app.float.robot_set_font_size'))
  534. .fontWeight(FontWeight.Medium)
  535. .fontColor($r('app.color.robot_set_card_blue'))
  536. .width('32%')
  537. .height('50%')
  538. .borderRadius($r('app.float.robot_set_radius'))
  539. .backgroundColor($r('app.color.robot_set_coord_card_grey'))
  540. .onClick(() => {
  541. this.controller.close()
  542. this.cancel()
  543. })
  544. Row()
  545. .width('2.5%')
  546. Button('确认')
  547. .fontSize($r('app.float.robot_set_font_size'))
  548. .fontWeight(FontWeight.Medium)
  549. .fontColor($r('app.color.general_font_white_color'))
  550. .width('32%')
  551. .height('50%')
  552. .borderRadius($r('app.float.robot_set_radius'))
  553. .backgroundColor($r('app.color.robot_set_card_blue'))
  554. .onClick(() => {
  555. if (this.controller != undefined) {
  556. this.controller.close()
  557. this.confirm()
  558. }
  559. })
  560. }
  561. .justifyContent(FlexAlign.Center)
  562. .height('24%')
  563. .width('100%')
  564. }
  565. .width('48%')
  566. .height('62%')
  567. .backgroundColor($r('app.color.page_general_background'))
  568. .justifyContent(FlexAlign.SpaceEvenly)
  569. .borderRadius($r('app.float.general_border_radius'))
  570. }
  571. }
  572. // 自检弹窗
  573. @CustomDialog
  574. struct SelfCheckDialog {
  575. private currentRobot: RobotInfo
  576. controller?: CustomDialogController
  577. @State checkList: RobotSelfCheck[] = []
  578. cancel: () => void = () => { }
  579. confirm: () => void = () => { }
  580. aboutToAppear() {
  581. console.log('testTag', '-----------自检弹窗' + JSON.stringify(this.currentRobot))
  582. if (this.currentRobot && this.currentRobot.id) {
  583. RobotSelfCheckModel.getListByRobotId(this.currentRobot.id).then(checks => {
  584. this.checkList = checks
  585. })
  586. }
  587. }
  588. build() {
  589. Column() {
  590. Row() {
  591. Text('自检')
  592. .fontSize($r('app.float.title_font_size'))
  593. .fontWeight(FontWeight.Medium)
  594. .fontColor($r('app.color.general_font_color'))
  595. .opacity($r('app.float.general_font_opacity'))
  596. }
  597. .height('15%')
  598. .alignItems(VerticalAlign.Center)
  599. List() {
  600. ForEach(this.checkList, (item: RobotSelfCheck)=>{
  601. ListItem(){
  602. Row(){
  603. Text(item.checkName + (item.checkStatus ? (item.checkStatus === 1 ? '正常' : '故障'): ''))
  604. .fontSize($r('app.float.set_card_font_size'))
  605. .fontWeight(FontWeight.Medium)
  606. .fontColor(item.checkStatus && item.checkStatus === 2 ? $r('app.color.robot_set_coord_card_red') : $r('app.color.general_font_color'))
  607. .opacity($r('app.float.general_font_opacity'))
  608. Text(item.checkTime)
  609. .fontSize($r('app.float.set_card_font_size'))
  610. .fontWeight(FontWeight.Medium)
  611. .fontColor($r('app.color.general_font_color'))
  612. .opacity($r('app.float.card_font_default_opacity'))
  613. }
  614. .width('100%')
  615. .padding({left: '3%', right: '3%'})
  616. .justifyContent(FlexAlign.SpaceBetween)
  617. }
  618. })
  619. }
  620. .height('65%')
  621. .width('95%')
  622. .alignListItem(ListItemAlign.Center)
  623. .borderRadius($r('app.float.general_border_radius'))
  624. .borderColor($r('app.color.general_border_color'))
  625. .borderWidth($r('app.float.general_border_width'))
  626. Row() {
  627. Button('取消')
  628. .fontSize($r('app.float.robot_set_font_size'))
  629. .fontWeight(FontWeight.Medium)
  630. .fontColor($r('app.color.robot_set_card_blue'))
  631. .width('32%')
  632. .height('50%')
  633. .borderRadius($r('app.float.robot_set_radius'))
  634. .backgroundColor($r('app.color.robot_set_coord_card_grey'))
  635. .onClick(() => {
  636. this.controller.close()
  637. this.cancel()
  638. })
  639. Row()
  640. .width('2.5%')
  641. Button('开始自检')
  642. .fontSize($r('app.float.robot_set_font_size'))
  643. .fontWeight(FontWeight.Medium)
  644. .fontColor($r('app.color.general_font_white_color'))
  645. .width('32%')
  646. .height('50%')
  647. .borderRadius($r('app.float.robot_set_radius'))
  648. .backgroundColor($r('app.color.robot_set_card_blue'))
  649. .onClick(() => {
  650. // todo 调用硬件接口
  651. let currentTime: string = TimeUtil.getCurrentTime()
  652. RobotSelfCheckModel.addRobotSelfCheck(this.currentRobot.id, '自检开始', currentTime)
  653. let check = {id:0, robotId: this.currentRobot.id, checkName: '自检开始', checkTime: currentTime}
  654. this.checkList = []
  655. this.checkList.push(check)
  656. console.log('testTag', '------'+JSON.stringify(check))
  657. // 休眠
  658. let fun = () => console.log('time out');
  659. let sleep1= (time)=> new Promise((resolve)=>{
  660. setTimeout(()=>{
  661. currentTime = TimeUtil.getCurrentTime()
  662. RobotSelfCheckModel.addRobotSelfCheck(this.currentRobot.id, '检查车轮电机', currentTime).then(id =>{
  663. RobotSelfCheckModel.updateStatus(id, 1, '')
  664. })
  665. let check2 = {id:0, robotId: this.currentRobot.id, checkName: '检查车轮电机', checkTime: currentTime, checkStatus: 1}
  666. this.checkList.push(check2)
  667. let sleep2= (time)=> new Promise((resolve)=>{
  668. currentTime = TimeUtil.getCurrentTime()
  669. setTimeout(()=>{
  670. RobotSelfCheckModel.addRobotSelfCheck(this.currentRobot.id, '自检完成', currentTime)
  671. this.controller.close()
  672. },time)
  673. })
  674. sleep2(500).then(fun);
  675. },time)
  676. })
  677. sleep1(1000).then(fun);
  678. })
  679. }
  680. .justifyContent(FlexAlign.Center)
  681. .alignItems(VerticalAlign.Center)
  682. .height('20%')
  683. .width('100%')
  684. }
  685. .width('48%')
  686. .height('74%')
  687. .backgroundColor($r('app.color.page_general_background'))
  688. .justifyContent(FlexAlign.SpaceEvenly)
  689. .borderRadius($r('app.float.general_border_radius'))
  690. }
  691. }
  692. // 编辑机器人朝向弹窗
  693. @CustomDialog
  694. struct RobotTowardDialog {
  695. @State robotToward: number = 0
  696. private currentRobot: RobotInfo
  697. selectRobot : number
  698. @Link robots: RobotInfo[]
  699. controller?: CustomDialogController
  700. cancel: () => void = () => {}
  701. confirm: () => void = () => {}
  702. aboutToAppear(){
  703. if (this.currentRobot && this.currentRobot.robotToward) {
  704. this.robotToward = this.currentRobot.robotToward
  705. }
  706. }
  707. build() {
  708. Column() {
  709. Row() {
  710. Text('机器人朝向')
  711. .fontSize($r('app.float.title_font_size'))
  712. .fontWeight(FontWeight.Medium)
  713. .fontColor($r('app.color.general_font_color'))
  714. .opacity($r('app.float.general_font_opacity'))
  715. }
  716. .height('10%')
  717. .alignItems(VerticalAlign.Bottom)
  718. Row() {
  719. Text(this.currentRobot && this.currentRobot.robotCode ? this.currentRobot.robotCode : '')
  720. .fontSize($r('app.float.card_info_font_size'))
  721. .fontWeight(FontWeight.Medium)
  722. .fontColor($r('app.color.general_font_color'))
  723. .opacity($r('app.float.card_font_default_opacity'))
  724. }
  725. .height('5%')
  726. .width('100%')
  727. .justifyContent(FlexAlign.SpaceEvenly)
  728. Row() {
  729. if (this.robotToward === 1) {
  730. Image($r('app.media.robot_toward_x_forward'))
  731. .objectFit(ImageFit.Contain)
  732. } else if (this.robotToward === 2){
  733. Image($r('app.media.robot_toward_x_negative'))
  734. .objectFit(ImageFit.Contain)
  735. } else if (this.robotToward === 3){
  736. Image($r('app.media.robot_toward_y_forward'))
  737. .objectFit(ImageFit.Contain)
  738. } else if (this.robotToward === 4){
  739. Image($r('app.media.robot_toward_y_negative'))
  740. .objectFit(ImageFit.Auto)
  741. }
  742. }
  743. .height('65%')
  744. .width('100%')
  745. Row() {
  746. this.setTowardCard(1, '+X轴')
  747. this.setTowardCard(2, '-X轴')
  748. this.setTowardCard(3, '+Y轴')
  749. this.setTowardCard(4, '-Y轴')
  750. }
  751. .height('10%')
  752. .width('88%')
  753. .borderRadius($r('app.float.general_border_radius'))
  754. .backgroundColor($r('app.color.robot_toward_set_card_background'))
  755. }
  756. .width('48%')
  757. .height('74%')
  758. .backgroundColor($r('app.color.page_general_background'))
  759. .borderRadius($r('app.float.general_border_radius'))
  760. }
  761. @Builder setTowardCard(index: number, name: string) {
  762. Row() {
  763. Stack() {
  764. if (this.robotToward === index) {
  765. Text()
  766. .backgroundColor($r('app.color.general_card_background_color'))
  767. .width('100%')
  768. .height('100%')
  769. .borderRadius($r('app.float.general_border_radius'))
  770. }
  771. Text(name)
  772. .fontSize($r('app.float.set_card_font_size'))
  773. .fontColor($r('app.color.general_font_color'))
  774. .opacity(this.robotToward === index ? $r('app.float.card_font_select_opacity') : $r('app.float.card_font_default_opacity'))
  775. }
  776. .width('100%')
  777. .height('100%')
  778. }
  779. .width('25%')
  780. .onClick(()=>{
  781. this.robotToward = index
  782. console.log('testTag', '--------------' + index)
  783. if (this.currentRobot) {
  784. this.currentRobot.robotToward = index
  785. let robot = Object.assign({}, this.robots[this.selectRobot]);
  786. robot.robotToward = this.robotToward
  787. this.robots[this.selectRobot] = robot
  788. }
  789. })
  790. }
  791. }