Showing
5 changed files
with
105 additions
and
5 deletions
| @@ -175,3 +175,4 @@ export { ReserveItemBean } from './src/main/ets/bean/live/ReserveItemBean'; | @@ -175,3 +175,4 @@ export { ReserveItemBean } from './src/main/ets/bean/live/ReserveItemBean'; | ||
| 175 | 175 | ||
| 176 | 176 | ||
| 177 | export { FeedbackTypeBean } from './src/main/ets/bean/detail/FeedbackTypeBean'; | 177 | export { FeedbackTypeBean } from './src/main/ets/bean/detail/FeedbackTypeBean'; |
| 178 | +export { FeedbackImageItem } from './src/main/ets/bean/detail/FeedbackImageItem'; |
| 1 | -import { FeedbackTypeBean } from 'wdBean/Index'; | ||
| 2 | -import { NetworkUtil } from 'wdKit/Index'; | 1 | +import { FeedbackImageItem, FeedbackTypeBean } from 'wdBean/Index'; |
| 2 | +import { FastClickUtil, Logger, NetworkUtil } from 'wdKit/Index'; | ||
| 3 | import { MultiPictureDetailViewModel } from '../viewmodel/MultiPictureDetailViewModel'; | 3 | import { MultiPictureDetailViewModel } from '../viewmodel/MultiPictureDetailViewModel'; |
| 4 | import { CustomTitleUI } from './reusable/CustomTitleUI' | 4 | import { CustomTitleUI } from './reusable/CustomTitleUI' |
| 5 | import { ArrayList } from '@kit.ArkTS'; | 5 | import { ArrayList } from '@kit.ArkTS'; |
| 6 | +import { picker } from '@kit.CoreFileKit'; | ||
| 7 | +import { BusinessError } from '@kit.BasicServicesKit'; | ||
| 8 | +import { router } from '@kit.ArkUI'; | ||
| 6 | 9 | ||
| 7 | const TAG = 'FeedBackActivity' | 10 | const TAG = 'FeedBackActivity' |
| 8 | // 意见反馈页面 | 11 | // 意见反馈页面 |
| @@ -15,6 +18,11 @@ export struct FeedBackActivity { | @@ -15,6 +18,11 @@ export struct FeedBackActivity { | ||
| 15 | @State isNetConnected: boolean = true | 18 | @State isNetConnected: boolean = true |
| 16 | 19 | ||
| 17 | @State feedbackTypeBeans: FeedbackTypeBean[] = [] as FeedbackTypeBean[] | 20 | @State feedbackTypeBeans: FeedbackTypeBean[] = [] as FeedbackTypeBean[] |
| 21 | + //添加图片 | ||
| 22 | + addPic: FeedbackImageItem = {itemType:1} as FeedbackImageItem | ||
| 23 | + @State pics: FeedbackImageItem[] = [this.addPic] as FeedbackImageItem[] | ||
| 24 | + // 选择媒体文件的最大数目 | ||
| 25 | + selectNum = 3; | ||
| 18 | 26 | ||
| 19 | async aboutToAppear() { | 27 | async aboutToAppear() { |
| 20 | await this.getContentDetailData() | 28 | await this.getContentDetailData() |
| @@ -35,13 +43,13 @@ export struct FeedBackActivity { | @@ -35,13 +43,13 @@ export struct FeedBackActivity { | ||
| 35 | GridRow({ | 43 | GridRow({ |
| 36 | gutter: { x: 2, y: 2 } | 44 | gutter: { x: 2, y: 2 } |
| 37 | }) { | 45 | }) { |
| 38 | - ForEach(this.feedbackTypeBeans, (item: FeedbackTypeBean, index: number) => { | 46 | + ForEach(this.feedbackTypeBeans, (feedbackTypeBean: FeedbackTypeBean, index: number) => { |
| 39 | GridCol({ | 47 | GridCol({ |
| 40 | span: 12 | 48 | span: 12 |
| 41 | }) { | 49 | }) { |
| 42 | Row(){ | 50 | Row(){ |
| 43 | Toggle({ type: ToggleType.Checkbox, isOn: false }) | 51 | Toggle({ type: ToggleType.Checkbox, isOn: false }) |
| 44 | - Text(item.classifyName) | 52 | + Text(feedbackTypeBean.classifyName) |
| 45 | .fontColor($r('app.color.color_222222')) | 53 | .fontColor($r('app.color.color_222222')) |
| 46 | .fontSize($r('app.float.font_size_14')) | 54 | .fontSize($r('app.float.font_size_14')) |
| 47 | .fontWeight(FontWeight.Bold) | 55 | .fontWeight(FontWeight.Bold) |
| @@ -68,10 +76,35 @@ export struct FeedBackActivity { | @@ -68,10 +76,35 @@ export struct FeedBackActivity { | ||
| 68 | GridRow({ | 76 | GridRow({ |
| 69 | gutter: { x: 2, y: 2 } | 77 | gutter: { x: 2, y: 2 } |
| 70 | }) { | 78 | }) { |
| 71 | - ForEach(this.feedbackTypeBeans, (item: FeedbackTypeBean, index: number) => { | 79 | + |
| 80 | + ForEach(this.pics, (feedbackImageItem: FeedbackImageItem, index: number) => { | ||
| 72 | GridCol({ | 81 | GridCol({ |
| 73 | span: 12 | 82 | span: 12 |
| 74 | }) { | 83 | }) { |
| 84 | + if(1 == feedbackImageItem.itemType){ | ||
| 85 | + Image($r('app.media.icon_add_attention')) | ||
| 86 | + .width(60) | ||
| 87 | + .height(60) | ||
| 88 | + .onClick(async (event: ClickEvent) => { | ||
| 89 | + if(await FastClickUtil.isMinDelayTime()){ | ||
| 90 | + return | ||
| 91 | + } | ||
| 92 | + this.callFilePickerSelectImage(); | ||
| 93 | + }) | ||
| 94 | + }else{ | ||
| 95 | + Stack({alignContent: Alignment.TopEnd}) { | ||
| 96 | + Image(feedbackImageItem.path) | ||
| 97 | + .width(60) | ||
| 98 | + .height(60) | ||
| 99 | + .borderRadius($r('app.float.margin_1')) | ||
| 100 | + Image($r('app.media.icon_feekback_delete')) | ||
| 101 | + .width(24) | ||
| 102 | + .height(24) | ||
| 103 | + .borderRadius($r('app.float.margin_1')) | ||
| 104 | + } | ||
| 105 | + .width(60) | ||
| 106 | + .height(60) | ||
| 107 | + } | ||
| 75 | } | 108 | } |
| 76 | }) | 109 | }) |
| 77 | } | 110 | } |
| @@ -126,4 +159,64 @@ export struct FeedBackActivity { | @@ -126,4 +159,64 @@ export struct FeedBackActivity { | ||
| 126 | console.log('请求失败',JSON.stringify(exception)) | 159 | console.log('请求失败',JSON.stringify(exception)) |
| 127 | } | 160 | } |
| 128 | } | 161 | } |
| 162 | + | ||
| 163 | + /** | ||
| 164 | + * 拉起picker选择图片/视频 | ||
| 165 | + */ | ||
| 166 | + async callFilePickerSelectImage(): Promise<void> { // async 用于申明一个 function 是异步的 | ||
| 167 | + let array: string[]; | ||
| 168 | + try { | ||
| 169 | + // 设置photoPicker的参数 | ||
| 170 | + let PhotoSelectOptions = new picker.PhotoSelectOptions(); | ||
| 171 | + PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型 | ||
| 172 | + PhotoSelectOptions.maxSelectNumber = this.selectNum; // 选择媒体文件的最大数目 | ||
| 173 | + let mediaFlag = false; | ||
| 174 | + let photoPicker = new picker.PhotoViewPicker(); // 使用图库选择器对象前,需要先创建PhotoViewPicker实例 | ||
| 175 | + photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult) => { | ||
| 176 | + Logger.info(TAG, 'PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); // 日志中记录成功信息 | ||
| 177 | + if (PhotoSelectResult !== null && PhotoSelectResult !== undefined) { // 接口采用callback异步返回形式,返回PhotoSelectResult对象,故进行下一步操作前要先判断是否已经成功返回PhotoSelectResult对象了 | ||
| 178 | + | ||
| 179 | + // PhotoSelectResult为返回的结果集。 | ||
| 180 | + // 其中包含Array<string>类型的photoUris,为返回图库选择后的媒体文件的uri数组;还包含boolean类型的isOriginalPhoto,指示返回图库选择后的媒体文件是否为原图。 | ||
| 181 | + // 声明变量array,其取值为PhotoSelectResult中的数组。 | ||
| 182 | + array = PhotoSelectResult['photoUris']; | ||
| 183 | + let totalLen = this.pics.length+array.length; | ||
| 184 | + if(totalLen > 3){ | ||
| 185 | + totalLen = 3 | ||
| 186 | + } | ||
| 187 | + this.pics.length = totalLen; | ||
| 188 | + let startIndex = this.pics.length-1; | ||
| 189 | + | ||
| 190 | + array.forEach((value) => { | ||
| 191 | + let pic: FeedbackImageItem = {itemType:2,path:value} as FeedbackImageItem | ||
| 192 | + this.pics[startIndex] = pic | ||
| 193 | + startIndex = startIndex+1; | ||
| 194 | + mediaFlag = true; | ||
| 195 | + Logger.info(TAG, `select image/video uri: ${value}`); | ||
| 196 | + }) | ||
| 197 | + if(this.pics.length<3){ | ||
| 198 | + this.pics[this.pics.length-1]=this.addPic; | ||
| 199 | + } | ||
| 200 | + } | ||
| 201 | + if (mediaFlag) { | ||
| 202 | + this.getFilenameByUriForMedia(array); | ||
| 203 | + } | ||
| 204 | + }) | ||
| 205 | + .catch((err: BusinessError) => { | ||
| 206 | + Logger.error(TAG, 'PhotoViewPicker.select failed with err: ' + JSON.stringify(err)); | ||
| 207 | + }); | ||
| 208 | + } catch (err) { | ||
| 209 | + Logger.error(TAG, 'PhotoViewPicker failed with err: ' + err); | ||
| 210 | + } | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + async getFilenameByUriForMedia(myUris: string[]) { | ||
| 214 | + router.pushUrl({ | ||
| 215 | + url: 'pages/ViewMedia', | ||
| 216 | + params: { | ||
| 217 | + uris: myUris | ||
| 218 | + } | ||
| 219 | + }, router.RouterMode.Standard); | ||
| 220 | + } | ||
| 221 | + | ||
| 129 | } | 222 | } |
1.95 KB
-
Please register or login to post a comment