@hzab/utils
v1.0.4
Published
utils
Readme
@hzab/utils
组件模板
注意:首次克隆先执行 npm run prepare 命令
组件
ossUpload 示例
import OssUpload from "@hzab/utils/src/ossUpload";
/**
* 批量文件上传
* @param {Array} files
* @param {Object} opt
* @returns
*/
export async function handleOssUpload(files, opt) {
const _files = files;
const { ossUrl, signatureParams, ossParams, axiosConf, useHashName } = opt || {};
const ossUpload = new OssUpload({
axios: opt.axios,
axiosConf: axiosConf,
serverUrl: ossUrl || "/api/v1/user/oss/getWebOssConfig",
});
const promise = [];
_files?.forEach((file) => {
if (!file) {
return;
}
// 数据已经是 url 的情况
if (typeof file === "string" || file.ossUrl || file.url) {
promise.push(Promise.resolve(file));
} else {
promise.push(
ossUpload
.upload(file, {
signatureParams: {
isPublic: 1,
...(signatureParams || {}),
},
ossParams,
axiosConf,
useHashName,
})
.then((res) => {
return Promise.resolve(res?.data?.data?.fileUrl);
}),
);
}
});
return Promise.all(promise).then((filePromises) => {
filePromises?.forEach((fileUrl, idx) => {
if (typeof fileUrl === "string") {
_files[idx].ossUrl = fileUrl;
_files[idx].url = fileUrl;
} else if (_files[idx].url) {
_files[idx].ossUrl = _files[idx].url;
}
});
return Promise.resolve(_files);
});
}API
InfoPanel Attributes
| 参数 | 类型 | 必填 | 默认值 | 说明 | | ------ | ------ | ---- | ------ | ----------------- | | schema | Object | 是 | - | 数据信息的 schema |
组件开发流程
- 在 config/webpack.config.js 中按需修改 library 配置的文件名
- 在 config/webpack.config.js 中按需修改 alias 配置的包名,便于本地调试
- 在 tsconfig.json 中按需修改 paths 配置的包名,解决 ts 报错问题
- npm run dev
文件目录
- example 本地开发测试代码
- src 组件源码
命令
Mac 执行该命令,设置 pre-commit 为可执行文件
- npm run mac-chmod
- chmod +x .husky && chmod +x .husky/pre-commit
生成文档:npm run docs
本地运行:npm run dev
打包编译:npm run build
发布
注意:示例代码生效,但发布之后未生效。确认是否执行了编译!!!
编译组件:npm run build
命令:npm publish --access public
发布目录:
- src
配置
配置文件
- 本地配置文件:config/config.js
webpack 配置文件
- config/webpack.config.js
