Procházet zdrojové kódy

Merge branch 'next' into next-sc

Lind před 3 roky
rodič
revize
21a0467310

binární
public/images/login.png


+ 1 - 1
src/components/ProTableCard/CardItems/noticeConfig.tsx

@@ -12,7 +12,7 @@ export interface NoticeCardProps extends ConfigItem {
 
 export default (props: NoticeCardProps) => {
   return (
-    <TableCard actions={props.actions} showStatus={false} showMask={false}>
+    <TableCard detail={props.detail} actions={props.actions} showStatus={false} showMask={false}>
       <div className={'pro-table-card-item'}>
         <div className={'card-item-avatar'}>
           <img width={88} height={88} src={imgMap[props.type]} alt={props.type} />

+ 1 - 1
src/components/ProTableCard/CardItems/noticeTemplate.tsx

@@ -39,7 +39,7 @@ export const typeList = {
 
 export default (props: NoticeCardProps) => {
   return (
-    <TableCard actions={props.actions} showStatus={false} showMask={false}>
+    <TableCard actions={props.actions} showStatus={false} detail={props.detail} showMask={false}>
       <div className={'pro-table-card-item'}>
         <div className={'card-item-avatar'}>
           <img width={88} height={88} src={imgMap[props.type]} alt={props.type} />

+ 11 - 2
src/pages/notice/Config/Detail/index.tsx

@@ -16,7 +16,6 @@ import {
   Radio,
   Select,
   Space,
-  Submit,
   Switch,
 } from '@formily/antd';
 import styles from './index.less';
@@ -32,6 +31,8 @@ import DingTalkRebot from '@/pages/notice/Config/Detail/doc/DingTalkRebot';
 import AliyunSms from '@/pages/notice/Config/Detail/doc/AliyunSms';
 import AliyunVoice from '@/pages/notice/Config/Detail/doc/AliyunVoice';
 import Email from '@/pages/notice/Config/Detail/doc/Email';
+import { PermissionButton } from '@/components';
+import usePermissions from '@/hooks/permission';
 
 export const docMap = {
   weixin: {
@@ -410,6 +411,8 @@ const Detail = observer(() => {
     }
   };
 
+  const { getOtherPermission } = usePermissions('notice');
+
   return (
     <PageContainer>
       <Card>
@@ -419,7 +422,13 @@ const Detail = observer(() => {
               <SchemaField scope={{ useAsyncDataSource, getTypes }} schema={schema} />
               <FormButtonGroup.Sticky>
                 <FormButtonGroup.FormItem>
-                  <Submit onSubmit={handleSave}>保存</Submit>
+                  <PermissionButton
+                    type="primary"
+                    onClick={handleSave}
+                    isPermission={getOtherPermission(['add', 'update'])}
+                  >
+                    保存
+                  </PermissionButton>
                 </FormButtonGroup.FormItem>
               </FormButtonGroup.Sticky>
             </Form>

+ 66 - 39
src/pages/notice/Config/index.tsx

@@ -6,10 +6,11 @@ import {
   BugOutlined,
   DeleteOutlined,
   EditOutlined,
+  EyeOutlined,
   PlusOutlined,
   UnorderedListOutlined,
 } from '@ant-design/icons';
-import { Button, message, Popconfirm, Space, Tooltip, Upload } from 'antd';
+import { message, Popconfirm, Space, Tooltip, Upload } from 'antd';
 import { useRef, useState } from 'react';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import { downloadObject } from '@/utils/util';
@@ -20,11 +21,12 @@ import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
 import { history, useLocation } from 'umi';
 import { model } from '@formily/reactive';
 import moment from 'moment';
-import { ProTableCard } from '@/components';
+import { PermissionButton, ProTableCard } from '@/components';
 import NoticeConfig from '@/components/ProTableCard/CardItems/noticeConfig';
 import Debug from '@/pages/notice/Config/Debug';
 import Log from '@/pages/notice/Config/Log';
 import { typeList } from '@/components/ProTableCard/CardItems/noticeTemplate';
+import usePermissions from '@/hooks/permission';
 
 export const service = new Service('notifier/config');
 
@@ -41,6 +43,7 @@ const Config = observer(() => {
   const actionRef = useRef<ActionType>();
   const location = useLocation<{ id: string }>();
 
+  const { permission: configPermission } = usePermissions('notice');
   const id = (location as any).query?.id;
 
   const columns: ProColumns<ConfigItem>[] = [
@@ -179,7 +182,8 @@ const Config = observer(() => {
         columns={columns}
         headerTitle={
           <Space>
-            <Button
+            <PermissionButton
+              isPermission={configPermission.add}
               onClick={() => {
                 state.current = undefined;
                 history.push(getMenuPathByParams(MENUS_CODE['notice/Config/Detail'], id));
@@ -192,8 +196,9 @@ const Config = observer(() => {
                 id: 'pages.data.option.add',
                 defaultMessage: '新增',
               })}
-            </Button>
+            </PermissionButton>
             <Upload
+              disabled={!configPermission.import}
               key={'import'}
               showUploadList={false}
               beforeUpload={(file) => {
@@ -207,10 +212,6 @@ const Config = observer(() => {
                   }
                   try {
                     const data = JSON.parse(text || '{}');
-                    if (Array.isArray(data)) {
-                      message.warning('文件内容格式错误');
-                      return;
-                    }
                     const res: any = await service.savePatch(data);
                     if (res.status === 200) {
                       message.success('操作成功');
@@ -223,22 +224,27 @@ const Config = observer(() => {
                 return false;
               }}
             >
-              <Button style={{ marginLeft: 12 }}>导入</Button>
+              <PermissionButton isPermission={configPermission.import} style={{ marginLeft: 12 }}>
+                导入
+              </PermissionButton>
             </Upload>
-            <Popconfirm
-              title={'确认导出当前页数据?'}
-              onConfirm={async () => {
-                const resp: any = await service.queryNoPagingPost({ ...param, paging: false });
-                if (resp.status === 200) {
-                  downloadObject(resp.result, '通知配置数据');
-                  message.success('导出成功');
-                } else {
-                  message.error('导出错误');
-                }
+            <PermissionButton
+              popConfirm={{
+                title: '确认导出当前页数据?',
+                onConfirm: async () => {
+                  const resp: any = await service.queryNoPagingPost({ ...param, paging: false });
+                  if (resp.status === 200) {
+                    downloadObject(resp.result, '通知配置数据');
+                    message.success('导出成功');
+                  } else {
+                    message.error('导出错误');
+                  }
+                },
               }}
+              isPermission={configPermission.export}
             >
-              <Button>导出</Button>
-            </Popconfirm>
+              导出
+            </PermissionButton>
           </Space>
         }
         gridColumn={3}
@@ -249,20 +255,34 @@ const Config = observer(() => {
           <NoticeConfig
             {...record}
             type={id}
+            detail={
+              <div
+                style={{ fontSize: 18, padding: 8 }}
+                onClick={() => {
+                  state.current = record;
+                  history.push(getMenuPathByParams(MENUS_CODE['notice/Config/Detail'], id));
+                }}
+              >
+                <EyeOutlined />
+              </div>
+            }
             actions={[
-              <Button
+              <PermissionButton
+                isPermission={configPermission.update}
+                type={'link'}
                 key="edit"
                 onClick={async () => {
-                  // setLoading(true);
                   state.current = record;
                   history.push(getMenuPathByParams(MENUS_CODE['notice/Config/Detail'], id));
                 }}
               >
                 <EditOutlined />
                 编辑
-              </Button>,
-              <Button
+              </PermissionButton>,
+              <PermissionButton
+                type={'link'}
                 key="debug"
+                isPermission={configPermission.debug}
                 onClick={() => {
                   state.debug = true;
                   state.current = record;
@@ -270,9 +290,11 @@ const Config = observer(() => {
               >
                 <BugOutlined />
                 调试
-              </Button>,
-              <Button
+              </PermissionButton>,
+              <PermissionButton
+                type={'link'}
                 key="export"
+                isPermission={configPermission.export}
                 onClick={() =>
                   downloadObject(
                     record,
@@ -282,9 +304,11 @@ const Config = observer(() => {
               >
                 <ArrowDownOutlined />
                 导出
-              </Button>,
-              <Button
+              </PermissionButton>,
+              <PermissionButton
+                type={'link'}
                 key="log"
+                isPermission={configPermission.log}
                 onClick={() => {
                   state.log = true;
                   state.current = record;
@@ -292,19 +316,22 @@ const Config = observer(() => {
               >
                 <UnorderedListOutlined />
                 通知记录
-              </Button>,
-              <Popconfirm
+              </PermissionButton>,
+
+              <PermissionButton
                 key="delete"
-                title="确认删除?"
-                onConfirm={async () => {
-                  await service.remove(record.id);
-                  actionRef.current?.reset?.();
+                isPermission={configPermission.delete}
+                popConfirm={{
+                  title: '确认删除?',
+                  onConfirm: async () => {
+                    await service.remove(record.id);
+                    actionRef.current?.reset?.();
+                  },
                 }}
+                type={'link'}
               >
-                <Button key="delete">
-                  <DeleteOutlined />
-                </Button>
-              </Popconfirm>,
+                <DeleteOutlined />
+              </PermissionButton>,
             ]}
           />
         )}

+ 118 - 80
src/pages/notice/Template/index.tsx

@@ -6,10 +6,11 @@ import {
   BugOutlined,
   DeleteOutlined,
   EditOutlined,
+  EyeOutlined,
   PlusOutlined,
   UnorderedListOutlined,
 } from '@ant-design/icons';
-import { Button, message, Popconfirm, Space, Tooltip, Upload } from 'antd';
+import { message, Space, Upload } from 'antd';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import Service from '@/pages/notice/Template/service';
 import ConfigService from '@/pages/notice/Config/service';
@@ -21,9 +22,10 @@ import Debug from './Debug';
 import Log from '@/pages/notice/Template/Log';
 import { downloadObject } from '@/utils/util';
 import moment from 'moment';
-import { ProTableCard } from '@/components';
+import { PermissionButton, ProTableCard } from '@/components';
 import NoticeCard, { typeList } from '@/components/ProTableCard/CardItems/noticeTemplate';
 import { observer } from '@formily/react';
+import usePermissions from '@/hooks/permission';
 
 export const service = new Service('notifier/template');
 
@@ -42,6 +44,8 @@ const Template = observer(() => {
   const id = (location as any).query?.id;
   const actionRef = useRef<ActionType>();
 
+  const { permission: templatePermission } = usePermissions('notice');
+
   const columns: ProColumns<TemplateItem>[] = [
     {
       dataIndex: 'name',
@@ -66,43 +70,31 @@ const Template = observer(() => {
       align: 'center',
       width: 200,
       render: (text, record) => [
-        <a
+        <PermissionButton
           key="edit"
+          style={{ padding: 0 }}
+          type="link"
+          isPermission={templatePermission.update}
           onClick={() => {
             state.current = record;
             history.push(getMenuPathByParams(MENUS_CODE['notice/Template/Detail'], id));
           }}
-        >
-          <Tooltip
-            title={intl.formatMessage({
+          tooltip={{
+            title: intl.formatMessage({
               id: 'pages.data.option.edit',
               defaultMessage: '编辑',
-            })}
-          >
-            <EditOutlined />
-          </Tooltip>
-        </a>,
-        <Popconfirm
-          key="delete"
-          title="确认删除?"
-          onConfirm={async () => {
-            await service.remove(record.id);
-            actionRef.current?.reload();
+            }),
           }}
         >
-          <a key="delete">
-            <Tooltip
-              title={intl.formatMessage({
-                id: 'pages.data.option.remove',
-                defaultMessage: '删除',
-              })}
-            >
-              <DeleteOutlined />
-            </Tooltip>
-          </a>
-        </Popconfirm>,
-        <a
+          <EditOutlined />
+        </PermissionButton>,
+
+        <PermissionButton
           key="download"
+          style={{ padding: 0 }}
+          type="link"
+          tooltip={{ title: '导出' }}
+          isPermission={templatePermission.export}
           onClick={() => {
             downloadObject(
               record,
@@ -110,36 +102,59 @@ const Template = observer(() => {
             );
           }}
         >
-          <Tooltip title="导出">
-            <ArrowDownOutlined />
-          </Tooltip>
-        </a>,
-        <a
+          <ArrowDownOutlined />
+        </PermissionButton>,
+        <PermissionButton
+          isPermission={templatePermission.debug}
           key="debug"
+          style={{ padding: 0 }}
+          type="link"
           onClick={() => {
             state.debug = true;
             state.current = record;
           }}
-        >
-          <Tooltip
-            title={intl.formatMessage({
+          tooltip={{
+            title: intl.formatMessage({
               id: 'pages.notice.option.debug',
               defaultMessage: '调试',
-            })}
-          >
-            <BugOutlined />
-          </Tooltip>
-        </a>,
-        <a
+            }),
+          }}
+        >
+          <BugOutlined />
+        </PermissionButton>,
+        <PermissionButton
+          isPermission={templatePermission.log}
           key="log"
+          style={{ padding: 0 }}
+          type="link"
           onClick={() => {
             state.log = true;
           }}
+          tooltip={{ title: '通知记录' }}
+        >
+          <UnorderedListOutlined />
+        </PermissionButton>,
+        <PermissionButton
+          style={{ padding: 0 }}
+          type="link"
+          popConfirm={{
+            title: '确认删除?',
+            onConfirm: async () => {
+              await service.remove(record.id);
+              actionRef.current?.reload();
+            },
+          }}
+          tooltip={{
+            title: intl.formatMessage({
+              id: 'pages.data.option.remove',
+              defaultMessage: '删除',
+            }),
+          }}
+          isPermission={templatePermission.delete}
+          key="delete"
         >
-          <Tooltip title="通知记录">
-            <UnorderedListOutlined />
-          </Tooltip>
-        </a>,
+          <DeleteOutlined />
+        </PermissionButton>,
       ],
     },
   ];
@@ -163,7 +178,8 @@ const Template = observer(() => {
         columns={columns}
         headerTitle={
           <Space>
-            <Button
+            <PermissionButton
+              isPermission={templatePermission.add}
               onClick={() => {
                 state.current = undefined;
                 history.push(getMenuPathByParams(MENUS_CODE['notice/Template/Detail'], id));
@@ -176,8 +192,9 @@ const Template = observer(() => {
                 id: 'pages.data.option.add',
                 defaultMessage: '新增',
               })}
-            </Button>
+            </PermissionButton>
             <Upload
+              disabled={!templatePermission.import}
               key={'import'}
               showUploadList={false}
               beforeUpload={(file) => {
@@ -203,22 +220,28 @@ const Template = observer(() => {
                 return false;
               }}
             >
-              <Button style={{ marginLeft: 12 }}>导入</Button>
+              <PermissionButton isPermission={templatePermission.import} style={{ marginLeft: 12 }}>
+                导入
+              </PermissionButton>
             </Upload>
-            <Popconfirm
-              title={'确认导出当前页数据?'}
-              onConfirm={async () => {
-                const resp: any = await service.queryNoPagingPost({ ...param, paging: false });
-                if (resp.status === 200) {
-                  downloadObject(resp.result, '通知模版数据');
-                  message.success('导出成功');
-                } else {
-                  message.error('导出错误');
-                }
+
+            <PermissionButton
+              popConfirm={{
+                title: '确认导出当前页数据?',
+                onConfirm: async () => {
+                  const resp: any = await service.queryNoPagingPost({ ...param, paging: false });
+                  if (resp.status === 200) {
+                    downloadObject(resp.result, '通知模版数据');
+                    message.success('导出成功');
+                  } else {
+                    message.error('导出错误');
+                  }
+                },
               }}
+              isPermission={templatePermission.export}
             >
-              <Button>导出</Button>
-            </Popconfirm>
+              导出
+            </PermissionButton>
           </Space>
         }
         gridColumn={3}
@@ -226,8 +249,20 @@ const Template = observer(() => {
           <NoticeCard
             {...record}
             type={id}
+            detail={
+              <div
+                style={{ fontSize: 18, padding: 8 }}
+                onClick={() => {
+                  state.current = record;
+                  history.push(getMenuPathByParams(MENUS_CODE['notice/Template/Detail'], id));
+                }}
+              >
+                <EyeOutlined />
+              </div>
+            }
             actions={[
-              <Button
+              <PermissionButton
+                isPermission={templatePermission.update}
                 key="edit"
                 onClick={() => {
                   state.current = record;
@@ -236,8 +271,9 @@ const Template = observer(() => {
               >
                 <EditOutlined />
                 编辑
-              </Button>,
-              <Button
+              </PermissionButton>,
+              <PermissionButton
+                isPermission={templatePermission.debug}
                 key="debug"
                 onClick={() => {
                   state.debug = true;
@@ -246,9 +282,10 @@ const Template = observer(() => {
               >
                 <BugOutlined />
                 调试
-              </Button>,
-              <Button
+              </PermissionButton>,
+              <PermissionButton
                 key="export"
+                isPermission={templatePermission.export}
                 onClick={() => {
                   downloadObject(
                     record,
@@ -258,8 +295,9 @@ const Template = observer(() => {
               >
                 <ArrowDownOutlined />
                 导出
-              </Button>,
-              <Button
+              </PermissionButton>,
+              <PermissionButton
+                isPermission={templatePermission.log}
                 key="log"
                 onClick={() => {
                   state.log = true;
@@ -268,19 +306,19 @@ const Template = observer(() => {
               >
                 <UnorderedListOutlined />
                 通知记录
-              </Button>,
-              <Popconfirm
-                key="delete"
-                title="确认删除?"
-                onConfirm={async () => {
-                  await service.remove(record.id);
-                  actionRef.current?.reset?.();
+              </PermissionButton>,
+              <PermissionButton
+                popConfirm={{
+                  title: '确认删除?',
+                  onConfirm: async () => {
+                    await service.remove(record.id);
+                    actionRef.current?.reset?.();
+                  },
                 }}
+                key="delete"
               >
-                <Button key="delete">
-                  <DeleteOutlined />
-                </Button>
-              </Popconfirm>,
+                <DeleteOutlined />
+              </PermissionButton>,
             ]}
           />
         )}

+ 3 - 1
src/utils/menu/router.ts

@@ -104,7 +104,7 @@ export enum MENUS_CODE {
   'link/Type/Detail' = 'link/Type/Detail',
 }
 
-export type MENUS_CODE_TYPE = keyof typeof MENUS_CODE;
+export type MENUS_CODE_TYPE = keyof typeof MENUS_CODE | string;
 
 export enum BUTTON_PERMISSION_ENUM {
   'add' = 'add',
@@ -120,6 +120,8 @@ export enum BUTTON_PERMISSION_ENUM {
   'active' = 'active',
   'sync' = 'sync',
   'channel' = 'channel',
+  'debug' = 'debug',
+  'log' = 'log'
 }
 
 // 调试按钮、通知记录、批量导出、批量导入、选择通道、推送、分配资产、绑定用户对应的ID是啥