RobotDebug.ets 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. import { TitleStateComp } from '../common/component/TitleStateComp';
  2. import { RobotPreviewComp } from '../common/component/RobotPreviewComp';
  3. import RobotInfo from '../model/RobotInfo';
  4. import CommonConstants from '../common/constants/CommonConstants';
  5. import StorageInfo from '../model/StorageInfo';
  6. import StorageSpace from '../model/StorageSpace';
  7. import SpaceStateList from '../model/SpaceStateList';
  8. import StorageModel from '../model/database/StorageModel';
  9. import StorageSpaceModel from '../model/database/StorageSpaceModel';
  10. import { RobotLogComp } from '../common/component/RobotLogComp';
  11. import StorageConfig from '../viewmodel/StorageConfig';
  12. import JGRequest from '../common/util/request/Request';
  13. export interface NavigationItem {
  14. id: number;
  15. text: string;
  16. icon: Resource;
  17. }
  18. export const NavigationList: NavigationItem[] = [
  19. {
  20. id: 0,
  21. text: '总控',
  22. icon: $r('app.media.daohangzongkong')
  23. },
  24. {
  25. id: 1,
  26. text: '位移',
  27. icon: $r('app.media.daohangyidong')
  28. },
  29. {
  30. id: 2,
  31. text: '车轮',
  32. icon: $r('app.media.daohangchelun')
  33. },
  34. {
  35. id: 3,
  36. text: '吊篮',
  37. icon: $r('app.media.daohangdiaolan')
  38. },
  39. {
  40. id: 4,
  41. text: '充电',
  42. icon: $r('app.media.daohangchongdian')
  43. },
  44. ]
  45. @Entry
  46. @Component
  47. export struct RobotDebug {
  48. @State mCurrentPage: number = 0;
  49. private isHomePage: boolean = false
  50. private mTabController: TabsController = new TabsController()
  51. @State selectRobot: number = 1
  52. // todo
  53. @State storages: StorageInfo[] = []
  54. @State list: Resource[] = [$r('app.media.car_preview'), $r('app.media.car_preview'), $r('app.media.car_preview')]
  55. @State robots: RobotInfo[] = CommonConstants.ROBOTS
  56. @State robotX: number | undefined = 0
  57. @State robotY: number | undefined = 0
  58. @State robotStorage: StorageInfo = {}
  59. // 机器人在网格中展示的图片
  60. @State robotImage: Resource = $r('app.media.robot_toward_1')
  61. @State robotArmX: number | undefined= 0
  62. @State robotArmY: number | undefined= 0
  63. scroller: Scroller = new Scroller()
  64. /*
  65. * 仓储格子相关
  66. * */
  67. // key为storageSpace的y值
  68. @State spaceArray: StorageSpace[][] = []
  69. // 储位状态(1:禁用 2:未设置类型 3:正常 4:禁用+选中 5:未设置类型+选中 6:正常+选中)
  70. @State stateArray: Array<SpaceStateList> = [];
  71. @State selectSpace: StorageSpace = {}
  72. @State yNum: number[] = []
  73. async aboutToAppear() {
  74. let storageId:number | undefined = 0
  75. if (this.robots && this.robots[this.selectRobot]) {
  76. let robot: RobotInfo = this.robots[this.selectRobot]
  77. storageId = robot.storageId
  78. switch (robot.robotToward) {
  79. case 1:
  80. this.robotImage = $r('app.media.robot_toward_1')
  81. this.robotArmX = (robot.x?robot.x:0) + 1
  82. this.robotArmY = robot.y
  83. break
  84. case 2:
  85. this.robotImage = $r('app.media.robot_toward_2')
  86. this.robotArmX = (robot.x?robot.x:0)- 1
  87. this.robotArmY = robot.y
  88. break
  89. case 3:
  90. this.robotImage = $r('app.media.robot_toward_3')
  91. this.robotArmX = (robot.x?robot.x:0)
  92. this.robotArmY = (robot.y?robot.y:0) + 1
  93. break
  94. default:
  95. this.robotImage = $r('app.media.robot_toward_4')
  96. this.robotArmX = (robot.x?robot.x:0)
  97. this.robotArmY = (robot.y?robot.y:0) - 1
  98. break
  99. }
  100. }
  101. if (storageId === 0) {
  102. return
  103. }
  104. let spaces: StorageSpace[] = []
  105. // 查询本地数据库,没有则添加数据(仓储和储位数据)
  106. this.storages = await StorageModel.getStorageList()
  107. if (!this.storages || this.storages.length <= 0) {
  108. // 查询后台数据库的线边库
  109. let config: StorageConfig = await JGRequest.get("/api/v1/wms/position/houseConfigInfo/" + 1, {})
  110. if (!config) {
  111. return
  112. }
  113. this.storages.push({
  114. storageName: config.houseName,
  115. xSize: config.xNum,
  116. ySize: config.yNum,
  117. defaultLayer: config.layer
  118. } as StorageInfo)
  119. let storageId = await StorageModel.addStorage(config.houseName as string, config.xNum as number, config.yNum as number, config.layer as number)
  120. this.storages[0].id = storageId
  121. if (config.xNum && config.xNum > 0 && config.yNum && config.yNum > 0) {
  122. for (let y = 1; y <= config.yNum; y++) {
  123. for (let x = 1; x <= config.xNum; x++) {
  124. let space: StorageSpace = {
  125. storageId: storageId,
  126. x: x,
  127. y: y,
  128. enableState: 1,
  129. storageType: '',
  130. capacity: config.layer,
  131. canWay: 1,
  132. canPark: 0
  133. }
  134. space.id = await StorageSpaceModel.addStorageSpace(space)
  135. // spaces.push(space)
  136. }
  137. }
  138. }
  139. }
  140. for (const storage of this.storages) {
  141. if (storageId === storage.id) {
  142. this.robotStorage = storage
  143. break
  144. }
  145. }
  146. if (this.robotStorage) {
  147. let x: number = 0
  148. if (this.robotStorage.xSize && this.robotStorage.xSize > 0) {
  149. x = this.robotStorage.xSize
  150. } else {
  151. return
  152. }
  153. // 生成需要遍历的行 (y倒序)
  154. if (this.robotStorage.ySize && this.robotStorage.ySize > 0) {
  155. if (this.robotStorage.ySize && this.robotStorage.ySize > 0) {
  156. for (let index = this.robotStorage.ySize - 1; index >= 0; index--) {
  157. this.yNum.push(index)
  158. }
  159. }
  160. } else {
  161. return
  162. }
  163. StorageSpaceModel.getListByStorageId((this.robotStorage.id?this.robotStorage.id:0)).then(spaces => {
  164. if (spaces && spaces.length > 0) {
  165. let tempArray: StorageSpace[] = []
  166. let stateList = new SpaceStateList()
  167. for (const space of spaces) {
  168. tempArray.push(space)
  169. // 储位状态创建
  170. if (space.enableState === 2) {
  171. stateList.push(1)
  172. } else if (!space.storageType || space.storageType.length === 0) {
  173. stateList.push(2)
  174. } else {
  175. stateList.push(3)
  176. }
  177. if (tempArray.length === x) {
  178. this.spaceArray.push(tempArray)
  179. this.stateArray.push(stateList)
  180. tempArray = []
  181. stateList = new SpaceStateList()
  182. }
  183. }
  184. }
  185. })
  186. }
  187. }
  188. updateViewData() {
  189. if (this.robots && this.robots[this.selectRobot]) {
  190. this.robotX = this.robots[this.selectRobot].x ? this.robots[this.selectRobot].x : 0
  191. this.robotY = this.robots[this.selectRobot].y ? this.robots[this.selectRobot].y : 0
  192. if (this.robots[this.selectRobot].robotType === 2) {
  193. let robot: RobotInfo = this.robots[this.selectRobot - 1]
  194. switch (robot.robotToward) {
  195. case 1:
  196. this.robotImage = $r('app.media.robot_toward_1')
  197. this.robotArmX =(robot.x?robot.x:0) + 1
  198. this.robotArmY = robot?.y
  199. break
  200. case 2:
  201. this.robotImage = $r('app.media.robot_toward_2')
  202. this.robotArmX = (robot.x?robot.x:0)- 1
  203. this.robotArmY = robot.y
  204. break
  205. case 3:
  206. this.robotImage = $r('app.media.robot_toward_3')
  207. this.robotArmX = robot.x
  208. this.robotArmY = (robot.y?robot.y:0) + 1
  209. break
  210. default:
  211. this.robotImage = $r('app.media.robot_toward_4')
  212. this.robotArmX = robot.x
  213. this.robotArmY = (robot.y?robot.y:0) - 1
  214. break
  215. }
  216. }
  217. }
  218. for (const storage of this.storages) {
  219. if (this.robots && this.robots[this.selectRobot] && this.robots[this.selectRobot].storageId && this.robots[this.selectRobot].storageId === storage.id) {
  220. this.robotStorage = storage
  221. }
  222. }
  223. }
  224. build() {
  225. Column() {
  226. TitleStateComp({ isHomePage: this.isHomePage})
  227. Row() {
  228. Column() {
  229. Column() {
  230. Text('机器人调试')
  231. .padding(10)
  232. .width('100%')
  233. .height('8%')
  234. .fontSize($r('app.float.title_font_size'))
  235. .textAlign(TextAlign.Start)
  236. Flex() {
  237. Tabs({ barPosition: BarPosition.Start, controller: this.mTabController }) {
  238. TabContent() {
  239. Column() {
  240. this.card('调试模式', $r('app.media.zongkongtiaoshi'))
  241. this.card('自动模式', $r('app.media.zongkongzidong'))
  242. Divider().width('90%')
  243. .margin({ bottom: '20px' })
  244. this.card('电机通电', $r('app.media.zongkongdianjitongdian'))
  245. this.card('电机断电', $r('app.media.zongkongguanbidianji'))
  246. }
  247. .alignItems(HorizontalAlign.Start)
  248. .width('100%')
  249. .height('100%')
  250. .margin({ left: '24px' })
  251. }
  252. .tabBar(this.TabBuilder(0))
  253. TabContent() {
  254. Column() {
  255. Row() {
  256. Column() {
  257. Text('当前坐标')
  258. .fontSize('24px')
  259. .fontWeight(FontWeight.Medium)
  260. .margin({ left: '26px' })
  261. Text('X:2 Y:3')
  262. .fontSize('20px')
  263. .fontWeight(FontWeight.Regular)
  264. .margin({ left: '26px' })
  265. }
  266. .height('52px')
  267. .alignItems(HorizontalAlign.Start)
  268. Blank()
  269. Image($r('app.media.weiyibianjiweizhi'))
  270. .width('48px')
  271. .height('48px')
  272. .margin('20px')
  273. }
  274. .width('90%')
  275. .height('12%')
  276. .backgroundColor('#FFFFFF')
  277. .alignItems(VerticalAlign.Center)
  278. .borderRadius('16px')
  279. .margin({ bottom: '18px' })
  280. Divider().margin({ bottom: '20px' }).width('90%')
  281. this.card('+X轴移1格', $r('app.media.weiyix'))
  282. this.card('-X轴移1格', $r('app.media.weiyixx'))
  283. this.card('+Y轴移1格', $r('app.media.weiyiy'))
  284. this.card('-Y轴移1格', $r('app.media.weiyiyy'))
  285. Divider().margin({ bottom: '20px' }).width('90%')
  286. this.card('中止', $r('app.media.weiyizhongzhi'))
  287. this.card('急停', $r('app.media.weiyijiting'))
  288. }
  289. .alignItems(HorizontalAlign.Start)
  290. .width('100%')
  291. .height('100%')
  292. .margin({ left: '24px' })
  293. }
  294. .tabBar(this.TabBuilder(1))
  295. TabContent() {
  296. Column() {
  297. this.card('置顶', $r('app.media.chelunzhiding'))
  298. this.card('置中', $r('app.media.chelunzhizhong'))
  299. this.card('置底', $r('app.media.chelunzhidi'))
  300. }
  301. .alignItems(HorizontalAlign.Start)
  302. .width('100%')
  303. .height('100%')
  304. .margin({ left: '24px' })
  305. }
  306. .tabBar(this.TabBuilder(2))
  307. TabContent() {
  308. Column() {
  309. Row() {
  310. Text('当前吊篮位')
  311. .fontSize('20px')
  312. .fontWeight(FontWeight.Medium)
  313. .margin({ right: '110px' })
  314. Text('上限位')
  315. .fontSize('20px')
  316. .fontWeight(FontWeight.Medium)
  317. }
  318. .height('7%')
  319. .width('90%')
  320. .justifyContent(FlexAlign.SpaceBetween)
  321. .alignItems(VerticalAlign.Bottom)
  322. Divider().margin({ bottom: '20px' }).width('90%')
  323. this.card('提起', $r('app.media.dianlanshang'))
  324. this.card('放下', $r('app.media.dianlanxia'))
  325. Divider().margin({ bottom: '20px' }).width('90%')
  326. this.card('张开爪夹', $r('app.media.dianlanzhangkai'))
  327. this.card('闭合爪夹', $r('app.media.dianlanbihe'))
  328. Divider().margin({ bottom: '20px' }).width('90%')
  329. this.card('急停', $r('app.media.dianlanjiting'))
  330. }
  331. .alignItems(HorizontalAlign.Start)
  332. .width('100%')
  333. .height('100%')
  334. .margin({ left: '24px' })
  335. }
  336. .tabBar(this.TabBuilder(3))
  337. TabContent() {
  338. Column() {
  339. Row() {
  340. Text('当前状态')
  341. .fontSize('20px')
  342. .fontWeight(FontWeight.Medium)
  343. .margin({ right: '130px' })
  344. .width('90px')
  345. .height('26px')
  346. Text('充电中')
  347. .fontSize('20px')
  348. .fontWeight(FontWeight.Medium)
  349. .width('60px')
  350. .height('26px')
  351. }
  352. .alignItems(VerticalAlign.Bottom)
  353. .width('90%')
  354. .justifyContent(FlexAlign.SpaceBetween)
  355. .height('5%')
  356. Divider().width('90%')
  357. Row() {
  358. Text('当前电量')
  359. .fontSize('20px')
  360. .fontWeight(FontWeight.Medium)
  361. .margin({ right: '130px' })
  362. .width('90px')
  363. .height('26px')
  364. Text('80%')
  365. .fontSize('20px')
  366. .fontWeight(FontWeight.Medium)
  367. .width('60px')
  368. .height('26px')
  369. }
  370. .width('90%')
  371. .justifyContent(FlexAlign.SpaceBetween)
  372. .height('26px')
  373. .margin({ top: '20px' })
  374. Divider().width('90%')
  375. Row() {
  376. Text('电压')
  377. .fontSize('20px')
  378. .fontWeight(FontWeight.Medium)
  379. .margin({ right: '130px' })
  380. .width('90px')
  381. .height('26px')
  382. Text('50V')
  383. .fontSize('20px')
  384. .fontWeight(FontWeight.Medium)
  385. .width('60px')
  386. .height('26px')
  387. }
  388. .height('26px')
  389. .margin({ top: '20px' })
  390. .width('90%')
  391. .justifyContent(FlexAlign.SpaceBetween)
  392. Divider().width('90%')
  393. Row() {
  394. Text('电流')
  395. .fontSize('20px')
  396. .fontWeight(FontWeight.Medium)
  397. .margin({ right: '130px' })
  398. .width('90px')
  399. .height('26px')
  400. Text('10mA')
  401. .fontSize('20px')
  402. .fontWeight(FontWeight.Medium)
  403. .width('60px')
  404. .height('26px')
  405. }
  406. .width('90%')
  407. .justifyContent(FlexAlign.SpaceBetween)
  408. .height('26px')
  409. .margin({ top: '20px' })
  410. Divider().margin({ bottom: '20px' }).width('90%')
  411. this.card('开始充电', $r('app.media.chongdianlianjie'))
  412. this.card('停止充电', $r('app.media.chongdianduankai'))
  413. }
  414. .alignItems(HorizontalAlign.Start)
  415. .width('100%')
  416. .height('100%')
  417. .margin({ left: '24px' })
  418. }
  419. .tabBar(this.TabBuilder(4))
  420. }
  421. .vertical(true)
  422. .onChange((index) => {
  423. this.mCurrentPage = index;
  424. })
  425. .borderRadius($r('app.float.general_border_radius'))
  426. .barWidth('30%')
  427. .barHeight('100%')
  428. .scrollable(false)
  429. .barMode(BarMode.Fixed)
  430. }
  431. .width('100%')
  432. .height('90%')
  433. .margin({ bottom: '27px', left: '40px' })
  434. }
  435. .width('100%')
  436. .height('95%')
  437. }
  438. .width('25%')
  439. .height('100%')
  440. Column() {
  441. // 机器人预览图片和当前机器人状态
  442. Row() {
  443. RobotPreviewComp({
  444. list: $list,
  445. selectRobot: $selectRobot,
  446. robots: $robots,
  447. robotX: $robotX,
  448. robotY: $robotY,
  449. robotStorage: $robotStorage,
  450. storages: $storages,
  451. })
  452. .width($r('app.float.robot_image_list_size'))
  453. Blank()
  454. Row() {
  455. Image($r('app.media.robot'))
  456. .width($r('app.float.card_image_size'))
  457. .height($r('app.float.card_image_size'))
  458. Text(this.robots && this.robots[this.selectRobot] && this.robots[this.selectRobot].robotCode ? this.robots[this.selectRobot].robotCode : '')
  459. .fontSize($r('app.float.robot_state_font_size'))
  460. .fontWeight(FontWeight.Medium)
  461. .fontColor($r('app.color.general_font_color'))
  462. .opacity($r('app.float.general_font_opacity'))
  463. .width('40%')
  464. }
  465. .width('15%')
  466. .justifyContent(FlexAlign.SpaceEvenly)
  467. Row() {
  468. Image($r('app.media.battery_level'))
  469. .width($r('app.float.card_image_size'))
  470. .height($r('app.float.card_image_size'))
  471. Text('98%')
  472. .fontSize($r('app.float.robot_state_font_size'))
  473. .fontWeight(FontWeight.Medium)
  474. .fontColor($r('app.color.general_font_color'))
  475. .opacity($r('app.float.general_font_opacity'))
  476. }
  477. .width('10%')
  478. .justifyContent(FlexAlign.SpaceEvenly)
  479. Row() {
  480. Image($r('app.media.coordinate'))
  481. .width($r('app.float.card_image_size'))
  482. .height($r('app.float.card_image_size'))
  483. 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 : ' '))
  484. .fontSize($r('app.float.robot_state_font_size'))
  485. .fontWeight(FontWeight.Medium)
  486. .fontColor($r('app.color.general_font_color'))
  487. .opacity($r('app.float.general_font_opacity'))
  488. }
  489. .width('10%')
  490. .justifyContent(FlexAlign.SpaceEvenly)
  491. Row() {
  492. Image($r('app.media.robot_auto_mode'))
  493. .width($r('app.float.card_image_size'))
  494. .height($r('app.float.card_image_size'))
  495. Text('自动模式')
  496. .fontSize($r('app.float.robot_state_font_size'))
  497. .fontWeight(FontWeight.Medium)
  498. .fontColor($r('app.color.general_font_color'))
  499. .opacity($r('app.float.general_font_opacity'))
  500. }
  501. .width('12%')
  502. .justifyContent(FlexAlign.SpaceEvenly)
  503. }
  504. .width('100%')
  505. .height('8%')
  506. .justifyContent(FlexAlign.End)
  507. .padding({ right: '2%' })
  508. Row() {
  509. SpaceGrid({
  510. stateArray: $stateArray,
  511. selectSpace: $selectSpace,
  512. yNum: $yNum,
  513. spaceArray: $spaceArray,
  514. robotX: $robotX,
  515. robotY: $robotY,
  516. robotArmX: $robotArmX,
  517. robotArmY: $robotArmY,
  518. robotImage: $robotImage,
  519. })
  520. }
  521. .width('100%')
  522. .alignItems(VerticalAlign.Center)
  523. .layoutWeight(1)
  524. .onDragEnter(() => {
  525. if (this.selectSpace) {
  526. this.stateArray[(this.selectSpace.y?this.selectSpace.y:0)-1][(this.selectSpace.x?this.selectSpace.x:0)-1] -= 3
  527. }
  528. this.selectSpace = {}
  529. })
  530. .onClick(()=>{
  531. if (this.selectSpace) {
  532. this.stateArray[(this.selectSpace.y?this.selectSpace.y:0)-1][(this.selectSpace.x?this.selectSpace.x:0)-1] -= 3
  533. }
  534. this.selectSpace = {}
  535. })
  536. Row() {
  537. Row() {
  538. RobotLogComp()
  539. }
  540. .width('20%')
  541. .height('100%')
  542. }
  543. .width('100%')
  544. .height('20%')
  545. .justifyContent(FlexAlign.End)
  546. .padding({ right: '3%' })
  547. }
  548. .width('75%')
  549. .height('100%')
  550. }
  551. .backgroundColor('#F1F3F5')
  552. .width('100%')
  553. .height('92%')
  554. }
  555. .width('100%')
  556. .height('100%')
  557. }
  558. // 动画效果
  559. pageTransition() {
  560. PageTransitionEnter({ duration: 400, curve: Curve.Linear, delay: 400 })
  561. .scale({
  562. x: 0,
  563. y: 0,
  564. z: 0,
  565. centerX: '50%',
  566. centerY: '50%'
  567. })
  568. PageTransitionExit({ duration: 400, curve: Curve.Linear })
  569. .scale({ x: 0, y: 0, z: 0 })
  570. }
  571. @Builder
  572. TabBuilder(index: number) {
  573. Column() {
  574. Image(NavigationList[index].icon)
  575. .width($r('app.float.general_icon_size'))
  576. .height($r('app.float.general_icon_size'))
  577. Text(NavigationList[index].text)
  578. .fontSize($r('app.float.set_card_font_size'))
  579. .fontColor($r('app.color.general_font_color'))
  580. .opacity($r('app.float.general_font_opacity'))
  581. .fontWeight(FontWeight.Medium)
  582. }
  583. .margin({ left: 10, right: 10 })
  584. .backgroundColor(index === this.mCurrentPage ? '#FFFFFF' : '#F1F3F5')
  585. .borderRadius($r('app.float.general_border_radius'))
  586. .justifyContent(FlexAlign.Center)
  587. .opacity(index === this.mCurrentPage ? 1 : 0.6)
  588. .width('100%')
  589. .height('80%')
  590. }
  591. @Builder
  592. card(text: string, icon: Resource) {
  593. Row() {
  594. Text(text)
  595. .fontSize('24px')
  596. .fontWeight(FontWeight.Medium)
  597. .margin({ left: '26px' })
  598. Blank()
  599. Image(icon)
  600. .width('48px')
  601. .height('48px')
  602. .margin('20px')
  603. }
  604. .width('90%')
  605. .height('12%')
  606. .backgroundColor('#FFFFFF')
  607. .alignItems(VerticalAlign.Center)
  608. .borderRadius('16px')
  609. .margin({ bottom: '20px' })
  610. }
  611. }
  612. @Component
  613. struct SpaceGrid {
  614. @Link stateArray: Array<SpaceStateList>
  615. @Link selectSpace: StorageSpace
  616. @Link yNum: number[]
  617. @Link spaceArray: StorageSpace[][]
  618. @Link robotX: number
  619. @Link robotY: number
  620. @Link robotArmX: number
  621. @Link robotArmY: number
  622. @Link robotImage: Resource
  623. scroller: Scroller = new Scroller()
  624. build() {
  625. Column() {
  626. Scroll(this.scroller) {
  627. Scroll(this.scroller) {
  628. List() {
  629. ForEach(this.yNum, (y: number) => {
  630. ListItem() {
  631. List() {
  632. ForEach(this.spaceArray[y], (item: StorageSpace) => {
  633. ListItem() {
  634. Stack() {
  635. if (this.robotX && this.robotY && item.x === this.robotX && item.y === this.robotY) {
  636. Image($r('app.media.robot_top'))
  637. .objectFit(ImageFit.Fill)
  638. } else if (this.robotArmX && this.robotArmY && item.x === this.robotArmX && item.y === this.robotArmY) {
  639. Image($r('app.media.robot_arm'))
  640. .objectFit(ImageFit.Fill)
  641. } else {
  642. Image((this.stateArray[y][(item.x?item.x:0)-1] === 1 || this.stateArray[y][(item.x?item.x:0)-1] === 4) ? $r("app.media.storage_space_disable") :
  643. (this.stateArray[y][(item.x?item.x:0)-1] === 2 || this.stateArray[y][(item.x?item.x:0)-1] === 5 ? $r('app.media.storage_space_no_type') : $r("app.media.storage_space")))
  644. .objectFit(ImageFit.Fill)
  645. }
  646. if (this.selectSpace && this.selectSpace.id === item.id) {
  647. Image($r('app.media.storage_space_select'))
  648. .objectFit(ImageFit.Auto)
  649. }
  650. if (this.selectSpace && this.selectSpace.id === item.id) {
  651. Text(item.x + ':' + item.y)
  652. .fontSize($r('app.float.robot_set_font_size'))
  653. .fontColor($r('app.color.general_font_color'))
  654. .opacity($r('app.float.card_font_default_opacity'))
  655. } else {
  656. Text(item.x + ':' + item.y)
  657. .fontSize($r('app.float.robot_set_font_size'))
  658. .fontColor(item.enableState === 2 ? $r('app.color.robot_set_card_white') : $r('app.color.general_font_color'))
  659. .opacity(item.enableState === 2 ? 1 : $r('app.float.card_font_default_opacity'))
  660. }
  661. }
  662. .width($r('app.float.storage_space_set_size'))
  663. .height($r('app.float.storage_space_set_size'))
  664. .onClick(() => {
  665. if (this.selectSpace) {
  666. this.stateArray[(this.selectSpace.y?this.selectSpace.y:0)-1][(this.selectSpace.y?this.selectSpace.y:0)-1] -= 3
  667. }
  668. this.stateArray[y][(item.x?item.x:0)-1] += 3
  669. this.selectSpace = item
  670. })
  671. .onDragStart(() => {
  672. let isRobotPosition = false
  673. if ((this.robotX && this.robotY && item.x === this.robotX && item.y === this.robotY) || (this.robotArmX && this.robotArmY && item.x === this.robotArmX && item.y === this.robotArmY)) {
  674. isRobotPosition = true
  675. }
  676. if (!isRobotPosition) {
  677. return
  678. }
  679. // 设置拖拽过程中显示的图片
  680. return this.pixelMapBuilder
  681. })
  682. .onDragEnter(() => {
  683. if (this.selectSpace) {
  684. this.stateArray[(this.selectSpace.y?this.selectSpace.y:0)-1][(this.selectSpace.x?this.selectSpace.x:0)-1] -= 3
  685. }
  686. this.stateArray[y][(item.x?item.x:0)-1] += 3
  687. this.selectSpace = item
  688. })
  689. }
  690. })
  691. }
  692. .listDirection(Axis.Horizontal)
  693. }
  694. })
  695. }
  696. .alignListItem(ListItemAlign.Center)
  697. .onDrop((event: DragEvent, extraParams: string) => {
  698. console.log('List onDragMove, ' + extraParams + 'X:' + event.getWindowX() + 'Y:' + event.getWindowY())
  699. })
  700. }
  701. .scrollable(ScrollDirection.Horizontal)
  702. }
  703. }
  704. .width('100%')
  705. .layoutWeight(1)
  706. .justifyContent(FlexAlign.Center)
  707. .alignItems(HorizontalAlign.Center)
  708. }
  709. @Builder
  710. pixelMapBuilder() {
  711. Column() {
  712. Image(this.robotImage)
  713. .width('262px')
  714. .height($r('app.float.storage_space_set_size'))
  715. }
  716. }
  717. }