Skip to content

引入 ​

ts
import {
  getLocationInPixui,
  loginInPixui,
  getLocalStorageInPixui,
  setLocalStorageInPixui,
  checkIsDebug,
  isPixUI,
  isSimulatorInPixui,
  isBrowserInPixui
} from 't-comm';

// 不支持 tree-shaking 的项目
import {
  getLocationInPixui,
  loginInPixui,
  getLocalStorageInPixui,
  setLocalStorageInPixui,
  checkIsDebug,
  isPixUI,
  isSimulatorInPixui,
  isBrowserInPixui
} from 't-comm/lib/pixui/index';

// 只支持 ESM 的项目
import {
  getLocationInPixui,
  loginInPixui,
  getLocalStorageInPixui,
  setLocalStorageInPixui,
  checkIsDebug,
  isPixUI,
  isSimulatorInPixui,
  isBrowserInPixui
} from 't-comm/es/pixui/index';

getLocationInPixui ​

描述:获取游戏定位信息,回调数据 { flag: LocationFlagInPixui, lat: number, lng: number, }

参数:

示例

ts
const res = await getLocationInPixui(platformAPI);
if (res.flag === LocationFlagInPixui.LocationSuccess) {
  console.log('lat:', res.lat, 'lng:', res.lng);
} else if (res.flag === LocationFlagInPixui.LocationNoPermission) {
  console.log('未开启系统定位权限');
}

loginInPixui ​

描述:用户登录(初始化游戏accToken等字段)

参数:

示例

ts
import { loginInPixui, getLoginUrlInPixui } from 't-comm/es/pixui';

await loginInPixui();

// 拼接登录态参数
const url = getLoginUrlInPixui('https://api.example.com/foo');
// => https://api.example.com/foo?appid=xxx&openid=xxx&access_token=xxx&acctype=wx

getLocalStorageInPixui ​

描述:读取本地数据,IDE中不生效,在真机上才生效 数据以 app + roleId 为维度隔离存储,。存储的信息如15天不更新,会自动清除。

参数:

参数名描述
key键

示例

ts
const token = await getLocalStorageInPixui('user-token');
console.log(token);

setLocalStorageInPixui ​

描述:设置本地数据,IDE中不生效,在真机上才生效 数据以 app + roleId 为维度隔离存储,。存储的信息如15天不更新,会自动清除。

参数:

参数名描述
key键
value值

示例

ts
await setLocalStorageInPixui('user-token', 'abc123');

checkIsDebug() ​

描述:是否是本地调试

参数:

isPixUI() ​

描述:判断是否是 PixUI

参数:

示例

ts
if (isPixUI()) {
  console.log('当前是 PixUI 环境');
}

isSimulatorInPixui() ​

描述:判断是否是模拟器

参数:

示例

ts
if (isSimulatorInPixui()) {
  console.log('当前是 PixUI 模拟器环境');
}

isBrowserInPixui() ​

描述:判断是否是普通浏览器

参数:

示例

ts
if (isBrowserInPixui()) {
  localStorage.setItem('foo', 'bar');
}