Просмотр исходного кода

add url protocol &
add web client on/off by api server

ljw 1 год назад
Родитель
Сommit
3cc460ac8b

+ 6 - 0
src/api/rustdesk.js

@@ -6,3 +6,9 @@ export function config () {
6 6
     method: 'get',
7 7
   })
8 8
 }
9
+export function appConfig () {
10
+  return request({
11
+    url: '/app-config',
12
+    method: 'get',
13
+  })
14
+}

+ 10 - 0
src/store/app.js

@@ -2,6 +2,7 @@ import { defineStore, acceptHMRUpdate } from 'pinia'
2 2
 import logo from '@/assets/logo.png'
3 3
 import zhCn from 'element-plus/es/locale/lang/zh-cn'
4 4
 import en from 'element-plus/es/locale/lang/en'
5
+import { appConfig } from '@/api/rustdesk'
5 6
 
6 7
 export const useAppStore = defineStore({
7 8
   id: 'App',
@@ -12,6 +13,9 @@ export const useAppStore = defineStore({
12 13
       logo,
13 14
       lang: localStorage.getItem('lang') || 'zh-CN',
14 15
       locale: localStorage.getItem('lang') === 'en' ? en : zhCn,
16
+      appConfig: {
17
+        web_client: 1,
18
+      },
15 19
     },
16 20
   }),
17 21
 
@@ -27,6 +31,12 @@ export const useAppStore = defineStore({
27 31
     changeLang () {
28 32
       this.setLang(this.setting.lang === 'zh-CN' ? 'en' : 'zh-CN')
29 33
     },
34
+    getAppConfig () {
35
+      console.log('getAppConfig')
36
+      appConfig().then(res => {
37
+        this.setting.appConfig = res.data
38
+      })
39
+    },
30 40
   },
31 41
 })
32 42
 

+ 3 - 0
src/store/user.js

@@ -2,6 +2,7 @@ import { defineStore, acceptHMRUpdate } from 'pinia'
2 2
 import { current, login } from '@/api/user'
3 3
 import { setToken, removeToken } from '@/utils/auth'
4 4
 import { useRouteStore } from '@/store/router'
5
+import { useAppStore } from '@/store/app'
5 6
 
