preview.js 2.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
import React, { useEffect, useState } from 'react';
import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons';
import { notification } from 'antd';
import classnames from 'classnames';
import { cloudService } from '@/api';
import useFullScreen from '../iframe/useFullScreen';
import styles from './index.less';

const PrevieView = props => {
  const params = Object.assign({}, props.params, {
    fullscreen: props.params !== undefined && props.params.fullscreen === 'true',
    canScroll: props.params !== undefined && props.params.longImg === 'true',
  });
  const { imgName, accountName, fullscreen, canScroll } = params;
  const [ref, isFullscreen, handleFullScreen, handleExitFullScreen] = useFullScreen(fullscreen);
  const [imgUrl, setImgUrl] = useState('');

  const getImgUrl = () => {
    cloudService
      .getAccountPageList({
        pageIndex: 1,
        pageSize: 5,
        sortFields: '录入时间',
        direction: 'desc',
        info: imgName,
        accountName,
      })
      .then(res => {
        const configData = JSON.parse(res.data.jsonData || '[]');
        if (configData.length > 0 && configData[0]['演示图片']) {
          const url = `${window.location.origin}/PandaWorkFlow/WorkFlow/AccountManage/DownloadFiles?filePath=${
            configData[0]['演示图片']
          }&_site=${window.globalConfig?.userInfo?.site}`;
          setImgUrl(url);
        }
      })
      .catch(err => {
        notification.error({ message: '提示', duration: 3, description: '获取图片信息错误' });
      });
  };

  useEffect(() => {
    getImgUrl();
李纪文's avatar
李纪文 committed
44
  }, []);
45 46 47 48 49 50 51 52 53 54 55 56 57

  return (
    <div className={classnames(styles['tab-preview'], canScroll ? styles['long-img'] : styles['normal-img'])} ref={ref}>
      <div className={styles['oper-wrap']}>
        <div className={styles['oper-btn']}>
          {isFullscreen ? (
            <FullscreenExitOutlined className={styles['btn-fullscreen_exit']} onClick={handleExitFullScreen} />
          ) : (
            <FullscreenOutlined className={styles['btn-fullscreen']} onClick={handleFullScreen} />
          )}
        </div>
      </div>

张瑶's avatar
张瑶 committed
58
      {imgUrl && <img src={imgUrl} display="block" position="relative" alt="演示图片" />}
59 60 61 62 63
    </div>
  );
};

export default PrevieView;