Showing
1 changed file
with
30 additions
and
21 deletions
| @@ -5,11 +5,11 @@ import { promptAction } from '@kit.ArkUI'; | @@ -5,11 +5,11 @@ import { promptAction } from '@kit.ArkUI'; | ||
| 5 | import { image } from '@kit.ImageKit'; | 5 | import { image } from '@kit.ImageKit'; |
| 6 | import { photoAccessHelper } from '@kit.MediaLibraryKit'; | 6 | import { photoAccessHelper } from '@kit.MediaLibraryKit'; |
| 7 | import fs from '@ohos.file.fs'; | 7 | import fs from '@ohos.file.fs'; |
| 8 | -import { DateTimeUtils, NetworkUtil, PermissionUtil } from 'wdKit'; | 8 | +import { DateTimeUtils, NetworkUtil, PermissionUtil, PermissionUtils } from 'wdKit'; |
| 9 | import { PrivacySettingModel } from '../model/PrivacySettingModel'; | 9 | import { PrivacySettingModel } from '../model/PrivacySettingModel'; |
| 10 | import { TrackConstants, TrackingButton } from 'wdTracking'; | 10 | import { TrackConstants, TrackingButton } from 'wdTracking'; |
| 11 | import { faceDetector } from '@kit.CoreVisionKit'; | 11 | import { faceDetector } from '@kit.CoreVisionKit'; |
| 12 | -import mediaLibrary from '@ohos.multimedia.mediaLibrary'; | 12 | +// import mediaLibrary from '@ohos.multimedia.mediaLibrary'; |
| 13 | import fileIo from '@ohos.file.fs'; | 13 | import fileIo from '@ohos.file.fs'; |
| 14 | import { httpRequest } from '../utils/httpRequest'; | 14 | import { httpRequest } from '../utils/httpRequest'; |
| 15 | import { taskpool } from '@kit.ArkTS'; | 15 | import { taskpool } from '@kit.ArkTS'; |
| @@ -61,6 +61,15 @@ export struct ImageDownloadComponent { | @@ -61,6 +61,15 @@ export struct ImageDownloadComponent { | ||
| 61 | .iconColor(Color.White) | 61 | .iconColor(Color.White) |
| 62 | .onClick(async () => { | 62 | .onClick(async () => { |
| 63 | //console.info(`cj2024 onClick ${this.imageBuffer}`) | 63 | //console.info(`cj2024 onClick ${this.imageBuffer}`) |
| 64 | + // let readGrant = await PermissionUtils.checkPermissions(PERMISSIONS[0]) | ||
| 65 | + // let writeGrant = await PermissionUtils.checkPermissions(PERMISSIONS[1]) | ||
| 66 | + // console.info(`cj2024 onClick readGrant ${readGrant} writeGrant ${writeGrant}`) | ||
| 67 | + // if (!readGrant && !writeGrant) { | ||
| 68 | + // const context = getContext(this) as common.UIAbilityContext; | ||
| 69 | + // let requestGrant = await PermissionUtils.reqPermissionsFromUser(PERMISSIONS, context); | ||
| 70 | + // } else { | ||
| 71 | + // | ||
| 72 | + // } | ||
| 64 | if (this.imageBuffer !== undefined) { | 73 | if (this.imageBuffer !== undefined) { |
| 65 | try { | 74 | try { |
| 66 | await this.saveImage(this.imageBuffer); | 75 | await this.saveImage(this.imageBuffer); |
| @@ -134,7 +143,7 @@ export struct ImageDownloadComponent { | @@ -134,7 +143,7 @@ export struct ImageDownloadComponent { | ||
| 134 | * @returns | 143 | * @returns |
| 135 | */ | 144 | */ |
| 136 | async saveImage(buffer: ArrayBuffer | string): Promise<void> { | 145 | async saveImage(buffer: ArrayBuffer | string): Promise<void> { |
| 137 | - //console.info(`cj2024 saveImage buffer ${buffer} isGranted = ${this.isGranted}`) | 146 | + console.info(`cj2024 saveImage buffer ${buffer} isGranted = ${this.isGranted}`) |
| 138 | if (!this.isGranted) { | 147 | if (!this.isGranted) { |
| 139 | //跳转权限设置 | 148 | //跳转权限设置 |
| 140 | // const permissionUtil = new PermissionUtil(); | 149 | // const permissionUtil = new PermissionUtil(); |
| @@ -154,23 +163,23 @@ export struct ImageDownloadComponent { | @@ -154,23 +163,23 @@ export struct ImageDownloadComponent { | ||
| 154 | // const file = await fs.open(uri, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); | 163 | // const file = await fs.open(uri, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); |
| 155 | // await fs.write(file.fd, buffer); | 164 | // await fs.write(file.fd, buffer); |
| 156 | // await fs.close(file.fd); | 165 | // await fs.close(file.fd); |
| 157 | - let media = mediaLibrary.getMediaLibrary(context); | ||
| 158 | - let publicPath = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); | ||
| 159 | - let picName = DateTimeUtils.getCurDate(DateTimeUtils.PATTERN_DATE_TIME_DEFAULT) + '.jpg' | ||
| 160 | - // //console.info(`cj2024 saveImage time ${picName}`) | ||
| 161 | - let asset = await media.createAsset(mediaLibrary.MediaType.IMAGE, picName, publicPath); | ||
| 162 | - | ||
| 163 | - if (asset) { | ||
| 164 | - let fd = await asset.open('rw'); | ||
| 165 | - await fileIo.write(fd, buffer); | ||
| 166 | - await asset.close(fd); | ||
| 167 | - promptAction.showToast({ message: '已保存至相册!' }); | ||
| 168 | - } else { | ||
| 169 | - if (this.isGranted) { | ||
| 170 | - promptAction.showToast({ message: '保存图片失败!' }); | ||
| 171 | - } | ||
| 172 | - | ||
| 173 | - throw new Error('Failed to create asset'); | ||
| 174 | - } | 166 | + // let media = mediaLibrary.getMediaLibrary(context); |
| 167 | + // let publicPath = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); | ||
| 168 | + // let picName = DateTimeUtils.getCurDate(DateTimeUtils.PATTERN_DATE_TIME_DEFAULT) + '.jpg' | ||
| 169 | + // // //console.info(`cj2024 saveImage time ${picName}`) | ||
| 170 | + // let asset = await media.createAsset(mediaLibrary.MediaType.IMAGE, picName, publicPath); | ||
| 171 | + // | ||
| 172 | + // if (asset) { | ||
| 173 | + // let fd = await asset.open('rw'); | ||
| 174 | + // await fileIo.write(fd, buffer); | ||
| 175 | + // await asset.close(fd); | ||
| 176 | + // promptAction.showToast({ message: '已保存至相册!' }); | ||
| 177 | + // } else { | ||
| 178 | + // if (this.isGranted) { | ||
| 179 | + // promptAction.showToast({ message: '保存图片失败!' }); | ||
| 180 | + // } | ||
| 181 | + // | ||
| 182 | + // throw new Error('Failed to create asset'); | ||
| 183 | + // } | ||
| 175 | } | 184 | } |
| 176 | } | 185 | } |
-
Please register or login to post a comment