6 7
 export const useUserStore = defineStore({
7 8
   id: 'user',
@@ -26,6 +27,7 @@ export const useUserStore = defineStore({
26 27
     async login (form) {
27 28
       const res = await login(form).catch(_ => false)
28 29
       if (res) {
30
+        useAppStore().getAppConfig()
29 31
         const userData = res.data
30 32
         setToken(userData.token)
31 33
         //
@@ -44,6 +46,7 @@ export const useUserStore = defineStore({
44 46
     async info () {
45 47
       const res = await current().catch(_ => false)
46 48
       if (res) {
49
+        useAppStore().getAppConfig()
47 50
         const userData = res.data
48 51
         setToken(userData.token)
49 52
         this.$patch({

+ 9 - 0
src/styles/style.scss

@@ -28,3 +28,12 @@ $sideBarWidth: 210px;
28 28
     --el-input-width: 160px;
29 29
   }
30 30
 }
31
+
32
+.table-actions{
33
+  .el-button{
34
+    margin-top: 5px;
35
+    margin-bottom: 5px;
36
+    margin-left: 5px;
37
+    margin-right: 5px;
38
+  }
39
+}

+ 3 - 0
src/utils/i18n/en.json

@@ -347,5 +347,8 @@
347 347
   },
348 348
   "CopyFailed": {
349 349
     "One": "Copy Failed"
350
+  },
351
+  "Timeout": {
352
+    "One": "Timeout"
350 353
   }
351 354
 }

+ 3 - 0
src/utils/i18n/zh_CN.json

@@ -334,5 +334,8 @@
334 334
   },
335 335
   "CopyFailed": {
336 336
     "One": "复制失败"
337
+  },
338
+  "Timeout": {
339
+    "One": "超时"
337 340
   }
338 341
 }

+ 9 - 0
src/utils/peer.js

@@ -0,0 +1,9 @@
1
+export const connectByClient = (id) => {
2
+  //不新开窗口打开url protocol ,格式是 rustdesk://<id>
3
+  // window.open(`rustdesk://${row.id}`)
4
+  let a = document.createElement('a')
5
+  a.href = `rustdesk://${id}`
6
+  a.target = '_self'
7
+  a.click()
8
+
9
+}

+ 6 - 2
src/views/address_book/components/shareByWebClient.vue

@@ -50,6 +50,7 @@
50 50
   import { shareByWebClient } from '@/api/address_book'
51 51
   import { CopyDocument } from '@element-plus/icons'
52 52
   import { handleClipboard } from '@/utils/clipboard'
53
+  import { ElMessageBox } from 'element-plus'
53 54
 
54 55
   const props = defineProps({
55 56
     id: String,
@@ -71,7 +72,7 @@
71 72
     formData.id = props.id
72 73
     formData.hash = props.hash
73 74
     formData.password = ''
74
-    formData.expire = 300
75
+    formData.expire = 1800
75 76
     formData.password_type = 'once'
76 77
     link.value = ''
77 78
   }
@@ -106,7 +107,10 @@
106 107
     loading.value = true
107 108
     const _formData = { ...formData }
108 109
     if (formData.password !== formData.hash) {
109
-      const res = await getPeerSlat(formData.id).catch(_ => false)
110
+      const res = await getPeerSlat(formData.id).catch(e => {
111
+        ElMessageBox.alert(T('Timeout'), T('Error'))
112
+        return false
113
+      })
110 114
       if (!res) {
111 115
         loading.value = false
112 116
         return

+ 11 - 9
src/views/address_book/index.vue

@@ -30,22 +30,23 @@
30 30
     <el-card class="list-body" shadow="hover">
31 31
       <!--      <el-tag type="danger" style="margin-bottom: 10px">不建议在此操作地址簿,可能会造成数据不同步</el-tag>-->
32 32
       <el-table :data="listRes.list" v-loading="listRes.loading" border>
33
-        <el-table-column prop="id" label="id" align="center"/>
34
-        <el-table-column :label="T('Owner')" align="center">
33
+        <el-table-column prop="id" label="id" align="center" width="200"/>
34
+        <el-table-column :label="T('Owner')" align="center" width="200">
35 35
           <template #default="{row}">
36 36
             <span v-if="row.user_id"> <el-tag>{{ allUsers?.find(u => u.id === row.user_id)?.username }}</el-tag> </span>
37 37
           </template>
38 38
         </el-table-column>
39
-        <el-table-column prop="username" :label="T('Username')" align="center"/>
40
-        <el-table-column prop="hostname" :label="T('Hostname')" align="center"/>
41
-        <el-table-column prop="alias" :label="T('Alias')" align="center"/>
42
-        <el-table-column prop="platform" :label="T('Platform')" align="center"/>
43
-        <el-table-column prop="hash" :label="T('Hash')" align="center"/>
44
-        <el-table-column prop="tags" :label="T('Tags')" align="center"/>
39
+        <el-table-column prop="username" :label="T('Username')" align="center" width="150"/>
40
+        <el-table-column prop="hostname" :label="T('Hostname')" align="center" width="150"/>
41
+        <el-table-column prop="alias" :label="T('Alias')" align="center" width="150"/>
42
+        <el-table-column prop="platform" :label="T('Platform')" align="center" width="120"/>
43
+        <el-table-column prop="hash" :label="T('Hash')" align="center" width="250"/>
44
+        <el-table-column prop="tags" :label="T('Tags')" align="center" width="250"/>
45 45
         <!--        <el-table-column prop="created_at" label="创建时间" align="center"/>-->
46 46
         <!--        <el-table-column prop="updated_at" label="更新时间" align="center"/>-->
47
-        <el-table-column label="操作" align="center" width="500">
47
+        <el-table-column :label="T('Actions')" align="center" class-name="table-actions">
48 48
           <template #default="{row}">
49
+            <el-button type="success" @click="connectByClient(row.id)">{{ T('Link') }}</el-button>
49 50
             <el-button type="success" @click="toWebClientLink(row)">Web Client</el-button>
50 51
             <!--            <el-button type="primary" @click="toShowShare(row)">{{ T('ShareByWebClient') }}</el-button>-->
51 52
             <el-button @click="toEdit(row)">{{ T('Edit') }}</el-button>
@@ -158,6 +159,7 @@
158 159
   import { T } from '@/utils/i18n'
159 160
   import { useRoute } from 'vue-router'
160 161
   import shareByWebClient from '@/views/address_book/components/shareByWebClient.vue'
162
+  import { connectByClient } from '@/utils/peer'
161 163
 
162 164
   const route = useRoute()
163 165
   const { allUsers, getAllUsers } = loadAllUsers()

+ 14 - 10
src/views/my/address_book/index.vue

@@ -20,19 +20,20 @@
20 20
     <el-card class="list-body" shadow="hover">
21 21
       <!--      <el-tag type="danger" style="margin-bottom: 10px">不建议在此操作地址簿,可能会造成数据不同步</el-tag>-->
22 22
       <el-table :data="listRes.list" v-loading="listRes.loading" border>
23
-        <el-table-column prop="id" label="id" align="center"/>
24
-        <el-table-column prop="username" :label="T('Username')" align="center"/>
25
-        <el-table-column prop="hostname" :label="T('Hostname')" align="center"/>
26
-        <el-table-column prop="alias" :label="T('Alias')" align="center"/>
27
-        <el-table-column prop="platform" :label="T('Platform')" align="center"/>
28
-        <el-table-column prop="hash" :label="T('Hash')" align="center"/>
29
-        <el-table-column prop="tags" :label="T('Tags')" align="center"/>
23
+        <el-table-column prop="id" label="id" align="center" width="200"/>
24
+        <el-table-column prop="username" :label="T('Username')" align="center" width="150"/>
25
+        <el-table-column prop="hostname" :label="T('Hostname')" align="center" width="150"/>
26
+        <el-table-column prop="alias" :label="T('Alias')" align="center" width="150"/>
27
+        <el-table-column prop="platform" :label="T('Platform')" align="center" width="120"/>
28
+        <el-table-column prop="hash" :label="T('Hash')" align="center" width="250"/>
29
+        <el-table-column prop="tags" :label="T('Tags')" align="center" width="250"/>
30 30
         <!--        <el-table-column prop="created_at" label="创建时间" align="center"/>-->
31 31
         <!--        <el-table-column prop="updated_at" label="更新时间" align="center"/>-->
32
-        <el-table-column :label="T('Actions')" align="center" width="500">
32
+        <el-table-column :label="T('Actions')" align="center" class-name="table-actions">
33 33
           <template #default="{row}">
34
-            <el-button type="success" @click="toWebClientLink(row)">Web Client</el-button>
35
-            <el-button type="primary" @click="toShowShare(row)">{{ T('ShareByWebClient') }}</el-button>
34
+            <el-button type="success" @click="connectByClient(row.id)">{{ T('Link') }}</el-button>
35
+            <el-button v-if="appStore.setting.appConfig.web_client" type="success" @click="toWebClientLink(row)">Web Client</el-button>
36
+            <el-button v-if="appStore.setting.appConfig.web_client" type="primary" @click="toShowShare(row)">{{ T('ShareByWebClient') }}</el-button>
36 37
             <el-button @click="toEdit(row)">{{ T('Edit') }}</el-button>
37 38
             <el-button type="danger" @click="del(row)">{{ T('Delete') }}</el-button>
38 39
           </template>
@@ -131,7 +132,10 @@
131 132
   import { toWebClientLink } from '@/utils/webclient'
132 133
   import { T } from '@/utils/i18n'
133 134
   import shareByWebClient from '@/views/address_book/components/shareByWebClient.vue'
135
+  import { useAppStore } from '@/store/app'
136
+  import { connectByClient } from '@/utils/peer'
134 137
 
138
+  const appStore = useAppStore()
135 139
   const tagList = ref([])
136 140
   const fetchTagListData = async () => {
137 141
     const res = await fetchTagList({ is_my: 1 }).catch(_ => false)

+ 14 - 2
src/views/peer/index.vue

@@ -2,6 +2,12 @@
2 2
   <div>
3 3
     <el-card class="list-query" shadow="hover">
4 4
       <el-form inline label-width="150px">
5
+        <el-form-item label="ID">
6
+          <el-input v-model="listQuery.id" clearable/>
7
+        </el-form-item>
8
+        <el-form-item :label="T('Hostname')">
9
+          <el-input v-model="listQuery.hostname" clearable/>
10
+        </el-form-item>
5 11
         <el-form-item :label="T('LastOnlineTime')">
6 12
           <el-select v-model="listQuery.time_ago" clearable>
7 13
             <el-option
@@ -42,9 +48,10 @@
42 48
 
43 49
           </template>
44 50
         </el-table-column>
45
-        <el-table-column :label="T('Actions')" align="center" width="500">
51
+        <el-table-column :label="T('Actions')" align="center" width="500" class-name="table-actions">
46 52
           <template #default="{row}">
47
-            <el-button type="success" @click="toWebClientLink(row)">Web-Client</el-button>
53
+            <el-button type="success" @click="connectByClient(row.id)">{{ T('Link') }}</el-button>
54
+            <el-button v-if="appStore.setting.appConfig.web_client" type="success" @click="toWebClientLink(row)">Web Client</el-button>
48 55
             <el-button type="primary" @click="toAddressBook(row)">{{ T('AddToAddressBook') }}</el-button>
49 56
             <el-button @click="toEdit(row)">{{ T('Edit') }}</el-button>
50 57
             <el-button type="danger" @click="del(row)">{{ T('Delete') }}</el-button>
@@ -161,7 +168,10 @@
161 168
   import { loadAllUsers } from '@/global'
162 169
   import { list as fetchTagList } from '@/api/tag'
163 170
   import { batchCreate } from '@/api/address_book'
171
+  import { useAppStore } from '@/store/app'
172
+  import { connectByClient } from '@/utils/peer'
164 173
 
174
+  const appStore = useAppStore()
165 175
   const listRes = reactive({
166 176
     list: [], total: 0, loading: false,
167 177
   })
@@ -169,6 +179,8 @@
169 179
     page: 1,
170 180
     page_size: 10,
171 181
     time_ago: null,
182
+    id: '',
183
+    hostname: '',
172 184
   })
173 185
 
174 186
   const getList = async () => {