TabHome.ets 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. import { Job } from '../../api/rsp/Job';
  2. import { Message } from '../../api/rsp/Message';
  3. import { Task } from '../../api/rsp/Task';
  4. import { CardContainer } from '../../components/CardContainer';
  5. import { VMHome } from '../../vm/VMHome';
  6. /**
  7. * 首页Tab页面
  8. */
  9. @Component
  10. export struct TabHome {
  11. // 父组件传递
  12. @Link vm: VMHome
  13. aboutToAppear(): void {
  14. this.vm.init()
  15. }
  16. build() {
  17. Column() {
  18. this.TopBar()
  19. Refresh({ refreshing: $$this.vm.isTabHomeRefreshing }) {
  20. Column() {
  21. this.TODOStatus()
  22. this.TODOList()
  23. }.width("100%").height("100%")
  24. }.width("100%").layoutWeight(1).onRefreshing(() => {
  25. this.vm.onTabHomeRefresh()
  26. })
  27. }
  28. .width("100%")
  29. .height("100%")
  30. .clip(false)
  31. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  32. }
  33. /**
  34. * 顶部状态栏
  35. */
  36. @Builder
  37. TopBar() {
  38. Column() {
  39. Row() {
  40. Stack() {
  41. Image($r("app.media.user")).fillColor(Color.White).margin(8)
  42. Image(this.vm.user.avatar)
  43. }
  44. .width(36)
  45. .height(36)
  46. .borderRadius("50%")
  47. .backgroundColor("#FFD700")
  48. Column() {
  49. Text(this.vm.user.nickname).fontSize(16).fontColor(Color.White).fontWeight(FontWeight.Medium)
  50. Text("角色类型").fontSize(12).fontColor(Color.White).opacity(0.8)
  51. }.layoutWeight(1).margin({ left: 10, right: 10 }).alignItems(HorizontalAlign.Start)
  52. Stack() {
  53. Image($r("app.media.bell")).width(19).height(19).fillColor(Color.White)
  54. Text(this.vm.messageUnreadCount > 99 ? "99+" : `${this.vm.messageUnreadCount}`)
  55. .backgroundColor("#FF4500")
  56. .borderRadius("50%")
  57. .fontColor(Color.White)
  58. .fontSize(10)
  59. .position({ top: -5, left: "52%" })
  60. .constraintSize({ minWidth: 15, minHeight: 15 })
  61. .textAlign(TextAlign.Center)
  62. .padding({ left: 2, right: 2 })
  63. .visibility(this.vm.messageUnreadCount == 0 ? Visibility.Hidden : Visibility.Visible)
  64. }.width(36).height(24).onClick(() => {
  65. this.getUIContext().getRouter().pushUrl({ url: "pages/PageMessage" }).catch()
  66. })
  67. // Stack() {
  68. // Image($r("app.media.settings")).width(18).height(18).fillColor(Color.White)
  69. // }.width(36).height(24).onClick(() => {
  70. // // const am = abilityAccessCtrl.createAtManager()
  71. // // am.requestPermissionsFromUser(this.getUIContext().getHostContext(), ["ohos.permission.ACCESS_BLUETOOTH"]).then((data) => {
  72. // // console.log("权限请求", JSON.stringify(data))
  73. // // })
  74. // // const bm = new BleManager("CC:BA:97:21:71:CA")
  75. // // bm.connect()
  76. // })
  77. }
  78. .width("100%")
  79. .padding({
  80. left: 16,
  81. top: 15,
  82. right: 16,
  83. bottom: 15
  84. })
  85. }
  86. .width("100%")
  87. .linearGradient({ angle: 90, colors: [['#FF8C00', 0.0], ['#FFA500', 1.0]] })
  88. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  89. }
  90. /**
  91. * 待办状态
  92. */
  93. @Builder
  94. TODOStatus() {
  95. Column() {
  96. Text(`今天有${this.vm.taskProgressCount}个待办任务`)
  97. .width("100%")
  98. .height(51)
  99. .backgroundColor("#E6F7FF")
  100. .fontSize(14)
  101. .fontColor("#333333")
  102. .textAlign(TextAlign.Center)
  103. Row() {
  104. Column() {
  105. Text(`${this.vm.taskProgressCount}`).fontSize(24).fontColor("#FFA500").fontWeight(FontWeight.Bold)
  106. Row() {
  107. Image($r("app.media.job_ing")).width(18).height(18).fillColor(Color.Black)
  108. Text("进行中").fontSize(14).fontColor($r("app.color.text")).fontWeight(FontWeight.Bold).margin({ left: 5 })
  109. }.margin({ top: 8 })
  110. }
  111. .margin(5)
  112. .layoutWeight(1)
  113. .height(80)
  114. .backgroundColor("#FFF5EB")
  115. .borderRadius(12)
  116. .justifyContent(FlexAlign.Center)
  117. Column() {
  118. Text(`${this.vm.taskFinishedCount}`).fontSize(24).fontColor("#32CD32").fontWeight(FontWeight.Bold)
  119. Row() {
  120. Image($r("app.media.job_finish")).width(18).height(18).fillColor(Color.Black)
  121. Text("本月完成").fontSize(14).fontColor($r("app.color.text")).fontWeight(FontWeight.Bold).margin({ left: 5 })
  122. }.margin({ top: 8 })
  123. }
  124. .margin(5)
  125. .layoutWeight(1)
  126. .height(80)
  127. .backgroundColor("#FFF5EB")
  128. .borderRadius(12)
  129. .justifyContent(FlexAlign.Center)
  130. }
  131. .padding({
  132. left: 5,
  133. right: 5,
  134. top: 10,
  135. bottom: 10
  136. })
  137. }.width("100%").margin({ top: 3 })
  138. }
  139. @Builder
  140. TODOList() {
  141. List() {
  142. ListItem() {
  143. Row() {
  144. Text("当前任务").fontSize(14).fontColor("#333333").fontWeight(FontWeight.Medium)
  145. Row().layoutWeight(1)
  146. Text("查看全部").fontSize(14).fontColor("#1E90FF").fontWeight(FontWeight.Medium)
  147. }.width("100%").height(46).onClick(() => {
  148. this.vm.updateTabIndex(2)
  149. })
  150. }.padding({ left: 16, right: 16 })
  151. // 空数据提示
  152. ListItem() {
  153. CardContainer() {
  154. Column() {
  155. Text("您当前暂无任务").fontSize(14).fontColor($r("app.color.text"))
  156. }.width("100%").height(102).justifyContent(FlexAlign.Center)
  157. }
  158. }.padding({ left: 16, right: 16 })
  159. .visibility(this.vm.homeTasks.length == 0 ? Visibility.Visible : Visibility.None)
  160. ForEach(this.vm.homeTasks, (task: Task, idx: number) => {
  161. ListItem() {
  162. CardContainer({ paddings: 16 }) {
  163. Column() {
  164. Row() {
  165. Text(task.name).fontSize(15).fontColor("#333333").fontWeight(FontWeight.Medium)
  166. Row().layoutWeight(1)
  167. // Text("待办")
  168. // .fontSize(12)
  169. // .fontColor("#333333")
  170. // .backgroundColor("#FFD700")
  171. // .borderRadius(20)
  172. // .height(24)
  173. // .padding({ left: 10, right: 10 })
  174. // .textAlign(TextAlign.Center)
  175. }
  176. Flex({ wrap: FlexWrap.Wrap, alignItems: ItemAlign.Center, direction: FlexDirection.Row }) {
  177. // Image($r("app.media.location")).width(12).height(12).fillColor("#1E90FF").margin({ right: 5 })
  178. // Text("车间B区")
  179. // .fontSize(13)
  180. // .fontColor("#666666")
  181. // .margin({ right: 12 })
  182. // .height(24)
  183. // .textAlign(TextAlign.Center)
  184. // 编号
  185. Image($r("app.media.jobs")).width(12).height(12).fillColor("#666666").margin({ right: 5 })
  186. Text(`${task.orderNo}`)
  187. .fontSize(13)
  188. .fontColor("#666666")
  189. .margin({ right: 12 })
  190. .height(24)
  191. .textAlign(TextAlign.Center)
  192. // 负责人
  193. Image($r("app.media.user")).width(12).height(12).fillColor("#666666").margin({ right: 5 })
  194. Text(`负责人:${task.initiatorName}`)
  195. .fontSize(13)
  196. .fontColor("#666666")
  197. .margin({ right: 12 })
  198. .height(24)
  199. .textAlign(TextAlign.Center)
  200. }.margin({ top: 10 })
  201. Row() {
  202. Text(`当前任务:`)
  203. .fontSize(13)
  204. .fontColor("#666666")
  205. .height(24)
  206. Text(`${task.currentNodeName ?? '--'}`)
  207. .backgroundColor("#1E90FF")
  208. .borderRadius(4)
  209. .padding({
  210. left: 5,
  211. top: 3,
  212. right: 5,
  213. bottom: 3
  214. })
  215. .fontSize(12)
  216. .fontColor(Color.White)
  217. Text("今天 14:00")
  218. .margin({ left: 10 })
  219. .fontColor("#999999")
  220. .fontSize(12)
  221. .layoutWeight(1)
  222. .textAlign(TextAlign.End)
  223. }.width("100%").margin({ bottom: -8 })
  224. }.width("100%").justifyContent(FlexAlign.Start).alignItems(HorizontalAlign.Start)
  225. }
  226. }
  227. .width("100%")
  228. .clip(false)
  229. .padding({ left: 16, right: 16 })
  230. .margin({ bottom: idx >= (this.vm.homeTasks.length - 1) ? 0 : 15 })
  231. })
  232. ListItem() {
  233. Row() {
  234. Text("最新消息").fontSize(14).fontColor("#333333").fontWeight(FontWeight.Medium)
  235. Row().layoutWeight(1)
  236. Text("全部消息").fontSize(14).fontColor("#1E90FF").fontWeight(FontWeight.Medium)
  237. }.width("100%").height(46).onClick(() => {
  238. this.getUIContext().getRouter().pushUrl({ url: "pages/PageMessage" }).catch()
  239. })
  240. }.padding({ left: 16, right: 16 })
  241. // 空数据提示
  242. ListItem() {
  243. CardContainer() {
  244. Column() {
  245. Text("您当前暂无消息").fontSize(14).fontColor($r("app.color.text"))
  246. }.width("100%").height(102).justifyContent(FlexAlign.Center)
  247. }
  248. }.padding({ left: 16, right: 16 })
  249. .visibility(this.vm.homeMessages.length == 0 ? Visibility.Visible : Visibility.None)
  250. ForEach(this.vm.homeMessages, (msg: Message) => {
  251. ListItem() {
  252. CardContainer({ paddings: 16 }) {
  253. Column() {
  254. Text(`${msg.title ?? "提醒"}`).fontSize(15).fontColor("#333333").fontWeight(FontWeight.Medium).margin({ bottom: 10 })
  255. Text(`${msg.templateContent}`).fontSize(13).fontColor("#666666").lineHeight(18)
  256. Row() {
  257. Text("作业管理").fontSize(12).fontColor("#999999").layoutWeight(1)
  258. Text("09:45").fontSize(12).fontColor("#999999")
  259. }.margin({ top: 6, bottom: -5 })
  260. }.width("100%").alignItems(HorizontalAlign.Start)
  261. }
  262. }
  263. .width("100%")
  264. .margin({ bottom: 15 })
  265. .padding({ left: 16, right: 16 })
  266. })
  267. }
  268. .width("100%").layoutWeight(1).scrollBar(BarState.Off)
  269. }
  270. }