@zhangjie6/x-taro
v0.0.3
Published
基于 Taro 的可复用组件库
Downloads
45
Readme
@zhangjie6/x-taro
@zhangjie6/x-taro 是一个面向 Taro 项目的可复用组件库,用来承接从业务项目中抽离出来的公共组件。
安装
pnpm add @zhangjie6/x-taro以下依赖需要由使用方项目自行安装:
npm install react @tarojs/components @tarojs/taro taro-ui全局配置
组件库支持通过 setupXTaro 注入项目级公共能力,例如资源前缀、接口前缀和请求方法。
import { setupXTaro } from "@zhangjie6/x-taro";
setupXTaro({
ossUrl: "https://example.com/assets",
apiOldUrl: "https://example.com",
request,
});如果某个组件有更特殊的需求,也可以通过组件 props 单独覆盖对应能力。
如果项目需要复用路径组件的默认业务逻辑,也可以把相关能力一起挂到全局配置里:
import { setupXTaro } from "@zhangjie6/x-taro";
setupXTaro({
ossUrl: "https://example.com/assets",
apiOldUrl: "https://example.com",
request,
route: {
addressSelectPage: "/pages/address/select/index",
pickAddress: async ({ index, current }) => {
return {
idx: index,
location: current,
};
},
createTraceByPosition: async (list) => list,
createTraces: async (list) => list,
},
});使用示例
import {
FormRow,
FormItemContentBox,
CommonInputFormItem,
CommonSelectFormItem,
CommonRouteFormItem,
} from "@zhangjie6/x-taro";路径组件的接入方式
CommonRouteFormItem 支持两层能力来源:
- 组件 props 显式传入
setupXTaro全局配置
如果项目想保留当前业务逻辑,可以在 setupXTaro 中注入地址选择和轨迹计算能力;如果不传,则组件会优先使用默认地址页跳转逻辑,轨迹计算则回退为原数据透传。
