th-design 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ /// <reference types="react" />
2
+ import type { ProTableProps, RequestData } from '@ant-design/pro-table';
3
+ import type { ButtonProps } from 'antd/es/button';
4
+ import type { SortOrder } from 'antd/es/table/interface';
5
+ /**
6
+ * ThTable 组件属性
7
+ */
8
+ export interface ThTableProps<T extends Record<string, any> = any, U extends Record<string, any> = any, ValueType = 'text'> extends Omit<ProTableProps<T, U, ValueType>, 'headerTitle'> {
9
+ /**
10
+ * 获取列表接口数据
11
+ */
12
+ request: (params: {
13
+ pageSize?: number;
14
+ current?: number;
15
+ sorter?: Record<string, SortOrder>;
16
+ filter?: Record<string, (string | number)[] | null>;
17
+ [key: string]: any;
18
+ }) => Promise<Partial<RequestData<T>>>;
19
+ /**
20
+ * 权限按钮列表,用于配合 btnPermissionCode 校验按钮显示权限
21
+ * @default []
22
+ */
23
+ btnPermissionList?: {
24
+ code: string;
25
+ }[];
26
+ /**
27
+ * 额外的查询参数,不会显示在搜索表单中
28
+ */
29
+ hideSearch?: Record<string, any>;
30
+ /**
31
+ * 横向滚动的宽度
32
+ */
33
+ scrollX?: string;
34
+ /**
35
+ * table 容器样式
36
+ */
37
+ style?: React.CSSProperties;
38
+ /**
39
+ * 其余高度偏移量
40
+ * @default 0
41
+ */
42
+ otherHeight?: number;
43
+ /**
44
+ * 操作栏按钮集
45
+ * @default []
46
+ */
47
+ headerOperation?: IHeaderOperationItem[];
48
+ /**
49
+ * 自定义入参格式化,在请求发送前格式化参数
50
+ */
51
+ requestFormatter?: (params: any, sorter: any, filter: any) => Promise<Partial<RequestData<T>>>;
52
+ }
53
+ export interface IHeaderOperationItem extends ButtonProps {
54
+ name: string;
55
+ key: string;
56
+ btnPermissionCode?: string;
57
+ btnRender?: React.ReactNode;
58
+ buttonRender?: () => React.ReactNode;
59
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ export declare const hasBtnPermission: (btnList: any, code: any) => boolean;
2
+ export declare const createUuid: () => any;
3
+ /**
4
+ * 辅助函数:用于获取用户传入的column
5
+ * @param:{key,columns}
6
+ * */
7
+ export declare const getColumnByKey: (key: any, columns: any) => any;
8
+ /**
9
+ * 用于转换查询条件、符合后台接受数据格式
10
+ * @params
11
+ */
12
+ export declare const formatterQueryParams: (queryParams: any, hideSearch: any, columns: any) => any;
@@ -0,0 +1,108 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
8
+ //判断是否有当前按钮权限
9
+ export var hasBtnPermission = function hasBtnPermission() {
10
+ var btnList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
11
+ var code = arguments.length > 1 ? arguments[1] : undefined;
12
+ var btnMap = Boolean(btnList) && btnList != 'null' && btnList != 'undefined' ? btnList : [];
13
+ return btnMap.filter(function (item) {
14
+ return item.code == code;
15
+ }).length == 0 ? false : true;
16
+ // return true
17
+ };
18
+
19
+ /*
20
+ *生成uuid
21
+ */
22
+ export var createUuid = function createUuid() {
23
+ var s = [];
24
+ var hexDigits = '0123456789abcdef';
25
+ for (var i = 0; i < 36; i++) {
26
+ s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
27
+ }
28
+ s[14] = '4'; // bits 12-15 of the time_hi_and_version field to 0010
29
+ s[19] = hexDigits.substr(s[19] & 0x3 | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
30
+ s[8] = s[13] = s[18] = s[23] = '-';
31
+ var uuid = s.join('');
32
+ return uuid;
33
+ };
34
+
35
+ /*
36
+ *辅助对象,用于储存默认格式opt
37
+ */
38
+ var defaultOptObject = {
39
+ text: 'like',
40
+ //文本框
41
+ select: 'eq',
42
+ //下拉框
43
+ radio: 'eq',
44
+ radioButton: 'eq',
45
+ //radio按钮
46
+ checkbox: 'in',
47
+ //复选框
48
+ treeSelect: 'eq',
49
+ //树形下拉框
50
+ dateTime: 'eq',
51
+ //带时间日期
52
+ date: 'eq',
53
+ //不带时间日期
54
+ dateRange: 'between',
55
+ dateTimeRange: 'between',
56
+ money: 'eq',
57
+ //钱
58
+ digit: 'eq',
59
+ //数字
60
+ percent: 'eq' //百分比
61
+ };
62
+ /**
63
+ * 辅助函数:用于获取用户传入的column
64
+ * @param:{key,columns}
65
+ * */
66
+ export var getColumnByKey = function getColumnByKey(key, columns) {
67
+ var column = columns.filter(function (i) {
68
+ return key == i.dataIndex;
69
+ });
70
+ return column[0] || {};
71
+ };
72
+
73
+ /**
74
+ * 用于转换查询条件、符合后台接受数据格式
75
+ * @params
76
+ */
77
+ export var formatterQueryParams = function formatterQueryParams(queryParams, hideSearch, columns) {
78
+ var params = {};
79
+ //先遍历隐藏查询条件
80
+ Object.keys(hideSearch).forEach(function (key) {
81
+ queryParams[key] = hideSearch[key].values;
82
+ });
83
+ //遍历所有有值的查询条件
84
+ Object.keys(queryParams).forEach(function (key) {
85
+ if (queryParams[key] && queryParams[key] != '') {
86
+ var column = getColumnByKey(key, columns);
87
+ if (column.search) {
88
+ //搜索列表中存在项
89
+ var valueType = column.valueType || 'text';
90
+ //做三重兼容,优先级 用户传入>默认>容错,
91
+ var opt = column.opt || defaultOptObject[valueType] || 'like';
92
+ params[key] = {
93
+ opt: opt,
94
+ values: _typeof(queryParams[key]) == 'object' ? _toConsumableArray(queryParams[key]) : [queryParams[key]]
95
+ };
96
+ } else {
97
+ var _hideSearch$key;
98
+ //隐藏项传来的值
99
+ var _opt = ((_hideSearch$key = hideSearch[key]) === null || _hideSearch$key === void 0 ? void 0 : _hideSearch$key.opt) || 'eq';
100
+ params[key] = {
101
+ opt: _opt,
102
+ values: _typeof(queryParams[key]) == 'object' ? _toConsumableArray(queryParams[key]) : [queryParams[key]]
103
+ };
104
+ }
105
+ }
106
+ });
107
+ return params;
108
+ };
@@ -0,0 +1,2 @@
1
+ export { default as ThSelect } from './components/ThSelect';
2
+ export { default as ThTable } from './components/ThTable';
@@ -0,0 +1,2 @@
1
+ export { default as ThSelect } from "./components/ThSelect";
2
+ export { default as ThTable } from "./components/ThTable";
@@ -0,0 +1,20 @@
1
+ declare module 'slash2';
2
+ declare module '*.css';
3
+ declare module '*.less';
4
+ declare module '*.scss';
5
+ declare module '*.sass';
6
+ declare module '*.svg';
7
+ declare module '*.png';
8
+ declare module '*.jpg';
9
+ declare module '*.jpeg';
10
+ declare module '*.gif';
11
+ declare module '*.bmp';
12
+ declare module '*.tiff';
13
+ declare module 'omit.js';
14
+ declare module 'numeral';
15
+ declare module 'mockjs';
16
+ declare module 'react-fittext';
17
+ declare module '*.css';
18
+ declare module '*.less';
19
+
20
+ declare const REACT_APP_ENV: 'test' | 'dev' | 'pre' | false;
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "private": false,
3
+ "name": "th-design",
4
+ "version": "1.0.0",
5
+ "description": "tellhow component library",
6
+ "author": "luohq",
7
+ "keywords": [
8
+ "tellhow",
9
+ "React",
10
+ "Component"
11
+ ],
12
+ "scripts": {
13
+ "start": "dumi dev",
14
+ "docs:build": "dumi build",
15
+ "docs:deploy": "gh-pages -d docs-dist",
16
+ "build": "father build",
17
+ "deploy": "npm run docs:build && npm run docs:deploy",
18
+ "prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
19
+ "lint": "eslint --ext .js,.jsx,.ts,.tsx src",
20
+ "test": "umi-test",
21
+ "test:coverage": "umi-test --coverage",
22
+ "prepublishOnly": "npm run build"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "module": "dist/esm/index.js",
28
+ "typings": "dist/esm/index.d.ts",
29
+ "gitHooks": {
30
+ "pre-commit": "lint-staged"
31
+ },
32
+ "slideEffects": false,
33
+ "lint-staged": {
34
+ "*.{js,jsx,less,md,json}": [
35
+ "prettier --write"
36
+ ],
37
+ "*.ts?(x)": [
38
+ "prettier --parser=typescript --write"
39
+ ]
40
+ },
41
+ "dependencies": {
42
+ "@umijs/max": "^4.6.15",
43
+ "ahooks": "^3.9.6",
44
+ "antd": "5.29.3",
45
+ "react": "^18.2.0",
46
+ "react-dom": "^18.2.0"
47
+ },
48
+ "peerDependencies": {
49
+ "react": ">=18.2.0",
50
+ "react-dom": ">=18.2.0",
51
+ "antd": ">=5.29.3"
52
+ },
53
+ "devDependencies": {
54
+ "@ant-design/icons": "^4.7.0",
55
+ "@ant-design/pro-table": "^3.0.10",
56
+ "@testing-library/jest-dom": "^5.15.1",
57
+ "@testing-library/react": "^13.0.0",
58
+ "@types/jest": "^27.0.3",
59
+ "@types/react": "^18.2.0",
60
+ "@types/react-dom": "^18.2.0",
61
+ "@types/react-resizable": "^3.0.3",
62
+ "@umijs/fabric": "^2.8.1",
63
+ "@umijs/test": "^3.0.5",
64
+ "babel-plugin-import": "^1.13.5",
65
+ "classnames": "^2.3.2",
66
+ "dumi": "^2.4.21",
67
+ "father": "^4.0.0-rc.2",
68
+ "gh-pages": "^3.0.0",
69
+ "lint-staged": "^10.0.7",
70
+ "prettier": "^2.2.1",
71
+ "react-docgen-typescript": "^2.4.0",
72
+ "react-resizable": "^3.0.4",
73
+ "yorkie": "^2.0.0"
74
+ }
75
+ }