0.0.50 • Published 11 months ago

@portalx/sdk v0.0.50

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

foundation

1. 类

1.1 GraphqlClient

  • 实例化
const graphqlIns = new GraphqlClient({
  url: GRAPHQL_ENDPOINT, // 默认的graphql请求的url
  headers: {
    'X-Requested-With': 'XMLHttpRequest', // 告知后端是ajax请求
  },
});
  • 方法
    • excute
    graphqlIns.exc(
      {
        query: GraphqlCmd.queryListWithStr(colListStr, formCode), // graphql的请求字符串
        variables: {
          limit: 10,
          offset: 0,
          where: {},
          orderBy: {},
        }, // 请求字符串中的变量对象
        controlId: '0',
      },
      {
        url: `${GRAPHQL_ENDPOINT}/views/${searchParams.viewId}`, // 修改了默认的url
      }
    );

2. 函数

2.1 createSignature

根据传入的参数,返回调用ajax时,需要使用的签名对象

  • 使用
createSignature({
  url: 'xxx', // 必填;可以是带http、带实例名的全量url;也可以是不带http,但是带实例名的url;也可以是什么都不带的url;头部的 / 内部做了兼容
  // 非必填;url实例名,开头可以不带 /
  // 可以使用正则表达式
  baseUrl: '/xxx/xxx',
  params: { a: 1, b: '2', c: true, d: [{ d1: [1, 2, 3] }, { d1: [2, 3, 4] }] }, // 非必填;url请求参数,可以一并在path中传入;可以为序列化后的string,也可以是对象
  method: 'post', // 非必填;请求类型,默认为get
  data: {
    a: 1,
    b: '2',
    c: true,
  }, // 非必填;当前请求的data参数,一般在post请求中
  salt: '123', // 必填;盐值
  timeDiff: 20, // 必填;服务器比浏览器快多少(毫秒数),慢就是负数。一般是登录时就计算好
  token: 'token111', // 必填; token值
});

2.2 excPromise

优雅的对 promise 请求进行 trycatch 操作。 若 promise 执行异常,则 promiseErr 有值,promiseRes 无有效值; 若 promise 执行正常,则 promiseErr 无值,promiseRes 有有效值。

  • 使用
const [promiseErr, promiseRes] = await excPromise(PromiseFunc);
if (promiseErr) {
  // 错误逻辑
} else {
  // 正常逻辑
}

2.3 getCookie

获取对应 name 的 cookie 值;有则返回转码后的值;没有则返回 null

  • 使用
const cookieVal = getCookie('name');

2.4 setCookie

设置修改 cookie

  • 使用
setCookie({
  name: 'name',
  value: 'value',
  expiredays: 1, // 非必填;过期时间,单位为天
  path: '/', // 非必填;路径
  domain: 'localhost', // 非必填;域名
});

2.5 delCookie

删除对应的 cookie

  • 使用
delCookie('name');

2.6 delAllCookie

删除所有 cookie

  • 使用
delAllCookie();

2.7 base64ToBlob

base64 转 blob

  • 使用
const blob = base64ToBlob(base64Str);

2.8 base64ToFile

base64 转 file

  • 使用
const file = base64ToFile(base64Str, 'fileName');

2.9 copyToClipboard

复制到剪贴板

  • 使用
copyToClipboard('内容');

2.10 getValueType

获取对象类型,只是将 Object.prototype.toString.call 返回的第二个参数返回

  • 使用
const type = getValueType(value);

3. hooks

3.1 useGetDateFormat

通用获取当前日期的显示内容 hooks

  • 使用
const { formatter } = useGetDateFormat({
  picker, // 日期模式
  savedFormat, // 日期存储的格式
});
0.0.43

1 year ago

0.0.44

1 year ago

0.0.45

1 year ago

0.0.46

12 months ago

0.0.47

12 months ago

0.0.48

11 months ago

0.0.49

11 months ago

0.0.50

11 months ago

0.0.42

1 year ago

0.0.41

1 year ago