lejianwen 1 год назад
Родитель
Сommit
0e9391a4c5

+ 69 - 0
src/views/rustdesk/always_use_relay.vue

@@ -0,0 +1,69 @@
1
+<template>
2
+  <el-card class="simple-card" shadow="hover" v-loading="form.loading">
3
+    <template #header>
4
+      <div class="card-header">
5
+        <span>ALWAYS_USE_RELAY</span>
6
+      </div>
7
+    </template>
8
+    <el-form :disabled="!canSend">
9
+      <el-form-item>
10
+        <el-switch v-model="form.option" active-value="Y" inactive-value="N"></el-switch>
11
+      </el-form-item>
12
+      <el-form-item>
13
+        <el-button @click="get">{{ T('Refresh') }}</el-button>
14
+        <el-button @click="save" type="primary">{{ T('Save') }}</el-button>
15
+      </el-form-item>
16
+    </el-form>
17
+  </el-card>
18
+</template>
19
+<script setup>
20
+
21
+  import { T } from '@/utils/i18n'
22
+  import { reactive, watch } from 'vue'
23
+  import { sendCmd } from '@/api/rustdesk'
24
+  import { ElMessage } from 'element-plus'
25
+  import { ID_TARGET } from '@/views/rustdesk/options'
26
+
27
+  const emits = defineEmits('success')
28
+  const props = defineProps({
29
+    canSend: Boolean,
30
+  })
31
+
32
+  const form = reactive({
33
+    cmd: 'aur',
34
+    option: '',
35
+    target: ID_TARGET,
36
+    value: 0,
37
+    loading: false,
38
+  })
39
+  const get = async () => {
40
+    form.loading = true
41
+    const res = await sendCmd({ cmd: 'aur', target: ID_TARGET }).catch(_ => false)
42
+    form.loading = false
43
+    if (res) {
44
+      if (res.data === 'ALWAYS_USE_RELAY: true' || res.data === 'ALWAYS_USE_RELAY: true\n') {
45
+        form.option = 'Y'
46
+      } else {
47
+        form.option = 'N'
48
+      }
49
+    }
50
+  }
51
+  const save = async () => {
52
+    const res = await sendCmd(form).catch(_ => false)
53
+    if (res) {
54
+      ElMessage.success(T('OperationSuccess'))
55
+      emits('success')
56
+    }
57
+  }
58
+
59
+  watch(() => props.canSend, (v) => {
60
+    if (v) {
61
+      get()
62
+    }
63
+  })
64
+</script>
65
+
66
+
67
+<style scoped lang="scss">
68
+
69
+</style>

+ 1 - 1
src/views/rustdesk/blacklist.vue

@@ -36,8 +36,8 @@
36
   import { reactive, watch } from 'vue'
36
   import { reactive, watch } from 'vue'
37
   import { sendCmd } from '@/api/rustdesk'
37
   import { sendCmd } from '@/api/rustdesk'
38
   import { ElMessage } from 'element-plus'
38
   import { ElMessage } from 'element-plus'
39
+  import { RELAY_TARGET } from '@/views/rustdesk/options'
39
 
40
 
40
-  const RELAY_TARGET = '21117'
41
   const props = defineProps({
41
   const props = defineProps({
42
     canSend: Boolean,
42
     canSend: Boolean,
43
   })
43
   })

+ 1 - 1
src/views/rustdesk/blocklist.vue

@@ -36,8 +36,8 @@
36
   import { reactive, watch } from 'vue'
36
   import { reactive, watch } from 'vue'
37
   import { sendCmd } from '@/api/rustdesk'
37
   import { sendCmd } from '@/api/rustdesk'
38
   import { ElMessage } from 'element-plus'
38
   import { ElMessage } from 'element-plus'
39
+  import { RELAY_TARGET } from '@/views/rustdesk/options'
39
 
40
 
40
-  const RELAY_TARGET = '21117'
41
   const props = defineProps({
41
   const props = defineProps({
42
     canSend: Boolean,
42
     canSend: Boolean,
43
   })
43
   })

