index.jsx 6.13 KB
Newer Older
TZW's avatar
TZW committed
1
import * as React from 'react';
TZW's avatar
TZW committed
2 3 4 5 6 7 8 9 10 11
import { useState, useMemo, useRef, useEffect } from 'react';
import DrawerPro from '@/components/DrawerPro';
import AutoTable from '@/components/AutoTable';
import PremButton from '@/components/PremButton';
import getcolumns from './columns';
import { useRequest } from 'ahooks';
import { doFetch } from '@/utils/doFetch';
import { Drawer, Space, Table, message } from 'antd';
import InitForm from '@/components/InitForm';
import copy from 'copy-to-clipboard';
TZW's avatar
TZW committed
12
import Notice from './Notice';
TZW's avatar
TZW committed
13

TZW's avatar
TZW committed
14
function Pushsetting(props) {
TZW's avatar
TZW committed
15
  let actionRef = useRef(),
TZW's avatar
TZW committed
16 17 18 19 20
    formRef = useRef();
  const [drawer, setdrawer] = useState({
    open: false,
  });
  const [checkVariableDraw, setCheckVariableDraw] = useState(false);
TZW's avatar
TZW committed
21
  const [variablePath, setVariablePath] = useState(null);
TZW's avatar
TZW committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  const pathconfig = useMemo(() => {
    let pathconf = getcolumns(setdrawer)?.pathconfig ?? {};
    return pathconf;
  }, []);
  const { run, loading } = useRequest(doFetch, {
    manual: true,
    onSuccess: (res, params) => {
      if (res?.code == '0000') {
        actionRef?.current?.reload();
        setdrawer((s) => ({
          ...s,
          open: false,
        }));
      }
    },
  });

  const news = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
              open: true,
              item: row,
TZW's avatar
TZW committed
49 50 51 52
              title: '通知',
              val: 'only',
              id: row?.id,
              pushSettingFlag: false,
TZW's avatar
TZW committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
            }));
          },
        }}
      >
        新增通知
      </PremButton>
    );
  };

  const edit = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
              open: true,
              item: row,
              title: '编辑',
              val: 'edit',
TZW's avatar
TZW committed
74
              pushSettingFlag: true,
TZW's avatar
TZW committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
            }));
          },
        }}
      >
        编辑
      </PremButton>
    );
  };

  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
          title: '是否删除?',
          okText: '确认',
          cancelText: '取消',
          onConfirm: () => {
            run({ url: pathconfig?.delete || '/delete', params: { id: row?.id } });
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        删除
      </PremButton>
    );
  };

  // 查看变量
  const checkVariableOpen = () => {
    setCheckVariableDraw(true);
  };
  const CheckVariable = () => {
    const columns = [
      {
        title: '变量名称',
        dataIndex: 'variableName',
        key: 'variableName',
      },
      {
        title: '变量编号',
        dataIndex: 'variableCode',
        key: 'variableCode',
      },
      {
        title: '操作',
        key: 'action',
        render: (_, record) => (
          <Space size="middle">
            <a
              onClick={() => {
                copy(record.variableCode);
                message.success('已成功复制到剪切板!');
              }}
            >
              复制
            </a>
          </Space>
        ),
TZW's avatar
TZW committed
136
      },
TZW's avatar
TZW committed
137 138 139 140 141
    ];

    return (
      <AutoTable
        columns={columns}
TZW's avatar
TZW committed
142
        resizeable={false}
TZW's avatar
TZW committed
143
        path="/base/paBusinessMsgSceneVariable/queryPageBySceneId"
TZW's avatar
TZW committed
144
        params={variablePath}
TZW's avatar
TZW committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
      />
    );
  };

  const columns = useMemo(() => {
    let defcolumn = getcolumns(setdrawer)?.columns;
    return defcolumn.concat({
      title: '操作',
      valueType: 'option',
      width: 150,
      render: (text, row, _, action) => [
        news(text, row, _, action),
        edit(text, row, _, action),
        remove(text, row, _, action),
      ],
TZW's avatar
TZW committed
160
    });
TZW's avatar
TZW committed
161
  }, []);
TZW's avatar
TZW committed
162

TZW's avatar
TZW committed
163 164 165 166 167 168 169 170 171
  const selectValueType = {
    1: '全部',
    2: '公司',
    3: '部门',
    4: '工厂',
    5: '车间',
    6: '工段',
    7: '产线',
  };
TZW's avatar
TZW committed
172

TZW's avatar
TZW committed
173 174 175
  return (
    <div style={{ position: 'relative' }}>
      <AutoTable
TZW's avatar
TZW committed
176
        pagetitle={<h3 className="page-title">推送配置</h3>}
TZW's avatar
TZW committed
177 178 179 180
        columns={columns}
        actionRef={actionRef}
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
        pageextra={pathconfig?.enableadd ? 'add' : null}
TZW's avatar
TZW committed
181
        resizeable={false}
TZW's avatar
TZW committed
182 183 184 185
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
TZW's avatar
TZW committed
186
            type: 'primary',
TZW's avatar
TZW committed
187 188 189
            onClick: () => {
              setdrawer((s) => ({
                ...s,
TZW's avatar
TZW committed
190
                pushSettingFlag: true,
TZW's avatar
TZW committed
191
                open: true,
TZW's avatar
TZW committed
192 193 194
                item: null,
                title: '新增',
                val: 'add',
TZW's avatar
TZW committed
195 196
              }));
            },
TZW's avatar
TZW committed
197 198 199
          },
        }}
      />
TZW's avatar
TZW committed
200

TZW's avatar
TZW committed
201 202 203 204 205 206 207 208 209 210 211 212
      <DrawerPro
        fields={columns}
        params={{ id: drawer?.item?.id }}
        formRef={formRef}
        placement="right"
        detailpath={pathconfig?.detail || null}
        checkVariableOpen={checkVariableOpen}
        detailData={drawer?.item}
        defaultFormValue={drawer?.item}
        onValuesChange={async (a, b) => {
          if (a?.fitField) {
            const res = doFetch({ url: selectValueType[a?.fitField] });
TZW's avatar
TZW committed
213 214 215 216
          } else if (a?.businessMsgSceneId) {
            setVariablePath({
              businessMsgSceneId: a?.businessMsgSceneId,
            });
TZW's avatar
TZW committed
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
          }
        }}
        onClose={() => {
          setdrawer((s) => ({
            ...s,
            open: false,
          }));
        }}
        {...drawer}
        onFinish={(vals) => {
          if (drawer?.val == 'add') {
            run({ url: pathconfig?.add || '/add', params: { ...vals } });
          } else if (drawer?.val == 'edit') {
            run({ url: pathconfig?.edit || '/edit', params: { ...vals, id: drawer?.item?.id } });
          }
        }}
TZW's avatar
TZW committed
233 234 235
      >
        <Notice businessMsgOptionId={drawer?.id} />
      </DrawerPro>
TZW's avatar
TZW committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249
      <Drawer
        title="查看变量"
        width={700}
        placement="right"
        onClose={() => {
          setCheckVariableDraw(false);
        }}
        open={checkVariableDraw}
      >
        <CheckVariable />
      </Drawer>
    </div>
  );
}
TZW's avatar
TZW committed
250

TZW's avatar
TZW committed
251
export default Pushsetting;