vap1 0.2.0 → 0.2.2

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.
@@ -4,7 +4,7 @@ import type { Key, BaseItem, PlainObject } from '../../basetype';
4
4
  import type { STreeProps } from '../Trees/STree';
5
5
  import type { DTreeProps } from '../Trees/DTree';
6
6
  import type { FTreeProps } from '../Trees/FTree';
7
- import type { SListPorps } from '../Lists/SList';
7
+ import type { SListProps } from '../Lists/SList';
8
8
  type SelectBarAction = BaseItem & {
9
9
  /**
10
10
  * action 图标
@@ -74,7 +74,7 @@ type ExtendSelectProps = {
74
74
  config: Omit<FTreeProps, 'searchValue' | 'onSelect'>;
75
75
  } | {
76
76
  type: 'slist';
77
- config: Omit<SListPorps, 'searchValue' | 'onSelect'>;
77
+ config: Omit<SListProps, 'searchValue' | 'onSelect'>;
78
78
  } | {
79
79
  type: 'custom';
80
80
  config?: any;
@@ -3,7 +3,9 @@ import type { PlainObject, Key } from '../../basetype';
3
3
  import type { ReactNode } from 'react';
4
4
  import type { IconProps } from '../_adapt/Icon';
5
5
  type ItemRenderFunction = (record: PlainObject, searchValue?: string) => ReactNode;
6
- export type SListPorps = {
6
+ export type SListProps = {
7
+ style?: React.CSSProperties;
8
+ className?: string;
7
9
  /**
8
10
  * key 字段,默认为ID
9
11
  */
@@ -54,5 +56,5 @@ export type SListPorps = {
54
56
  */
55
57
  mustSelect?: true | ((list: PlainObject[]) => PlainObject);
56
58
  };
57
- export declare const SList: React.FC<SListPorps>;
59
+ export declare const SList: React.FC<SListProps>;
58
60
  export {};
@@ -134,23 +134,26 @@ exports.SList = (0, react_1.memo)((props) => {
134
134
  setSelected(item[keyField]);
135
135
  onSelect(item[keyField], item);
136
136
  }, [list]);
137
- const listProps = {
138
- className: 'c-selectbar-list',
139
- size: "small",
140
- dataSource: list,
141
- };
142
- if (lodash_1.default.isFunction(props.onSelect)) {
143
- listProps.className += ' c-selectbar-list-canselect';
144
- listProps.renderItem = (item) => react_1.default.createElement(antd_1.List.Item, { className: item[keyField] == selected ? 'c-selectbar-list-selected' : '', onClick: evt => {
137
+ const listProps = (0, react_1.useMemo)(() => {
138
+ const clazz = ['c-selectbar-list'];
139
+ let listProps = { size: "small", style: props.style };
140
+ if (lodash_1.default.isFunction(props.onSelect))
141
+ clazz.push('c-selectbar-list-canselect');
142
+ if (props.className)
143
+ clazz.push(props.className);
144
+ listProps.className = clazz.join(' ');
145
+ return listProps;
146
+ }, [props.className]);
147
+ const renderItem = item => {
148
+ if (!lodash_1.default.isFunction(props.onSelect))
149
+ return react_1.default.createElement(antd_1.List.Item, null, render(item, searchValue));
150
+ return react_1.default.createElement(antd_1.List.Item, { className: item[keyField] == selected ? 'c-selectbar-list-selected' : '', onClick: evt => {
145
151
  utils_1.PageUtil.stopEvent(evt);
146
152
  setSelected(item[keyField]);
147
153
  onSelect(item[keyField], item);
148
154
  } }, render(item, searchValue));
149
- }
150
- else {
151
- listProps.renderItem = (item) => react_1.default.createElement(antd_1.List.Item, null, render(item, searchValue));
152
- }
153
- return react_1.default.createElement(antd_1.List, Object.assign({}, listProps));
155
+ };
156
+ return react_1.default.createElement(antd_1.List, Object.assign({}, listProps, { dataSource: list, renderItem: renderItem }));
154
157
  }, (prev, next) => {
155
158
  if (prev.searchValue != next.searchValue)
156
159
  return false;
@@ -46,7 +46,11 @@ const STable = (props) => {
46
46
  arrOption.pageSize = 0;
47
47
  }
48
48
  const model = (0, useArray_1.useArray)(arrOption);
49
- (0, react_1.useEffect)(() => { model.setList(props.list); }, [props.list]);
49
+ (0, react_1.useEffect)(() => {
50
+ if (lodash_1.default.isArray(props.list)) {
51
+ model.setList(props.list);
52
+ }
53
+ }, [props.list]);
50
54
  return react_1.default.createElement(VTable_1.VTable, Object.assign({}, props, { pagination: arrOption.pageSize == 0 ? false : { hideOnSinglePage: true }, model: model }));
51
55
  };
52
56
  exports.STable = STable;
@@ -79,10 +79,10 @@ const getFormLayout = (props, root) => {
79
79
  width = totalWidth;
80
80
  }
81
81
  }
82
- let isInfo = false, isEdit = false, isCreate = false;
82
+ let isInfo = false, isEdit = false, isAdd = false;
83
83
  switch (props.mode) {
84
84
  case 'ADD':
85
- isCreate = true;
85
+ isAdd = true;
86
86
  break;
87
87
  case 'EDIT':
88
88
  isEdit = true;
@@ -99,14 +99,14 @@ const getFormLayout = (props, root) => {
99
99
  isEdit = true;
100
100
  break;
101
101
  }
102
- isCreate = true;
102
+ isAdd = true;
103
103
  // if (props.data != null || _.keys(props.data).length == 0) {
104
104
  // isInfo = true;
105
105
  // break;
106
106
  // }
107
107
  // isInfo = true;
108
108
  }
109
- return [isGroup, cols, width, colMax, isInfo, isEdit, isCreate];
109
+ return [isGroup, cols, width, colMax, isInfo, isEdit, isAdd];
110
110
  };
111
111
  const getMaxTitleWidth = (field) => {
112
112
  if (field.type && (0, _register_1.getUFormInput)(field.type).breakTitle)
@@ -128,7 +128,7 @@ const getMaxTitleWidth = (field) => {
128
128
  return Math.ceil(sum);
129
129
  };
130
130
  // 遍历字段,计算表单属性
131
- const _LOOP = (fs, maxLabel, isInfo, isEdit, isCreate, hiddFields, disableFields) => {
131
+ const _LOOP = (fs, maxLabel, isInfo, isEdit, isAdd, hiddFields, disableFields) => {
132
132
  fs.map(field => {
133
133
  // @ts-ignore // 兼容 && 写法
134
134
  if (field == null || field === false)
@@ -144,22 +144,22 @@ const _LOOP = (fs, maxLabel, isInfo, isEdit, isCreate, hiddFields, disableFields
144
144
  else if (field.show) {
145
145
  switch (field.show) {
146
146
  case 'A':
147
- show = !isInfo && !isEdit;
148
- break;
149
- case 'AE':
150
- show = !isInfo;
147
+ show = isAdd;
151
148
  break;
152
149
  case 'I':
153
150
  show = isInfo;
154
151
  break;
155
- case 'IE':
156
- show = !isEdit;
152
+ case 'E':
153
+ show = isEdit;
154
+ break;
155
+ case 'AE':
156
+ show = isAdd || isEdit;
157
157
  break;
158
158
  case 'IE':
159
159
  show = isInfo || isEdit;
160
160
  break;
161
- case 'E':
162
- show = isEdit && !isInfo;
161
+ case 'IA':
162
+ show = isAdd || isEdit;
163
163
  break;
164
164
  case 'IAE':
165
165
  show = true;
@@ -222,14 +222,14 @@ const FormWrapper = (props) => {
222
222
  const { fields } = props;
223
223
  if (fields == null || fields.length == 0)
224
224
  throw new Error('Must Have Fields');
225
- const [isGroup, cols, width, colMax, isInfo, isEdit, isCreate] = getFormLayout(props, formContainer.current);
225
+ const [isGroup, cols, width, colMax, isInfo, isEdit, isAdd] = getFormLayout(props, formContainer.current);
226
226
  let colSpan = 24 / cols;
227
227
  // const MAX_LABEL_SPAN = COLMAX[cols];
228
228
  if (isGroup) {
229
- fields.map(group => _LOOP(group.fields, maxLabelRef, isInfo, isEdit, isCreate, HiddenFieldRef.current, DisableFieldRef.current));
229
+ fields.map(group => _LOOP(group.fields, maxLabelRef, isInfo, isEdit, isAdd, HiddenFieldRef.current, DisableFieldRef.current));
230
230
  }
231
231
  else {
232
- _LOOP(fields, maxLabelRef, isInfo, isEdit, isCreate, HiddenFieldRef.current, DisableFieldRef.current);
232
+ _LOOP(fields, maxLabelRef, isInfo, isEdit, isAdd, HiddenFieldRef.current, DisableFieldRef.current);
233
233
  }
234
234
  let fieldWidth = width / cols;
235
235
  var percent = (maxLabelRef.current * FONT_SIZE + 20) / fieldWidth;
@@ -85,7 +85,7 @@ export type Link = {
85
85
  * 1. 传 **data** = Update ,
86
86
  * 2. 不传= Add
87
87
  */
88
- export type APPEAR_MODE = 'I' | 'A' | 'E' | 'IE' | 'IE' | 'AE' | 'IAE' | false | true;
88
+ export type APPEAR_MODE = 'I' | 'A' | 'E' | 'IE' | 'IA' | 'AE' | 'IAE' | false | true;
89
89
  /**
90
90
  * 表单的字段定义
91
91
  */
@@ -70,26 +70,6 @@ const SearchFieldInput_1 = require("./SearchFieldInput");
70
70
  let options = utils_1.PageUtil.getOptions(props.field.options);
71
71
  return react_1.default.createElement(antd_1.Checkbox.Group, Object.assign({}, config, { className: "i-checkbox", disabled: disabled, onChange: val => onChange(val.join(',')), value: (lodash_1.default.has(data, field) && data[field]) ? data[field].split(',') : [] }), options.map(option => react_1.default.createElement(antd_1.Checkbox, { value: option.value + '' }, option.label)));
72
72
  }, { outside: true });
73
- // registerSearchField('checkbox-button', (props: SearchFieldProps) => {
74
- // const { field: { field, config, placeholder, allowClear, }, disabled, onChange, data, width } = props;
75
- // if (!_.isArray(props.field.options)) {
76
- // console.error('field type : select must have a options field')
77
- // return <TEXT {...props} />
78
- // }
79
- // let options = PageUtil.getOptions(props.field.options);
80
- // return <Checkbox.Group
81
- // {...config}
82
- // style={{ width }}
83
- // optionType="button"
84
- // buttonStyle="solid"
85
- // disabled={disabled}
86
- // onChange={val => onChange(val.join(','))}
87
- // value={(_.has(data, field) && data[field].split(',')) ? data[field] : undefined}
88
- // options={options}
89
- // >
90
- // {/* {options.map(option => <Checkbox value={option.value + ''}>{option.label}</Checkbox>)} */}
91
- // </Checkbox.Group>
92
- // });
93
73
  (0, _register_1.registerSearchField)('switch', (props) => {
94
74
  const { field: { field, config, placeholder, allowClear, }, disabled, onChange, data, width } = props;
95
75
  if (!lodash_1.default.isArray(props.field.options) || (props.field.options.length <= 1)) {
package/index.d.ts CHANGED
@@ -134,7 +134,7 @@ export { UForm, UFormModal, UInfo, UInfoModal, UModal, UDescriptions } from './c
134
134
  export { VTable, ApiTable, ApiTableModal, STable, TopTable, TopTableModal } from './components/Tables';
135
135
  export { STree, DTree, FTree } from './components/Trees';
136
136
  export { UploadFile, UploadImage, UploadModal } from './components/Upload';
137
- export { SList } from './components/Lists/SList';
137
+ export { SList, type SListProps } from './components/Lists/SList';
138
138
  export type { UFromProps, UModalProps, UFormField, UFormFieldGroup, LinkResult, UDescriptionsProps, UFormRef, Link, LinkValue } from './components/UForm';
139
139
  export type { TableColumn } from './components/Tables/index';
140
140
  export type { VTableProps, VTableRef } from './components/Tables/VTable';
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"vap1","version":"0.2.0","description":"vap1, Both support MicroService and SAP FrameWork, Support IE>9","main":"index.js","author":"Xiang da","license":"ISC"}
1
+ {"name":"vap1","version":"0.2.2","description":"vap1, Both support MicroService and SAP FrameWork, Support IE>9","main":"index.js","author":"Xiang da","license":"ISC"}
@@ -1,12 +1,12 @@
1
- import React from 'react';
2
1
  import type { FormSchema } from './schema';
3
- import type { UModalProps, PlainObject } from '../index';
2
+ import type { RefAttributes, ForwardRefExoticComponent, FC } from 'react';
3
+ import type { UModalProps, UFormRef, PlainObject } from '../index';
4
4
  type ModalProps = Pick<UModalProps, 'open' | 'onOk' | 'onCancel' | 'title' | 'data'>;
5
5
  type FormViewProps = {
6
6
  schema: FormSchema | string;
7
7
  data?: PlainObject;
8
8
  };
9
9
  export declare const initSchama: (data: string | FormSchema) => FormSchema;
10
- export declare const FormViewer: React.FC<FormViewProps>;
11
- export declare const FormModal: React.FC<FormViewProps & ModalProps>;
10
+ export declare const FormViewer: ForwardRefExoticComponent<FormViewProps & RefAttributes<UFormRef>>;
11
+ export declare const FormModal: FC<FormViewProps & ModalProps>;
12
12
  export {};
@@ -49,21 +49,20 @@ const initSchama = (data) => {
49
49
  return DEFAULT;
50
50
  };
51
51
  exports.initSchama = initSchama;
52
- const _FormRender = props => {
52
+ const _FormRender = (0, react_1.forwardRef)((props, ref) => {
53
53
  const uformProps = (0, react_1.useMemo)(() => (0, Convert_1.schemaToForm)(props.schema), [props]);
54
- return react_1.default.createElement(index_1.UForm, Object.assign({}, uformProps, { data: props.data }));
55
- };
54
+ return react_1.default.createElement(index_1.UForm, Object.assign({}, uformProps, { data: props.data, ref: ref }));
55
+ });
56
56
  const _ModalRender = props => {
57
57
  const uformProps = (0, react_1.useMemo)(() => (0, Convert_1.schemaToForm)(props.schema), [props]);
58
58
  let modalProps = {};
59
59
  modalProps.title = props.title || props.schema.title || '';
60
60
  return react_1.default.createElement(index_1.UFormModal, Object.assign({}, uformProps, modalProps, { data: props.data, open: props.open, onOk: props.onOk, onCancel: props.onCancel }));
61
61
  };
62
- const FormViewer = props => {
62
+ exports.FormViewer = (0, react_1.forwardRef)((props, ref) => {
63
63
  const schema = (0, react_1.useMemo)(() => (0, exports.initSchama)(props.schema), [props.schema]);
64
- return react_1.default.createElement(_FormRender, { schema: schema, data: props.data });
65
- };
66
- exports.FormViewer = FormViewer;
64
+ return react_1.default.createElement(_FormRender, { schema: schema, data: props.data, ref: ref });
65
+ });
67
66
  const FormModal = props => {
68
67
  const schema = (0, react_1.useMemo)(() => (0, exports.initSchama)(props.schema), [props.schema]);
69
68
  return react_1.default.createElement(_ModalRender, Object.assign({}, props, { schema: schema }));
package/utils/Global.d.ts CHANGED
@@ -16,8 +16,20 @@ export type GlobalSetting = {
16
16
  * 应用相关参数:
17
17
  */
18
18
  APP: {
19
+ /**
20
+ * 默认语言,默认简体中文
21
+ */
19
22
  LANG: Language;
23
+ /**
24
+ * 显示:回到首页,默认为 true
25
+ */
26
+ USER_MENU_HOMEPAGE: boolean;
20
27
  };
28
+ /**
29
+ * 基础API设置,
30
+ * 说明,如果只是前缀与通用版不同,则只需设置 PREFIX 即可,
31
+ * 其它还有不同的可单独设置
32
+ */
21
33
  BASIC: {
22
34
  PREFIX: string;
23
35
  SYSTEM: string;
package/utils/Global.js CHANGED
@@ -20,6 +20,7 @@ var LOG_LEVEL;
20
20
  const DEFAULT = {
21
21
  APP: {
22
22
  LANG: _Support_1.Language.ZH_CN,
23
+ USER_MENU_HOMEPAGE: true,
23
24
  },
24
25
  BASIC: {
25
26
  PREFIX: '/api-common',
package/utils/PageUtil.js CHANGED
@@ -68,7 +68,9 @@ exports.clearURL = (len == 0) ? (val => val) : (url) => {
68
68
  /**
69
69
  * 判断是否有权限
70
70
  */
71
- const hasRole = (roleCode) => Global_1.CONFIG.PROMISSION.ROLE.has(lodash_1.default.trim(roleCode).toLowerCase());
71
+ const hasRole = (roleCode) => {
72
+ return Global_1.CONFIG.PROMISSION.ROLE.has(roleCode) || Global_1.CONFIG.PROMISSION.ROLE.has((0, StringUtil_1.trimLower)(roleCode));
73
+ };
72
74
  exports.hasRole = hasRole;
73
75
  // export const hasRole = (roleCode: string): boolean => true; // 测试中,总返回有权限
74
76
  const GLOBAL_APPS = new Map();
@@ -91,6 +91,7 @@ export declare const searchText: (sentence: string, keyword: string) => MatchPat
91
91
  * 拼 className
92
92
  */
93
93
  export declare const className: (base: string[], classNameProps?: string) => string;
94
+ export declare const replaceAll: (text: string, keyword: string | RegExp, replaceText: string) => string;
94
95
  /**
95
96
  * 试图转px的值
96
97
  * 300px -> 300
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getFileType = exports.getFloat = exports.getInteger = exports.getBoolean = exports.getString = exports.copy = exports.px = exports.className = exports.searchText = exports.trimLower = exports.isBoolean = exports.isBTCAddress = exports.uuid = exports.genKey = exports.isId = exports.isId15 = exports.isId18 = exports.REG_ID_15 = exports.REG_ID_18 = exports.isIP = exports.isIP6 = exports.isIP4 = exports.isPhone = exports.isMAC = exports.isURL = exports.isEmail = exports.isTelePhone = exports.isMobilePhone = exports.REG_PORT = exports.REG_URL = exports.REG_IPV6 = exports.REG_IPV4 = exports.REG_TELEPHONE = exports.REG_PHONE = exports.REG_EMAIL = void 0;
6
+ exports.getFileType = exports.getFloat = exports.getInteger = exports.getBoolean = exports.getString = exports.copy = exports.px = exports.replaceAll = exports.className = exports.searchText = exports.trimLower = exports.isBoolean = exports.isBTCAddress = exports.uuid = exports.genKey = exports.isId = exports.isId15 = exports.isId18 = exports.REG_ID_15 = exports.REG_ID_18 = exports.isIP = exports.isIP6 = exports.isIP4 = exports.isPhone = exports.isMAC = exports.isURL = exports.isEmail = exports.isTelePhone = exports.isMobilePhone = exports.REG_PORT = exports.REG_URL = exports.REG_IPV6 = exports.REG_IPV4 = exports.REG_TELEPHONE = exports.REG_PHONE = exports.REG_EMAIL = void 0;
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
8
  const _Support_1 = require("./_Support");
9
9
  const dayjs_1 = __importDefault(require("dayjs"));
@@ -205,6 +205,12 @@ const className = (base, classNameProps) => {
205
205
  return base.join(' ');
206
206
  };
207
207
  exports.className = className;
208
+ const replaceAll = (text, keyword, replaceText) => {
209
+ let reg = lodash_1.default.isRegExp(keyword) ? new RegExp(keyword, 'g') : new RegExp(keyword, "g");
210
+ return lodash_1.default.replace(text, reg, replaceText);
211
+ ;
212
+ };
213
+ exports.replaceAll = replaceAll;
208
214
  /**
209
215
  * 试图转px的值
210
216
  * 300px -> 300