index.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-11-09 14:58:08
  4. * @LastEditTime: 2022-02-10 16:52:48
  5. * @LastEditors: Please set LastEditors
  6. * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  7. * @FilePath: /KC-MiddlePlatform/src/pages/login/index.tsx
  8. */
  9. import React, { useRef, useEffect, useState, Children } from 'react';
  10. import { Select, message } from 'antd';
  11. import './style.less';
  12. import { useModel, history, Location } from 'umi';
  13. import { Form, Input, Button, Checkbox, notification } from 'antd';
  14. import logo from '../../../public/images/kc-logo.png';
  15. import KCSelect from '@/components/kc-select';
  16. import { getHospConfigBySign, login } from '@/service/login';
  17. const { Option } = Select;
  18. export interface LoginPageType {
  19. location: Location;
  20. }
  21. const LoginPage: React.FC<LoginPageType> = ({ location, children }) => {
  22. const [transitionObj, setTransitionObj] = useState<string>();
  23. const [transformObj, setTransformObj] = useState<string>();
  24. const loginPageRef = useRef<HTMLDivElement>(null);
  25. const [subHospList, setSubHospList] = useState<
  26. { name: string; value: string | number }[]
  27. >([]); //分院列表
  28. const [ifSelectSystem, setIfSelectSystem] = useState(false); //是否跳转到选择系统界面
  29. const [ifLoading, setIfLoading] = useState(false);
  30. const [systemList, setSystemList] = useState<userRelationInfo.OwnAppsItem[]>(
  31. [],
  32. ); //可选平台列表
  33. const [currentHospName, setCurrentHospName] =
  34. useState('欢迎进入医务管理系统');
  35. const { initialState, setInitialState } = useModel('@@initialState');
  36. const onMouseMoveHandle = (mouseEvent: any) => {
  37. // console.log({mouseEvent});
  38. const loginPage = loginPageRef.current;
  39. if (loginPage) {
  40. let centerX = loginPage.offsetLeft + loginPage.offsetWidth / 2, //div中心点到页面左边距离
  41. centerY = loginPage.offsetTop + loginPage.offsetHeight / 2;
  42. let deltaX = mouseEvent.pageX - centerX,
  43. deltaY = mouseEvent.pageY - centerY;
  44. let percentageX = deltaX / centerX, //向左或向右的 偏差率
  45. percentageY = deltaY / centerY;
  46. let deg = 20; //控制 偏差的 程度
  47. // console.log(percentageX*20,percentageY*20);
  48. setTransformObj(
  49. `translate(${percentageX * deg}px,${percentageY * deg}px)`,
  50. );
  51. // setTransformObj('rotateX(' + percentageY * deg + 'deg)');
  52. }
  53. };
  54. const onMouseLeaveHandle = () => {
  55. setTransformObj(`translate(0px,0px)`);
  56. setTransitionObj('all 0.2s linear');
  57. };
  58. //获取当前账号分院列表
  59. const getSubHospFunc = async () => {
  60. const hospSign = history.location.query?.hospSign as string;
  61. if (hospSign) {
  62. const data = await getHospConfigBySign(hospSign);
  63. if (!data) return;
  64. setSubHospList(
  65. data.map((t) => ({
  66. name: t.name,
  67. value: t.hospSign,
  68. })),
  69. );
  70. setCurrentHospName(data[0].systemName);
  71. }
  72. };
  73. const onFinish = async (values: LoginPageTypes.LoginInfo) => {
  74. setIfLoading(true);
  75. const hospSign = history.location.query?.hospSign as string;
  76. if (!hospSign) {
  77. notification.error({
  78. message: '网址标记缺失,请检查网址!',
  79. });
  80. setIfLoading(false);
  81. return;
  82. }
  83. const resp = await login({
  84. account: values.account,
  85. password: values.password,
  86. hospSign: hospSign,
  87. // remember:false,
  88. });
  89. setIfLoading(false);
  90. if (resp) {
  91. localStorage.setItem('userData', JSON.stringify(resp));
  92. localStorage.setItem('hospSign', hospSign);
  93. if (initialState && initialState.getHospSubSystemListFunc) {
  94. const data = await initialState.getHospSubSystemListFunc();
  95. await setInitialState((s) => ({
  96. ...s,
  97. systemLists: data,
  98. userData: resp,
  99. }));
  100. setSystemList(data);
  101. if (data.length > 1) {
  102. //当前医院拥有多个子平台时,进入选择
  103. setIfSelectSystem(true);
  104. history.replace('/index');
  105. } else {
  106. //否则直接进入首页
  107. const { query } = history.location;
  108. const { redirect } = query as { redirect: string };
  109. history.replace(redirect || '/index');
  110. return;
  111. }
  112. }
  113. setIfLoading(false);
  114. }
  115. };
  116. useEffect(() => {
  117. //根据hospSign获取分院信息
  118. location.pathname == '/login' && getSubHospFunc();
  119. // window.addEventListener('message',(e)=>{
  120. // console.log(e.origin)
  121. // if(e.origin == 'http://192.168.50.76:8902'){
  122. // console.log({e})
  123. // }
  124. // }, false);
  125. }, []);
  126. // return (
  127. // <div>
  128. // <iframe src="http://192.168.50.76:8902/TracerMethodology/?hospSign=IGlcn5nc4xBWc08C"></iframe>
  129. // </div>
  130. // )
  131. return (
  132. <div
  133. className="loginPage"
  134. onMouseMove={onMouseMoveHandle}
  135. onMouseLeave={onMouseLeaveHandle}
  136. ref={loginPageRef}
  137. >
  138. <div
  139. className="circleBigOne"
  140. style={{ transform: transformObj, transition: transitionObj }}
  141. ></div>
  142. <div className="circleBigerOne"></div>
  143. <div
  144. className="circleLittleOne"
  145. style={{ transform: transformObj, transition: transitionObj }}
  146. ></div>
  147. {location.pathname == '/login' ? (
  148. <div className="loginBlock">
  149. <div className="left">
  150. <img
  151. className="bannerImg"
  152. src={require('../../../public/images/loginBannner.png')}
  153. />
  154. </div>
  155. <div className="rightLoginArea">
  156. <div className="subHospSelector">
  157. {subHospList.length > 0 && (
  158. <KCSelect
  159. allowClear={false}
  160. style={{ width: 150 }}
  161. defaultValue={subHospList[0].value}
  162. suffixIcon={
  163. <img
  164. style={{ width: '10px', height: '6px' }}
  165. src={require('../../../public/images/arrow.png')}
  166. />
  167. }
  168. >
  169. {subHospList.map((item) => {
  170. return (
  171. <Option value={item.value} key={item.value}>
  172. {item.name}
  173. </Option>
  174. );
  175. })}
  176. </KCSelect>
  177. )}
  178. </div>
  179. <div className="systemName">{currentHospName}</div>
  180. <Form onFinish={onFinish}>
  181. <Form.Item
  182. name="account"
  183. rules={[
  184. { required: true, message: 'Please input your username!' },
  185. ]}
  186. >
  187. <Input className="input" />
  188. </Form.Item>
  189. <Form.Item
  190. name="password"
  191. rules={[
  192. { required: true, message: 'Please input your password!' },
  193. ]}
  194. >
  195. <Input.Password className="input" />
  196. </Form.Item>
  197. <Form.Item>
  198. <Button
  199. className="loginBtn"
  200. type="primary"
  201. htmlType="submit"
  202. loading={ifLoading}
  203. >
  204. 登录
  205. </Button>
  206. </Form.Item>
  207. {/* <Form.Item name="remember" valuePropName="checked">
  208. <Checkbox className="checkBtn">记住密码</Checkbox>
  209. </Form.Item> */}
  210. </Form>
  211. </div>
  212. </div>
  213. ) : (
  214. children
  215. )}
  216. <div className="bottomLogo">
  217. <img className="logo" src={logo} />
  218. <div className="copyright">© 2021 康程智医(成都)技术部出品</div>
  219. </div>
  220. </div>
  221. );
  222. };
  223. export default LoginPage;