JsCallAppService.ets 1.42 KB
import HashMap from '@ohos.util.HashMap';
import { Message } from 'wdJsBridge/src/main/ets/bean/Message';
import { H5ReceiveDataJsonBean, postBatchAttentionStatusResult } from 'wdBean';
import { ResponseDTO, WDHttp, HttpUrlUtils } from 'wdNetwork';

const TAG = 'JsCallAppService'


export function handleJsCallAppService(data: Message, callback: (res: string) => void) {
  let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
  let url: string = HttpUrlUtils.getHost() + data?.data?.url

  let responseMap: ResponseDTO<postBatchAttentionStatusResult> = {} as ResponseDTO<postBatchAttentionStatusResult>

  let h5ReceiveDataJson: H5ReceiveDataJsonBean<ResponseDTO<postBatchAttentionStatusResult>> = {
    netError: '0',
    responseMap
  } as H5ReceiveDataJsonBean<ResponseDTO<postBatchAttentionStatusResult>>

  // if (data?.data?.method === 'get') {
  //   WDHttp.get<ResponseDTO<postBatchAttentionStatusResult>>(url, headers).then((res: ResponseDTO<postBatchAttentionStatusResult>) => {
  //     callback(JSON.stringify(res))
  //   })
  // }
  if (data?.data?.method === 'post' && data?.data?.url === '/api/rmrb-interact/interact/zh/c/batchAttention/status') {
    WDHttp.post<ResponseDTO<postBatchAttentionStatusResult>>(url, data?.data?.parameters, headers).then((res: ResponseDTO<postBatchAttentionStatusResult>) => {
      h5ReceiveDataJson.responseMap = res
      callback(JSON.stringify(h5ReceiveDataJson))
    })
  }
}