1/* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import hiSysEvent from '@ohos.hiSysEvent'; 16import { Log } from './Log'; 17import { MediaItem } from '../model/browser/photo/MediaItem'; 18 19const TAG: string = 'common_ReportToBigDataUtil'; 20 21export class ReportToBigDataUtil { 22 /** 23 * 前缀的字符个数是4(IMG_,VID_) 24 */ 25 private static PREFIX_NUMBER: number = 4; 26 static readonly PHOTOS_DFX_DOMAIN: string = 'PHOTOS'; 27 28 public static report(eventId: string, eventMsg?: object): void { 29 hiSysEvent.write({ 30 domain: ReportToBigDataUtil.PHOTOS_DFX_DOMAIN, 31 name: eventId, 32 eventType: hiSysEvent.EventType.BEHAVIOR, 33 params: eventMsg 34 }, (err, val) => { 35 Log.error(TAG, `report to bigData error because: ${err}`); 36 }) 37 38 Log.info(TAG, `report, eventId: ${eventId} msg: ${JSON.stringify(eventMsg)}`); 39 } 40 41 public static statisticReport(eventId: string, eventMsg?: object): void { 42 hiSysEvent.write({ 43 domain: ReportToBigDataUtil.PHOTOS_DFX_DOMAIN, 44 name: eventId, 45 eventType: hiSysEvent.EventType.STATISTIC, 46 params: eventMsg 47 }, (err, val) => { 48 Log.error(TAG, `report to bigData error because: ${err}`); 49 }) 50 51 Log.info(TAG, `report, eventId: ${eventId} msg: ${JSON.stringify(eventMsg)}`); 52 } 53 54 public static errEventReport(eventId: string, eventMsg?: object): void { 55 hiSysEvent.write({ 56 domain: ReportToBigDataUtil.PHOTOS_DFX_DOMAIN, 57 name: eventId, 58 eventType: hiSysEvent.EventType.FAULT, 59 params: eventMsg 60 }, (err, val) => { 61 Log.error(TAG, `report to bigData error because: ${err}`); 62 }) 63 Log.info(TAG, 'errEventReport, eventId: ' + eventId + ' msg: ' + JSON.stringify(eventMsg)); 64 } 65 66 // 获取相机拍摄照片视频的名称 67 public static getFileNameOfPhotoTakenByCamera(mediaItem: MediaItem): string { 68 if (mediaItem == null) { 69 return ''; 70 } 71 let name = mediaItem.getTitle(); 72 if (name == null) { 73 return ''; 74 } 75 // 匹配相机拍摄照片视频的命名格式 76 let formatExp: RegExp = /^(IMG|VID)\_\d{8}\_\d{6}$/; 77 if (name.match(formatExp) == null) { 78 return ''; 79 } 80 // 去除前缀 81 return name.slice(ReportToBigDataUtil.PREFIX_NUMBER, name.length); 82 } 83 84 public static setFileNameProperty(eventMsg: object, name: string): void { 85 if (eventMsg == null) { 86 return; 87 } 88 if (name == null || name == '') { 89 return; 90 } 91 Object.defineProperty(eventMsg, 'FileName', { value: name, enumerable: true }); 92 } 93} 94 95export class BigDataConstants { 96 97 // 进入图库方式 98 public static readonly ENTER_PHOTOS_ID: string = 'ENTER_PHOTO'; 99 // param 100 public static readonly ENTER_BY_CAMERA: string = 'ENTER_BY_CAMERA'; 101 102 // Tab切换 103 public static readonly TAB_SWITCH_ID: string = 'TAB_SWITCH'; 104 // param 105 public static readonly CLICK_SWITCH: string = 'Click'; 106 107 // 查看大图 108 public static readonly ENTER_PHOTO_BROWSER_ID: string = 'ENTER_PHOTO_BROWSER'; 109 // param 110 public static readonly LOCAL_MEDIA: string = 'LOCAL_MEDIA'; 111 112 // 查看大图 113 public static readonly PHOTO_BROWSER_SLIDE_ID: string = 'PHOTO_BROWSER_SLIDE'; 114 // param 115 public static readonly NORMAL_PHOTO: string = 'PHOTO'; 116 public static readonly VIDEO: string = 'VIDEO'; 117 118 // 删除类型操作 119 public static readonly DELETE_TYPE_ID: string = 'DELETE_TYPE'; 120 // param 121 public static readonly DELETE_CLOUD_ONLY: string = 'DELETE_CLOUD_ONLY' 122 public static readonly DELETE_LOCAL_ONLY: string = 'DELETE_LOCAL_ONLY' 123 124 public static readonly REMOVE_TYPE_ID: string = 'REMOVE_TYPE'; 125 public static readonly REMOVE: string = 'REMOVE' 126 127 128 // 删除类型操作 129 public static readonly SPLIT_SCREEN_ID: string = 'SPLIT_SCREEN'; 130 131 // 相机进入大图操作 132 public static readonly BROWSE_PHOTO_FROM_CAMERA_ID: string = 'BROWSE_PHOTO_FROM_CAMERA'; 133 134 // 照片按钮点击操作 135 public static readonly CLICK_PHOTO_BUTTON_ID: string = 'CLICK_PHOTO_BUTTON'; 136 // param 137 public static readonly PHOTO_BUTTON_VIDEO: string = 'VIDEO'; 138 139 // 下拉返回操作 140 public static readonly PHOTO_PULL_DOWN_ID: string = 'PHOTO_PULL_DOWN'; 141 142 // 全选操作 143 public static readonly SELECT_ALL_ID: string = 'SELECT_ALL'; 144 145 // 多选分享操作 146 public static readonly MULTI_SHARE_ID: string = 'MULTI_SHARE'; 147 148 // 多选删除操作 149 public static readonly MULTI_DELETE_ID: string = 'MULTI_DELETE'; 150 151 // 发送至U盘操作 152 public static readonly EXPORT_ID: string = 'EXPORT'; 153 154 // 发送至U盘结果 155 public static readonly EXPORT_RESULT_ID: string = 'EXPORT_RESULT'; 156 public static readonly CREATE_FA_CARD_ID: string = 'CREATE_FA_CARD'; 157 public static readonly DELETE_FA_CARD_ID: string = 'DELETE_FA_CARD'; 158 public static readonly CREATE_THIRD_EDIT_SAVE: string = 'CREATE_THIRD_EDIT_SAVE'; 159 public static readonly CHANGE_FA_CARD_IMAGE_ID: string = 'CHANGE_FA_CARD_IMAGE'; 160 public static readonly SET_FA_CARD_CAROUSEL_ID: string = 'SET_FA_CARD_CAROUSEL'; 161 public static readonly SET_FA_CARD_IS_NAME_ID: string = 'SET_FA_CARD_IS_NAME'; 162 163 // 选择Picker操作 164 public static readonly SELECT_PICKER_ID: string = 'SELECT_PICKER'; 165 public static readonly SELECT_PICKER_RESULT: string = 'SELECT_PICKER_RESULT'; 166 public static readonly SELECT_PICKER_CLICK_CAMERA_ID: string = 'SELECT_PICKER_CLICK_CAMERA'; 167 public static readonly SELECT_PICKER_CLICK_PREVIEW: string = 'SELECT_PICKER_CLICK_PREVIEW'; 168 public static readonly SELECT_PICKER_SWITCH_ALBUM: string = 'SELECT_PICKER_SWITCH_ALBUM'; 169 170 // ERROR 171 public static readonly FA_CARD_ERROR: string = 'FA_CARD_ERROR'; 172 public static readonly CREATE_FA_CARD_ERROR: string = 'CREATE_FA_CARD_ERROR'; 173 public static readonly DELETE_FA_CARD_ERROR: string = 'DELETE_FA_CARD_ERROR'; 174 public static readonly CHANGE_FA_CARD_IMAGE_ERROR: string = 'CHANGE_FA_CARD_IMAGE_ERROR'; 175 public static readonly SET_FA_CARD_CAROUSEL_ERROR: string = 'SET_FA_CARD_CAROUSEL_ERROR'; 176 public static readonly SET_FA_CARD_IS_NAME_ERROR: string = 'SET_FA_CARD_IS_NAME_ERROR'; 177 178 // Tab 179 public static readonly PHOTO_TAB: string = 'TIME'; 180 public static readonly ALBUM_TAB: string = 'LIST'; 181 182 // 进入大图编辑 183 public static readonly ENTER_PHOTO_EDIT_ID: string = 'ENTER_PHOTO_EDIT'; 184 185 // 大图编辑操作 186 public static readonly PHOTO_EDIT_TYPE_ID: string = 'PHOTO_EDIT_OPERATION'; 187 // param 188 public static readonly PHOTO_EDIT_ROTATE: string = 'ROTATE' 189 public static readonly PHOTO_EDIT_MIRROR: string = 'MIRROR' 190 public static readonly PHOTO_EDIT_RESET: string = 'RESET' 191 192 // 编辑保存 193 public static readonly PHOTO_EDIT_SAVE_ID: string = 'PHOTO_EDIT_SAVE' 194 //param 195 public static readonly SAVE_AS_NEW: string = 'SAVE_AS_NEW' 196 public static readonly SAVE_REPLACE: string = 'SAVE_REPLACE' 197 198 199 // 编辑保存失败 200 public static readonly PHOTO_EDIT_SAVE_ERROR_ID: string = 'GALLERY_FILE_EDIT_SAVE_FAIL' 201 202 // 进入大图方式 203 public static readonly ENTER_PHOTO_BROWSER_WAY: string = 'ENTER_PHOTO_BROWSER_WAY'; 204 // 退出大图方式 205 public static readonly ESC_PHOTO_BROWSER_WAY: string = 'ESC_PHOTO_BROWSER_WAY'; 206 // 方式 207 public static readonly BY_KEYBOARD: string = 'BY_KEYBOARD'; 208 public static readonly BY_CLICK: string = 'BY_CLICK'; 209 210 // 相册操作 211 public static readonly ALBUM_OPERATION_ID: string = 'ALBUM_OPERATION'; 212 public static readonly ALBUM_CREATE: string = 'ALBUM_CREATE'; 213 public static readonly ALBUM_RENAME: string = 'ALBUM_RENAME'; 214 public static readonly MEDIA_MOVE: string = 'MEDIA_MOVE'; 215 public static readonly MEDIA_COPY: string = 'MEDIA_COPY'; 216 // error 217 public static readonly ALBUM_OPERATION_ERROR_ID: string = 'ALBUM_OPERATION_ERROR'; 218 public static readonly ALBUM_CREATE_ERROR: string = 'ALBUM_CREATE_ERROR'; 219 public static readonly ALBUM_RENAME_ERROR: string = 'ALBUM_RENAME_ERROR'; 220 public static readonly MEDIA_MOVE_ERROR: string = 'MEDIA_MOVE_ERROR'; 221 public static readonly MEDIA_COPY_ERROR: string = 'MEDIA_COPY_ERROR'; 222 223 //是否显示菜单栏 224 public static readonly IS_SHOW_MENU_ID: string = 'IS_SHOW_MENU_FROM_THIRDVIEW'; 225 public static readonly UNDEFINED_IS_SHOW_MENU: string = 'UNDEFINED_IS_SHOW_MENU'; 226 public static readonly SHOW_MENU: string = 'SHOW_MENU'; 227 public static readonly HIDE_MENU: string = 'HIDE_MENU'; 228}