Preference.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 '@/views/preference/typedef'
  11. import LogrotateSettings from '@/views/preference/LogrotateSettings.vue'
  12. import { useSettingsStore } from '@/pinia'
  13. const data = ref<Settings>({
  14. server: {
  15. http_host: '0.0.0.0',
  16. http_port: '9000',
  17. run_mode: 'debug',
  18. jwt_secret: '',
  19. start_cmd: '',
  20. email: '',
  21. http_challenge_port: '9180',
  22. github_proxy: '',
  23. ca_dir: '',
  24. node_secret: '',
  25. cert_renewal_interval: 7,
  26. recursive_nameservers: [],
  27. name: '',
  28. },
  29. nginx: {
  30. access_log_path: '',
  31. error_log_path: '',
  32. config_dir: '',
  33. pid_path: '',
  34. reload_cmd: '',
  35. restart_cmd: '',
  36. },
  37. openai: {
  38. model: '',
  39. base_url: '',
  40. proxy: '',
  41. token: '',
  42. },
  43. logrotate: {
  44. enabled: false,
  45. cmd: '',
  46. interval: 1440,
  47. },
  48. })
  49. settings.get().then(r => {
  50. data.value = r
  51. })
  52. const settingsStore = useSettingsStore()
  53. const { server_name } = storeToRefs(settingsStore)
  54. const errors = ref({}) as Ref<Record<string, Record<string, string>>>
  55. async function save() {
  56. // fix type
  57. data.value.server.http_challenge_port = data.value.server.http_challenge_port.toString()
  58. settings.save(data.value).then(r => {
  59. if (!settingsStore.is_remote)
  60. server_name.value = r?.server?.name ?? ''
  61. data.value = r
  62. message.success($gettext('Save successfully'))
  63. errors.value = {}
  64. }).catch(e => {
  65. errors.value = e.errors
  66. message.error(e?.message ?? $gettext('Server error'))
  67. })
  68. }
  69. provide('data', data)
  70. provide('errors', errors)
  71. const router = useRouter()
  72. const route = useRoute()
  73. const activeKey = ref('basic')
  74. watch(activeKey, () => {
  75. router.push({
  76. query: {
  77. tab: activeKey.value,
  78. },
  79. })
  80. })
  81. onMounted(() => {
  82. if (route.query?.tab)
  83. activeKey.value = route.query.tab.toString()
  84. })
  85. </script>
  86. <template>
  87. <ACard :title="$gettext('Preference')">
  88. <div class="preference-container">
  89. <ATabs v-model:activeKey="activeKey">
  90. <ATabPane
  91. key="basic"
  92. :tab="$gettext('Basic')"
  93. >
  94. <BasicSettings />
  95. </ATabPane>
  96. <ATabPane
  97. key="nginx"
  98. :tab="$gettext('Nginx')"
  99. >
  100. <NginxSettings />
  101. </ATabPane>
  102. <ATabPane
  103. key="openai"
  104. :tab="$gettext('OpenAI')"
  105. >
  106. <OpenAISettings />
  107. </ATabPane>
  108. <ATabPane
  109. key="logrotate"
  110. :tab="$gettext('Logrotate')"
  111. >
  112. <LogrotateSettings />
  113. </ATabPane>
  114. </ATabs>
  115. </div>
  116. <FooterToolBar>
  117. <AButton
  118. type="primary"
  119. @click="save"
  120. >
  121. {{ $gettext('Save') }}
  122. </AButton>
  123. </FooterToolBar>
  124. </ACard>
  125. </template>
  126. <style lang="less" scoped>
  127. .preference-container {
  128. width: 100%;
  129. max-width: 600px;
  130. margin: 0 auto;
  131. padding: 0 10px;
  132. }
  133. </style>