RightContent.js 8.34 KB
Newer Older
邓晓峰's avatar
邓晓峰 committed
1
import React, { useState } from 'react';
dengxiaofeng's avatar
dengxiaofeng committed
2

邓晓峰's avatar
邓晓峰 committed
3
import { message } from 'antd';
邓晓峰's avatar
邓晓峰 committed
4
import _ from 'lodash';
邓晓峰's avatar
邓晓峰 committed
5 6
import { connect } from 'react-redux';
import Icon from '@ant-design/icons';
邓晓峰's avatar
邓晓峰 committed
7 8 9 10 11
import {
  HeaderSearch,
  useIntl,
  AvatarDropdown as Avatar,
} from '@wisdom-utils/components';
12

邓晓峰's avatar
邓晓峰 committed
13
import { actionCreators } from '../../containers/App/store';
dengxiaofeng's avatar
dengxiaofeng committed
14
import styles from './index.less';
邓晓峰's avatar
邓晓峰 committed
15
import NoticeIconView from './NoticeIconView';
16

邓晓峰's avatar
邓晓峰 committed
17
/* eslint-disable */
邓晓峰's avatar
邓晓峰 committed
18
const orderSvg = () => (
邓晓峰's avatar
邓晓峰 committed
19 20 21 22 23 24 25 26 27 28 29 30 31
  <svg
    version="1.1"
    x="0px"
    y="0px"
    width="24px"
    height="24px"
    viewBox="0 0 24 24"
    enableBackground="new 0 0 24 24"
    space="preserve"
  >
    <path
      fill="#5F718C"
      d="M7.223,13.131c-0.445,0-0.815,0.364-0.815,0.816c0,0.446,0.37,0.816,0.815,0.816
邓晓峰's avatar
邓晓峰 committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
      c0.446,0,0.816-0.37,0.816-0.816C8.039,13.495,7.669,13.131,7.223,13.131L7.223,13.131z M7.223,16.574L7.223,16.574
      c-0.445,0-0.815,0.371-0.815,0.817c0,0.45,0.37,0.814,0.815,0.814c0.446,0,0.816-0.364,0.816-0.814
      C8.039,16.945,7.669,16.574,7.223,16.574L7.223,16.574z M7.223,9.688L7.223,9.688c-0.445,0-0.815,0.366-0.815,0.817
      c0,0.445,0.37,0.815,0.815,0.815c0.446,0,0.816-0.37,0.816-0.815C8.039,10.054,7.669,9.688,7.223,9.688L7.223,9.688z M20.469,4.533
      L20.469,4.533h-2.246V4.082c0-0.268-0.22-0.48-0.485-0.48h-2.622c-0.138-0.59-0.434-1.1-0.839-1.505
      c-0.59-0.591-1.388-0.95-2.28-0.95c-0.884,0-1.677,0.359-2.262,0.95C9.323,2.502,9.022,3.012,8.879,3.602H6.263
      c-0.267,0-0.492,0.213-0.492,0.48v0.451H3.548c-0.451,0-0.821,0.363-0.821,0.814v16.688c0,0.452,0.37,0.817,0.821,0.817h16.921
      c0.438,0,0.805-0.365,0.805-0.817V5.348C21.273,4.896,20.907,4.533,20.469,4.533L20.469,4.533z M10.671,3.027
      c0.405-0.404,0.718-0.653,1.325-0.653c0.614,0,0.933,0.249,1.337,0.653c0.221,0.227,0.158,0.256,0.273,0.574h-3.208
      C10.516,3.283,10.44,3.254,10.671,3.027 M7.015,4.822L7.015,4.822h9.982v1.054H7.015 M19.647,21.215L19.647,21.215H4.359V6.158
      h1.411v0.451c0,0.267,0.226,0.486,0.492,0.486h11.475c0.266,0,0.485-0.22,0.485-0.486V6.158h1.425V21.215L19.647,21.215z
      M16.742,9.765L16.742,9.765H9.659c-0.267,0-0.485,0.468-0.485,0.74c0,0.267,0.219,0.739,0.485,0.739h7.083
      c0.277,0,0.491-0.473,0.491-0.739C17.233,10.232,17.02,9.765,16.742,9.765L16.742,9.765z M16.742,16.65L16.742,16.65H9.659
      c-0.267,0-0.485,0.468-0.485,0.741c0,0.271,0.219,0.728,0.485,0.728h7.083c0.277,0,0.491-0.457,0.491-0.728
      C17.233,17.118,17.02,16.65,16.742,16.65L16.742,16.65z M16.742,13.213L16.742,13.213H9.659c-0.267,0-0.485,0.462-0.485,0.735
      c0,0.271,0.219,0.734,0.485,0.734h7.083c0.277,0,0.491-0.464,0.491-0.734C17.233,13.675,17.02,13.213,16.742,13.213L16.742,13.213z"
邓晓峰's avatar
邓晓峰 committed
48 49 50
    />
  </svg>
);
邓晓峰's avatar
邓晓峰 committed
51
const homeSvg = () => (
邓晓峰's avatar
邓晓峰 committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  <svg
    version="1.1"
    x="0px"
    y="0px"
    width="24px"
    height="24px"
    viewBox="0 0 24 24"
    enableBackground="new 0 0 24 24"
    space="preserve"
  >
    <path
      fill="#5F718C"
      d="M23.359,13.561v-1.313L12.057,1.064L0.642,12.247v1.37h2.84v9.318h7.381v-4.935h2.271v4.935h7.385v-9.318
	    L23.359,13.561z M18.815,11.917v9.319H14.84v-4.935H9.161v4.935H5.185v-9.319H3.311l8.746-8.551l8.577,8.551H18.815z"
    />
邓晓峰's avatar
邓晓峰 committed
67
  </svg>
邓晓峰's avatar
邓晓峰 committed
68
);
邓晓峰's avatar
邓晓峰 committed
69
const OrderIcon = props => <Icon component={orderSvg} {...props} />;
邓晓峰's avatar
邓晓峰 committed
70 71 72
const HomeIcon = props => <Icon component={homeSvg} {...props} />;
const MESSAGE_BOX_URL =
  'product/maintenance/CaseManage/CaseDoingBox/StardCaseDoingBoxView|isDelay=1';
