Pre Merge pull request !109 from 张琥珀/master
This commit is contained in:
commit
87439793db
|
@ -49,6 +49,9 @@ export default class EntryAbility extends UIAbility {
|
||||||
imageKnife.setEngineKeyImpl(new CustomEngineKeyImpl())
|
imageKnife.setEngineKeyImpl(new CustomEngineKeyImpl())
|
||||||
// 设置全局内存缓存大小张数
|
// 设置全局内存缓存大小张数
|
||||||
imageKnife.setLruCacheSize(100, 100 * 1204 * 1024)
|
imageKnife.setLruCacheSize(100, 100 * 1204 * 1024)
|
||||||
|
// 请求头调用
|
||||||
|
imageKnife.addHeader('aaa', "全局调用iamgeKnife");
|
||||||
|
imageKnife.deleteHeader('aaa');
|
||||||
}
|
}
|
||||||
// 开启ImageKnife所有级别日志开关
|
// 开启ImageKnife所有级别日志开关
|
||||||
LogUtil.mLogLevel = LogUtil.ALL
|
LogUtil.mLogLevel = LogUtil.ALL
|
||||||
|
|
|
@ -34,6 +34,9 @@ struct RequestOptionLoadImage {
|
||||||
load(src: string | image.PixelMap | Resource) {
|
load(src: string | image.PixelMap | Resource) {
|
||||||
clearTimeout(timeId)
|
clearTimeout(timeId)
|
||||||
let request = new RequestOption()
|
let request = new RequestOption()
|
||||||
|
//*requestOption调用*
|
||||||
|
request.addHeader('aaa', "RequestOption拿到了");
|
||||||
|
|
||||||
request.load(src)
|
request.load(src)
|
||||||
.addListener({ callback: (err: BusinessError | string, data: ImageKnifeData) => {
|
.addListener({ callback: (err: BusinessError | string, data: ImageKnifeData) => {
|
||||||
if (data.isPixelMap()) {
|
if (data.isPixelMap()) {
|
||||||
|
|
|
@ -306,6 +306,14 @@ struct IndexFunctionDemo {
|
||||||
router.pushUrl({ url: 'pages/testImageKnifeRouter1' });
|
router.pushUrl({ url: 'pages/testImageKnifeRouter1' });
|
||||||
}).margin({ top: 5, left: 3 })
|
}).margin({ top: 5, left: 3 })
|
||||||
}.width('100%').height(60).backgroundColor(Color.Pink)
|
}.width('100%').height(60).backgroundColor(Color.Pink)
|
||||||
|
|
||||||
|
Text('测试图片header属性').fontSize(15)
|
||||||
|
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||||
|
Button('图片header属性设置')
|
||||||
|
.onClick(() => {
|
||||||
|
router.pushUrl({ url: 'pages/testImageKnifeHttpRequestHeader' });
|
||||||
|
}).margin({ top: 5, left: 3 })
|
||||||
|
}.width('100%').height(60).backgroundColor(Color.Pink)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.width('100%')
|
.width('100%')
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import router from '@ohos.router';
|
import router from '@ohos.router';
|
||||||
|
import { HeaderOption } from '@ohos/imageKnife/src/main/ets/components/imageKnife/ImageKnifeOption';
|
||||||
import {
|
import {
|
||||||
ImageKnifeComponent,
|
ImageKnifeComponent,
|
||||||
ImageKnifeOption,
|
ImageKnifeOption,
|
||||||
|
@ -25,21 +26,30 @@ import { ObjectKey } from '@ohos/libraryimageknife';
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
struct IndexFunctionDemo {
|
struct IndexFunctionDemo {
|
||||||
|
@State headerOptions: HeaderOptions = {
|
||||||
|
key: 'aaa',
|
||||||
|
values: '单个image组件调用'
|
||||||
|
};
|
||||||
|
|
||||||
|
@State headerOptions1: HeaderOptions = {
|
||||||
|
key: 'bbb',
|
||||||
|
values: '单个image组件调用1'
|
||||||
|
};
|
||||||
|
|
||||||
@State imageKnifeOption1: ImageKnifeOption =
|
@State imageKnifeOption1: ImageKnifeOption =
|
||||||
{
|
{
|
||||||
loadSrc: $r('app.media.icon'),
|
loadSrc: $r('app.media.icon'),
|
||||||
|
|
||||||
placeholderSrc: $r('app.media.icon_loading'),
|
placeholderSrc: $r('app.media.icon_loading'),
|
||||||
errorholderSrc: $r('app.media.icon_failed')
|
errorholderSrc: $r('app.media.icon_failed'),
|
||||||
|
headerOption: [this.headerOptions, this.headerOptions1]
|
||||||
};
|
};
|
||||||
|
|
||||||
@State imageKnifeOption2: ImageKnifeOption =
|
@State imageKnifeOption2: ImageKnifeOption =
|
||||||
{
|
{
|
||||||
loadSrc: $r('app.media.icon'),
|
loadSrc: $r('app.media.icon'),
|
||||||
|
|
||||||
placeholderSrc: $r('app.media.icon_loading'),
|
placeholderSrc: $r('app.media.icon_loading'),
|
||||||
errorholderSrc: $r('app.media.icon_failed')
|
errorholderSrc: $r('app.media.icon_failed'),
|
||||||
|
headerOption: [this.headerOptions, this.headerOptions1]
|
||||||
};
|
};
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
"pages/testImageAntiAliasingWithPage",
|
"pages/testImageAntiAliasingWithPage",
|
||||||
"pages/testImageKnifeRouter1",
|
"pages/testImageKnifeRouter1",
|
||||||
"pages/testImageKnifeRouter2",
|
"pages/testImageKnifeRouter2",
|
||||||
"pages/RequestOptionLoadImage"
|
"pages/RequestOptionLoadImage",
|
||||||
|
"pages/testImageKnifeHttpRequestHeader"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -99,7 +99,7 @@ export { ObjectKey } from './src/main/ets/components/imageknife/ObjectKey'
|
||||||
export {RequestOption,Size,DetachFromLayout} from './src/main/ets/components/imageknife/RequestOption'
|
export {RequestOption,Size,DetachFromLayout} from './src/main/ets/components/imageknife/RequestOption'
|
||||||
export { ImageKnifeComponent, ScaleType, ScaleTypeHelper, AntiAliasing} from './src/main/ets/components/imageknife/ImageKnifeComponent'
|
export { ImageKnifeComponent, ScaleType, ScaleTypeHelper, AntiAliasing} from './src/main/ets/components/imageknife/ImageKnifeComponent'
|
||||||
export { ImageKnifeDrawFactory } from './src/main/ets/components/imageknife/ImageKnifeDrawFactory'
|
export { ImageKnifeDrawFactory } from './src/main/ets/components/imageknife/ImageKnifeDrawFactory'
|
||||||
export {ImageKnifeOption,CropCircleWithBorder,Crop,GifOptions,TransformOptions} from './src/main/ets/components/imageknife/ImageKnifeOption'
|
export {ImageKnifeOption,CropCircleWithBorder,Crop,GifOptions,TransformOptions,HeaderOptions} from './src/main/ets/components/imageknife/ImageKnifeOption'
|
||||||
export { ImageKnifeData } from './src/main/ets/components/imageknife/ImageKnifeData'
|
export { ImageKnifeData } from './src/main/ets/components/imageknife/ImageKnifeData'
|
||||||
export {IAllCacheInfoCallback,AllCacheInfo,ResourceCacheInfo,MemoryCacheInfo,DataCacheInfo} from './src/main/ets/components/imageknife/interface/IAllCacheInfoCallback'
|
export {IAllCacheInfoCallback,AllCacheInfo,ResourceCacheInfo,MemoryCacheInfo,DataCacheInfo} from './src/main/ets/components/imageknife/interface/IAllCacheInfoCallback'
|
||||||
export {IParseImage} from './src/main/ets/components/imageknife/interface/IParseImage'
|
export {IParseImage} from './src/main/ets/components/imageknife/interface/IParseImage'
|
||||||
|
|
|
@ -50,7 +50,7 @@ export class ImageKnife {
|
||||||
resourceFetch: IResourceFetch<ArrayBuffer>;
|
resourceFetch: IResourceFetch<ArrayBuffer>;
|
||||||
filesPath: string = ""; // data/data/包名/files目录
|
filesPath: string = ""; // data/data/包名/files目录
|
||||||
|
|
||||||
|
headerMap: Map<String, String> = new Map<String, String>(); //定义全局map
|
||||||
placeholderCache: string = "placeholderCache"
|
placeholderCache: string = "placeholderCache"
|
||||||
runningMaps: EasyLinkedHashMap<string, RequestOption>;
|
runningMaps: EasyLinkedHashMap<string, RequestOption>;
|
||||||
pendingMaps: EasyLinkedHashMap<string, RequestOption>;
|
pendingMaps: EasyLinkedHashMap<string, RequestOption>;
|
||||||
|
@ -99,6 +99,14 @@ export class ImageKnife {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//全局设置请求头调用方法
|
||||||
|
addHeader(key: string, value: string) {
|
||||||
|
this.headerMap.set(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteHeader(key: string) {
|
||||||
|
this.headerMap.delete(key);
|
||||||
|
}
|
||||||
|
|
||||||
getMemoryCache(): MemoryLruCache {
|
getMemoryCache(): MemoryLruCache {
|
||||||
return this.memoryCache;
|
return this.memoryCache;
|
||||||
|
@ -279,6 +287,10 @@ export class ImageKnife {
|
||||||
// 每个request 公共信息补充
|
// 每个request 公共信息补充
|
||||||
request.setFilesPath(this.filesPath);
|
request.setFilesPath(this.filesPath);
|
||||||
|
|
||||||
|
if (this.headerMap.size > 0) {
|
||||||
|
request.addHeaderMap(this.headerMap)
|
||||||
|
}
|
||||||
|
|
||||||
// 首先执行占位图 解析任务
|
// 首先执行占位图 解析任务
|
||||||
if (request.placeholderSrc) {
|
if (request.placeholderSrc) {
|
||||||
PlaceHolderManager.execute(request)
|
PlaceHolderManager.execute(request)
|
||||||
|
|
|
@ -222,6 +222,14 @@ export struct ImageKnifeComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
configDisplay(request: RequestOption) {
|
configDisplay(request: RequestOption) {
|
||||||
|
//单个image组件多个请求头调用
|
||||||
|
if (this.imageKnifeOption.headerOption != underfined && this.imageKnifeOption.headerOption?.length > 0) {
|
||||||
|
for (let i = 0; i < this.imageKnifeOption.headerOption.length; i++) {
|
||||||
|
let headerOptions = this.imageKnifeOption.headerOption[i];
|
||||||
|
request.addHeader(headerOptions.key, headerOptions.values);
|
||||||
|
}
|
||||||
|
console.log('wxxx 999:' + JSON.stringify(this.imageKnifeOption.headerOption.length));
|
||||||
|
}
|
||||||
if (this.imageKnifeOption.placeholderSrc) {
|
if (this.imageKnifeOption.placeholderSrc) {
|
||||||
request.placeholder(this.imageKnifeOption.placeholderSrc, {asyncSuccess:(data:ImageKnifeData) => {
|
request.placeholder(this.imageKnifeOption.placeholderSrc, {asyncSuccess:(data:ImageKnifeData) => {
|
||||||
LogUtil.log('ImageKnifeComponent request.placeholder callback')
|
LogUtil.log('ImageKnifeComponent request.placeholder callback')
|
||||||
|
|
|
@ -57,9 +57,15 @@ export interface TransformOptions{
|
||||||
rotateImage?: number
|
rotateImage?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface HeaderOptions {
|
||||||
|
key: string;
|
||||||
|
values: string;
|
||||||
|
}
|
||||||
|
|
||||||
@Observed
|
@Observed
|
||||||
export class ImageKnifeOption {
|
export class ImageKnifeOption {
|
||||||
|
// header请求列表
|
||||||
|
headerOption?: Array<HeaderOptions>;
|
||||||
// 主图资源
|
// 主图资源
|
||||||
loadSrc: string | PixelMap | Resource = '';
|
loadSrc: string | PixelMap | Resource = '';
|
||||||
mainScaleType?: ScaleType = ScaleType.FIT_CENTER
|
mainScaleType?: ScaleType = ScaleType.FIT_CENTER
|
||||||
|
|
|
@ -60,6 +60,17 @@ export interface DetachFromLayout{
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RequestOption {
|
export class RequestOption {
|
||||||
|
// 遍历添加图片http请求头
|
||||||
|
map: Map<string, string> = new Map<string, string>();
|
||||||
|
// RequestOption调用header对于的方法
|
||||||
|
addHeader(key: string, value: string) {
|
||||||
|
this.map.set(key, value);
|
||||||
|
}
|
||||||
|
// 全局调用header对应的方法,包含RequestOption的形式
|
||||||
|
addHeaderMap(map: Map<string, string>) {
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
uuid:string ='' // 唯一标识
|
uuid:string ='' // 唯一标识
|
||||||
loadSrc: string | PixelMap | Resource = '';
|
loadSrc: string | PixelMap | Resource = '';
|
||||||
strategy: DiskStrategy = new AUTOMATIC();
|
strategy: DiskStrategy = new AUTOMATIC();
|
||||||
|
|
|
@ -29,6 +29,13 @@ class RequestData{
|
||||||
totalSize: number = 2000
|
totalSize: number = 2000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Header {
|
||||||
|
public map: Map<string, string> = new Map<string, string>();
|
||||||
|
constructor(map: Map<string, string>) {
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class HttpDownloadClient implements IDataFetch {
|
export class HttpDownloadClient implements IDataFetch {
|
||||||
loadData(request: RequestOption, onComplete: (img: ArrayBuffer) => void, onError: (err: string) => void) {
|
loadData(request: RequestOption, onComplete: (img: ArrayBuffer) => void, onError: (err: string) => void) {
|
||||||
try {
|
try {
|
||||||
|
@ -45,7 +52,6 @@ export class HttpDownloadClient implements IDataFetch {
|
||||||
// 下载数据流多次返回
|
// 下载数据流多次返回
|
||||||
arrayBuffers.push(data);
|
arrayBuffers.push(data);
|
||||||
})
|
})
|
||||||
|
|
||||||
httpRequest.on('dataReceiveProgress', (data: RequestData) => {
|
httpRequest.on('dataReceiveProgress', (data: RequestData) => {
|
||||||
// 下载进度
|
// 下载进度
|
||||||
if(data != undefined && (typeof data.receiveSize == 'number') && (typeof data.totalSize == 'number') ) {
|
if(data != undefined && (typeof data.receiveSize == 'number') && (typeof data.totalSize == 'number') ) {
|
||||||
|
@ -55,16 +61,17 @@ export class HttpDownloadClient implements IDataFetch {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
httpRequest.on('dataEnd', () => {
|
httpRequest.on('dataEnd', () => {
|
||||||
// 下载完毕
|
// 下载完毕
|
||||||
let combineArray = this.combineArrayBuffers(arrayBuffers);
|
let combineArray = this.combineArrayBuffers(arrayBuffers);
|
||||||
onComplete(combineArray)
|
onComplete(combineArray)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log('refer' + JSON.stringify(request.map.get('aaa')));
|
||||||
httpRequest.requestInStream(
|
httpRequest.requestInStream(
|
||||||
request.loadSrc as string,
|
request.loadSrc as string,
|
||||||
{
|
{
|
||||||
|
header: new Header(request.map),
|
||||||
method: http.RequestMethod.GET,
|
method: http.RequestMethod.GET,
|
||||||
expectDataType: http.HttpDataType.ARRAY_BUFFER,
|
expectDataType: http.HttpDataType.ARRAY_BUFFER,
|
||||||
connectTimeout: 60000, // 可选 默认60000ms
|
connectTimeout: 60000, // 可选 默认60000ms
|
||||||
|
|
|
@ -101,7 +101,7 @@ export {RequestOption,Size} from '@ohos/imageknife'
|
||||||
export {ObjectKey} from '@ohos/imageknife'
|
export {ObjectKey} from '@ohos/imageknife'
|
||||||
export { ImageKnifeComponent, ScaleType, ScaleTypeHelper, AntiAliasing} from '@ohos/imageknife'
|
export { ImageKnifeComponent, ScaleType, ScaleTypeHelper, AntiAliasing} from '@ohos/imageknife'
|
||||||
export { ImageKnifeDrawFactory } from '@ohos/imageknife'
|
export { ImageKnifeDrawFactory } from '@ohos/imageknife'
|
||||||
export {ImageKnifeOption,CropCircleWithBorder,Crop,GifOptions,TransformOptions} from '@ohos/imageknife'
|
export {ImageKnifeOption,CropCircleWithBorder,Crop,GifOptions,TransformOptions,HeaderOptions} from '@ohos/imageknife'
|
||||||
export { ImageKnifeData } from '@ohos/imageknife'
|
export { ImageKnifeData } from '@ohos/imageknife'
|
||||||
export {IAllCacheInfoCallback,AllCacheInfo,ResourceCacheInfo,MemoryCacheInfo,DataCacheInfo} from '@ohos/imageknife'
|
export {IAllCacheInfoCallback,AllCacheInfo,ResourceCacheInfo,MemoryCacheInfo,DataCacheInfo} from '@ohos/imageknife'
|
||||||
export {IParseImage} from '@ohos/imageknife'
|
export {IParseImage} from '@ohos/imageknife'
|
||||||
|
|
Loading…
Reference in New Issue