Index.jsx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 BigScreenOld from '@pages/bigScreen/IndexOld.jsx';
  6. import OperateScreen from '@pages/operateScreen/Index.jsx';
  7. import FingerprintJS from '@fingerprintjs/fingerprintjs';
  8. import { initSocket } from '@api/index.js';
  9. import { AntOutline, SetOutline } from 'antd-mobile-icons';
  10. import { Toast } from 'antd-mobile';
  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. isGm: false,
  19. visibleLogin: false,
  20. userData: {}, // 用户及房间数据
  21. patList: [], // 就诊等待数据
  22. waitPat: [],
  23. reWaitPat: [], // 复诊的患者
  24. roomObj: {},
  25. delayPat: [], //候诊数据
  26. showType: 'doctor', // doctor医生诊室 area诊区叫号 operate手术室
  27. cache: {},
  28. colorName: localStorage.getItem('ZZJ-color'), // white-bg白色 dark-bg深色
  29. deviceID: '',
  30. hosLogo: '',
  31. voiceSrc: [],
  32. isPlay: false,
  33. voiceList: [],
  34. myStatus: false,
  35. roomObjtmp: {},
  36. patListArea: [],
  37. updateTime: '',
  38. };
  39. }
  40. componentDidMount() {
  41. this.initDevice();
  42. this.initAndroidVoice();
  43. }
  44. initAndroidVoice() {
  45. window.mediaPlayOver = (flag) => {
  46. if (flag == 'success') {
  47. this.state.voiceList.splice(0, 1);
  48. this.setState(
  49. {
  50. voiceList: this.state.voiceList,
  51. },
  52. () => {
  53. this.soundPaly();
  54. },
  55. );
  56. } else {
  57. Toast.show({
  58. duration: 10000,
  59. content: '播放失败',
  60. });
  61. }
  62. };
  63. }
  64. soundPaly() {
  65. const isDev = import.meta.env.MODE == 'development';
  66. if (isDev || this.state.voiceList.length > 0) {
  67. this.setState(
  68. {
  69. myStatus: true,
  70. },
  71. () => {
  72. const ua = navigator.userAgent.toLowerCase();
  73. if (/android/.test(ua)) {
  74. const src = isDev
  75. ? 'https://np.h03.p0551.com/images/wav/eba7ea72748b33c07d55ca7c443d6146.wav'
  76. : this.state.voiceList[0];
  77. window.JavaClientCall && window.JavaClientCall.mediaFilePlay(src);
  78. }
  79. },
  80. );
  81. } else {
  82. this.setState({
  83. myStatus: false,
  84. });
  85. }
  86. }
  87. initDevice = async () => {
  88. //接收Android端身份证信息函数
  89. window.webGetDeviceId = (deviceId) => {
  90. this.setState(
  91. {
  92. deviceID: deviceId,
  93. },
  94. () => {
  95. this.loginInit();
  96. },
  97. );
  98. };
  99. const ua = navigator.userAgent.toLowerCase();
  100. if (/android/.test(ua)) {
  101. window.JavaClientCall && window.JavaClientCall.getDeviceID();
  102. }
  103. // 测试环境无法从安卓获取数据
  104. const isDev = import.meta.env.MODE == 'development';
  105. if (isDev) {
  106. const fp = await FingerprintJS.load();
  107. const AndroidInfo = await fp.get();
  108. this.setState(
  109. {
  110. deviceID: AndroidInfo.visitorId,
  111. },
  112. () => {
  113. this.loginInit();
  114. },
  115. );
  116. }
  117. };
  118. // 改变颜色
  119. changeSwitch = () => {
  120. let { colorName } = this.state;
  121. // if (!colorName) {
  122. // colorName = 'white-bg';
  123. // } else if (colorName == 'white-bg') {
  124. // colorName = 'dark-bg';
  125. // } else {
  126. // colorName = '';
  127. // }
  128. this.setState({
  129. // colorName,
  130. isGm: !this.state.isGm,
  131. });
  132. // localStorage.setItem('ZZJ-color', colorName);
  133. };
  134. openLogin = (cache) => {
  135. if (!cache) {
  136. cache = {
  137. BASE_URL: 'http://10.1.?.29:8090',
  138. Address: '/bdhealth/',
  139. room: '',
  140. use: '',
  141. hospital: '',
  142. };
  143. }
  144. this.setState({
  145. cache,
  146. visibleLogin: true,
  147. });
  148. };
  149. hideLogin = () => {
  150. this.setState({
  151. visibleLogin: false,
  152. });
  153. };
  154. loginInit = async () => {
  155. let cache = localStorage.getItem('ZZJ-base');
  156. if (cache) {
  157. cache = JSON.parse(cache);
  158. }
  159. if (!cache || (cache && !cache.room)) {
  160. this.openLogin(cache);
  161. return;
  162. }
  163. const obj = await this.login(cache);
  164. if (!obj) {
  165. return;
  166. }
  167. obj.deviceID = this.state.deviceID;
  168. initSocket(obj, (data) => {
  169. // console.log('Room接收消息:', data);
  170. data = JSON.parse(data);
  171. if (data.callMsg) {
  172. const patList = [
  173. ...data.callMsg.callPat,
  174. ...data.callMsg.waitPat.map((v) => {
  175. return { ...v, status: 'waiting' };
  176. }),
  177. ];
  178. const { roomObjtmp } = this.state;
  179. roomObjtmp[data.roomDesc] = data;
  180. const newArray = Object.keys(roomObjtmp).map((key) => {
  181. return roomObjtmp[key];
  182. });
  183. this.setState({
  184. userData: {
  185. ...data?.userData,
  186. areaDesc: data?.locDesc || '', // 大屏诊区
  187. roomDesc: data?.roomDesc || '', // 诊室
  188. },
  189. patList,
  190. callPat: data?.callMsg?.callPat || [],
  191. waitPat: data?.callMsg?.waitPat || [],
  192. reWaitPat: data?.callMsg?.reWaitPat || [],
  193. updateTime: data?.callMsg?.updateTime || '',
  194. roomObj: data,
  195. delayPat: data.delayPat,
  196. roomObjtmp: roomObjtmp,
  197. patListArea: newArray,
  198. });
  199. if (!data.path || !data.voiceFileName) {
  200. return;
  201. }
  202. this.state.voiceList.push(data.path + data.voiceFileName);
  203. this.setState(
  204. {
  205. voiceList: this.state.voiceList,
  206. },
  207. () => {
  208. if (!this.state.myStatus) {
  209. this.soundPaly();
  210. }
  211. },
  212. );
  213. }
  214. });
  215. };
  216. //登录事件
  217. login = async () => {
  218. let cache = localStorage.getItem('ZZJ-base');
  219. if (!cache) {
  220. return;
  221. }
  222. cache = JSON.parse(cache);
  223. return React.$fetchPost(
  224. '04150020',
  225. {
  226. params: [
  227. {
  228. ip: cache.BASE_URL,
  229. identifyCode: this.state.deviceID,
  230. },
  231. ],
  232. },
  233. true,
  234. ).then((data) => {
  235. if (data) {
  236. const obj = {
  237. Loc: 'area',
  238. Room: 'doctor',
  239. OptomeRoom: 'doctor',
  240. OperLoc: 'operate',
  241. };
  242. this.setState({
  243. userData: data?.result[0] || {},
  244. // https://172.16.1.6/images/hoslogo/H02.png 医院logo
  245. hosLogo: `/images/hoslogo/${data?.result[0]?.hospCode}.png`,
  246. });
  247. if (obj[data.code]) {
  248. this.setState({
  249. showType: obj[data.code], // Loc医生诊室 Room,OptomeRoom大屏 OperLoc 手术室
  250. });
  251. if (obj[data.code] == 'doctor') {
  252. document.querySelector('html').className = '';
  253. } else {
  254. document.querySelector('html').className = 'big';
  255. }
  256. return data?.result[0] || null;
  257. } else {
  258. this.openLogin();
  259. return null;
  260. }
  261. }
  262. });
  263. };
  264. render() {
  265. return (
  266. <>
  267. <div className={this.state.colorName}>
  268. {/* 设备信息配置,选择医院 */}
  269. <Login
  270. visibleLogin={this.state.visibleLogin}
  271. formData={this.state.cache}
  272. hideLogin={this.hideLogin}
  273. loginInit={this.loginInit}
  274. deviceID={this.state.deviceID}
  275. />
  276. {this.state.showType == 'doctor' ? (
  277. <DoctorScreen
  278. userData={this.state.userData}
  279. patList={this.state.patList}
  280. callPat={this.state.callPat}
  281. waitPat={this.state.waitPat}
  282. reWaitPat={this.state.reWaitPat}
  283. hosLogo={this.state.hosLogo}
  284. />
  285. ) : this.state.showType == 'operate' ? (
  286. <OperateScreen
  287. patList={this.state.waitPat}
  288. userData={this.state.userData}
  289. hosLogo={this.state.hosLogo}
  290. />
  291. ) : this.state.isGm ? (
  292. <BigScreen
  293. userData={this.state.userData}
  294. roomObj={this.state.roomObj}
  295. delayPat={this.state.delayPat}
  296. hosLogo={this.state.hosLogo}
  297. />
  298. ) : (
  299. <BigScreen
  300. userData={this.state.userData}
  301. roomObj={this.state.roomObj}
  302. patListArea={this.state.patListArea}
  303. delayPat={this.state.delayPat}
  304. hosLogo={this.state.hosLogo}
  305. />
  306. )}
  307. <span className="bottom-set">
  308. {/* 测试用,现在出现的问题就是显示的与实际的数据不符,不知道是没有监听到还是前端拿到了数据没更新 */}
  309. {!!this.state?.updateTime && (
  310. <span
  311. style={{
  312. color: this.state.colorName == 'dark-bg' ? '#fff' : '#0D2764',
  313. marginLeft: '10px',
  314. }}>
  315. {this.state?.updateTime || ''}
  316. </span>
  317. )}
  318. <AntOutline
  319. style={{
  320. color: this.state.colorName == 'dark-bg' ? '#fff' : '#0D2764',
  321. marginLeft: '10px',
  322. }}
  323. onClick={this.changeSwitch}
  324. />
  325. <SetOutline
  326. onClick={this.openLogin}
  327. style={{
  328. color: this.state.colorName == 'dark-bg' ? '#fff' : '#0D2764',
  329. marginLeft: '10px',
  330. }}
  331. />
  332. </span>
  333. <audio
  334. controls
  335. id="audio"
  336. style={{
  337. position: 'fixed',
  338. left: '-1000px',
  339. top: '100px',
  340. }}></audio>
  341. </div>
  342. </>
  343. );
  344. }
  345. }
  346. export default Home;