diff --git a/package.json b/package.json
index 836ed66..8192ebf 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@kne-components/components-admin",
- "version": "1.1.31",
+ "version": "1.1.32",
"description": "用于实现一个后台管理系统的必要组件",
"scripts": {
"init": "husky",
diff --git a/src/components/GroupSelect/index.js b/src/components/GroupSelect/index.js
index 3a7d1d9..82c2969 100644
--- a/src/components/GroupSelect/index.js
+++ b/src/components/GroupSelect/index.js
@@ -14,162 +14,186 @@ const createComponent = (callback = item => item) => {
'components-core:Global@useGlobalValue'
]
})(
- withLocale(({
- remoteModules,
- name,
- label,
- type,
- language: propsLanguage,
- rule,
- apis,
- valueKey = 'code',
- labelKey = 'name',
- single,
- placeholder,
- disabled,
- groupName: propsGroupName,
- ...props
- }) => {
- const { formatMessage } = useIntl();
- const groupName = propsGroupName || formatMessage({ id: 'GroupSelectDefaultName' });
- const [FormInfo, useFormModal, usePreset, useGlobalValue] = remoteModules;
- const { fields } = FormInfo;
- const { SuperSelectTableList, SuperSelectTree } = fields;
- const { ajax, apis: presetApis } = usePreset();
- const { message, modal } = App.useApp();
- const formModal = useFormModal();
- const locale = useGlobalValue('locale');
+ withLocale(
+ ({
+ remoteModules,
+ name,
+ label,
+ type,
+ language: propsLanguage,
+ rule,
+ apis,
+ valueKey = 'code',
+ labelKey = 'name',
+ single,
+ placeholder,
+ disabled,
+ groupName: propsGroupName,
+ ...props
+ }) => {
+ const { formatMessage } = useIntl();
+ const groupName = propsGroupName || formatMessage({ id: 'GroupSelectDefaultName' });
+ const [FormInfo, useFormModal, usePreset, useGlobalValue] = remoteModules;
+ const { fields } = FormInfo;
+ const { SuperSelectTableList, SuperSelectTree } = fields;
+ const { ajax, apis: presetApis } = usePreset();
+ const { message, modal } = App.useApp();
+ const formModal = useFormModal();
+ const locale = useGlobalValue('locale');
- const language = propsLanguage || locale || 'zh-CN';
+ const language = propsLanguage || locale || 'zh-CN';
- const handleDelete = async (item, { fetchApi, value, setValue }) => {
- try {
- const { data: resData } = await ajax(
- Object.assign({}, apis?.remove || presetApis?.group?.remove, {
- data: { id: item.id, code: item.code, type }
- })
- );
+ const handleDelete = async (item, { fetchApi, value, setValue }) => {
+ try {
+ const { data: resData } = await ajax(
+ Object.assign({}, apis?.remove || presetApis?.group?.remove, {
+ data: { id: item.id, code: item.code, type }
+ })
+ );
- if (resData.code !== 0) {
- return;
- }
+ if (resData.code !== 0) {
+ return;
+ }
- message.success(formatMessage({ id: 'GroupSelectDeleteSuccess' }));
- fetchApi.reload();
+ message.success(formatMessage({ id: 'GroupSelectDeleteSuccess' }));
+ fetchApi.reload();
- // 如果删除的项目在已选值中,从已选值中移除
- if (value && value.length > 0 && value.find(target => item[valueKey] === target[valueKey])) {
- const index = value.findIndex(target => item[valueKey] === target[valueKey]);
- const newValue = value.slice(0);
- newValue.splice(index, 1);
- setValue(newValue);
+ // 如果删除的项目在已选值中,从已选值中移除
+ if (value && value.length > 0 && value.find(target => item[valueKey] === target[valueKey])) {
+ const index = value.findIndex(target => item[valueKey] === target[valueKey]);
+ const newValue = value.slice(0);
+ newValue.splice(index, 1);
+ setValue(newValue);
+ }
+ } catch (error) {
+ message.error(formatMessage({ id: 'GroupSelectDeleteFailed' }));
}
- } catch (error) {
- message.error(formatMessage({ id: 'GroupSelectDeleteFailed' }));
- }
- };
+ };
- const handleAdd = ({ reload }) => {
- formModal({
- title: formatMessage({ id: 'GroupSelectAdd' }, { name: groupName }),
- size: 'small',
- formProps: {
- onSubmit: async formData => {
- const { data: resData } = await ajax(
- Object.assign({}, apis?.create || presetApis?.group?.create, {
- data: Object.assign({}, formData, { type, language })
- })
- );
- if (resData.code !== 0) {
- return false;
+ const handleAdd = ({ reload }) => {
+ formModal({
+ title: formatMessage({ id: 'GroupSelectAdd' }, { name: groupName }),
+ size: 'small',
+ formProps: {
+ onSubmit: async formData => {
+ const { data: resData } = await ajax(
+ Object.assign({}, apis?.create || presetApis?.group?.create, {
+ data: Object.assign({}, formData, { type, language })
+ })
+ );
+ if (resData.code !== 0) {
+ return false;
+ }
+ message.success(formatMessage({ id: 'GroupSelectAddSuccess' }));
+ reload();
}
- message.success(formatMessage({ id: 'GroupSelectAddSuccess' }));
- reload();
- }
- },
- children: (
- ,
- ,
- ,
-
- ]}
- />
- )
- });
- };
+ },
+ children: (
+ ,
+ ,
+ ,
+
+ ]}
+ />
+ )
+ });
+ };
- const hasApis = apis !== undefined;
- const showAdd = hasApis ? !!apis?.create : !!presetApis?.group?.create;
- const showDelete = hasApis ? !!apis?.remove : !!presetApis?.group?.remove;
+ const hasApis = apis !== undefined;
+ const showAdd = hasApis ? !!apis?.create : !!presetApis?.group?.create;
+ const showDelete = hasApis ? !!apis?.remove : !!presetApis?.group?.remove;
- const columns = [
- { title: formatMessage({ id: 'GroupSelectCode' }), name: 'code', span: 4 },
- { title: formatMessage({ id: 'GroupSelectName' }), name: 'name', span: 6 },
- { title: formatMessage({ id: 'GroupSelectDescription' }), name: 'description', span: showDelete ? 10 : 14 }
- ];
+ const columns = [
+ { title: formatMessage({ id: 'GroupSelectCode' }), name: 'code', span: 4 },
+ { title: formatMessage({ id: 'GroupSelectName' }), name: 'name', span: 6 },
+ { title: formatMessage({ id: 'GroupSelectDescription' }), name: 'description', span: showDelete ? 10 : 14 }
+ ];
- if (showDelete) {
- columns.push({
- title: formatMessage({ id: 'GroupSelectOperation' }),
- name: 'options',
- span: 4,
- getValueOf: (item, { context }) => {
- const { fetchApi, value, setValue } = context;
- return (
- e.stopPropagation()}>
- {
- modal.confirm({
- title: formatMessage({ id: 'GroupSelectConfirmDelete' }),
- content: formatMessage({ id: 'GroupSelectDeleteConfirm' }, { name: groupName, title: item.name }),
- okText: formatMessage({ id: 'GroupSelectConfirm' }),
- cancelText: formatMessage({ id: 'GroupSelectCancel' }),
- onOk: () => handleDelete(item, { fetchApi, value, setValue })
- });
- }}>
- {formatMessage({ id: 'GroupSelectDelete' })}
-
-
- );
- }
- });
- }
+ if (showDelete) {
+ columns.push({
+ title: formatMessage({ id: 'GroupSelectOperation' }),
+ name: 'options',
+ span: 4,
+ getValueOf: (item, { context }) => {
+ const { fetchApi, value, setValue } = context;
+ return (
+ e.stopPropagation()}>
+ {
+ modal.confirm({
+ title: formatMessage({ id: 'GroupSelectConfirmDelete' }),
+ content: formatMessage({ id: 'GroupSelectDeleteConfirm' }, { name: groupName, title: item.name }),
+ okText: formatMessage({ id: 'GroupSelectConfirm' }),
+ cancelText: formatMessage({ id: 'GroupSelectCancel' }),
+ onOk: () => handleDelete(item, { fetchApi, value, setValue })
+ });
+ }}>
+ {formatMessage({ id: 'GroupSelectDelete' })}
+
+
+ );
+ }
+ });
+ }
- const Component = callback(SuperSelectTableList);
- return (
- ({
- filter: { keyword: searchText }
- })}
- pagination={{ paramsType: 'params' }}
- columns={columns}
- isPopup={false}
- footer={showAdd ? ({ reload }) => : null}
- {...props}
- />
- );
- })
+ const Component = callback(SuperSelectTableList);
+ return (
+ ({
+ filter: { keyword: searchText }
+ })}
+ pagination={{ paramsType: 'params' }}
+ columns={columns}
+ isPopup={false}
+ footer={
+ showAdd
+ ? ({ reload }) => (
+
+ )
+ : null
+ }
+ {...props}
+ />
+ );
+ }
+ )
);
};