index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div class="p-4">
  3. <el-card shadow="never">
  4. <template #header>
  5. <div class="card-header">
  6. <span class="card-title">TextIn 配置</span>
  7. <span class="card-subtitle">配置 TextIn API 的认证信息</span>
  8. </div>
  9. </template>
  10. <el-form
  11. ref="textinFormRef"
  12. :model="form"
  13. :rules="rules"
  14. label-width="150px"
  15. class="textin-form"
  16. v-loading="loading"
  17. >
  18. <el-form-item label="x-ti-app-id" prop="appId">
  19. <el-input
  20. v-model="form.appId"
  21. placeholder="请输入 x-ti-app-id"
  22. clearable
  23. maxlength="100"
  24. show-word-limit
  25. />
  26. <div class="form-tip">用于 TextIn API 认证的应用 ID</div>
  27. </el-form-item>
  28. <el-form-item label="x-ti-secret-code" prop="secretCode">
  29. <el-input
  30. v-model="form.secretCode"
  31. placeholder="请输入 x-ti-secret-code"
  32. clearable
  33. maxlength="100"
  34. show-word-limit
  35. type="password"
  36. show-password
  37. />
  38. <div class="form-tip">用于 TextIn API 认证的密钥</div>
  39. </el-form-item>
  40. <el-form-item>
  41. <el-button type="primary" @click="handleSave" :loading="saving" v-hasPermi="['setting:textin:edit']">
  42. <el-icon><Check /></el-icon>
  43. 保存配置
  44. </el-button>
  45. </el-form-item>
  46. </el-form>
  47. </el-card>
  48. </div>
  49. </template>
  50. <script setup name="Textin" lang="ts">
  51. import { getTextinConfig, updateTextinConfig } from '@/api/setting/textin';
  52. import { TextinForm } from '@/api/setting/textin/types';
  53. import { Check } from '@element-plus/icons-vue';
  54. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  55. const textinFormRef = ref<ElFormInstance>();
  56. const loading = ref(false);
  57. const saving = ref(false);
  58. const initFormData: TextinForm = {
  59. id: undefined,
  60. appId: undefined,
  61. secretCode: undefined,
  62. };
  63. const form = ref<TextinForm>({ ...initFormData });
  64. const rules = reactive({
  65. appId: [
  66. { required: true, message: '请输入 App ID', trigger: 'blur' }
  67. ],
  68. secretCode: [
  69. { required: true, message: '请输入 Secret Code', trigger: 'blur' }
  70. ]
  71. });
  72. /** 获取配置 */
  73. const getConfig = async () => {
  74. loading.value = true;
  75. try {
  76. const res = await getTextinConfig();
  77. form.value = { ...res.data };
  78. } catch (error) {
  79. console.error('获取配置失败:', error);
  80. proxy?.$modal.msgError('获取配置失败');
  81. } finally {
  82. loading.value = false;
  83. }
  84. };
  85. /** 保存配置 */
  86. const handleSave = () => {
  87. textinFormRef.value?.validate(async (valid: boolean) => {
  88. if (valid) {
  89. saving.value = true;
  90. try {
  91. await updateTextinConfig(form.value);
  92. proxy?.$modal.msgSuccess('保存成功');
  93. } catch (error) {
  94. console.error('保存失败:', error);
  95. proxy?.$modal.msgError('保存失败');
  96. } finally {
  97. saving.value = false;
  98. }
  99. }
  100. });
  101. };
  102. onMounted(() => {
  103. getConfig();
  104. });
  105. </script>
  106. <style scoped lang="scss">
  107. .card-header {
  108. display: flex;
  109. flex-direction: column;
  110. gap: 4px;
  111. .card-title {
  112. font-size: 16px;
  113. font-weight: 600;
  114. color: #303133;
  115. }
  116. .card-subtitle {
  117. font-size: 13px;
  118. color: #909399;
  119. }
  120. }
  121. .textin-form {
  122. max-width: 800px;
  123. margin-top: 20px;
  124. .form-tip {
  125. font-size: 12px;
  126. color: #909399;
  127. margin-top: 4px;
  128. line-height: 1.5;
  129. }
  130. :deep(.el-form-item__content) {
  131. flex-direction: column;
  132. align-items: flex-start;
  133. }
  134. }
  135. </style>