item-component.tsx 2.95 KB
/*
 * @Author: zhuqin zq627501913@163.com
 * @Date: 2022-05-30 17:40:47
 * @LastEditors: yantao 821714016@qq.com
 * @LastEditTime: 2022-07-11 11:47:15
 * @FilePath: \qx-apaas-fe\src\pages\app-view\custom\item-component.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import React, { useEffect, useState } from 'react';
import { getCustomSchema, getCustomData } from '@/pages/editor/custom/service';
import { Empty } from 'antd';

interface ItemComponentProps {
  component: any;
  id?: string;
  appCode: string;
  customCode: string;
  taskData: any;
}

const ItemComponent: React.FC<ItemComponentProps> = (props) => {
  const [config, setConfig] = useState({});
  const [dataSource, setData] = useState([]);
  const [isLoading, setIsLoading] = useState(true);
  const [nullFlag, setNullFlag] = useState(false);

  const { appCode, customCode } = props;
  const current = props.component;
  const _key = current.widget || current.key;
  // TODO:
  const ViewComponent = () => <></>;
  useEffect(() => {
    if (!current.code) return;
    getCustomSchema(appCode, customCode, current.code).then((data) => {
      setConfig(data || {});
    });

    getCustomData(appCode, customCode, current.code)
      .then((data) => {
        setData(data || []);
        setIsLoading(false);
        setNullFlag(false);
      })
      .catch((e) => {
        if (e?.msg === '暂无操作权限') {
          setNullFlag(true);
        } else {
          setNullFlag(false);
        }
      });
  }, []);

  return (
    <div
      className={`qx-item-custom qx-item-custom-production ${
        current.widget === 'VIEW' ? 'qx-page-comp--view-card' : ''
      }`}
    >
      <div className={'qx-item-custom-view'}>
        {nullFlag ? (
          <>
            <Empty
              image={require('/public/img/none-jurisdiction.png')}
              style={{
                margin: 0,
                padding: 0,
                height: '100%',
                minHeight: '120px',
                width: '100%',
                display: 'flex',
                flexDirection: 'column',
                alignItems: 'center',
                justifyContent: 'center',
              }}
              imageStyle={{
                height: 200,
                marginBottom: 0,
              }}
              description={
                <span style={{ fontSize: '16px', color: '#999' }}>
                  暂无权限
                </span>
              }
            ></Empty>
          </>
        ) : (
          <>
            {ViewComponent && (
              <ViewComponent
                item={current}
                config={config || {}}
                dataSoure={dataSource || []}
                isLoading={isLoading}
                taskData={props.taskData || {}}
              />
            )}
          </>
        )}
      </div>
    </div>
  );
};

export default ItemComponent;