+ 22 - 87
src/views/rustdesk/control.vue

@@ -19,38 +19,9 @@
19
     >
19
     >
20
       <el-tab-pane :label="T('Simple')" name="Simple">
20
       <el-tab-pane :label="T('Simple')" name="Simple">
21
         <el-space>
21
         <el-space>
22
-          <el-card class="simple-card" shadow="hover" v-loading="rsForm.loading">
23
-            <template #header>
24
-              <div class="card-header">
25
-                <span>RELAY_SERVERS</span>
26
-              </div>
27
-            </template>
28
-            <el-form :disabled="!canSendCmd(rsForm.target)">
29
-              <el-form-item>
30
-                <el-input v-model="rsForm.option"></el-input>
31
-              </el-form-item>
32
-              <el-form-item>
33
-                <el-button @click="getRS">{{ T('Refresh') }}</el-button>
34
-                <el-button @click="saveRS" type="primary">{{ T('Save') }}</el-button>
35
-              </el-form-item>
36
-            </el-form>
37
-          </el-card>
38
-          <el-card class="simple-card" shadow="hover" v-loading="aurForm.loading">
39
-            <template #header>
40
-              <div class="card-header">
41
-                <span>ALWAYS_USE_RELAY</span>
42
-              </div>
43
-            </template>
44
-            <el-form :disabled="!canSendCmd(aurForm.target)">
45
-              <el-form-item>
46
-                <el-switch v-model="aurForm.option" active-value="Y" inactive-value="N"></el-switch>
47
-              </el-form-item>
48
-              <el-form-item>
49
-                <el-button @click="getAUR">{{ T('Refresh') }}</el-button>
50
-                <el-button @click="saveAUR" type="primary">{{ T('Save') }}</el-button>
51
-              </el-form-item>
52
-            </el-form>
53
-          </el-card>
22
+          <RelayServers ref="rs" :can-send="canSendCmd(ID_TARGET)"></RelayServers>
23
+          <alwaysUseRelay :can-send="canSendCmd(ID_TARGET)" @success="handleAlwaysUseRelaySuccess"></alwaysUseRelay>
24
+          <mustLogin :can-send="canSendCmd(ID_TARGET)"></mustLogin>
54
           <blocklist :can-send="canSendCmd(RELAY_TARGET)"></blocklist>
25
           <blocklist :can-send="canSendCmd(RELAY_TARGET)"></blocklist>
55
           <blacklist :can-send="canSendCmd(RELAY_TARGET)"></blacklist>
26
           <blacklist :can-send="canSendCmd(RELAY_TARGET)"></blacklist>
56
         </el-space>
27
         </el-space>
@@ -63,12 +34,12 @@
63
             <el-form-item>
34
             <el-form-item>
64
               <el-button type="primary" @click="handlerQuery">{{ T('Filter') }}</el-button>
35
               <el-button type="primary" @click="handlerQuery">{{ T('Filter') }}</el-button>
65
               <el-button type="danger" @click="toAdd">{{ T('Add') }}</el-button>
36
               <el-button type="danger" @click="toAdd">{{ T('Add') }}</el-button>
66
-              <el-button type="success" :disabled="!canSendIdServerCmd" @click="showCmd({cmd:'',option:''})">{{ T('Send') }}</el-button>
37
+              <el-button type="success" :disabled="!canSendIdServerCmd" @click="showCmd({cmd:'',option:'',target:ID_TARGET})">{{ T('Send') }} To Id</el-button>
38
+              <el-button type="success" :disabled="!canSendRelayServerCmd" @click="showCmd({cmd:'',option:'',target:RELAY_TARGET})">{{ T('Send') }} To Relay</el-button>
67
             </el-form-item>
39
             </el-form-item>
68
           </el-form>
40
           </el-form>
69
         </el-card>
41
         </el-card>
70
         <el-card class="list-body" shadow="hover">
