index.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <script setup lang="ts">
  2. import { Plus } from '@element-plus/icons-vue'
  3. import { ElButton, ElDialog, ElEmpty, ElInput, ElMessage, ElOption, ElPagination, ElSelect, ElTable, ElTableColumn, ElTag } from 'element-plus'
  4. import { selectGlobalPrompt, updateGlobalPrompt } from '@/api/modules/model'
  5. import { toast } from 'vue-sonner'
  6. import LangSelector from '@/components/LangSelector.vue'
  7. const loading = ref(false)
  8. const input = ref<string>('')
  9. const lang = ref<string>('zh_CN')
  10. async function fetchData() {
  11. if(!lang.value.length){
  12. return;
  13. }
  14. loading.value = true
  15. try{
  16. const {code, data} = await selectGlobalPrompt({i18nKey: lang.value})
  17. if(code === 0){
  18. input.value = data
  19. }
  20. }finally{
  21. loading.value = false
  22. }
  23. }
  24. async function handleSave () {
  25. if(!lang.value.length){
  26. return;
  27. }
  28. const {code, data} = await updateGlobalPrompt({i18nKey: lang.value, text: input.value})
  29. if(code === 0){
  30. toast.success('保存成功')
  31. }
  32. }
  33. watch(()=> lang.value, ()=> {
  34. fetchData()
  35. }, {immediate: true})
  36. </script>
  37. <template>
  38. <div class="absolute-container">
  39. <FaPageHeader title="全局提示词" />
  40. <FaPageMain class="flex-1 overflow-auto" main-class="flex-1 flex flex-col overflow-auto">
  41. <div class="flex flex-col overflow-auto gap-4" v-loading="loading">
  42. <LangSelector v-model="lang"></LangSelector>
  43. <el-input
  44. v-model="input"
  45. style="width: 100%;"
  46. :autosize="{ minRows: 4, maxRows: 10 }"
  47. type="textarea"
  48. placeholder="Please input"
  49. class="mb-4"
  50. />
  51. <ElSpace>
  52. <ElButton type="primary" @click="handleSave">保存</ElButton>
  53. </ElSpace>
  54. </div>
  55. </FaPageMain>
  56. </div>
  57. </template>
  58. <style scoped>
  59. .absolute-container {
  60. position: absolute;
  61. display: flex;
  62. flex-direction: column;
  63. width: 100%;
  64. height: 100%;
  65. }
  66. </style>