MultimediaCollectView.ets 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import CommonConstants from '../../common/constants/CommonConstants'
  2. import JGRequest from '../../common/util/request/Request'
  3. import PageModel from '../../viewmodel/PageModel'
  4. import StartWorkInfo from '../../viewmodel/StartWorkInfo'
  5. @Component
  6. export struct MultimediaCollectView {
  7. @State collectImages: CollectData[] = []
  8. // 照片选中状态,1:选中 2:未选中
  9. @State selectStates: number[] = []
  10. // 是否可选,默认不能选择,也不会出现删除的选项;长按某一张图片后才能选择
  11. @State canSelect: boolean = false
  12. // 生产过程id(开工信息id)
  13. processId: number
  14. // 工序id
  15. operationId: number
  16. pageNo: number = 1
  17. pageSize: number = 10
  18. totalPages: number = 1
  19. scroller: Scroller = new Scroller()
  20. async aboutToAppear() {
  21. let res: PageModel<CollectData> = await JGRequest.post('/api/v1/process/media/page', {
  22. "pageNo": this.pageNo,
  23. "pageSize": this.pageSize,
  24. "processId": this.processId,
  25. "operationId": this.operationId,
  26. })
  27. if (res && res.records && res.records.length > 0) {
  28. this.collectImages = res.records
  29. this.totalPages = res.totalPages
  30. this.pageNo++
  31. // 多次查询直到,查出所有的数据
  32. while (this.pageNo <= this.totalPages) {
  33. res = await JGRequest.post('/api/v1/process/media/page', {
  34. "pageNo": this.pageNo,
  35. "pageSize": this.pageSize,
  36. "processId": this.processId,
  37. "operationId": this.operationId,
  38. })
  39. this.totalPages = res.totalPages
  40. this.pageNo++
  41. this.collectImages = this.collectImages.concat(res.records)
  42. }
  43. }
  44. // 往数组头部插入数据 占位(包含拍照、上传按钮)
  45. this.collectImages.unshift({id: '0'})
  46. for (let index = 0; index < this.collectImages.length; index++) {
  47. this.selectStates.push(2)
  48. }
  49. }
  50. build() {
  51. Scroll(this.scroller) {
  52. Flex({ wrap: FlexWrap.Wrap }) {
  53. ForEach(this.collectImages, (item: CollectData, index: number) => {
  54. Column() {
  55. if (index === 0) {
  56. Row() {
  57. Row() {
  58. Image($r('app.media.process_camera'))
  59. .width('60%')
  60. }
  61. .width('50%')
  62. .height('80%')
  63. .justifyContent(FlexAlign.Center)
  64. Row() {
  65. Image($r('app.media.local_upload'))
  66. .width('60%')
  67. }
  68. .width('50%')
  69. .height('80%')
  70. .justifyContent(FlexAlign.Center)
  71. }
  72. .width('100%')
  73. .layoutWeight(1)
  74. .borderRadius($r('app.float.general_border_radius'))
  75. .borderStyle(BorderStyle.Dashed)
  76. .borderColor($r('app.color.material_collect_border_color'))
  77. .borderWidth(1)
  78. Row() {}
  79. .height('8%')
  80. } else {
  81. Column() {
  82. Stack() {
  83. Image(CommonConstants.FILE_URL_PREFIX + item.filePath)
  84. .objectFit(ImageFit.Fill)
  85. .borderRadius($r('app.float.general_border_radius'))
  86. if (this.canSelect) {
  87. Row() {
  88. Checkbox()
  89. .select(this.selectStates[index] === 1 ? true : false)
  90. }
  91. .width('90%')
  92. .height('90%')
  93. .justifyContent(FlexAlign.End)
  94. .alignItems(VerticalAlign.Top)
  95. }
  96. }
  97. }
  98. .layoutWeight(1)
  99. .onClick(()=> {
  100. if (this.selectStates[index] === 1) {
  101. this.selectStates[index] = 2
  102. } else {
  103. this.selectStates[index] = 1
  104. }
  105. })
  106. .gesture(
  107. LongPressGesture()
  108. .onAction(()=>{
  109. this.canSelect = true
  110. })
  111. )
  112. Row() {
  113. Text(item.created)
  114. .fontSize($r('app.float.process_card_small_font_size'))
  115. .fontColor($r('app.color.general_font_color'))
  116. .opacity($r('app.float.material_collect_font_opacity'))
  117. .fontWeight(FontWeight.Medium)
  118. }
  119. .height('8%')
  120. }
  121. }
  122. .width('17.6%')
  123. .height('39%')
  124. .justifyContent(FlexAlign.SpaceAround)
  125. Row().width('2%').height('39%')
  126. })
  127. if (this.canSelect) {
  128. Row() {
  129. Row() {
  130. Row() {
  131. Text('取消')
  132. .fontSize($r('app.float.set_card_font_size'))
  133. .fontColor($r('app.color.general_font_white_color'))
  134. }
  135. .width('50%')
  136. .height('100%')
  137. .justifyContent(FlexAlign.Center)
  138. .onClick(() => {
  139. for (let index = 0; index < this.collectImages.length; index++) {
  140. this.selectStates[index] = 2
  141. }
  142. this.canSelect = false
  143. })
  144. Divider()
  145. .height('60%')
  146. .borderWidth(1)
  147. .vertical(true)
  148. .borderColor($r('app.color.process_divider_white_color'))
  149. Row() {
  150. Text('删除')
  151. .fontSize($r('app.float.set_card_font_size'))
  152. .fontColor($r('app.color.general_font_white_color'))
  153. }
  154. .width('50%')
  155. .height('100%')
  156. .justifyContent(FlexAlign.Center)
  157. .onClick(async () => {
  158. let deleteIds: number[] = []
  159. for (let index = this.selectStates.length - 1; index >= 0; index--) {
  160. if (this.selectStates[index] === 1) {
  161. deleteIds.push(Number.parseFloat(this.collectImages[index].id))
  162. this.collectImages.splice(index, 1);
  163. }
  164. }
  165. if (deleteIds.length > 0) {
  166. await JGRequest.post('/api/v1/process/media/batch-del', {
  167. 'ids': deleteIds
  168. })
  169. }
  170. this.selectStates = []
  171. for (let index = 0; index < this.collectImages.length; index++) {
  172. this.selectStates.push(2)
  173. }
  174. this.canSelect = false
  175. })
  176. }
  177. .width('100%')
  178. .height('27.6%')
  179. .borderRadius($r('app.float.general_border_radius'))
  180. .backgroundColor($r('app.color.process_card_black_color'))
  181. }
  182. .width('37.2%')
  183. .height('39%')
  184. .alignItems(VerticalAlign.Top)
  185. }
  186. }
  187. .width('100%')
  188. .margin({top: 11, left: '2%'})
  189. }
  190. .width('100%')
  191. .scrollBar(BarState.Off) // 滚动条常驻显示
  192. .edgeEffect(EdgeEffect.None)
  193. }
  194. }
  195. class CollectData {
  196. // 创建时间
  197. created?: string
  198. // 创建人
  199. creator?: string
  200. // 删除标识
  201. deleted?: number
  202. // 部门ID
  203. deptId?: string
  204. // 修改时间
  205. updated?: string
  206. // 上次修改人
  207. updator?: string
  208. // 文件名称
  209. fileName?: string
  210. // 文件路径
  211. filePath?: string
  212. // 文件大小
  213. fileSize?: string
  214. // 文件类型
  215. fileType?: string
  216. // 主键
  217. id?: string
  218. // 预留类型字段
  219. mediaType?: number
  220. // 组织ID
  221. orgId?: string
  222. // 生产过程id
  223. processId?: string
  224. // 排序号
  225. sortNum?: number
  226. // 步骤id
  227. stepInstanceId?: string
  228. }