SettingsModal.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <div v-if="isVisible" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
  3. <div class="bg-white rounded-lg p-6 max-w-2xl w-full mx-4 max-h-[90vh] overflow-y-auto">
  4. <div class="flex justify-between items-center mb-6">
  5. <h2 class="text-2xl font-bold text-gray-800">系统设置</h2>
  6. <button @click="closeModal" class="text-gray-500 hover:text-gray-700">
  7. <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  8. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
  9. </svg>
  10. </button>
  11. </div>
  12. <div class="space-y-8">
  13. <!-- 302.ai 推荐广告 -->
  14. <div class="hidden bg-gradient-to-r from-blue-50 to-purple-50 border-2 border-blue-200 rounded-lg p-4">
  15. <div class="flex items-start gap-4">
  16. <div class="flex-shrink-0">
  17. <div class="w-12 h-12 bg-gradient-to-br from-blue-500 to-purple-600 rounded-lg flex items-center justify-center">
  18. <span class="text-white text-lg font-bold">302</span>
  19. </div>
  20. </div>
  21. <div class="flex-1">
  22. <div class="flex items-center gap-2 mb-2">
  23. <h3 class="text-lg font-semibold text-gray-800">🚀 推荐API服务商</h3>
  24. </div>
  25. <p class="text-sm text-gray-600 mb-3">
  26. 本项目正在使用 <strong>302.ai</strong> 提供的高质量AI API服务。302.ai 提供稳定可靠的AI模型接口,支持多种主流大模型,价格优惠,服务稳定。
  27. </p>
  28. <div class="flex flex-wrap gap-2 mb-3">
  29. <span class="bg-green-100 text-green-800 text-xs px-2 py-1 rounded">✓ 多模型支持</span>
  30. <span class="bg-green-100 text-green-800 text-xs px-2 py-1 rounded">✓ 价格优惠</span>
  31. <span class="bg-green-100 text-green-800 text-xs px-2 py-1 rounded">✓ 服务稳定</span>
  32. <span class="bg-green-100 text-green-800 text-xs px-2 py-1 rounded">✓ 快速接入</span>
  33. </div>
  34. <a
  35. href="https://302.ai/"
  36. target="_blank"
  37. class="inline-flex items-center gap-2 bg-blue-500 hover:bg-blue-600 text-white text-sm px-4 py-2 rounded-lg transition-colors"
  38. >
  39. <span>访问 302.ai</span>
  40. <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  41. <path
  42. stroke-linecap="round"
  43. stroke-linejoin="round"
  44. stroke-width="2"
  45. d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"
  46. ></path>
  47. </svg>
  48. </a>
  49. </div>
  50. </div>
  51. </div>
  52. <!-- 菜谱生成模型配置 -->
  53. <div class="border rounded-lg p-4">
  54. <h3 class="text-lg font-semibold text-gray-800 mb-4 flex items-center">
  55. <svg class="w-5 h-5 mr-2 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  56. <path
  57. stroke-linecap="round"
  58. stroke-linejoin="round"
  59. stroke-width="2"
  60. d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"
  61. ></path>
  62. </svg>
  63. 菜谱生成模型配置
  64. </h3>
  65. <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
  66. <div>
  67. <label class="block text-sm font-medium text-gray-700 mb-1">API地址</label>
  68. <input
  69. v-model="textConfig.baseUrl"
  70. type="text"
  71. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
  72. placeholder="https://api.example.com/v1/"
  73. />
  74. </div>
  75. <div>
  76. <label class="block text-sm font-medium text-gray-700 mb-1">API密钥</label>
  77. <input
  78. v-model="textConfig.apiKey"
  79. type="password"
  80. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
  81. placeholder="输入API密钥"
  82. />
  83. </div>
  84. <div>
  85. <label class="block text-sm font-medium text-gray-700 mb-1">模型名称</label>
  86. <input
  87. v-model="textConfig.model"
  88. type="text"
  89. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
  90. placeholder="yi-lightning"
  91. />
  92. </div>
  93. <div>
  94. <label class="block text-sm font-medium text-gray-700 mb-1">温度参数 (0-1)</label>
  95. <input
  96. v-model.number="textConfig.temperature"
  97. type="number"
  98. min="0"
  99. max="1"
  100. step="0.1"
  101. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
  102. />
  103. </div>
  104. <div class="md:col-span-2">
  105. <label class="block text-sm font-medium text-gray-700 mb-1">超时时间 (毫秒)</label>
  106. <input
  107. v-model.number="textConfig.timeout"
  108. type="number"
  109. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
  110. placeholder="300000"
  111. />
  112. </div>
  113. </div>
  114. </div>
  115. <!-- 图片生成模型配置 -->
  116. <div class="border rounded-lg p-4">
  117. <h3 class="text-lg font-semibold text-gray-800 mb-4 flex items-center">
  118. <svg class="w-5 h-5 mr-2 text-green-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  119. <path
  120. stroke-linecap="round"
  121. stroke-linejoin="round"
  122. stroke-width="2"
  123. d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"
  124. ></path>
  125. </svg>
  126. 图片生成模型配置
  127. </h3>
  128. <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
  129. <div>
  130. <label class="block text-sm font-medium text-gray-700 mb-1">API地址</label>
  131. <input
  132. v-model="imageConfig.baseUrl"
  133. type="text"
  134. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-green-500"
  135. placeholder="https://api.example.com/v4/"
  136. />
  137. </div>
  138. <div>
  139. <label class="block text-sm font-medium text-gray-700 mb-1">API密钥</label>
  140. <input
  141. v-model="imageConfig.apiKey"
  142. type="password"
  143. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-green-500"
  144. placeholder="输入API密钥"
  145. />
  146. </div>
  147. <div class="md:col-span-2">
  148. <label class="block text-sm font-medium text-gray-700 mb-1">模型名称</label>
  149. <input
  150. v-model="imageConfig.model"
  151. type="text"
  152. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-green-500"
  153. placeholder="cogview-3-flash"
  154. />
  155. </div>
  156. </div>
  157. </div>
  158. </div>
  159. <!-- 操作按钮 -->
  160. <div class="flex justify-end space-x-3 mt-8 pt-4 border-t">
  161. <button @click="resetToDefault" class="px-4 py-2 text-gray-600 border border-gray-300 rounded-md hover:bg-gray-50 transition-colors">恢复默认</button>
  162. <button @click="closeModal" class="px-4 py-2 text-gray-600 border border-gray-300 rounded-md hover:bg-gray-50 transition-colors">取消</button>
  163. <button @click="saveSettings" class="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 transition-colors">保存设置</button>
  164. </div>
  165. </div>
  166. </div>
  167. </template>
  168. <script setup>
  169. import { ref, reactive, watch } from 'vue'
  170. import { useSettingsStore } from '../stores/settings'
  171. const props = defineProps({
  172. isVisible: {
  173. type: Boolean,
  174. default: false
  175. }
  176. })
  177. const emit = defineEmits(['close', 'save'])
  178. const settingsStore = useSettingsStore()
  179. // 文本生成配置
  180. const textConfig = reactive({
  181. baseUrl: '',
  182. apiKey: '',
  183. model: '',
  184. temperature: 0.7,
  185. timeout: 300000
  186. })
  187. // 图片生成配置
  188. const imageConfig = reactive({
  189. baseUrl: '',
  190. apiKey: '',
  191. model: ''
  192. })
  193. // 监听弹窗显示状态,加载当前配置
  194. watch(
  195. () => props.isVisible,
  196. visible => {
  197. if (visible) {
  198. loadCurrentSettings()
  199. }
  200. }
  201. )
  202. // 加载当前设置
  203. const loadCurrentSettings = () => {
  204. const settings = settingsStore.getSettings()
  205. // 加载文本生成配置
  206. textConfig.baseUrl = settings.textGeneration.baseUrl
  207. textConfig.apiKey = settings.textGeneration.apiKey
  208. textConfig.model = settings.textGeneration.model
  209. textConfig.temperature = settings.textGeneration.temperature
  210. textConfig.timeout = settings.textGeneration.timeout
  211. // 加载图片生成配置
  212. imageConfig.baseUrl = settings.imageGeneration.baseUrl
  213. imageConfig.apiKey = settings.imageGeneration.apiKey
  214. imageConfig.model = settings.imageGeneration.model
  215. }
  216. // 保存设置
  217. const saveSettings = () => {
  218. const newSettings = {
  219. textGeneration: {
  220. baseUrl: textConfig.baseUrl,
  221. apiKey: textConfig.apiKey,
  222. model: textConfig.model,
  223. temperature: textConfig.temperature,
  224. timeout: textConfig.timeout
  225. },
  226. imageGeneration: {
  227. baseUrl: imageConfig.baseUrl,
  228. apiKey: imageConfig.apiKey,
  229. model: imageConfig.model
  230. }
  231. }
  232. settingsStore.updateSettings(newSettings)
  233. emit('save')
  234. closeModal()
  235. }
  236. // 恢复默认设置
  237. const resetToDefault = () => {
  238. settingsStore.resetToDefault()
  239. loadCurrentSettings()
  240. }
  241. // 关闭弹窗
  242. const closeModal = () => {
  243. emit('close')
  244. }
  245. </script>