Browse Source

webSocket推送逻辑流程修改

develop
fuguobin 9 months ago
parent
commit
11b9c8ea99
  1. 29
      src/App.vue
  2. 7
      src/api/user/index.ts
  3. 14
      src/permission.ts
  4. 4
      src/store/modules/user.ts
  5. 4
      src/types/auto-imports.d.ts
  6. 63
      src/views/dashboard/index.vue
  7. 2
      src/views/data-visual/components/charts.vue
  8. 2
      src/views/data-visual/components/header.vue
  9. 6
      src/views/data-visual/index.scss
  10. 4
      src/views/data-visual/index.vue
  11. 4
      src/views/login/index.vue
  12. 23
      src/views/monitoring/screen/components/main.vue
  13. 20
      src/views/monitoring/screen/index.vue
  14. 2
      vite.config.ts

29
src/App.vue

@ -7,5 +7,34 @@
<script setup lang="ts"> <script setup lang="ts">
import { ElConfigProvider } from 'element-plus'; import { ElConfigProvider } from 'element-plus';
import { useAppStore } from '@/store/modules/app'; import { useAppStore } from '@/store/modules/app';
import { userVersionRelation } from '@/api/user/index';
const appStore = useAppStore(); const appStore = useAppStore();
//
const notice = ref({});
const webVersion = sessionStorage.getItem('webVersion');
if (webVersion != '' && webVersion != null) {
const version = JSON.parse(webVersion);
notice.value = ElNotification({
title: version.noticeTitle,
dangerouslyUseHTMLString: true,
customClass: 'notice',
duration: 0,
message: version.noticeContent.replace(/\n/g, '<br>'),
onClose: () => {
noticeCloce(version.noticeId);
}
});
}
function noticeCloce(id: any) {
//
const params = {
noticeId: id
};
userVersionRelation(params).then((res: any) => {
if (res.code === 200) {
console.log('更新日志关闭!');
}
});
}
</script> </script>

7
src/api/user/index.ts