邓晓峰's avatar
邓晓峰 committed
73

邓晓峰's avatar
邓晓峰 committed
74
export const getConfig = (widgets, url, key) => {
邓晓峰's avatar
邓晓峰 committed
75
  let widgetconfig = {};
邓晓峰's avatar
邓晓峰 committed
76 77 78
  if (widgets) {
    // eslint-disable-next-line no-plusplus
    for (let i = 0; i < widgets.length; i++) {
邓晓峰's avatar
邓晓峰 committed
79
      const widget = widgets[i];
邓晓峰's avatar
邓晓峰 committed
80

邓晓峰's avatar
邓晓峰 committed
81 82 83 84
      if (widget && widget[key])
        widget[key] = widget[key].replace(/\\/g, '/').trim();
      // eslint-disable-next-line eqeqeq
      if (widget[key] && url.toLowerCase() === widget[key].toLowerCase()) {
邓晓峰's avatar
邓晓峰 committed
85 86 87
        widgetconfig = widget;
        break;
      } else {
邓晓峰's avatar
邓晓峰 committed
88
        const children = widget.widgets ? widget.widgets : widget.routes;
邓晓峰's avatar
邓晓峰 committed
89
        if (children) {
邓晓峰's avatar
邓晓峰 committed
90 91 92 93
          widgetconfig = getConfig(children, url, key);
          if (widgetconfig) {
            break;
          }
邓晓峰's avatar
邓晓峰 committed
94 95 96 97
        }
      }
    }
  }
邓晓峰's avatar
邓晓峰 committed
98 99
  return widgetconfig;
};
dengxiaofeng's avatar
dengxiaofeng committed
100 101
const GlobalHeaderRight = props => {
  const { theme, layout } = props;
邓晓峰's avatar
邓晓峰 committed
102
  const [options, setOptions] = useState([]);
dengxiaofeng's avatar
dengxiaofeng committed
103 104 105 106 107
  let className = styles.right;

  if (theme === 'dark' && layout === 'top') {
    className = `${styles.right}  ${styles.dark}`;
  }
邓晓峰's avatar
邓晓峰 committed
108

109
  const intl = useIntl();
邓晓峰's avatar
邓晓峰 committed
110

邓晓峰's avatar
邓晓峰 committed
111
  /* eslint-disable */
邓晓峰's avatar
邓晓峰 committed
112
  const handleSearch = value => {
邓晓峰's avatar
邓晓峰 committed
113
    // eslint-disable-next-line no-undef
邓晓峰's avatar
邓晓峰 committed
114 115
    const search = new AMap.Autocomplete();
    const areaName =
邓晓峰's avatar
邓晓峰 committed
116
      // eslint-disable-next-line no-undef
邓晓峰's avatar
邓晓峰 committed
117
      createStoreage.get('globalConfig').mapsettings.areasettings &&
邓晓峰's avatar
邓晓峰 committed
118
      // eslint-disable-next-line no-undef
邓晓峰's avatar
邓晓峰 committed
119
      createStoreage.get('globalConfig').mapsettings.areasettings.areaName;
邓晓峰's avatar
邓晓峰 committed
120
    const area = (areaName || '') + value;
邓晓峰's avatar
邓晓峰 committed
121
    setOptions([]);
邓晓峰's avatar
邓晓峰 committed
122
    // eslint-disable-next-line no-unused-expressions
邓晓峰's avatar
邓晓峰 committed
123 124
    value
      ? search.search(area, (status, res) => {
邓晓峰's avatar
邓晓峰 committed
125
        if (res && res.tips) {
邓晓峰's avatar
邓晓峰 committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
            const result = res.tips.map(item => {
              item.value = item.name;
              item.label = (
                <>
                  <span>{item.name}</span>
                  <span style={{ color: '#c1c1c1' }}>
                    {item.district + item.address}
                  </span>
                </>
              );
              return item;
            });

            setOptions(result);
          }
        })
      : setOptions([]);
  };

邓晓峰's avatar
邓晓峰 committed
145 146
  const goHome = event => {
    event.stopPropagation();
邓晓峰's avatar
邓晓峰 committed
147 148 149 150 151 152 153 154 155 156
    const url = _.isString(props.global.get('homepage'))
      ? props.global.get('homepage')
      : props.global.get('homepage.url');
    //      // props.history.replace(`/civweb4/${url}`)
    url ? (
      window.share.event.emit('listenerMointer', {
        label: '首页',
        url: url,
      })
    ) : null;
邓晓峰's avatar
邓晓峰 committed
157
  };
邓晓峰's avatar
邓晓峰 committed
158

邓晓峰's avatar
邓晓峰 committed
159

邓晓峰's avatar
邓晓峰 committed
160 161 162
  const handleOrder = event => {
    event.stopPropagation();
    const widgetConfig = getConfig(
邓晓峰's avatar
邓晓峰 committed
163
      props.global.get('widgets').concat(props.global.get('uiwidgets')),
邓晓峰's avatar
邓晓峰 committed
164 165 166 167 168 169
      MESSAGE_BOX_URL,
      'url',
    );

    if (Object.keys(widgetConfig).length > 0) {
      props.history.push(`/civweb4/${MESSAGE_BOX_URL}`);
邓晓峰's avatar
邓晓峰 committed
170
    } else {
邓晓峰's avatar
邓晓峰 committed
171
      message.warning('对不起,您没有菜单权限!');
邓晓峰's avatar
邓晓峰 committed
172
    }
邓晓峰's avatar
邓晓峰 committed
173
  };
邓晓峰's avatar
邓晓峰 committed
174

邓晓峰's avatar
邓晓峰 committed
175 176 177 178
  const handleSelect = (value, data) => {
    window.share.event.emit('addTips', options, data);
  };

dengxiaofeng's avatar
dengxiaofeng committed
179 180 181 182
  return (
    <div className={className}>
      <HeaderSearch
        className={`${styles.action} ${styles.search}`}
183
        placeholder={intl.formatMessage({id:'component.search.menu.placeholder'})}
dengxiaofeng's avatar
dengxiaofeng committed
184
        defaultValue=""
邓晓峰's avatar
邓晓峰 committed
185
        options={options}
邓晓峰's avatar
邓晓峰 committed
186
        {...props}
邓晓峰's avatar
邓晓峰 committed
187 188 189
        onSelect={handleSelect}
        onChange={handleSearch}
        onSearch={handleSearch}
dengxiaofeng's avatar
dengxiaofeng committed
190
      />
邓晓峰's avatar
邓晓峰 committed
191
      <div className={styles.nav}>
192 193
        <HomeIcon onClick={goHome} title={intl.formatMessage({id: 'component.header.icon.home'})} />
        <OrderIcon onClick={handleOrder} title={intl.formatMessage({id: 'component.header.icon.order'})} />
邓晓峰's avatar
邓晓峰 committed
194
      </div>
邓晓峰's avatar
邓晓峰 committed
195
      {/* <NoticeIconView title={intl.formatMessage({id: 'component.header.icon.alarm'})} /> */}
196
      <Avatar menu global={props.global} updateCurrentIndex={props.updateCurrentIndex} updateConfig={props.updateConfig} logout={props.logout}/>
dengxiaofeng's avatar
dengxiaofeng committed
197 198 199 200 201
      {/* <SelectLang className={styles.action} /> */}
    </div>
  );
};

