Files
biz_firstpage/src/main/ets/util/ImageLoader.ets
T
clz af0025ce38 Initial commit: @b2c/first_page HarmonyOS stage-mode HAR
## Repository
- HarmonyOS stage-mode HAR module, consumed by host app
- No standalone build — hvigorw, oh_modules, and ../biz_quote absent here

## Architecture
### Feed Cards
- FirstPage.createNodeView dispatches cards by FirstPageConstant.KEY_*
- Card config from first_page_cards_config.json loaded by FirstPageCardsConfigLoader
- Public entrypoint: Index.ets

### Market Ranking (src/main/ets/market-ranking/)
- HTTP: MarketRankingDataFetcher fetches recommend_futures contracts
- HQ: MarketRankingHqRequestClient subscribes via 4106/frame 2201/scenario qht_qihuo_sort
- TCP reconnect rebuilds subscription from original HTTP contract list
- Async callbacks guarded by request/subscription versions

### Other Cards
- HotList, CommodityOptions, AiDiagnosis, AiRiseFall, SelfSelectedStock, CustomEntryList, FourEntryList
- Each has DataFetcher + HQ request client + NodeComponent

## Key Changes (from CardHarmonyOS reference)
- Added MetricId, PeriodId, SortOrder enums (MarketRankingModels.ets)
- Replaced string comparisons with enum switches in thirdColumnTitle/Value/Color
- Removed redundant undefined guards in thirdColumnColor/priceColor, delegated to riseFallColor
- Inlined priceColor(), use riseFallColor directly
- Tab bar Stack.height(30), Alignment.End (reverted from 46/TopEnd)
- Name column fontWeight removed (default regular)
2026-07-26 01:13:28 +08:00

72 lines
2.3 KiB
Plaintext

import { image } from "@kit.ImageKit";
import { http } from "@kit.NetworkKit";
import { HXLog } from "biz_common";
import { BusinessError } from "@kit.BasicServicesKit";
/**
* author : liuqingliang@myhexin.com
* time : created on 2026/6/1
* desc : 网络图片加载
*/
const TAG = 'ImageLoader'
export class ImageLoader {
static load(imgUrl: string, onLoadFailed: (errMsg: string) => void, onResourceReady: (img: image.PixelMap) => void) {
try {
const httpRequest = http.createHttp()
httpRequest.request(imgUrl).then(async (response) => {
if (response.responseCode === 200) {
const arrayBuffer = response.result as ArrayBuffer
const imageSource = image.createImageSource(arrayBuffer)
try {
let img = imageSource.createPixelMapSync()
onResourceReady(img)
} finally {
await imageSource.release()
}
} else {
onLoadFailed(`ImageLoader load request failed. responseCode:${response.responseCode}`)
}
}).catch((err: Error) => {
onLoadFailed(err.message)
HXLog.e(TAG, JSON.stringify(err))
}).finally(() => {
httpRequest.destroy()
})
} catch (e) {
const err = e as BusinessError
HXLog.e(TAG, `ImageLoader load failed. msg:${err.message}`)
onLoadFailed(err.message)
}
}
static async loadSync(imgUrl: string): Promise<image.PixelMap | null> {
let img: image.PixelMap | null = null
let imageSource: image.ImageSource | null = null
try {
const httpRequest = http.createHttp()
try {
const response: http.HttpResponse = await httpRequest.request(imgUrl)
if (response.responseCode === 200) {
const arrayBuffer = response.result as ArrayBuffer
imageSource = image.createImageSource(arrayBuffer)
img = imageSource.createPixelMapSync()
}
} catch (e) {
const err = e as BusinessError
HXLog.e(TAG, `ImageLoader load failed. msg:${err.message}`)
} finally {
httpRequest.destroy()
}
} catch (e) {
const err = e as BusinessError
HXLog.e(TAG, `ImageLoader load failed. msg:${err.message}`)
} finally {
if (imageSource) {
imageSource.release()
}
}
return img
}
}