<template>
  <router-view v-slot="{ Component }">
    <keep-alive>
      <component :is="Component"/>
    </keep-alive>
  </router-view>
</template>

<script>
import {defineComponent} from 'vue'
import locale from 'element-plus/lib/locale/lang/zh-cn'
import {useStore} from 'vuex'
import store from "@/store";
import {setCallback} from "@/utils/websocket";
import {ElMessageBox, ElNotification} from "element-plus";
import sleep from "@/utils/sleep";

export default defineComponent({
  name: 'App',
  setup() {
    const store = useStore()
    let windowSize = getWindowSize()
    store.commit('app/setWindowSize', windowSize)
    store.commit('app/setJdt', {
      title: '数据上传',
      isOpen: false,
      abnormalClosing: false,
    })

    window.onresize = () => {
      store.commit('app/setWindowSize', getWindowSize())
    }

    onMounted(() => {

      setCallback('refreshToken', (data) => {
        store.commit('user/tokenChange', data.token)
      })

      setCallback('sidSingle', async () => {
        await store.dispatch('user/loginOut')
        await ElMessageBox.alert('您的账号已在其他地方登陆，如需修改密码请在个人中心中修改。', '提示', {
          type: 'warning',
        })
      })


      setCallback('criticalValue', (data) => {
        ElMessageBox.alert(data.message, '患者危急值', {
          type: 'error'
        }).then(() => {

        }).catch(() => {

        })
      })

      setCallback('systemNotification', (data) => {
        if (data.count) {
          let newCount = store.state.app.unreadMessageCount + data.count
          store.commit('app/setUnreadMessageCount', newCount)
        }

        if (data.refreshDelay) {
          sleep(data.refreshDelay).then(() => {
            location.reload();
          })
        }

        if (data?.donTDisplay) {
          return
        }

        ElNotification({
          title: typeof data.title === 'undefined' ? '新消息' : data.title,
          message: data.message,
          dangerouslyUseHTMLString: true,
          type: typeof data.type === 'undefined' ? 'warning' : data.type,
          duration: 0,
        })

      })
    })

    return {
      locale,
    }
  },
})

function getWindowSize() {
  const w = window.innerWidth
  const h = window.innerHeight - 96
  return {w, h}
}
</script>

<style lang="scss">

::-webkit-scrollbar {
  width: 6px;

  &:hover {
    cursor: pointer;
  }
}

::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background: rgba(144, 147, 153, .3);

  &:hover {
    cursor: pointer;
  }
}

::-webkit-scrollbar-button {
  width: 0;
  height: 0;
  display: none;
}

html,
body,
#app {
  height: 100%;
  margin: 0;
  padding: 0;
  background-color: #f5f5f5;
}

ul, li {
  list-style: none;
  margin: 0;
  padding: 0;
}


.小手指 {
  cursor: pointer;
}


.xc_box {
  box-shadow: 0 4px 8px rgb(0 0 0 / 20%), 0 6px 20px rgb(0 0 0 / 19%);
}

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  width: 100%;
  height: 100vh;
  font-size: 13px;
}

.ellipsis-text {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.sex-icon {
  width: 15px;
  height: 15px;
}

.el-table .cell {
  padding-left: 4px;
  padding-right: 4px;
}

.el-header {
  padding: 0 14px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.el-header > * {
  flex-wrap: nowrap;
  flex-shrink: 0;
  flex-grow: 0;
}

.el-main {
  padding: 0 14px;
  overflow: hidden;
}

.el-table__body tr.current-row > td,
.el-table--striped .el-table__body tr.el-table__row--striped.current-row td {
  background-color: #a7d3ff !important;
}

.el-input.is-disabled .el-input__inner {
  color: blue;
}

.icon-shangxiatuodong {
  cursor: move;
  font-size: 12px;
}

.shangxiatuodong {
  cursor: move;
}

.el-checkbox__inner {
  width: 16px;
  height: 16px;
  border: 1px solid #000;
  border-radius: 4px;
}

.axios-loading2 {
  animation: axiosloading 1s;
  background-image: url('/src/assets/images/loading.gif');
  -webkit-background-image: url('/src/assets/images/loading.gif');
  background-repeat: no-repeat;
  background-position: center;
}

.el-dialog__header {
  border-bottom: 1px solid #ebeef5;
  background-color: #f8f8f8;
  border-radius: 4px;
}

.el-dialog {
  border-radius: 4px;
}

@keyframes axiosloading {
  0% {
    opacity: 0;
  }
  99% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

.component-box-wrapper__fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: white;
  padding: 20px;
  z-index: 10000;
  height: 100%;
  overflow: auto;
}

.component-box-wrapper__half-transparent {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  padding: 20px;
  z-index: 1000;
  height: 100%;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.finger:hover {
  cursor: pointer;
}

.component-content-box__dialog-like {
  width: 60%;
  padding: 20px;
  background: white;
  margin-top: 15vh;
}

.component-header-box {
  position: relative;
  width: 100%;
  display: flex;
  padding: 0 0 12px 0;
}

.component-header__title {
  width: 70%;
  font-size: 16px;
  display: flex;
  align-items: center;
}

.component-header__close-button {
  width: 30%;
  text-align: right;
}

table th.star div::before {
  content: '*';
  color: #f56c6cff;
  margin-right: 4px;
}

.bi_tian .el-form-item__label::before {
  content: '*';
  color: #f56c6cff;
  margin-right: 4px;
}

.el-select-dropdown__item.selected {
  background-color: #71abed66;
}

.el-select-dropdown__item.hover,
.el-select-dropdown__item:hover {
  background-color: #fac44d;
  color: white;
}

.el-message {
  border: none;
  border-radius: 2px;
  background-color: white;
  padding: 10px 16px;
  box-shadow: 1px 3px 8px 4px rgb(0 0 0 / 10%);

  .el-message__content {
    color: #333333;
  }
}

.el-table .el_table__current {
  background-color: #a7d3ff;
}

.remove_hover tbody tr:hover > td {
  background-color: transparent !important;
}

input[type=number] {
  -moz-appearance: textfield;
}

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
</style>
