TokenManager.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <div class="token-page">
  3. <div class="top-bar">
  4. <el-button type="info" plain @click="goBack">返回首页</el-button>
  5. </div>
  6. <el-card class="token-card">
  7. <h2>更新 Token / Cookie</h2>
  8. <el-form :model="form" label-width="100px">
  9. <el-form-item label="gh_id">
  10. <el-input v-model="form.gzh_id" placeholder="请输入公众号 ID" clearable />
  11. </el-form-item>
  12. <el-form-item label="Token">
  13. <el-input v-model="form.token" placeholder="请输入 Token" clearable />
  14. </el-form-item>
  15. <el-form-item label="Cookie">
  16. <el-input
  17. v-model="form.cookie"
  18. placeholder="请输入 Cookie"
  19. type="textarea"
  20. rows="4"
  21. clearable
  22. />
  23. </el-form-item>
  24. <el-form-item>
  25. <el-button type="primary" @click="onSave" :loading="loading" style="width: 120px">
  26. 保存
  27. </el-button>
  28. <el-button @click="onReset" :disabled="loading" style="width: 120px">
  29. 重置
  30. </el-button>
  31. </el-form-item>
  32. </el-form>
  33. </el-card>
  34. </div>
  35. </template>
  36. <script setup lang="ts">
  37. import { ref } from 'vue'
  38. import { useRouter } from 'vue-router'
  39. import { ElMessage } from 'element-plus'
  40. import axios from 'axios'
  41. import { API_CONFIG, API_ENDPOINTS } from '../config/api'
  42. const router = useRouter()
  43. interface TokenForm {
  44. gzh_id: string
  45. token: string
  46. cookie: string
  47. }
  48. const form = ref<TokenForm>({
  49. gzh_id: '',
  50. token: '',
  51. cookie: '',
  52. })
  53. const loading = ref(false)
  54. const onSave = async () => {
  55. if (!form.value.gzh_id || !form.value.token || !form.value.cookie) {
  56. ElMessage.warning('请填写完整信息(gh_id / Token / Cookie)')
  57. return
  58. }
  59. loading.value = true
  60. try {
  61. const res = await axios.post(`${API_CONFIG.BASE_URL}${API_ENDPOINTS.SAVE_TOKEN}`, {
  62. gzh_id: form.value.gzh_id,
  63. token: form.value.token,
  64. cookie: form.value.cookie,
  65. })
  66. if (res.data?.success) {
  67. ElMessage.success('更新成功')
  68. form.value = { gzh_id: '', token: '', cookie: '' }
  69. } else {
  70. ElMessage.error(res.data?.error || '更新失败')
  71. }
  72. } catch (err) {
  73. console.error('保存请求出错:', err)
  74. ElMessage.error('请求异常,请稍后重试')
  75. } finally {
  76. loading.value = false
  77. }
  78. }
  79. const onReset = () => {
  80. form.value = { gzh_id: '', token: '', cookie: '' }
  81. }
  82. const goBack = () => {
  83. router.push('/welcome')
  84. }
  85. </script>
  86. <style scoped>
  87. .token-page {
  88. background: linear-gradient(180deg, #f6f8fb, #e8ecf3);
  89. min-height: 100vh;
  90. display: flex;
  91. flex-direction: column;
  92. }
  93. .top-bar {
  94. padding: 12px 16px;
  95. background: #fff;
  96. border-bottom: 1px solid #f0f2f5;
  97. display: flex;
  98. justify-content: flex-start;
  99. }
  100. .token-card {
  101. width: 520px;
  102. margin: 80px auto 0;
  103. padding: 40px 30px 30px;
  104. box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
  105. border-radius: 14px;
  106. background: #fff;
  107. }
  108. h2 {
  109. text-align: center;
  110. font-size: 22px;
  111. margin-bottom: 30px;
  112. color: #333;
  113. font-weight: 600;
  114. }
  115. </style>