| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- import React from 'react';
- import Login from '@components/login/Index.jsx';
- import DoctorScreen from '@pages/doctorScreen/Index.jsx';
- import BigScreen from '@pages/bigScreen/Index.jsx';
- import BigScreenOld from '@pages/bigScreen/IndexOld.jsx';
- import OperateScreen from '@pages/operateScreen/Index.jsx';
- import FingerprintJS from '@fingerprintjs/fingerprintjs';
- import { initSocket } from '@api/index.js';
- import { AntOutline, SetOutline } from 'antd-mobile-icons';
- import { Toast } from 'antd-mobile';
- window.webGetDeviceId = function (callback) {
- window.callback = callback;
- };
- class Home extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- isGm: false,
- visibleLogin: false,
- userData: {}, // 用户及房间数据
- patList: [], // 就诊等待数据
- waitPat: [],
- reWaitPat: [], // 复诊的患者
- roomObj: {},
- delayPat: [], //候诊数据
- showType: 'doctor', // doctor医生诊室 area诊区叫号 operate手术室
- cache: {},
- colorName: localStorage.getItem('ZZJ-color'), // white-bg白色 dark-bg深色
- deviceID: '',
- hosLogo: '',
- voiceSrc: [],
- isPlay: false,
- voiceList: [],
- myStatus: false,
- roomObjtmp: {},
- patListArea: [],
- updateTime: '',
- };
- }
- componentDidMount() {
- this.initDevice();
- this.initAndroidVoice();
- }
- initAndroidVoice() {
- window.mediaPlayOver = (flag) => {
- if (flag == 'success') {
- this.state.voiceList.splice(0, 1);
- this.setState(
- {
- voiceList: this.state.voiceList,
- },
- () => {
- this.soundPaly();
- },
- );
- } else {
- Toast.show({
- duration: 10000,
- content: '播放失败',
- });
- }
- };
- }
- soundPaly() {
- const isDev = import.meta.env.MODE == 'development';
- if (isDev || this.state.voiceList.length > 0) {
- this.setState(
- {
- myStatus: true,
- },
- () => {
- const ua = navigator.userAgent.toLowerCase();
- if (/android/.test(ua)) {
- const src = isDev
- ? 'https://np.h03.p0551.com/images/wav/eba7ea72748b33c07d55ca7c443d6146.wav'
- : this.state.voiceList[0];
- window.JavaClientCall && window.JavaClientCall.mediaFilePlay(src);
- }
- },
- );
- } else {
- this.setState({
- myStatus: false,
- });
- }
- }
- initDevice = async () => {
- //接收Android端身份证信息函数
- window.webGetDeviceId = (deviceId) => {
- this.setState(
- {
- deviceID: deviceId,
- },
- () => {
- this.loginInit();
- },
- );
- };
- const ua = navigator.userAgent.toLowerCase();
- if (/android/.test(ua)) {
- window.JavaClientCall && window.JavaClientCall.getDeviceID();
- }
- // 测试环境无法从安卓获取数据
- const isDev = import.meta.env.MODE == 'development';
- if (isDev) {
- const fp = await FingerprintJS.load();
- const AndroidInfo = await fp.get();
- this.setState(
- {
- deviceID: AndroidInfo.visitorId,
- },
- () => {
- this.loginInit();
- },
- );
- }
- };
- // 改变颜色
- changeSwitch = () => {
- let { colorName } = this.state;
- // if (!colorName) {
- // colorName = 'white-bg';
- // } else if (colorName == 'white-bg') {
- // colorName = 'dark-bg';
- // } else {
- // colorName = '';
- // }
- this.setState({
- // colorName,
- isGm: !this.state.isGm,
- });
- // localStorage.setItem('ZZJ-color', colorName);
- };
- openLogin = (cache) => {
- if (!cache) {
- cache = {
- BASE_URL: 'http://10.1.?.29:8090',
- Address: '/bdhealth/',
- room: '',
- use: '',
- hospital: '',
- };
- }
- this.setState({
- cache,
- visibleLogin: true,
- });
- };
- hideLogin = () => {
- this.setState({
- visibleLogin: false,
- });
- };
- loginInit = async () => {
- let cache = localStorage.getItem('ZZJ-base');
- if (cache) {
- cache = JSON.parse(cache);
- }
- if (!cache || (cache && !cache.room)) {
- this.openLogin(cache);
- return;
- }
- const obj = await this.login(cache);
- if (!obj) {
- return;
- }
- obj.deviceID = this.state.deviceID;
- initSocket(obj, (data) => {
- // console.log('Room接收消息:', data);
- data = JSON.parse(data);
- if (data.callMsg) {
- const patList = [
- ...data.callMsg.callPat,
- ...data.callMsg.waitPat.map((v) => {
- return { ...v, status: 'waiting' };
- }),
- ];
- const { roomObjtmp } = this.state;
- roomObjtmp[data.roomDesc] = data;
- const newArray = Object.keys(roomObjtmp).map((key) => {
- return roomObjtmp[key];
- });
- this.setState({
- userData: {
- ...data?.userData,
- areaDesc: data?.locDesc || '', // 大屏诊区
- roomDesc: data?.roomDesc || '', // 诊室
- },
- patList,
- callPat: data?.callMsg?.callPat || [],
- waitPat: data?.callMsg?.waitPat || [],
- reWaitPat: data?.callMsg?.reWaitPat || [],
- updateTime: data?.callMsg?.updateTime || '',
- roomObj: data,
- delayPat: data.delayPat,
- roomObjtmp: roomObjtmp,
- patListArea: newArray,
- });
- if (!data.path || !data.voiceFileName) {
- return;
- }
- this.state.voiceList.push(data.path + data.voiceFileName);
- this.setState(
- {
- voiceList: this.state.voiceList,
- },
- () => {
- if (!this.state.myStatus) {
- this.soundPaly();
- }
- },
- );
- }
- });
- };
- //登录事件
- login = async () => {
- let cache = localStorage.getItem('ZZJ-base');
- if (!cache) {
- return;
- }
- cache = JSON.parse(cache);
- return React.$fetchPost(
- '04150020',
- {
- params: [
- {
- ip: cache.BASE_URL,
- identifyCode: this.state.deviceID,
- },
- ],
- },
- true,
- ).then((data) => {
- if (data) {
- const obj = {
- Loc: 'area',
- Room: 'doctor',
- OptomeRoom: 'doctor',
- OperLoc: 'operate',
- };
- this.setState({
- userData: data?.result[0] || {},
- // https://172.16.1.6/images/hoslogo/H02.png 医院logo
- hosLogo: `/images/hoslogo/${data?.result[0]?.hospCode}.png`,
- });
- if (obj[data.code]) {
- this.setState({
- showType: obj[data.code], // Loc医生诊室 Room,OptomeRoom大屏 OperLoc 手术室
- });
- if (obj[data.code] == 'doctor') {
- document.querySelector('html').className = '';
- } else {
- document.querySelector('html').className = 'big';
- }
- return data?.result[0] || null;
- } else {
- this.openLogin();
- return null;
- }
- }
- });
- };
- render() {
- return (
- <>
- <div className={this.state.colorName}>
- {/* 设备信息配置,选择医院 */}
- <Login
- visibleLogin={this.state.visibleLogin}
- formData={this.state.cache}
- hideLogin={this.hideLogin}
- loginInit={this.loginInit}
- deviceID={this.state.deviceID}
- />
- {this.state.showType == 'doctor' ? (
- <DoctorScreen
- userData={this.state.userData}
- patList={this.state.patList}
- callPat={this.state.callPat}
- waitPat={this.state.waitPat}
- reWaitPat={this.state.reWaitPat}
- hosLogo={this.state.hosLogo}
- />
- ) : this.state.showType == 'operate' ? (
- <OperateScreen
- patList={this.state.waitPat}
- userData={this.state.userData}
- hosLogo={this.state.hosLogo}
- />
- ) : this.state.isGm ? (
- <BigScreen
- userData={this.state.userData}
- roomObj={this.state.roomObj}
- delayPat={this.state.delayPat}
- hosLogo={this.state.hosLogo}
- />
- ) : (
- <BigScreen
- userData={this.state.userData}
- roomObj={this.state.roomObj}
- patListArea={this.state.patListArea}
- delayPat={this.state.delayPat}
- hosLogo={this.state.hosLogo}
- />
- )}
- <span className="bottom-set">
- {/* 测试用,现在出现的问题就是显示的与实际的数据不符,不知道是没有监听到还是前端拿到了数据没更新 */}
- {!!this.state?.updateTime && (
- <span
- style={{
- color: this.state.colorName == 'dark-bg' ? '#fff' : '#0D2764',
- marginLeft: '10px',
- }}>
- {this.state?.updateTime || ''}
- </span>
- )}
- <AntOutline
- style={{
- color: this.state.colorName == 'dark-bg' ? '#fff' : '#0D2764',
- marginLeft: '10px',
- }}
- onClick={this.changeSwitch}
- />
- <SetOutline
- onClick={this.openLogin}
- style={{
- color: this.state.colorName == 'dark-bg' ? '#fff' : '#0D2764',
- marginLeft: '10px',
- }}
- />
- </span>
- <audio
- controls
- id="audio"
- style={{
- position: 'fixed',
- left: '-1000px',
- top: '100px',
- }}></audio>
- </div>
- </>
- );
- }
- }
- export default Home;
|