42
         <el-card class="list-body" shadow="hover">
71
-
72
           <el-table :data="listRes.list" v-loading="listRes.loading" border>
43
           <el-table :data="listRes.list" v-loading="listRes.loading" border>
73
             <el-table-column prop="cmd" label="cmd" align="center"></el-table-column>
44
             <el-table-column prop="cmd" label="cmd" align="center"></el-table-column>
74
             <el-table-column prop="alias" label="alias" align="center"></el-table-column>
45
             <el-table-column prop="alias" label="alias" align="center"></el-table-column>
@@ -144,17 +115,20 @@
144
 
115
 
145
 
116
 
146
 <script setup>
117
 <script setup>
147
-  import { list, sendCmd, remove, create, update } from '@/api/rustdesk'
118
+  import { create, list, remove, sendCmd, update } from '@/api/rustdesk'
148
   import { onMounted, reactive, ref } from 'vue'
119
   import { onMounted, reactive, ref } from 'vue'
149
   import { T } from '@/utils/i18n'
120
   import { T } from '@/utils/i18n'
150
   import { ElMessage, ElMessageBox } from 'element-plus'
121
   import { ElMessage, ElMessageBox } from 'element-plus'
151
   import blocklist from '@/views/rustdesk/blocklist.vue'
122
   import blocklist from '@/views/rustdesk/blocklist.vue'
152
   import blacklist from '@/views/rustdesk/blacklist.vue'
123
   import blacklist from '@/views/rustdesk/blacklist.vue'
124
+  import alwaysUseRelay from '@/views/rustdesk/always_use_relay.vue'
125
+  import RelayServers from '@/views/rustdesk/relay_servers.vue'
126
+  import mustLogin from '@/views/rustdesk/must_login.vue'
127
+  import { ID_TARGET, RELAY_TARGET } from '@/views/rustdesk/options'
153
 
128
 
154
-  const ID_TARGET = '21115'
155
-  const RELAY_TARGET = '21117'
156
   const activeName = ref('Simple')
129
   const activeName = ref('Simple')
157
 
130
 
131
+
158
   const canSendIdServerCmd = ref(false)
132
   const canSendIdServerCmd = ref(false)
