Index.jsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. import React from 'react';
  2. import Login from '@components/login/Index.jsx';
  3. import DoctorScreen from '@pages/doctorScreen/Index.jsx';
  4. import BigScreen from '@pages/bigScreen/Index.jsx';
  5. import OperateScreen from '@pages/operateScreen/Index.jsx';
  6. // import FingerprintJS from '@fingerprintjs/fingerprintjs';
  7. import { initSocket } from '@api/index.js';
  8. import { AntOutline, SetOutline } from 'antd-mobile-icons';
  9. import { Toast } from 'antd-mobile';
  10. // // 安卓相关处理
  11. window.webGetDeviceId = function (callback) {
  12. window.callback = callback;
  13. };
  14. class Home extends React.Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. visibleLogin: false,
  19. userData: {}, // 用户及房间数据
  20. patList: [], // 就诊等待数据
  21. waitPat: [],
  22. patListArea: [], //区域等待就诊患者数据
  23. roomObj: {},
  24. delayPat: [], //候诊数据
  25. showType: 'doctor', // doctor医生诊室 area诊区叫号 operate手术室
  26. cache: {},
  27. colorName: localStorage.getItem('ZZJ-color'), // white-bg白色 dark-bg深色
  28. audioSrc: '', // 音频路径
  29. deviceID: '',
  30. hosLogo: '',
  31. };
  32. }
  33. componentDidMount() {
  34. this.initDevice();
  35. }
  36. initDevice = async () => {
  37. //接收Android端身份证信息函数
  38. window.webGetDeviceId = (deviceId) => {
  39. Toast.show({
  40. duration: 10000,
  41. content: deviceId + '安卓',
  42. });
  43. this.setState({
  44. deviceID: deviceId,
  45. }, () => {
  46. this.loginInit();
  47. });
  48. };
  49. const ua = navigator.userAgent.toLowerCase();
  50. if (/android/.test(ua)) {
  51. window.JavaClientCall && window.JavaClientCall.getDeviceID();
  52. }
  53. // const fp = await FingerprintJS.load();
  54. // const AndroidInfo = await fp.get();
  55. };
  56. // 改变颜色
  57. changeSwitch = () => {
  58. let { colorName } = this.state;
  59. if (!colorName) {
  60. colorName = 'white-bg';
  61. } else if (colorName == 'white-bg') {
  62. colorName = 'dark-bg';
  63. } else {
  64. colorName = '';
  65. }
  66. this.setState({
  67. colorName,
  68. });
  69. localStorage.setItem('ZZJ-color', colorName);
  70. };
  71. openLogin = (cache) => {
  72. if (!cache) {
  73. cache = {
  74. BASE_URL: 'http://10.1.42.29:8090',
  75. Address: '/bdhealth/',
  76. room: '',
  77. use: '',
  78. hospital: '',
  79. };
  80. }
  81. this.setState({
  82. cache,
  83. visibleLogin: true,
  84. });
  85. };
  86. hideLogin = () => {
  87. this.setState({
  88. visibleLogin: false,
  89. });
  90. };
  91. loginInit = async() => {
  92. let cache = localStorage.getItem('ZZJ-base');
  93. if (cache) {
  94. cache = JSON.parse(cache);
  95. }
  96. if (!cache || (cache && !cache.room)) {
  97. this.openLogin(cache);
  98. return;
  99. }
  100. const obj = await this.login(cache);
  101. if (!obj) {
  102. return;
  103. }
  104. obj.deviceID = this.state.deviceID;
  105. initSocket(obj, (data) => {
  106. console.log('Room接收消息:',data );
  107. data = JSON.parse(data);
  108. if (data.callMsg) {
  109. const patList = [...data.callMsg.callPat, ...data.callMsg.waitPat.map(v => {
  110. return { ...v, status: 'waiting' };
  111. })];
  112. const { roomObj } = this.state;
  113. roomObj[data.roomDesc] = data;
  114. const newArray = Object.keys(roomObj).map(key => {
  115. return roomObj[key];
  116. });
  117. this.setState({
  118. userData: {
  119. ...data?.userData,
  120. areaDesc: data.locDesc, // 大屏诊区
  121. roomDesc: data.roomDesc, // 诊室
  122. },
  123. patList,
  124. waitPat: data.callMsg.waitPat,
  125. patListArea: newArray,
  126. roomObj,
  127. delayPat: data.delayPat,
  128. });
  129. if (!data.path || !data.voiceFileName) {
  130. return;
  131. }
  132. this.setState({
  133. audioSrc: data.path + data.voiceFileName,
  134. }, () => {
  135. const domAudio = document.querySelector('#audio');
  136. domAudio.currentTime = 0;
  137. domAudio.play();
  138. });
  139. }
  140. });
  141. };
  142. //登录事件
  143. login = async () => {
  144. let cache = localStorage.getItem('ZZJ-base');
  145. if (!cache) {
  146. return;
  147. }
  148. cache = JSON.parse(cache);
  149. return React.$fetchPost('04150020', {
  150. params: [{
  151. ip: cache.BASE_URL,
  152. identifyCode: this.state.deviceID,
  153. }],
  154. }, true).then((data) => {
  155. if (data) {
  156. const obj = {
  157. Loc: 'area',
  158. Room: 'doctor',
  159. OptomeRoom: 'doctor',
  160. OperLoc: 'operate',
  161. };
  162. this.setState({
  163. userData: data?.result[0] || {},
  164. // https://172.16.1.6/images/hoslogo/H02.png 医院logo
  165. hosLogo: `/images/hoslogo/${data?.result[0]?.hospCode}.png`
  166. });
  167. if (obj[data.code]) {
  168. this.setState({
  169. showType: obj[data.code], // Loc医生诊室 Room,OptomeRoom大屏 OperLoc 手术室
  170. });
  171. return data?.result[0] || null;
  172. } else {
  173. this.openLogin();
  174. return null;
  175. }
  176. }
  177. });
  178. };
  179. render () {
  180. return (
  181. <>
  182. <div className={ this.state.colorName}>
  183. {/* 设备信息配置,选择医院 */}
  184. <Login
  185. visibleLogin={this.state.visibleLogin}
  186. formData={this.state.cache}
  187. hideLogin={this.hideLogin}
  188. loginInit={this.loginInit}
  189. deviceID={this.state.deviceID}
  190. />
  191. {/* 医生诊室呼叫 */}
  192. {this.state.showType == 'doctor'
  193. ? <DoctorScreen
  194. userData={this.state.userData}
  195. patList={this.state.patList}
  196. hosLogo={this.state.hosLogo}
  197. />
  198. : this.state.showType == 'operate'
  199. ? < OperateScreen
  200. patList={this.state.waitPat}
  201. userData={this.state.userData}
  202. hosLogo={this.state.hosLogo}
  203. />
  204. : < BigScreen
  205. userData={this.state.userData}
  206. patListArea={this.state.patListArea}
  207. delayPat={this.state.delayPat}
  208. hosLogo={this.state.hosLogo}
  209. />
  210. }
  211. </div>
  212. <span
  213. style={{ position: 'fixed', right: 0, bottom: 0, padding: '1rem' }}
  214. >
  215. <AntOutline
  216. style={{color: this.state.colorName == 'dark-bg' ? '#fff' : '#0D2764', marginLeft: '10px'}}
  217. onClick={this.changeSwitch}
  218. />
  219. <SetOutline
  220. onClick={this.openLogin}
  221. style={{color: this.state.colorName == 'dark-bg' ? '#fff' : '#0D2764', marginLeft: '10px'}}
  222. />
  223. </span>
  224. <audio src={this.state.audioSrc} controls id="audio" style={{display: 'none'}}></audio>
  225. </>
  226. );
  227. }
  228. }
  229. export default Home;