邓晓峰's avatar
邓晓峰 committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
const mapStateToProps = state => ({
  global: state.getIn(['global', 'globalConfig']),
  flatMenu: state.getIn(['global', 'flatMenu']),
  menu: state.getIn(['global', 'menu']),
  recentKeywords: state.getIn(['global', 'recentKeywords']),
  recentVisited: state.getIn(['global', 'recentVisited']),
  recentProducts: state.getIn(['global', 'recentProducts']),
});
const mapDispatchToProps = dispatch => ({
  updateRecentKeywords(keyword) {
    dispatch(actionCreators.updateRecentKeywords(keyword));
  },
  updateRecentVisited(history) {
    dispatch(actionCreators.updateRecentVisited(history));
  },
  updateRecentProduct(history) {
    dispatch(actionCreators.updateRecentProduct(history));
  },
  clearRecentProduct() {
    dispatch(actionCreators.clearRecentProduct());
  },
邓晓峰's avatar
邓晓峰 committed
223 224
  updateCurrentIndex(index) {
    dispatch(actionCreators.updateCurrentIndex(index))
225 226 227 228
  },
  updateConfig(config) {
    dispatch(actionCreators.getConfig(config))
  },
邓晓峰's avatar
邓晓峰 committed
229 230 231
  updateComplexConfig(config) {
    dispatch(actionCreators.updateComplexConfig(config))
  },
232 233 234
  logout() {
    dispatch(actionCreators.logout())
  }
邓晓峰's avatar
邓晓峰 committed
235
});
邓晓峰's avatar
邓晓峰 committed
236 237
export default connect(
  mapStateToProps,
邓晓峰's avatar
邓晓峰 committed
238
  mapDispatchToProps,
邓晓峰's avatar
邓晓峰 committed
239
)(GlobalHeaderRight);