@ray-js/ty-outdoor-utils
v1.0.1
Published
出行工具库
Downloads
203
Readme
English | 简体中文
@ray-js/ty-outdoor-utils
Outdoor Utils
Installation
Note: DeviceKit needs to be introduced when using the travel secondary page jump, and it must be in version >=1.2.6
$ npm install @ray-js/ty-outdoor-utils
# or
$ yarn add @ray-js/ty-outdoor-utils
Develop
# watch compile component code
yarn watch
# watch compile demo
yarn start:tuya
Usage
import OutdoorUtils from '@ray-js/ty-outdoor-utils';
const { hooks } = OutdoorUtils;
const { usePayUrls } = hooks;
export default function Home() {
const [qrcode, setQrcode] = useState('');
const { returnUrl } = usePayUrls();
const makeQrcode = () => {
const img = OutdoorUtils.QRcode.make('hello world!');
setQrcode(img);
};
const openSubPage = () => {
OutdoorUtils.jumpSubPage.toCyclingRecord({
deviceId: 'devId',
fail: e => console.log('err', e),
});
};
return (
<View className={styles.view}>
<Button onClick={makeQrcode}>生成二维码</Button>
<Button onClick={openSubPage}>跳转出行二级页</Button>
{qrcode && (
<View className={styles.center}>
<Image src={qrcode} />
</View>
)}
<Button onClick={() => console.log('returnUrl', returnUrl)}>获取收银台地址</Button>
<Button
onClick={() =>
console.log(
OutdoorUtils.pageParameters.setQuery({
query: { name: '小钻风', age: 20, isBoy: true },
chineseKey: ['name'],
})
)
}
>
参数编码
</Button>
<Button
onClick={() =>
console.log(
OutdoorUtils.pageParameters.getQuery({
query: { name: '小钻风', age: '20', isBoy: 'true' },
chineseKey: ['name'],
numberKeys: ['age'],
booleanKeys: ['isBoy'],
})
)
}
>
参数解码
</Button>
</View>
);
}