diff --git a/src/App.vue b/src/App.vue index 8f8ff313b2dcafce585979af853171f39f19bea7..0370c1b67c7114e5b0657dac54aba7da597d3912 100644 --- a/src/App.vue +++ b/src/App.vue @@ -6,7 +6,6 @@ + diff --git a/src/store/index.js b/src/store/index.js index 8840ba62b455849d71459c483a71271ba4286157..3be0e95049255f110c44898ce9a5996901e95a85 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -2,7 +2,6 @@ import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) - export default new Vuex.Store({ state: { dataPageData: { lowerLeftVO: {}, rightTop: {}}, diff --git a/src/utils/config.js b/src/utils/config.js index 4f4058809ce3f488c7e6711e8154fe2375afc3d4..6a81261fab1559149fa99de710cff8c4d477832d 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -1,7 +1,8 @@ module.exports = { // baseUrl: 'localhost:2011' // baseUrl: '49.234.81.196:2011' - baseUrl: '192.168.0.107:2011' + // baseUrl: '120.25.106.20:2011' // baseUrl: '120.25.106.20:2011' // baseUrl: 'localhost:40000' + baseUrl: '192.168.0.100:2011' } diff --git a/src/utils/notify.js b/src/utils/notify.js new file mode 100644 index 0000000000000000000000000000000000000000..74b5789614940436addfd582bff7c6ae2b6a12bc --- /dev/null +++ b/src/utils/notify.js @@ -0,0 +1,119 @@ +import Vue from 'vue' +import Notification from './Notification.vue' + +const NotificationConstructor = Vue.extend(Notification) + +const instances = [] +let seed = 1 +// 消除Vue实例 +const removeInstance = (instance) => { + if (!instance) return + const len = instances.length + const index = instances.findIndex((ins) => instance.id === ins.id) + + instances.splice(index, 1) + + if (len <= 1) return + const removeHeight = instance.height + for (let i = index; i < len - 1; i++) { + instances[i].verticalOffset = + parseInt(instances[i].verticalOffset) - removeHeight - 16 + } +} + +const notify = (options = {}) => { + if (Vue.prototype.$isServer) return + // 获取vue实例 + let instance = new NotificationConstructor({ + propsData: options, // 这里是传进来一组props + data() { + return { + verticalOffset: 0, + timer: null, + visible: false, + height: 0 + } + }, + computed: { + // 配置消息组件的位置 + style() { + return { + position: 'fixed', + right: '20px', + bottom: `${this.verticalOffset}px` + } + } + }, + mounted() { + this.createTimer() + this.$el.addEventListener('mouseenter', () => { + if (this.timer) { + this.clearTimer(this.timer) + } + }) + this.$el.addEventListener('mouseleave', () => { + if (this.timer) { + this.clearTimer(this.timer) + } + this.createTimer() + }) + }, + updated() { + this.height = this.$el.offsetHeight + }, + beforeDestroy() { + this.clearTimer() + }, + methods: { + // 创建计时器 + createTimer() { + this.timer = setTimeout(() => { + this.visible = false + document.body.removeChild(this.$el) + removeInstance(this) + this.$destroy() + }, options.timeout || 5000) + }, + // 清除计时器 + clearTimer() { + if (this.timer) { + clearTimeout(this.timer) + } + }, + // 关闭消息弹窗 + handleClose() { + this.visible = false + document.body.removeChild(this.$el) + removeInstance(this) + this.$destroy(true) + }, + // 过渡js钩子 + handleAfterEnter() { + this.height = this.$el.offsetHeight + } + } + }) + + const id = `notification_${seed++}` // 动态生成唯一Id + instance.id = id + // 生成vue中的$el + instance = instance.$mount() + // 将$el中的内容插入dom节点中去 + document.body.appendChild(instance.$el) + instance.visible = true + + let verticalOffset = 0 + + instances.forEach((item) => { + verticalOffset += item.$el.offsetHeight + 16 + }) + + verticalOffset += 16 + instance.verticalOffset = verticalOffset + + instances.push(instance) + + return instance +} + +export default notify diff --git a/src/utils/websocket_service.js b/src/utils/websocket_service.js index fde0df814caab58cc1c5a308e46e796cd28fce33..e7a74d36e2b70cd47cdd3b409f0f30b6a8546e7d 100644 --- a/src/utils/websocket_service.js +++ b/src/utils/websocket_service.js @@ -32,7 +32,7 @@ connect() { /* if (!Window.WebSocket) { return console.log('您的浏览器不支持WebSocket') } */ - this.ws = new WebSocket(`ws://${baseUrl}/WebSocket/1`) // Websocket ip+端口 + this.ws = new WebSocket(`ws://${baseUrl}/WebSocket/${window.localStorage.getItem('staffNumber')}`) // Websocket ip+端口 // 连接成功 this.ws.onopen = () => { // Message.success('WebSocket连接成功') diff --git a/src/views/FacilityManagement/OperationLogs.vue b/src/views/FacilityManagement/OperationLogs.vue index dcaaf5225a095061c394bbbca94f0d31967a4181..5c2ac910d7682b24203ccd175b2f2f7b9b36fc48 100644 --- a/src/views/FacilityManagement/OperationLogs.vue +++ b/src/views/FacilityManagement/OperationLogs.vue @@ -1,42 +1,40 @@ - +