@ -27,9 +27,7 @@ export function getWeather(): AxiosPromise<[]> {
* *
* @param queryParams * @param queryParams
*/ */
export function getUserPage( export function getUserPage(queryParams: UserQuery): AxiosPromise<PageResult<UserPageVO[]>> {
queryParams: UserQuery
): AxiosPromise<PageResult<UserPageVO[]>> {
return request({ return request({
url: '/api/v1/users/page', url: '/api/v1/users/page',
method: 'get', method: 'get',
@ -168,7 +166,8 @@ export function importUser(deptId: number, file: File) {
*/ */
export function userVersionRelation(data: any) { export function userVersionRelation(data: any) {
return request({ return request({
url: 'model/userVersionRelation', // url: 'model/userVersionRelation',
url: 'system/userNoticeRelation',
method: 'post', method: 'post',
data: data data: data
}); });

14
src/permission.ts

@ -9,6 +9,7 @@
import router from '@/router'; import router from '@/router';
import { useUserStoreHook } from '@/store/modules/user'; import { useUserStoreHook } from '@/store/modules/user';
import { usePermissionStoreHook } from '@/store/modules/permission'; import { usePermissionStoreHook } from '@/store/modules/permission';
import socket from '@/utils/socket';
import NProgress from 'nprogress'; import NProgress from 'nprogress';
import 'nprogress/nprogress.css'; import 'nprogress/nprogress.css';
NProgress.configure({ showSpinner: false }); // 进度条 NProgress.configure({ showSpinner: false }); // 进度条
@ -34,6 +35,11 @@ router.beforeEach(async (to, from, next) => {
if (to.matched.length === 0) { if (to.matched.length === 0) {
from.name ? next({ name: from.name }) : next('/404'); from.name ? next({ name: from.name }) : next('/404');
} else { } else {
console.log('切换页面发送websocket信息');
const exitStatu = {
code: 'exitDataMonitor'
};
socket.onSend(exitStatu);
next(); next();
} }
} else { } else {
@ -43,6 +49,14 @@ router.beforeEach(async (to, from, next) => {
accessRoutes.forEach(route => { accessRoutes.forEach(route => {
router.addRoute(route); router.addRoute(route);
}); });
console.log('登录后链接websocket');
//登录后连接webSocket
const userStorageInfo = sessionStorage.getItem('userInfo');
const userInfo = JSON.parse(userStorageInfo === null ? '' : userStorageInfo);
// const wsUrl = `ws://${window.location.host}/ws/websocket/${userInfo.userName}`; //websocket地址
const wsUrl = `ws://10.10.10.56:9010/websocket/${userInfo.userName}`; //websocket地址
socket.initialize(wsUrl);
next({ ...to, replace: true }); next({ ...to, replace: true });
} catch (error) { } catch (error) {
// 移除 token 并跳转登录页 // 移除 token 并跳转登录页

4
src/store/modules/user.ts

@ -57,10 +57,10 @@ export const useUserStore = defineStore('user', () => {
roles.value = data.roles; roles.value = data.roles;
perms.value = data.permissions; perms.value = data.permissions;
userInfo.value = user; userInfo.value = user;
if (data.webVersion === null) { if (data.notice === null) {
webVersion.value = ''; webVersion.value = '';
} else { } else {
webVersion.value = JSON.stringify(data.webVersion); webVersion.value = JSON.stringify(data.notice);
} }
// useStorage('userInfo', user); // useStorage('userInfo', user);
resolve(data); resolve(data);

4
src/types/auto-imports.d.ts

@ -2,11 +2,9 @@
export {} export {}
declare global { declare global {
const EffectScope: typeof import('vue')['EffectScope'] const EffectScope: typeof import('vue')['EffectScope']
const ElForm: typeof import('element-plus/es')['ElForm']
const ElMessage: typeof import('element-plus/es')['ElMessage'] const ElMessage: typeof import('element-plus/es')['ElMessage']
const ElMessageBox: typeof import('element-plus/es')['ElMessageBox'] const ElMessageBox: typeof import('element-plus/es')['ElMessageBox']
const ElNotification: typeof import('element-plus/es')['ElNotification'] const ElNotification: typeof import('element-plus/es')['ElNotification']
const NEllipsis: typeof import('naive-ui')['NEllipsis']
const asyncComputed: typeof import('@vueuse/core')['asyncComputed'] const asyncComputed: typeof import('@vueuse/core')['asyncComputed']
const autoResetRef: typeof import('@vueuse/core')['autoResetRef'] const autoResetRef: typeof import('@vueuse/core')['autoResetRef']
const computed: typeof import('vue')['computed'] const computed: typeof import('vue')['computed']
@ -273,11 +271,9 @@ import { UnwrapRef } from 'vue'
declare module 'vue' { declare module 'vue' {
interface ComponentCustomProperties { interface ComponentCustomProperties {
readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']> readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
readonly ElForm: UnwrapRef<typeof import('element-plus/es')['ElForm']>
readonly ElMessage: UnwrapRef<typeof import('element-plus/es')['ElMessage']> readonly ElMessage: UnwrapRef<typeof import('element-plus/es')['ElMessage']>
readonly ElMessageBox: UnwrapRef<typeof import('element-plus/es')['ElMessageBox']> readonly ElMessageBox: UnwrapRef<typeof import('element-plus/es')['ElMessageBox']>
readonly ElNotification: UnwrapRef<typeof import('element-plus/es')['ElNotification']> readonly ElNotification: UnwrapRef<typeof import('element-plus/es')['ElNotification']>
readonly NEllipsis: UnwrapRef<typeof import('naive-ui')['NEllipsis']>
readonly asyncComputed: UnwrapRef<typeof import('@vueuse/core')['asyncComputed']> readonly asyncComputed: UnwrapRef<typeof import('@vueuse/core')['asyncComputed']>
readonly autoResetRef: UnwrapRef<typeof import('@vueuse/core')['autoResetRef']> readonly autoResetRef: UnwrapRef<typeof import('@vueuse/core')['autoResetRef']>
readonly computed: UnwrapRef<typeof import('vue')['computed']> readonly computed: UnwrapRef<typeof import('vue')['computed']>

63
src/views/dashboard/index.vue

@ -86,13 +86,19 @@ import LineChart from './components/LineChart.vue';
import BarChart from './components/BarChart.vue'; import BarChart from './components/BarChart.vue';
import PieChart from './components/PieChart.vue'; import PieChart from './components/PieChart.vue';
import avatar from '@/assets/images/avatar.png'; import avatar from '@/assets/images/avatar.png';
import mitt from '@/plugins/bus';
// import socket from '@/utils/socket';
// const userStorageInfo = sessionStorage.getItem('userInfo');
// const userInfo = JSON.parse(userStorageInfo === null ? '' : userStorageInfo);
// const wsUrl = `ws://10.10.10.56:9010/websocket/${userInfo.userName}`; //websocket
const timer = ref(); const timer = ref();
const isCurrentRoute = ref(true); const isCurrentRoute = ref(true);
const userStore = useUserStore(); const userStore = useUserStore();
const duration = 5000; const duration = 5000;
const userNumber = ref(2800); const userNumber = ref(2800);
const notice = ref({}); // const notice = ref({});
// const vsitsNumber = transitionNum(720, 5000); // const vsitsNumber = transitionNum(720, 5000);
const currentTime = useDateFormat(useNow(), 'YYYY-MM-DD HH:mm:ss'); const currentTime = useDateFormat(useNow(), 'YYYY-MM-DD HH:mm:ss');
const hoursNow = useNow().value.getHours(); const hoursNow = useNow().value.getHours();
@ -170,32 +176,33 @@ const timePeriod = computed(() => {
onMounted(() => { onMounted(() => {
getWeatherData(); getWeatherData();
const webVersion = sessionStorage.getItem('webVersion'); // socket.initialize(wsUrl);
if (webVersion != '' && webVersion != null) { // const webVersion = sessionStorage.getItem('webVersion');
const version = JSON.parse(webVersion); // if (webVersion != '' && webVersion != null) {
notice.value = ElNotification({ // const version = JSON.parse(webVersion);
title: '更新日志', // notice.value = ElNotification({
dangerouslyUseHTMLString: true, // title: version.noticeTitle,
customClass: 'notice', // dangerouslyUseHTMLString: true,
duration: 0, // customClass: 'notice',
message: version.versionDesc.replace(/\n/g, '<br>'), // duration: 0,
onClose: () => { // message: version.noticeContent.replace(/\n/g, '<br>'),
noticeCloce(version.id); // onClose: () => {
} // noticeCloce(version.noticeId);
}); // }
} // });
// }
}); });
function noticeCloce(id: any) { // function noticeCloce(id: any) {
// // //
const params = { // const params = {
versionId: id // versionId: id
}; // };
userVersionRelation(params).then((res: any) => { // userVersionRelation(params).then((res: any) => {
if (res.code === 200) { // if (res.code === 200) {
console.log('更新日志关闭!'); // console.log('');
} // }
}); // });
} // }
function getWeatherData() { function getWeatherData() {
// //
getWeather().then((res: any) => { getWeather().then((res: any) => {
@ -212,6 +219,10 @@ function getWeatherData() {
} }
}); });
} }
// mitt.on('tableMessage', (res: any) => {
// //
// console.log('noticeMessage--', res.data);
// });
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

2
src/views/data-visual/components/charts.vue

@ -73,7 +73,7 @@ import PriPress from './priPress.vue';
.flow { .flow {
height: 421px; height: 421px;
padding: 20px 27px; padding: 20px 27px;
background-color: #1A2537; background-color: #1a2537;
} }
.temp { .temp {
margin-bottom: 28px; margin-bottom: 28px;

2
src/views/data-visual/components/header.vue

@ -14,7 +14,7 @@
<svg-icon class="logoIcon" icon-class="BIlogo" /> <svg-icon class="logoIcon" icon-class="BIlogo" />
</div> </div>
<div class="line"></div> <div class="line"></div>
<div class="text">生产监控大屏 - {{ deviceTitle }}</div> <div class="text">运营管控平台 - {{ deviceTitle }}</div>
</div> </div>
<div class="home"> <div class="home">
<div class="homeBtn" @click="returnBack"> <div class="homeBtn" @click="returnBack">

6
src/views/data-visual/index.scss

@ -1,8 +1,8 @@
@import url('@/assets/fonts/font.css'); @import url('@/assets/fonts/font.css');
.screenContainer { .screenContainer {
position: fixed; // position: fixed;
left: 50%; // left: 50%;
top: 50%; // top: 50%;
transform-origin: 0 0; transform-origin: 0 0;
transition: 0.3s; transition: 0.3s;
color: #fff; color: #fff;

4
src/views/data-visual/index.vue

@ -32,11 +32,11 @@ const baseHeight = 1440;
// * 32:9 // * 32:9
const baseProportion = parseFloat((baseWidth / baseHeight).toFixed(5)); const baseProportion = parseFloat((baseWidth / baseHeight).toFixed(5));
onMounted(() => { onMounted(() => {
calcRate(); // calcRate();
}); });
window.addEventListener('resize', () => { window.addEventListener('resize', () => {
// //
resize(); // resize();
}); });
function calcRate() { function calcRate() {
const appRef = screenRef.value; const appRef = screenRef.value;

4
src/views/login/index.vue

@ -73,7 +73,9 @@
<div class="videoCover" v-if="!videoCanPlay && settingsStore.showVideo"> <div class="videoCover" v-if="!videoCanPlay && settingsStore.showVideo">
<img :style="resizeStyle" src="../../assets/images/login-bg.png" alt="视频封面" /> <img :style="resizeStyle" src="../../assets/images/login-bg.png" alt="视频封面" />
</div> </div>
<div class="copyright">Copyright © {{ $t('copyright.year') }} {{ $t('copyright.company') }} {{ $t('copyright.document') }}</div> <div class="copyright">
Copyright © {{ $t('copyright.year') }} {{ $t('copyright.company') }} {{ $t('copyright.document') }}
</div>
</div> </div>
</template> </template>

23
src/views/monitoring/screen/components/main.vue

@ -135,7 +135,7 @@ import mitt from '@/plugins/bus';
import socket from '@/utils/socket'; import socket from '@/utils/socket';
import useStorage from '@/utils/useStorage'; import useStorage from '@/utils/useStorage';
import { useUserStoreHook } from '@/store/modules/user'; import { useUserStoreHook } from '@/store/modules/user';
import { useDateFormat } from '@vueuse/core'; // import { useDateFormat } from '@vueuse/core';
const sessionStorageIns = useStorage('sessionStorage'); const sessionStorageIns = useStorage('sessionStorage');
const { perms } = useUserStoreHook(); const { perms } = useUserStoreHook();
@ -211,8 +211,8 @@ const userInfo = JSON.parse(userStorageInfo === null ? '' : userStorageInfo);
// const baseApi = "http://board.heatiot.cn:8001/prod-api"//websocket // const baseApi = "http://board.heatiot.cn:8001/prod-api"//websocket
//const baseApi = import.meta.env.VITE_APP_BASE_API //const baseApi = import.meta.env.VITE_APP_BASE_API
//const apiUrl = baseApi.replace(/https?:/, ''); //const apiUrl = baseApi.replace(/https?:/, '');
const wsUrl = `ws://${window.location.host}/ws/websocket/${userInfo.userName}`; //websocket // const wsUrl = `ws://${window.location.host}/ws/websocket/${userInfo.userName}`; //websocket
// const wsUrl = `ws://10.10.10.56:9010/websocket/${userInfo.userName}`; //websocket const wsUrl = `ws://10.10.10.56:9010/websocket/${userInfo.userName}`; //websocket
const emit = defineEmits(['tableHeaderData']); const emit = defineEmits(['tableHeaderData']);
// const listData = ref([ // const listData = ref([
@ -258,13 +258,13 @@ const headerData = ref<HeaderVo[]>();
onMounted(() => { onMounted(() => {
// stationInfo(); // stationInfo();
// tableHeader(); // tableHeader();
console.log('起始时间:', useDateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss').value); // console.log(':', useDateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss').value);
console.log('aaaa', sessionStorage.getItem('currentPage')); console.log('aaaa', sessionStorage.getItem('currentPage'));
tablePage.currentPage = tablePage.currentPage =
sessionStorage.getItem('currentPage') === null ? 1 : Number(sessionStorage.getItem('currentPage')); sessionStorage.getItem('currentPage') === null ? 1 : Number(sessionStorage.getItem('currentPage'));
console.log(Number(sessionStorage.getItem('currentPage'))); console.log(Number(sessionStorage.getItem('currentPage')));
tablePage.pageSize = sessionStorage.getItem('pageSize') === null ? 10 : Number(sessionStorage.getItem('pageSize')); tablePage.pageSize = sessionStorage.getItem('pageSize') === null ? 10 : Number(sessionStorage.getItem('pageSize'));
socket.initialize(wsUrl); //websocket http:// // socket.initialize(wsUrl); //websocket http://
}); });
mitt.on('currentPageEmit', (res: any) => { mitt.on('currentPageEmit', (res: any) => {
@ -409,7 +409,7 @@ function tableHeader() {
function tableDatas() { function tableDatas() {
// //
// const params = menuKey.value; // const params = menuKey.value;
console.log('接口开始:', useDateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss').value); // console.log(':', useDateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss').value);
const params = { const params = {
pageNum: tablePage.currentPage, pageNum: tablePage.currentPage,
pageSize: tablePage.pageSize, pageSize: tablePage.pageSize,
@ -424,10 +424,9 @@ function tableDatas() {
tablePage.total = res.total; tablePage.total = res.total;
// gridOptions.data = res.data; // gridOptions.data = res.data;
loadingShow.value = false; loadingShow.value = false;
console.log('接口结束:', useDateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss').value); // console.log(':', useDateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss').value);
} }
}); });
} }
const cellDBLClickEvent: VxeTableEvents.CellDblclick<TableVo> = ({ row, column }) => { const cellDBLClickEvent: VxeTableEvents.CellDblclick<TableVo> = ({ row, column }) => {
@ -454,7 +453,7 @@ const cellDBLClickEvent: VxeTableEvents.CellDblclick<TableVo> = ({ row, column }
}; };
const formatRole: VxeColumnPropTypes.Formatter<HeaderVo> = ({ cellValue }) => { const formatRole: VxeColumnPropTypes.Formatter<HeaderVo> = ({ cellValue }) => {
console.log('渲染开始:', useDateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss').value); // console.log(':', useDateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss').value);
//object //object
// console.log(cellValue); // console.log(cellValue);
// const iconFont=cellValue.changeProp===-1?'<i class="iconfont icon-decline" />':(cellValue.changeProp===1?'<i class="iconfont icon-rise" />':'<i/>') // const iconFont=cellValue.changeProp===-1?'<i class="iconfont icon-decline" />':(cellValue.changeProp===1?'<i class="iconfont icon-rise" />':'<i/>')
@ -473,13 +472,13 @@ const formatRole: VxeColumnPropTypes.Formatter<HeaderVo> = ({ cellValue }) => {
${cellValue.ctrlPro.valueType != 'bool' ? cellValue.val : cellValue.val === 'true' ? '启' : '停'} ${cellValue.ctrlPro.valueType != 'bool' ? cellValue.val : cellValue.val === 'true' ? '启' : '停'}
</span> </span>
${cellValue.canBeControl === '1' && controlPerm ? '<i class="iconfont icon-edit-icon"></i>' : ''}`; ${cellValue.canBeControl === '1' && controlPerm ? '<i class="iconfont icon-edit-icon"></i>' : ''}`;
console.log('渲染完成:', useDateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss').value); // console.log(':', useDateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss').value);
return cellData; return cellData;
}; };
// //
const mergeRowMethod: VxeTablePropTypes.SpanMethod<TableVo> = ({ row, _rowIndex, column, visibleData }) => { const mergeRowMethod: VxeTablePropTypes.SpanMethod<TableVo> = ({ row, _rowIndex, column, visibleData }) => {
console.log('通用行合并渲染开始:', useDateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss').value); // console.log(':', useDateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss').value);
const fields = ['gTitle']; const fields = ['gTitle'];
const cellValue = row[column.field]; const cellValue = row[column.field];
if (cellValue && fields.includes(column.field)) { if (cellValue && fields.includes(column.field)) {
@ -497,7 +496,7 @@ const mergeRowMethod: VxeTablePropTypes.SpanMethod<TableVo> = ({ row, _rowIndex,
} }
} }
} }
console.log('通用行合并渲染完成:', useDateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss').value); // console.log(':', useDateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss').value);
}; };
const submitEvent: VxeFormEvents.Submit = () => { const submitEvent: VxeFormEvents.Submit = () => {

20
src/views/monitoring/screen/index.vue

@ -79,7 +79,9 @@
</div> </div>
<div class="panelBtn" :class="menuShow ? 'left' : 'right'" @click="panelClick"> <div class="panelBtn" :class="menuShow ? 'left' : 'right'" @click="panelClick">
<i class="iconfont icon-up" :class="!panelShow ? 'up' : 'down'"></i> <i class="iconfont icon-up" :class="!panelShow ? 'up' : 'down'"></i>
<div class="copyright">Copyright © {{ $t('copyright.year') }} {{ $t('copyright.abbr') }} {{ $t('copyright.document') }}</div> <div class="copyright">
Copyright © {{ $t('copyright.year') }} {{ $t('copyright.abbr') }} {{ $t('copyright.document') }}
</div>
<!-- <n-button type="info" size="tiny" ghost @click="panelClick">按钮</n-button> --> <!-- <n-button type="info" size="tiny" ghost @click="panelClick">按钮</n-button> -->
</div> </div>
</div> </div>
@ -135,14 +137,14 @@ window.addEventListener('resize', () => {
console.log('监听sidebar:', sidebar.value?.offsetHeight); console.log('监听sidebar:', sidebar.value?.offsetHeight);
}); });
onBeforeRouteLeave((to, from) => { // onBeforeRouteLeave((to, from) => {
// // //
console.log('onBeforeRouteLeave--', to.path, from.path); // console.log('onBeforeRouteLeave--', to.path, from.path);
if (to.path != from.path) { // if (to.path != from.path) {
console.log('离开页面'); // console.log('');
socket.close(false); // socket.close(false);
} // }
}); // });
function tableMenuData(data: any) { function tableMenuData(data: any) {
// //

2
vite.config.ts

@ -45,7 +45,7 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
hmr: true, //配置HMR hmr: true, //配置HMR
proxy: { proxy: {
'/dev-api': { '/dev-api': {
// target: 'http://172.1.2.39:9010/', //本地接口地址 // target: 'http://172.1.2.76:9010/', //本地接口地址
// target: 'http://172.1.2.90:9010/', //本地接口地址 // target: 'http://172.1.2.90:9010/', //本地接口地址
target: 'http://10.10.10.56:9010/', //线上测试接口地址 target: 'http://10.10.10.56:9010/', //线上测试接口地址
changeOrigin: true, changeOrigin: true,

Loading…
Cancel
Save