Preference.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <script setup lang="ts">
  2. import { message } from 'ant-design-vue'
  3. import type { Ref } from 'vue'
  4. import { storeToRefs } from 'pinia'
  5. import FooterToolBar from '@/components/FooterToolbar/FooterToolBar.vue'
  6. import settings from '@/api/settings'
  7. import BasicSettings from '@/views/preference/BasicSettings.vue'
  8. import OpenAISettings from '@/views/preference/OpenAISettings.vue'
  9. import NginxSettings from '@/views/preference/NginxSettings.vue'
  10. import type { Settings } from '@/api/settings'
  11. import LogrotateSettings from '@/views/preference/LogrotateSettings.vue'
  12. import { useSettingsStore } from '@/pinia'
  13. import AuthSettings from '@/views/preference/AuthSettings.vue'
  14. import use2FAModal from '@/components/TwoFA/use2FAModal'
  15. import CertSettings from '@/views/preference/CertSettings.vue'
  16. const data = ref<Settings>({
  17. app: {
  18. page_size: 10,
  19. jwt_secret: '',
  20. },
  21. server: {
  22. host: '0.0.0.0',
  23. port: 9000,
  24. run_mode: 'debug',
  25. },
  26. database: {
  27. name: '',
  28. },
  29. auth: {
  30. ip_white_list: [],
  31. ban_threshold_minutes: 10,
  32. max_attempts: 10,
  33. },
  34. casdoor: {
  35. endpoint: '',
  36. client_id: '',
  37. client_secret: '',
  38. certificate_path: '',
  39. organization: '',
  40. application: '',
  41. redirect_uri: '',
  42. },
  43. cert: {
  44. email: '',
  45. ca_dir: '',
  46. renewal_interval: 7,
  47. recursive_nameservers: [],
  48. http_challenge_port: '9180',
  49. },
  50. http: {
  51. github_proxy: '',
  52. insecure_skip_verify: false,
  53. },
  54. logrotate: {
  55. enabled: false,
  56. cmd: '',
  57. interval: 1440,
  58. },
  59. nginx: {
  60. access_log_path: '',
  61. error_log_path: '',
  62. config_dir: '',
  63. log_dir_white_list: [],
  64. pid_path: '',
  65. reload_cmd: '',
  66. restart_cmd: '',
  67. },
  68. node: {
  69. name: '',
  70. secret: '',
  71. },
  72. openai: {
  73. model: '',
  74. base_url: '',
  75. proxy: '',
  76. token: '',
  77. },
  78. terminal: {
  79. start_cmd: '',
  80. },
  81. webauthn: {
  82. rp_display_name: '',
  83. rpid: '',
  84. rp_origins: [],
  85. },
  86. })
  87. settings.get().then(r => {
  88. data.value = r
  89. })
  90. const settingsStore = useSettingsStore()
  91. const { server_name } = storeToRefs(settingsStore)
  92. const errors = ref({}) as Ref<Record<string, Record<string, string>>>
  93. const refAuthSettings = ref()
  94. async function save() {
  95. // fix type
  96. data.value.cert.http_challenge_port = data.value.cert.http_challenge_port.toString()
  97. const otpModal = use2FAModal()
  98. otpModal.open().then(() => {
  99. settings.save(data.value).then(r => {
  100. if (!settingsStore.is_remote)
  101. server_name.value = r?.server?.name ?? ''
  102. data.value = r
  103. refAuthSettings.value?.getBannedIPs?.()
  104. message.success($gettext('Save successfully'))
  105. errors.value = {}
  106. }).catch(e => {
  107. errors.value = e.errors
  108. message.error(e?.message ?? $gettext('Server error'))
  109. })
  110. })
  111. }
  112. provide('data', data)
  113. provide('errors', errors)
  114. const router = useRouter()
  115. const route = useRoute()
  116. const activeKey = ref('basic')
  117. watch(activeKey, () => {
  118. router.push({
  119. query: {
  120. tab: activeKey.value,
  121. },
  122. })
  123. })
  124. onMounted(() => {
  125. if (route.query?.tab)
  126. activeKey.value = route.query.tab.toString()
  127. })
  128. </script>
  129. <template>
  130. <ACard :title="$gettext('Preference')">
  131. <div class="preference-container">
  132. <ATabs v-model:active-key="activeKey">
  133. <ATabPane
  134. key="basic"
  135. :tab="$gettext('Basic')"
  136. >
  137. <BasicSettings />
  138. </ATabPane>
  139. <ATabPane
  140. key="auth"
  141. :tab="$gettext('Auth')"
  142. >
  143. <AuthSettings ref="refAuthSettings" />
  144. </ATabPane>
  145. <ATabPane
  146. key="cert"
  147. :tab="$gettext('Cert')"
  148. >
  149. <CertSettings />
  150. </ATabPane>
  151. <ATabPane
  152. key="nginx"
  153. :tab="$gettext('Nginx')"
  154. >
  155. <NginxSettings />
  156. </ATabPane>
  157. <ATabPane
  158. key="openai"
  159. :tab="$gettext('OpenAI')"
  160. >
  161. <OpenAISettings />
  162. </ATabPane>
  163. <ATabPane
  164. key="logrotate"
  165. :tab="$gettext('Logrotate')"
  166. >
  167. <LogrotateSettings />
  168. </ATabPane>
  169. </ATabs>
  170. </div>
  171. <FooterToolBar>
  172. <AButton
  173. type="primary"
  174. @click="save"
  175. >
  176. {{ $gettext('Save') }}
  177. </AButton>
  178. </FooterToolBar>
  179. </ACard>
  180. </template>
  181. <style lang="less" scoped>
  182. .preference-container {
  183. width: 100%;
  184. max-width: 600px;
  185. margin: 0 auto;
  186. padding: 0 10px;
  187. }
  188. </style>