123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <template>
- <section class="app-main">
- <transition name="fade-transform" mode="out-in">
- <keep-alive :include="cachedViews">
- <router-view :key="key" />
- </keep-alive>
- </transition>
- <span class="footer">
- Copyright © 2023 厦门市巨龙信息科技有限公司 建议使用1280*768以上分辨率
- </span>
- <section>
- <information ref="Information" />
- </section>
- </section>
- </template>
- <script>
- import { fetchRealCount } from '@/api/message'
- import { isNull } from '@/utils/convert'
- import Information from '@/views/home/Information'
- let sseClient
- export default {
- name: 'AppMain',
- components: {
- Information
- },
- computed: {
- cachedViews() {
- return this.$store.state.tagsView.cachedViews
- },
- key() {
- return this.$route.path
- }
- },
- mounted() {
- this.getMessageCount()
- this.connect()
- },
- beforeDestroy() {
- if (sseClient) {
- sseClient.disconnect()
- }
- },
- methods: {
- getMessageCount() {
- fetchRealCount().then(res => {
- if (!isNull(res.data)) {
- this.$store.dispatch('message/setMessgeCount', res.data)
- }
- }).catch(error => {
- console.log(error)
- this.$message({
- type: 'error',
- duration: 0,
- showClose: true,
- message: '获取消息数量出错: ' + error.message
- })
- })
- },
- connect() {
- sseClient = this.$sse.create({
- url: process.env.VUE_APP_BASE_API + '/subscribe/' + this.$store.getters.idCard,
- format: 'json',
- withCredentials: false
-
-
-
-
-
-
- })
- sseClient.on('error', (e) => {
- console.error('lost connection or failed to parse!', e)
-
-
-
- })
- sseClient.on('message', this.handleMessage)
- sseClient.connect()
- .then(sse => {
- console.log('We\'re connected!')
- })
- .catch((err) => {
-
-
- console.error('Failed to connect to server', err)
- })
- },
- handleMessage(message) {
- console.log(message)
- if (message && message.recordType) {
- this.$store.dispatch('message/addNewMessage', message)
- if (message.recordType === 1) {
- this.$refs['Information'].open(message)
- }
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import "~@/styles/variables.scss";
- .app-main {
- min-height: calc(100vh - #{$headerHeight});
- width: 100%;
- position: relative;
- // overflow: auto;
- padding-bottom: $footerHeight;
- &>div:not(.home-container) {
- height: calc(100vh - #{$layoutHeight});
- padding: 10px 0 0 10px;
- }
- }
- .hasTagsView {
- .app-main {
- min-height: calc(100vh - #{$headerHeight} - #{$tagHeight});
- }
- .fixed-header+.app-main {
- min-height: calc(100vh - #{$headerHeight});
- padding-top: $tagHeight;
- }
- }
- .footer {
- display: block;
- width: 100%;
- height: $footerHeight;
- line-height: $footerHeight;
- font-size: 12px;
- color: rgba(0,0,0,0.45);
- text-align: center;
- position: absolute;
- left: 0;
- bottom: 0;
- }
- </style>
- <style lang="scss">
- // fix css style bug in open el-dialog
- .el-popup-parent--hidden {
- .fixed-header {
- padding-right: 15px;
- }
- }
- </style>
|