App.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. import React, { Component, Suspense } from 'react';
  2. import ReactDOM from 'react-dom';
  3. import './App.css';
  4. import { Menu, Button, Result, notification, Spin } from 'antd';
  5. import { $Axios } from './common/publish';
  6. import { SettingOutlined, DollarCircleOutlined, } from '@ant-design/icons';
  7. import * as Icons from "@ant-design/icons";
  8. import cookie from 'react-cookies'
  9. import {
  10. MenuUnfoldOutlined,
  11. MenuFoldOutlined,
  12. PieChartOutlined,
  13. } from '@ant-design/icons';
  14. export default class App extends React.Component {
  15. constructor(props) {
  16. super(props)
  17. this.state = {
  18. isLogin: true,
  19. current: 1,
  20. arr1: [
  21. { txt: '商户入网', icon: 'GlobalOutlined', assembly: 'Layout' }, // no 1-0
  22. { txt: '商户入网列表', icon: 'SlidersOutlined', assembly: 'center-tab' } // ok 1-1
  23. ],
  24. arr2: [
  25. { txt: '账户概览', icon: '', assembly: 'Account-overview' }, //ok 2-0
  26. { txt: '订单查询', icon: '', assembly: 'Finance-orderQuery' },//ok 2-1
  27. { txt: '退款查询', icon: '', assembly: 'Refund-inquiry' }, //ok 2-2
  28. { txt: '发起提现', icon: '', assembly: 'Cash-initiated' }, //ok 2-3
  29. { txt: '提现记录', icon: '', assembly: 'Withdrawal-record' }, //ok 2-4
  30. { txt: '分账结算记录', icon: '', assembly: 'Income-record' }, //ok 2-5
  31. // { txt : 'demo' , icon : '', assembly:'homePage'},
  32. ],
  33. assembly: 'Layout',
  34. defaultSelectedKeys: 'Layout',
  35. assembly_cw: 'Account-overview',
  36. user_txt: {},
  37. signout: false,
  38. isSignout: 'no',
  39. yc: ''
  40. }
  41. }
  42. //初始化执行
  43. componentDidMount() {
  44. let isSignout = localStorage.getItem('isSignout'); //获取退出时存储的数据,用于判断用户退出后是否刷新页面
  45. let userData = cookie.load('userInformation');// 获取上游跳转时带给的信息
  46. // userData = JSON.parse(unescape(userData));
  47. let obj = { //默认信息
  48. userName: '泱泱华夏',
  49. mallId: 2, //多商户所属商城id
  50. merchantNo: 'com.depushuyuan',//入网的appname、社群name、商户号等(香香或者嘉旺提供)
  51. merchantType: 2,//入网来源,2:app或社群3:商户或店铺(香香或者嘉旺提供)
  52. Jur: 1,//用户权限
  53. pages: '1-0'
  54. }
  55. this.autoLogin(obj) //跳转查询用户信息,验证用户是否入网
  56. // if(isSignout == 'yes' && userData == undefined){ //拦截是否为刷新页面
  57. // this.setState({
  58. // signout : true
  59. // })
  60. // }
  61. }
  62. initJurisdiction() {//初始化用户权限
  63. let e = JSON.parse(localStorage.getItem('userData'));
  64. let page = e.pages.split('-'); //切割拿到的跳转菜单字符串,分割跳转
  65. if (page[0] == 1) {
  66. let arr = this.state.arr1;
  67. this.setState({
  68. user_txt: e,
  69. current: page[0],
  70. assembly: arr.find((item, index) => { return index == page[1] }).assembly
  71. })
  72. } else {
  73. let arr = this.state.arr2;
  74. this.setState({
  75. user_txt: e,
  76. current: page[0],
  77. assembly_cw: arr.find((item, index) => { return index == page[1] }).assembly
  78. })
  79. }
  80. }
  81. handleClick(e) { //上方导航菜单点击
  82. this.setState({
  83. current: e.key,
  84. });
  85. this.initassembly()
  86. }
  87. toggleCollapsed(e) { //收缩左侧菜单
  88. this.setState({
  89. collapsed: !this.state.collapsed,
  90. });
  91. }
  92. toggleNavs(e) { //左侧菜单点击
  93. let current = this.state.current;
  94. if (current == 1) {
  95. this.setState({
  96. assembly: e.key,
  97. });
  98. } else {
  99. this.setState({
  100. assembly_cw: e.key
  101. });
  102. }
  103. }
  104. initassembly() { //按需引入插件进行加载
  105. let current = this.state.current;
  106. let Assembly = null;
  107. if (current == 1) {
  108. Assembly = React.lazy(() => import(`./component/${this.state.assembly}/${this.state.assembly}.jsx`));
  109. } else {
  110. Assembly = React.lazy(() => import(`./component/${this.state.assembly_cw}/${this.state.assembly_cw}.jsx`));
  111. }
  112. return <Suspense fallback="" key="dialog"><Assembly refModal={this.state.current} /></Suspense>
  113. }
  114. initIcon(item) { //用于遍历渲染左侧菜单ICON
  115. let Icon = item.icon;
  116. return React.createElement(Icons[Icon])
  117. }
  118. /**
  119. * 逻辑更改:如果商户已入网则不会跳转到入网页面并且隐藏入网菜单
  120. * 逻辑更改:如果商户未入网无论指定跳转到任何页面全部跳转为入网页面
  121. */
  122. autoLogin = (e) => { //初始化进入页面请求查询用户是否入网以及其他信息
  123. localStorage.removeItem('userData') //退出清除用户本地数据
  124. let that_ = this;
  125. let url = '/payment/merchant.query.groovy'
  126. let param = {
  127. action: "queryInfo",
  128. // merchantNo: 'com.depushuyuan',
  129. // merchantType: 2,
  130. merchantNo: e.merchantNo,
  131. merchantType: e.merchantType,
  132. }
  133. $Axios('get', url, param, (res) => {
  134. let status = res.data.head.status;
  135. if (status == 200) {
  136. let data = res.data.body;
  137. let type = data.status
  138. if (type !== undefined) {
  139. that_.setState({
  140. // yc: true
  141. })
  142. notification.open({
  143. message: '提示:',
  144. style: {
  145. color: 'red',
  146. },
  147. description:
  148. '当前账户存在异常情况,请联系管理员!',
  149. onClick: () => { },
  150. });
  151. localStorage.setItem('userData', JSON.stringify(e)) //存储上游信息 到本地储存
  152. } else {
  153. // let s = data.status;
  154. // if (s == undefined) { //商户已入网
  155. // that_.setState({
  156. // arr1: [{ txt: '商户入网列表', icon: 'SlidersOutlined', assembly: 'center-tab' }],
  157. // assembly: 'center-tab'
  158. // });
  159. // if (e.pages == '1-0') {
  160. // notification.open({
  161. // message: '提示:',
  162. // description:
  163. // '当前用户已入网,自动跳转为账户概览',
  164. // onClick: () => { },
  165. // });
  166. // e.pages = '2-0'
  167. // }
  168. // } else if (s == 1) { //未入网
  169. // notification.open({
  170. // message: '提示:',
  171. // description:
  172. // '当前用户未入网,请您入网后在进行其他操作',
  173. // onClick: () => { },
  174. // });
  175. // e.pages = '1-0'
  176. // that_.setState({
  177. // assembly: 'Layout'
  178. // });
  179. // }
  180. localStorage.setItem('userData', JSON.stringify(e)) //存储上游信息 到本地储存
  181. that_.initJurisdiction(); //初始化用户权限以及各种信息
  182. }
  183. }
  184. });
  185. return e
  186. }
  187. signout() {
  188. localStorage.setItem('isSignout', 'yes')
  189. localStorage.removeItem('userData') //退出清除用户本地数据
  190. cookie.remove('userInformation')
  191. this.setState({
  192. signout: true
  193. });
  194. }
  195. render() {
  196. const { current, arr1, arr2, user_txt, signout, assembly, assembly_cw, yc } = this.state;
  197. const { SubMenu } = Menu;
  198. return (
  199. <React.Fragment>
  200. {
  201. yc == true && <div style={{ width: '100%', height: '100%' }}>
  202. <Result
  203. status="error"
  204. title="您的账户存在异常情况,请联系管理员!"
  205. subTitle="There are exceptions in your account, please contact the administrator."
  206. // extra={}
  207. />
  208. </div>
  209. }
  210. {
  211. signout == true && <div style={{ width: '100%', height: '100%' }}>
  212. <Result
  213. status="success"
  214. title="您已退出登录!"
  215. subTitle="You have logged out."
  216. // extra={}
  217. />
  218. </div>
  219. }
  220. {
  221. signout == false && yc == '' && <div style={{ width: '100%', height: '100%' }}>
  222. <div className='wrap'>
  223. <div ></div>
  224. <div className='header_nav'>
  225. <div className='header_title'>商户入网信息管理平台</div>
  226. <div className='header_menu'>
  227. <div className='head-sj'>
  228. <Button type="primary" onClick={this.toggleCollapsed.bind(this)} style={{ marginBottom: 16 }} style={{ height: '100%' }}>
  229. {React.createElement(this.state.collapsed ? MenuUnfoldOutlined : MenuFoldOutlined)}
  230. </Button>
  231. </div>
  232. <Menu onClick={this.handleClick.bind(this)} selectedKeys={[current]} mode="horizontal" className='header_navs'>
  233. <Menu.Item key={1} icon={<SettingOutlined />}>
  234. 高级设置
  235. </Menu.Item>
  236. <Menu.Item key={2} icon={<DollarCircleOutlined />}>
  237. 财务管理
  238. </Menu.Item>
  239. </Menu>
  240. </div>
  241. <div className='header_user' style={{ lineHeight: '60px' }}>
  242. <div style={{ width: '50%', lineHeight: '60px', display: 'inline-block' }}>用户名 : {user_txt.userName}</div>
  243. <div style={{ width: '50%', lineHeight: '60px', display: 'inline-block' }}>
  244. {/* <a>修改密码</a> */}
  245. <a style={{ marginLeft: '10px' }} onClick={this.signout.bind(this)}>退出</a>
  246. </div>
  247. </div>
  248. </div>
  249. <div className='main_centers'>
  250. {current == 1 && <Menu
  251. className='main_left_nav'
  252. defaultSelectedKeys={[this.state.assembly]}
  253. mode="inline"
  254. theme="dark"
  255. key={assembly}
  256. inlineCollapsed={this.state.collapsed}
  257. onClick={this.toggleNavs.bind(this)}
  258. >
  259. {current == 1 && (arr1.map((item, index) => (
  260. <Menu.Item key={item.assembly} data={item.txt} icon={this.initIcon(item)}>
  261. {item.txt}
  262. </Menu.Item>
  263. )))}
  264. </Menu>}
  265. {current == 2 && <Menu
  266. className='main_left_nav'
  267. defaultSelectedKeys={[this.state.assembly_cw]}
  268. mode="inline"
  269. theme="dark"
  270. key={assembly_cw}
  271. inlineCollapsed={this.state.collapsed}
  272. onClick={this.toggleNavs.bind(this)}
  273. >
  274. {current == 2 && (arr2.map((item, index) => (
  275. <Menu.Item key={item.assembly} data={item.txt} icon={<DollarCircleOutlined />}>
  276. {item.txt}
  277. </Menu.Item>
  278. )))}
  279. </Menu>}
  280. <div className='main_right_center'>
  281. {
  282. this.initassembly()
  283. }
  284. </div>
  285. </div>
  286. </div>
  287. </div>
  288. }
  289. </React.Fragment>
  290. )
  291. }
  292. }
  293. ReactDOM.render(
  294. <App></App>,
  295. document.getElementById('root')
  296. );