Răsfoiți Sursa

websocket 调整

mxd 3 ani în urmă
părinte
comite
473e24eabe

+ 1 - 1
src/components/common/dialog/magic-alert.vue

@@ -1,6 +1,6 @@
 <template>
     <magic-dialog v-model:value="show" :title="title" ref="dialog" @close="onClose()">
-        <pre style="white-space:normal">{{ message }}</pre>
+        <pre style="white-space:pre-wrap">{{ message }}</pre>
         <magic-button-group align="center" style="padding: 5px 0">
             <magic-button :value="ok" type="active" @onClick="$refs.dialog.close()"/>
         </magic-button-group>

+ 1 - 2
src/components/magic-editor.vue

@@ -33,7 +33,6 @@ import store from '../scripts/store.js'
 import * as monaco from 'monaco-editor'
 import modal from './common/dialog/magic-modal.js'
 import $i from '../scripts/i18n.js'
-console.log($i('message.save'))
 initializeMagicScript()
 self.MonacoEnvironment = {
 	getWorker: function(moduleId, label) {
@@ -160,7 +159,7 @@ const init = () => {
 	}).catch(e => {
 		console.error(e)
 		hideLoadingElement()
-		modal.alert($i('message.tips'), $i('message.loadConfigError'))
+		modal.alert($i('message.loadConfigError'), $i('message.tips'))
 		bus.status('message.loadConfigError', false)
 	})
 }

+ 7 - 1
src/components/panel/footer/magic-online.vue

@@ -33,11 +33,17 @@ const addUser = user => {
 		users.push(user)
 	}
 }
+let timer = null
 bus.$event(Socket.LOGIN_RESPONSE, ([ret, user]) => {
 	activateUserFiles.value = {}
 	users.splice(0, users.length)
+	if(timer !== null){
+		clearInterval(timer)
+	}
 	if(ret === '1') {
+		timer = setInterval(() => bus.send(Socket.PING, new Date().getTime()), 10000)
 		addUser(user)
+	} else if (ret === '-1'){
 	}
 	
 })
@@ -55,7 +61,7 @@ bus.$event(Socket.USER_LOGIN, ([user]) => {
 bus.$event(Socket.USER_LOGOUT, ([user]) => {
 	if(constants.CLIENT_ID !== user.cid ){
 		bus.$emit(Message.NOTIFY, {
-			title: $i('online.lotout'),
+			title: $i('online.logout'),
 			content: $i('online.logoutTips', user.username, user.ip),
 			duration: 3000
 		})

+ 0 - 1
src/components/panel/header/magic-header.vue

@@ -43,7 +43,6 @@ for(let k in localeScripts){
             name: v.default.name
         })
     })
-   
 }
 const { themeStyle } = defineProps({
     title: {

+ 1 - 1
src/components/panel/main/magic-resource.vue

@@ -289,7 +289,7 @@ const onContextMenu = (item, event) => {
 					const info = {
 						groupId: item.id,
 						name: $i('message.untitled'),
-						script: 'hello',
+						script: `return 'Hello magic-api'`,
 						path: config.requirePath ? '' : undefined
 					}
 					updateNode(info)

+ 2 - 1
src/scripts/constants/socket.js

@@ -11,5 +11,6 @@ export default {
     USER_LOGOUT: 'user_logout',
     ONLINE_USERS: 'online_users',
     SET_FILE_ID: 'set_file_id',
-    INTO_FILE_ID: 'into_file_id'
+    INTO_FILE_ID: 'into_file_id',
+    PING: 'ping'
 }

+ 7 - 1
src/scripts/i18n.js

@@ -1,5 +1,11 @@
 import store from './store.js'
-const locale = (await import(`./i18n/${store.get('locale') || 'zh-cn'}.js`)).default
+import en from './i18n/en.js'
+import zhCN from './i18n/zh-cn.js'
+const localeName = store.get('locale')
+let locale = zhCN
+if(localeName === 'en'){
+    locale = en
+}
 
 export default function(key, ...args){
     try{

+ 9 - 0
src/scripts/websocket.js

@@ -1,8 +1,17 @@
 import bus from './bus.js'
 import ReconnectingWebSocket from './reconnecting-websocket.js'
+let openedSocket = {}
 function MagicWebSocket(url) {
+	if(openedSocket[url]) {
+		try{
+			openedSocket[url].close()
+		} catch(e){
+
+		}
+	}
 	this.listeners = {};
 	this.socket = new ReconnectingWebSocket(url);
+	openedSocket[url] = this
 	this.socket.onmessage = this.messageReceived;
 	this.socket.onconnecting = () => {
         bus.status('message.connectDebugServer')