فهرست منبع

添加单点登录

wkw 6 ماه پیش
والد
کامیت
c53ba06e73
2فایلهای تغییر یافته به همراه61 افزوده شده و 8 حذف شده
  1. 54 3
      src/views/home.vue
  2. 7 5
      src/views/resume/addResume.vue

+ 54 - 3
src/views/home.vue

@@ -17,6 +17,8 @@
 </template>
 
 <script>
+	import {ElMessage} from 'element-plus'
+	import {ROOTPATH2} from '../../comment/httpUrl.js'
 	import headers from '../components/header/header.vue'
 	import sidebars from '../components/sidebar/sidebar.vue'
 	import copyright from '../components/copyright/copyright.vue'
@@ -33,17 +35,66 @@
 		},
 		data() {
 			return {
-
+				ws: null,
 			}
 		},
 		mounted() {
 			if (localStorage.getItem('token')) {
 				this.getUserInfo();
 			}
-
+			const userId = localStorage.getItem('userId');
+			// 连接websocket
+			this.connectSocket(userId);
+			
+		},
+		beforeDestroy() {
+			if (this.ws && this.ws.readyState === WebSocket.OPEN) {
+				console.log('♻️ 组件销毁前关闭 WebSocket');
+				this.ws.close();
+			}
 		},
 		methods: {
-			
+			connectSocket(userId) {
+				if (!userId) return;
+				// 若已有连接则关闭
+				if (this.ws) {
+					this.ws.close();
+				}
+				this.ws = new WebSocket(ROOTPATH2 + '' + userId)
+				// 连接成功
+				this.ws.onopen = () => {
+					console.log('WebSocket 已连接:', ROOTPATH2 + '' + userId);
+				};
+				// 收到消息
+				this.ws.onmessage = (event) => {
+					console.log(event)
+					if (event.data === 'HeartBeat') return;
+					let msg;
+					try {
+						msg = JSON.parse(event.data);
+					} catch (e) {
+						console.warn('非JSON消息:', event.data);
+						return;
+					}
+					if (msg.type === 'kickOut') {
+						ElMessage({
+							message: msg.content || '您的账号已在其他设备登录',
+							type: 'warning',
+							duration: 1500,
+							offset: this.screenHeight / 2
+						})
+						localStorage.removeItem('token');
+						localStorage.removeItem('userId');
+						localStorage.removeItem('userType');
+						localStorage.removeItem('companyId');
+						// 调用重置状态的函数  
+						this.$store.dispatch('SET_DATA');
+						this.$router.push({
+							name: 'login'
+						})
+					}
+				};
+			},
 			//获取用户信息
 			getUserInfo() {
 				this.$Request.get('/app/user/selectUserById').then(res => {

+ 7 - 5
src/views/resume/addResume.vue

@@ -14,7 +14,7 @@
                                 <div class="info-box-l-info-hovers" v-if="userInfoEdit == false">
                                     <div class="info-box-l-info flex align-center justify-between">
                                         <div class="info-box-l-info-l flex align-center">
-                                            <div class="info-box-l-info-avatar">
+                                            <div class="info-box-l-info-avatar" style="flex-shrink: 0;">
                                                 <el-upload class="avatar-uploader flex align-center justify-center"
                                                     :action="action" :show-file-list="false" :on-success="handleAvatarSuccess
                                                         ">
@@ -501,9 +501,11 @@
                                     : '至今'
                                     }}
                                 </div>
-                                <div class="info-boxsWorks-content-con">
+                                <div class="info-boxsWorks-content-con" style="white-space: pre-wrap;">
                                     <span>工作内容:</span>
-                                    {{ detail.workContent || '未填写工作内容' }}
+                                    <div>
+                                        {{ detail.workContent || '未填写工作内容' }}
+                                    </div>
                                 </div>
                                 <!-- 显示技能标签 -->
                                 <div v-if="detail.skills && detail.skills.length > 0"
@@ -702,9 +704,9 @@
                                 : '至今'
                                 }}
                             </div>
-                            <div class="info-boxsWorks-content-con">
+                            <div class="info-boxsWorks-content-con" style="white-space: pre-wrap;">
                                 <span>详细描述:</span>
-                                {{ item.detail || '未填写详细描述' }}
+                                <div>{{ item.detail || '未填写详细描述' }}</div>
                             </div>
                         </div>
                         <!-- 添加/编辑教育经历 -->