From 3cc460ac8b914a6679151c2cda243a20f4fc732f Mon Sep 17 00:00:00 2001 From: ljw <84855512@qq.com> Date: Mon, 14 Oct 2024 10:34:40 +0800 Subject: [PATCH] add url protocol & add web client on/off by api server --- src/api/rustdesk.js | 6 +++++ src/store/app.js | 10 ++++++++ src/store/user.js | 3 +++ src/styles/style.scss | 9 +++++++ src/utils/i18n/en.json | 3 +++ src/utils/i18n/zh_CN.json | 3 +++ src/utils/peer.js | 9 +++++++ .../components/shareByWebClient.vue | 8 +++++-- src/views/address_book/index.vue | 20 +++++++++------- src/views/my/address_book/index.vue | 24 +++++++++++-------- src/views/peer/index.vue | 16 +++++++++++-- 11 files changed, 88 insertions(+), 23 deletions(-) create mode 100644 src/utils/peer.js diff --git a/src/api/rustdesk.js b/src/api/rustdesk.js index ffc1ecc..9a70451 100644 --- a/src/api/rustdesk.js +++ b/src/api/rustdesk.js @@ -6,3 +6,9 @@ export function config () { method: 'get', }) } +export function appConfig () { + return request({ + url: '/app-config', + method: 'get', + }) +} diff --git a/src/store/app.js b/src/store/app.js index 8a6ec89..611c57a 100644 --- a/src/store/app.js +++ b/src/store/app.js @@ -2,6 +2,7 @@ import { defineStore, acceptHMRUpdate } from 'pinia' import logo from '@/assets/logo.png' import zhCn from 'element-plus/es/locale/lang/zh-cn' import en from 'element-plus/es/locale/lang/en' +import { appConfig } from '@/api/rustdesk' export const useAppStore = defineStore({ id: 'App', @@ -12,6 +13,9 @@ export const useAppStore = defineStore({ logo, lang: localStorage.getItem('lang') || 'zh-CN', locale: localStorage.getItem('lang') === 'en' ? en : zhCn, + appConfig: { + web_client: 1, + }, }, }), @@ -27,6 +31,12 @@ export const useAppStore = defineStore({ changeLang () { this.setLang(this.setting.lang === 'zh-CN' ? 'en' : 'zh-CN') }, + getAppConfig () { + console.log('getAppConfig') + appConfig().then(res => { + this.setting.appConfig = res.data + }) + }, }, }) diff --git a/src/store/user.js b/src/store/user.js index 54222ef..d1201d0 100644 --- a/src/store/user.js +++ b/src/store/user.js @@ -2,6 +2,7 @@ import { defineStore, acceptHMRUpdate } from 'pinia' import { current, login } from '@/api/user' import { setToken, removeToken } from '@/utils/auth' import { useRouteStore } from '@/store/router' +import { useAppStore } from '@/store/app' export const useUserStore = defineStore({ id: 'user', @@ -26,6 +27,7 @@ export const useUserStore = defineStore({ async login (form) { const res = await login(form).catch(_ => false) if (res) { + useAppStore().getAppConfig() const userData = res.data setToken(userData.token) // @@ -44,6 +46,7 @@ export const useUserStore = defineStore({ async info () { const res = await current().catch(_ => false) if (res) { + useAppStore().getAppConfig() const userData = res.data setToken(userData.token) this.$patch({ diff --git a/src/styles/style.scss b/src/styles/style.scss index db8e424..b30bd9f 100644 --- a/src/styles/style.scss +++ b/src/styles/style.scss @@ -28,3 +28,12 @@ $sideBarWidth: 210px; --el-input-width: 160px; } } + +.table-actions{ + .el-button{ + margin-top: 5px; + margin-bottom: 5px; + margin-left: 5px; + margin-right: 5px; + } +} diff --git a/src/utils/i18n/en.json b/src/utils/i18n/en.json index 692fea0..8a4c4c7 100644 --- a/src/utils/i18n/en.json +++ b/src/utils/i18n/en.json @@ -347,5 +347,8 @@ }, "CopyFailed": { "One": "Copy Failed" + }, + "Timeout": { + "One": "Timeout" } } diff --git a/src/utils/i18n/zh_CN.json b/src/utils/i18n/zh_CN.json index c308ad7..4e55a58 100644 --- a/src/utils/i18n/zh_CN.json +++ b/src/utils/i18n/zh_CN.json @@ -334,5 +334,8 @@ }, "CopyFailed": { "One": "复制失败" + }, + "Timeout": { + "One": "超时" } } diff --git a/src/utils/peer.js b/src/utils/peer.js new file mode 100644 index 0000000..d7d6198 --- /dev/null +++ b/src/utils/peer.js @@ -0,0 +1,9 @@ +export const connectByClient = (id) => { + //不新开窗口打开url protocol ,格式是 rustdesk:// + // window.open(`rustdesk://${row.id}`) + let a = document.createElement('a') + a.href = `rustdesk://${id}` + a.target = '_self' + a.click() + +} diff --git a/src/views/address_book/components/shareByWebClient.vue b/src/views/address_book/components/shareByWebClient.vue index 6762be6..c3a60e3 100644 --- a/src/views/address_book/components/shareByWebClient.vue +++ b/src/views/address_book/components/shareByWebClient.vue @@ -50,6 +50,7 @@ import { shareByWebClient } from '@/api/address_book' import { CopyDocument } from '@element-plus/icons' import { handleClipboard } from '@/utils/clipboard' + import { ElMessageBox } from 'element-plus' const props = defineProps({ id: String, @@ -71,7 +72,7 @@ formData.id = props.id formData.hash = props.hash formData.password = '' - formData.expire = 300 + formData.expire = 1800 formData.password_type = 'once' link.value = '' } @@ -106,7 +107,10 @@ loading.value = true const _formData = { ...formData } if (formData.password !== formData.hash) { - const res = await getPeerSlat(formData.id).catch(_ => false) + const res = await getPeerSlat(formData.id).catch(e => { + ElMessageBox.alert(T('Timeout'), T('Error')) + return false + }) if (!res) { loading.value = false return diff --git a/src/views/address_book/index.vue b/src/views/address_book/index.vue index 808e38f..390abbe 100644 --- a/src/views/address_book/index.vue +++ b/src/views/address_book/index.vue @@ -30,22 +30,23 @@ - - + + - - - - - - + + + + + + - +