RightSettings.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <script setup lang="ts">
  2. import { Modal, message } from 'ant-design-vue'
  3. import type { Ref } from 'vue'
  4. import type { Site } from '@/api/domain'
  5. import domain from '@/api/domain'
  6. import ChatGPT from '@/components/ChatGPT/ChatGPT.vue'
  7. import { formatDateTime } from '@/lib/helper'
  8. import Deploy from '@/views/domain/components/Deploy.vue'
  9. import { useSettingsStore } from '@/pinia'
  10. import type { ChatComplicationMessage } from '@/api/openai'
  11. import type { NgxConfig } from '@/api/ngx'
  12. import type { CheckedType } from '@/types'
  13. const settings = useSettingsStore()
  14. const configText = inject('configText') as Ref<string>
  15. const ngx_config = inject('ngx_config') as Ref<NgxConfig>
  16. const enabled = inject('enabled') as Ref<boolean>
  17. const name = inject('name') as Ref<string>
  18. const history_chatgpt_record = inject('history_chatgpt_record') as Ref<ChatComplicationMessage[]>
  19. const filename = inject('filename') as Ref<string | number | undefined>
  20. const data = inject('data') as Ref<Site>
  21. const [modal, ContextHolder] = Modal.useModal()
  22. const active_key = ref(['1', '2', '3'])
  23. function enable() {
  24. domain.enable(name.value).then(() => {
  25. message.success($gettext('Enabled successfully'))
  26. enabled.value = true
  27. }).catch(r => {
  28. message.error($gettext('Failed to enable %{msg}', { msg: r.message ?? '' }), 10)
  29. })
  30. }
  31. function disable() {
  32. domain.disable(name.value).then(() => {
  33. message.success($gettext('Disabled successfully'))
  34. enabled.value = false
  35. }).catch(r => {
  36. message.error($gettext('Failed to disable %{msg}', { msg: r.message ?? '' }))
  37. })
  38. }
  39. function on_change_enabled(checked: CheckedType) {
  40. modal.confirm({
  41. title: checked ? $gettext('Do you want to enable this site?') : $gettext('Do you want to disable this site?'),
  42. mask: false,
  43. centered: true,
  44. okText: $gettext('OK'),
  45. cancelText: $gettext('Cancel'),
  46. async onOk() {
  47. if (checked)
  48. enable()
  49. else
  50. disable()
  51. },
  52. })
  53. }
  54. </script>
  55. <template>
  56. <ACard
  57. class="right-settings"
  58. :bordered="false"
  59. >
  60. <ContextHolder />
  61. <ACollapse
  62. v-model:activeKey="active_key"
  63. ghost
  64. >
  65. <ACollapsePanel
  66. key="1"
  67. :header="$gettext('Basic')"
  68. >
  69. <AFormItem :label="$gettext('Enabled')">
  70. <ASwitch
  71. :checked="enabled"
  72. @change="on_change_enabled"
  73. />
  74. </AFormItem>
  75. <AFormItem :label="$gettext('Name')">
  76. <AInput v-model:value="filename" />
  77. </AFormItem>
  78. <AFormItem :label="$gettext('Updated at')">
  79. {{ formatDateTime(data.modified_at) }}
  80. </AFormItem>
  81. </ACollapsePanel>
  82. <ACollapsePanel
  83. v-if="!settings.is_remote"
  84. key="2"
  85. :header="$gettext('Deploy')"
  86. >
  87. <Deploy />
  88. </ACollapsePanel>
  89. <ACollapsePanel
  90. key="3"
  91. header="ChatGPT"
  92. >
  93. <ChatGPT
  94. v-model:history-messages="history_chatgpt_record"
  95. :content="configText"
  96. :path="ngx_config.file_name"
  97. />
  98. </ACollapsePanel>
  99. </ACollapse>
  100. </ACard>
  101. </template>
  102. <style scoped lang="less">
  103. .right-settings {
  104. position: sticky;
  105. top: 78px;
  106. :deep(.ant-card-body) {
  107. max-height: 100vh;
  108. overflow-y: scroll;
  109. }
  110. }
  111. :deep(.ant-collapse-ghost > .ant-collapse-item > .ant-collapse-content > .ant-collapse-content-box) {
  112. padding: 0;
  113. }
  114. :deep(.ant-collapse > .ant-collapse-item > .ant-collapse-header) {
  115. padding: 0 0 10px 0;
  116. }
  117. </style>