3.3.11 • Published 2 years ago

ali-ltcom-ltao-u-utils v3.3.11

Weekly downloads
-
License
-
Repository
gitlab
Last release
2 years ago

Badges

Build status Line coverage Branch coverage TNPM version TNPM downloads


how to use

import { mtop, viewport, util, tracker } from '@ali/ltcom-ltao-u-utils';

const queryData = (params) => {
  return mtop({
    api: 'mtop.ltao.interaction.platform.api',
    v: '1.0',
    data: params
  });
}

viewport();

const {
  headerBarHeight,
  headerTotalHeight,
  nativeBackListener,
  nativeGoBack,
  openWindow,
  goldLogExp,
  goldLogClk,
} = util;

util 说明

属性类型描述
spmArrarraya, b码]
isAndroidbool是否是安卓
headerBarHeightnumber头部刘海区域的高度
headerTotalHeightnumber整体头部的高度
isLTAppfunction返回是否是特价版
isLiteLTAppfunction返回是否是特价版极简包
isOfficialLTAppfunction返回是否是特价版正式包
getTtidfunction获得用户的ttid
isDebugAllfunction是否是debug模式
getUrlParamsfunction(url = window.location.href)获取url上所有query的对象
queryfunction(name, url = window.location.href)获取url上指定参数的值
getDataFromArrayfunction(key, value, arr)在数组上找到指定key=value的对象
formatBoolfunction(value)将value转化为bool
openLTAppfunction(channelId)唤端, 自定义频道id
throttlefunction(fn, delay = 300)防抖
toastfunction(message = '', delay = 1500, options = {})toast防抖
goldLogExpfunction(key, param)黄金令箭曝光
goldLogClkfunction(key, param)黄金令箭点击
setLocalStoragefunction(name, value, expires)设置ls, expires为设置过期的毫秒数
getLocalStoragefunction(name)获取ls
nativeGoBackfunction回退
openWindowfunction(link, spmc, spmd)打开一个链接
replaceWindowfunction(link, spmc, spmd)replace的方式打开一个链接
nativeBackListenerfunction监听返回的回调事件
setCustomPageTitlefunction(params)设置native的title
setNavBarStylefunction(params)设置native头部样式
setStatusBarStylefunction(params)设置状态栏样式

tracker 说明

import { tracker } from '@ali/ltcom-ltao-u-utils';

const {
  loadingStartTrigger,           // 记录loadingstart的时间,只记录不上报
  loadingEndTrigger,             // 记录loadingend的时间,只记录不上报
  firstScreenCompletedTrigger,   // 记录首屏加载完成的时间, 也会上报fsTime,只记录不上报
  fsTimeTrigger,                 // 记录fsTime的时间,优先级高于firstScreenCompleted上报的值,只记录不上报
  pushTracker,                   // 一次性上报之前记录的时间,参数为采样率的分母
} = tracker;

useEffect(() => {
  // 比如:认为 dom 出来的时候,就是loading开始的时间点
  loadingStartTrigger();
}, []);

useEffect(() => {
  // 比如:认为在页面的loading隐藏的时候,记录时间点
  if (!isLoading) {
    loadingEndTrigger();
  }
}, [isLoading]);

useEffect(() => {
  // 比如:认为请求返回的时候,认为是页面加载完成,记录时间点
  // 并发送上报的请求
  if (!isLoading) {
    firstScreenCompletedTrigger();
    pushTracker();
  }
}, [applyFinish]);
方法名参数描述
loadingStartTrigger(duration)传入performance的时间长度,默认为performance.now()
loadingEndTrigger(duration)传入performance的时间长度,默认为performance.now()
firstScreenCompletedTrigger(duration, unInteractive)传入performance的时间长度,默认为performance.now(), unInteractive: 自动上传interactive数据,默认false,true时不上传
fsTimeTrigger(duration)传入performance的时间长度,默认为performance.now()
pushTracker(sampling = 10)传入采样率的分母,如传入5,则采样率为1/5 = 20%
interactiveTrigger()手动上传interactive数据