159
   const checkCanSendIdServerCmd = async () => {
133
   const checkCanSendIdServerCmd = async () => {
160
     const res = await sendCmd({ cmd: 'h', target: ID_TARGET }).catch(_ => false)
134
     const res = await sendCmd({ cmd: 'h', target: ID_TARGET }).catch(_ => false)
@@ -163,17 +137,20 @@
163
   const refreshCanSendIdServerCmd = () => {
137
   const refreshCanSendIdServerCmd = () => {
164
     checkCanSendIdServerCmd().then(_ => {
138
     checkCanSendIdServerCmd().then(_ => {
165
       if (canSendIdServerCmd.value) {
139
       if (canSendIdServerCmd.value) {
166
-        getAUR()
167
-        getRS()
168
       }
140
       }
169
     })
141
     })
170
   }
142
   }
171
   onMounted(refreshCanSendIdServerCmd)
143
   onMounted(refreshCanSendIdServerCmd)
172
 
144
 
173
   const canSendRelayServerCmd = ref(false)
145
   const canSendRelayServerCmd = ref(false)
146
+  const canControlMustLogin = ref(false)
174
   const checkCanSendRelayServerCmd = async () => {
147
   const checkCanSendRelayServerCmd = async () => {
175
     const res = await sendCmd({ cmd: 'h', target: RELAY_TARGET }).catch(_ => false)
148
     const res = await sendCmd({ cmd: 'h', target: RELAY_TARGET }).catch(_ => false)
176
     canSendRelayServerCmd.value = !!res.data
149
     canSendRelayServerCmd.value = !!res.data
150
+    if (canSendRelayServerCmd.value) {
151
+      const commands = res.data.split('\n').filter(i => i)
152
+      canControlMustLogin.value = commands.some(i => i.includes('must-login'))
153
+    }
177
   }
154
   }
178
   const refreshCanSendRelayServerCmd = () => {
155
   const refreshCanSendRelayServerCmd = () => {
179
     checkCanSendRelayServerCmd().then(_ => {
156
     checkCanSendRelayServerCmd().then(_ => {
@@ -183,6 +160,12 @@
183
   }
160
   }
184
   onMounted(refreshCanSendRelayServerCmd)
161
   onMounted(refreshCanSendRelayServerCmd)
185
 
162
 
163
+  const rs = ref(null)
164
+  console.log(rs)
165
+  const handleAlwaysUseRelaySuccess = () => {
166
+    rs.value.save()
167
+  }
168
+
186
   const canSendCmd = (target) => {
169
   const canSendCmd = (target) => {
187
     if (target === ID_TARGET) {
170
     if (target === ID_TARGET) {
188
       return canSendIdServerCmd.value
171
       return canSendIdServerCmd.value
@@ -193,54 +176,6 @@
193
     return false
176
     return false
194
   }
177
   }
195
 
178
 
196
-  const rsForm = reactive({
197
-    cmd: 'rs',
198
-    option: '',
199
-    target: ID_TARGET,
200
-    loading: false,
201
-  })
202
-  const getRS = async () => {
203
-    rsForm.loading = true
204
-    const res = await sendCmd({ cmd: 'rs', target: ID_TARGET }).catch(_ => false)
205
-    rsForm.loading = false
206
-    if (res) {
207
-      const data = res.data.split('\n').filter(i => i)
208
-      rsForm.option = data.join(',')
209
-    }
210
-  }
211
-  const saveRS = async () => {
212
-    const res = await sendCmd(rsForm).catch(_ => false)
213
-    if (res) {
214
-      ElMessage.success(T('OperationSuccess'))
215
-    }
216
-  }
217
-
218
-  const aurForm = reactive({
219
-    cmd: 'aur',
220
-    option: '',
221
-    target: ID_TARGET,
222
-    value: 0,
223
-    loading: false,
224
-  })
225
-  const getAUR = async () => {
226
-    aurForm.loading = true
227
-    const res = await sendCmd({ cmd: 'aur', target: ID_TARGET }).catch(_ => false)
228
-    aurForm.loading = false
229
-    if (res) {
230
-      if (res.data === 'ALWAYS_USE_RELAY: true' || res.data === 'ALWAYS_USE_RELAY: true\n') {
231
-        aurForm.option = 'Y'
232
-      } else {
233
-        aurForm.option = 'N'
234
-      }
235
-    }
236
-  }
237
-  const saveAUR = async () => {
238
-    const res = await sendCmd(aurForm).catch(_ => false)
239
-    if (res) {
240
-      ElMessage.success(T('OperationSuccess'))
241
-    }
242
-  }
243
-
244
   const listRes = reactive({
179
   const listRes = reactive({
245
     list: [], total: 0, loading: false,
180
     list: [], total: 0, loading: false,
246
   })
181
   })

+ 67 - 0
src/views/rustdesk/must_login.vue

@@ -0,0 +1,67 @@
1
+<template>
2
+  <el-card class="simple-card" shadow="hover" v-loading="form.loading">
3
+    <template #header>
4
+      <div class="card-header">
5
+        <span>MUST_LOGIN</span>
6
+      </div>
7
+    </template>
8
+    <el-form :disabled="!canSend">
9
+      <el-form-item>
10
+        <el-switch v-model="form.option" active-value="Y" inactive-value="N"></el-switch>
11
+      </el-form-item>
12
+      <el-form-item>
13
+        <el-button @click="get">{{ T('Refresh') }}</el-button>
14
+        <el-button @click="save" type="primary">{{ T('Save') }}</el-button>
15
+      </el-form-item>
16
+    </el-form>
17
+  </el-card>
18
+</template>
19
+<script setup>
20
+
21
+  import { T } from '@/utils/i18n'
22
+  import { reactive, watch } from 'vue'
23
+  import { sendCmd } from '@/api/rustdesk'
24
+  import { ElMessage } from 'element-plus'
25
+  import { ID_TARGET } from '@/views/rustdesk/options'
26
+
27
+  const props = defineProps({
28
+    canSend: Boolean,
29
+  })
30
+
31
+  const form = reactive({
32
+    cmd: 'ml',
33
+    option: '',
34
+    target: ID_TARGET,
35
+    value: 0,
36
+    loading: false,
37
+  })
38
+  const get = async () => {
39
+    form.loading = true
40
+    const res = await sendCmd({ cmd: 'ml', target: ID_TARGET }).catch(_ => false)
41
+    form.loading = false
42
+    if (res) {
43
+      if (res.data === 'MUST_LOGIN: true' || res.data === 'MUST_LOGIN: true\n') {
44
+        form.option = 'Y'
45
+      } else {
46
+        form.option = 'N'
47
+      }
48
+    }
49
+  }
50
+  const save = async () => {
51
+    const res = await sendCmd(form).catch(_ => false)
52
+    if (res) {
53
+      ElMessage.success(T('OperationSuccess'))
54
+    }
55
+  }
56
+
57
+  watch(() => props.canSend, (v) => {
58
+    if (v) {
59
+      get()
60
+    }
61
+  })
62
+</script>
63
+
64
+
65
+<style scoped lang="scss">
66
+
67
+</style>

+ 4 - 0
src/views/rustdesk/options.js

@@ -0,0 +1,4 @@
1
+
2
+export const ID_TARGET = '21115'
3
+
4
+export const RELAY_TARGET = '21117'

+ 65 - 0
src/views/rustdesk/relay_servers.vue

@@ -0,0 +1,65 @@
1
+<template>
2
+  <el-card class="simple-card" shadow="hover" v-loading="form.loading">
3
+    <template #header>
4
+      <div class="card-header">
5
+        <span>RELAY_SERVERS</span>
6
+      </div>
7
+    </template>
8
+    <el-form :disabled="!canSend">
9
+      <el-form-item>
10
+        <el-input v-model="form.option"></el-input>
11
+      </el-form-item>
12
+      <el-form-item>
13
+        <el-button @click="get">{{ T('Refresh') }}</el-button>
14
+        <el-button @click="save" type="primary">{{ T('Save') }}</el-button>
15
+      </el-form-item>
16
+    </el-form>
17
+  </el-card>
18
+</template>
19
+<script setup>
20
+
21
+  import { T } from '@/utils/i18n'
22
+  import { reactive, watch } from 'vue'
23
+  import { sendCmd } from '@/api/rustdesk'
24
+  import { ElMessage } from 'element-plus'
25
+  import { ID_TARGET } from '@/views/rustdesk/options'
26
+
27
+  const props = defineProps({
28
+    canSend: Boolean,
29
+  })
30
+
31
+
32
+  const form = reactive({
33
+    cmd: 'rs',
34
+    option: '',
35
+    target: ID_TARGET,
36
+    loading: false,
37
+  })
38
+  const get = async () => {
39
+    form.loading = true
40
+    const res = await sendCmd({ cmd: 'rs', target: ID_TARGET }).catch(_ => false)
41
+    form.loading = false
42
+    if (res) {
43
+      const data = res.data.split('\n').filter(i => i)
44
+      form.option = data.join(',')
45
+    }
46
+  }
47
+  const save = async () => {
48
+    const res = await sendCmd(form).catch(_ => false)
49
+    if (res) {
50
+      ElMessage.success(T('OperationSuccess'))
51
+    }
52
+  }
53
+  watch(() => props.canSend, (v) => {
54
+    if (v) {
55
+      get()
56
+    }
57
+  })
58
+  //为了在设置always_use_relay之后自动重新保存,防止被重置
59
+  defineExpose({
60
+    save,
61
+  });
62
+</script>
63
+<style scoped lang="scss">
64
+
65
+</style>