JsBridgeBiz.ets 1.72 KB
import { Callback, BridgeWebViewControl } from 'wdJsBridge';
import { Message } from 'wdJsBridge/src/main/ets/bean/Message';
import { Logger, StringUtils, } from 'wdKit';
import { H5CallNativeType } from './H5CallNativeType';
import { ContentDTO } from 'wdBean';
//TODO 这里引用了 features模块,是否考虑将跳转抽到公共模块
import { ProcessUtils } from '../../../../../../features/wdComponent/src/main/ets/utils/ProcessUtils';

const TAG = 'JsBridgeBiz'

/**
 * h5调用native代码
 * @param data
 * @param call
 */
export function performJSCallNative(data: Message, call: Callback) {
  Logger.debug(TAG, 'performJSCallNative handlerName: ' + data.handlerName + ', data: ' + JSON.stringify(data.data))
  switch (data.handlerName) {
    case H5CallNativeType.jsCall_currentPageOperate:
      break;
    case H5CallNativeType.jsCall_getAppPublicInfo:
    // h5获取app配置信息
      call(getAppPublicInfo())
      break;
    case H5CallNativeType.jsCall_getArticleDetailBussinessData:
      break;
    case H5CallNativeType.jsCall_callAppService:
      break;
    case H5CallNativeType.jsCall_receiveH5Data:
      handleH5Data(JSON.parse(data?.data?.dataJson || '{}'))
      break;
    case 'changeNativeMessage':
      call("this is change Web Message")
      break;
    default:
      call("this is def value")
  }

}

class AppInfo {
  plat: string = ''
  system: string = ''
  // TODO 完善
}

/**
 * 获取App公共信息
 */
function getAppPublicInfo(): string {
  let info = new AppInfo()
  info.plat = 'Phone'
  // 直接用Android,后续适配再新增鸿蒙
  info.system = 'Android'
  let result = JSON.stringify(info)
  return result;
}

function handleH5Data(content:ContentDTO) {
  ProcessUtils.processPage(content)
}