| 9 | <div class="editor-header"> |
| 10 | <div class="header-left"> |
| 11 | <a |
| 12 | href="https://github.com/fatedier/frp#configuration-files" |
| 13 | target="_blank" |
| 14 | class="docs-link" |
| 15 | > |
| 16 | <el-icon><Link /></el-icon> |
| 17 | Documentation |
| 18 | </a> |
| 19 | </div> |
| 20 | <div class="header-actions"> |
| 21 | <ActionButton @click="handleUpload">Update & Reload</ActionButton> |
| 22 | </div> |
| 23 | </div> |
| 24 |
| 25 | <div class="editor-wrapper"> |
| 26 | <el-input |
| 27 | type="textarea" |
| 28 | :autosize="false" |
| 29 | v-model="configContent" |
| 30 | placeholder="# frpc configuration file content... |
| 31 |
| 32 | serverAddr = "127.0.0.1" |
| 33 | serverPort = 7000" |
| 34 | class="code-editor" |
| 35 | ></el-input> |
| 36 | </div> |
| 37 |
| 38 | <ConfirmDialog |
| 39 | v-model="confirmVisible" |
| 40 | title="Confirm Update" |
| 41 | message="This operation will update your frpc configuration and reload it. Do you want to continue?" |
| 42 | confirm-text="Update" |
| 43 | :loading="uploading" |
| 44 | :is-mobile="isMobile" |
| 45 | @confirm="doUpload" |
| 46 | /> |
| 47 | </div> |
| 48 | </template> |
| 49 |
| 50 | <script setup lang="ts"> |
| 51 | import { ref } from 'vue' |
| 52 | import { ElMessage } from 'element-plus' |
| 53 | import { Link } from '@element-plus/icons-vue' |
| 54 | import { useClientStore } from '../stores/client' |
| 55 | import ActionButton from '@shared/components/ActionButton.vue' |
| 56 | import ConfirmDialog from '@shared/components/ConfirmDialog.vue' |
| 57 | import { useResponsive } from '../composables/useResponsive' |
| 58 |
| 59 | const { isMobile } = useResponsive() |
| 60 | const clientStore = useClientStore() |
| 61 | const configContent = ref('') |
| 62 |
| 63 | const fetchData = async () => { |
| 64 | try { |
| 65 | await clientStore.fetchConfig() |
| 66 | configContent.value = clientStore.config |
| 67 | } catch (err: any) { |
| 68 | ElMessage({ |
| 69 | showClose: true, |
| 70 | message: 'Get configuration failed: ' + err.message, |
| 71 | type: 'warning', |
| 72 | }) |
| 73 | } |
| 74 | } |
| 75 |
| 76 | const confirmVisible = ref(false) |
| 77 | const uploading = ref(false) |
| 78 |
| 79 | const handleUpload = () => { |
| 80 | confirmVisible.value = true |
| 81 | } |
| 82 |
| 83 | const doUpload = async () => { |
| 84 | if (!configContent.value.trim()) { |
| 85 | ElMessage.warning('Configuration content cannot be empty!') |
| 86 | return |
| 87 | } |
| 88 |
| 89 | uploading.value = true |
| 90 | try { |
| 91 | await clientStore.saveConfig(configContent.value) |
| 92 | await clientStore.reload() |
| 93 | ElMessage.success('Configuration updated and reloaded successfully') |
| 94 | confirmVisible.value = false |
| 95 | } catch (err: any) { |
| 96 | ElMessage.error('Update failed: ' + err.message) |
| 97 | } finally { |
| 98 | uploading.value = false |
| 99 | } |
| 100 | } |
| 101 |
| 102 | fetchData() |
| 103 | </script> |
| 104 |
| 105 | <style scoped lang="scss"> |
| 106 | .configure-page { |
| 107 | height: 100%; |
| 108 | overflow: hidden; |
| 109 | padding: $spacing-xl 40px; |
| 110 | max-width: 960px; |
| 111 | margin: 0 auto; |
| 112 | @include flex-column; |
| 113 | gap: $spacing-sm; |
| 114 | } |
| 115 |
| 116 | .editor-wrapper { |
| 117 | flex: 1; |
| 118 | min-height: 0; |
| 119 | overflow: hidden; |
| 120 | } |
| 121 |
| 122 |
| 123 | .page-header { |
| 124 | @include flex-column; |
| 125 | gap: $spacing-sm; |
| 126 | margin-bottom: $spacing-sm; |
| 127 | } |
| 128 |
| 129 |
| 130 | .editor-header { |
| 131 | display: flex; |
| 132 | justify-content: space-between; |
| 133 | align-items: center; |
| 134 | } |
| 135 |
| 136 | .header-left { |
| 137 | display: flex; |
| 138 | align-items: center; |
| 139 | } |
| 140 |
| 141 | .header-actions { |
| 142 | display: flex; |
| 143 | align-items: center; |
| 144 | gap: $spacing-sm; |
| 145 | } |
| 146 |
| 147 | .docs-link { |
| 148 | display: flex; |
| 149 | align-items: center; |
| 150 | gap: $spacing-xs; |
| 151 | color: $color-text-muted; |
| 152 | text-decoration: none; |
| 153 | font-size: $font-size-sm; |
| 154 | transition: color $transition-fast; |
| 155 |
| 156 | &:hover { |
| 157 | color: $color-text-primary; |
| 158 | } |
| 159 | } |
| 160 |
| 161 | .code-editor { |
| 162 | height: 100%; |
| 163 |
| 164 | :deep(.el-textarea__inner) { |
| 165 | height: 100% !important; |
| 166 | overflow-y: auto; |
| 167 | font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; |
| 168 | font-size: $font-size-sm; |
| 169 | line-height: 1.6; |
| 170 | padding: $spacing-lg; |
| 171 | border-radius: $radius-md; |
| 172 | background: $color-bg-tertiary; |
| 173 | border: 1px solid $color-border-light; |
| 174 | resize: none; |
| 175 |
| 176 | &:focus { |
| 177 | border-color: $color-text-light; |
| 178 | box-shadow: none; |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 |
| 183 | @include mobile { |
| 184 | .configure-page { |
| 185 | padding: $spacing-xl $spacing-lg; |
| 186 | } |
| 187 |
| 188 | .header-left { |
| 189 | justify-content: space-between; |
| 190 | } |
| 191 |
| 192 | .header-actions { |
| 193 | justify-content: flex-end; |
| 194 | } |
| 195 | } |
| 196 | </style> |