SettingsModal.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <div v-if="isVisible" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-2 md:p-4">
  3. <div class="bg-white rounded-lg max-w-2xl w-full max-h-[95vh] md:max-h-[90vh] flex flex-col">
  4. <!-- 固定头部 -->
  5. <div class="flex justify-between items-center p-4 md:p-6 pb-3 md:pb-4 border-b">
  6. <h2 class="text-xl md:text-2xl font-bold text-gray-800">系统设置</h2>
  7. <button @click="closeModal" class="text-gray-500 hover:text-gray-700">
  8. <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  9. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
  10. </svg>
  11. </button>
  12. </div>
  13. <!-- 可滚动内容区域 -->
  14. <div class="flex-1 overflow-y-auto px-4 md:px-6 py-3 md:py-4">
  15. <div class="space-y-4 md:space-y-6">
  16. <!-- 302.AI 推荐广告 -->
  17. <div class="bg-gradient-to-r from-blue-50 to-purple-50 border border-blue-200 rounded-lg p-3 md:p-4">
  18. <!-- 手机端:垂直布局,桌面端:水平布局 -->
  19. <div class="flex flex-col md:flex-row md:items-center gap-3">
  20. <div class="flex-shrink-0 flex justify-center md:justify-start">
  21. <div class="w-10 h-10 from-blue-500 to-purple-600 rounded-xl flex items-center justify-center">
  22. <img src="/logo.svg" alt="302.AI Logo" class="w-8 h-8 md:w-10 md:h-10" />
  23. </div>
  24. </div>
  25. <div class="flex-1 text-center md:text-left">
  26. <h3 class="text-sm md:text-base font-semibold text-gray-800 mb-1">🚀 推荐API服务商</h3>
  27. <p class="text-xs text-gray-600 mb-2 leading-relaxed">
  28. 本项目正在使用 <strong>302.AI</strong> 提供的高质量AI API服务!<strong>302.AI</strong>
  29. 是一个按用量付费的企业级AI资源平台,提供市场上最新、最全面的AI模型和API,以及多种开箱即用的在线AI应用
  30. </p>
  31. <div class="flex flex-col md:flex-row items-center gap-2">
  32. <div class="flex flex-wrap gap-1 justify-center md:justify-start">
  33. <span class="bg-green-100 text-green-800 text-xs px-2 py-0.5 rounded">✓ 多模型</span>
  34. <span class="bg-green-100 text-green-800 text-xs px-2 py-0.5 rounded">✓ 优惠</span>
  35. <span class="bg-green-100 text-green-800 text-xs px-2 py-0.5 rounded">✓ 稳定</span>
  36. </div>
  37. <a
  38. href="https://share.302.AI/DymMSI"
  39. target="_blank"
  40. class="inline-flex items-center gap-1 bg-blue-500 hover:bg-blue-600 text-white text-xs px-3 py-1 rounded transition-colors md:ml-auto"
  41. >
  42. <span>访问</span>
  43. <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  44. <path
  45. stroke-linecap="round"
  46. stroke-linejoin="round"
  47. stroke-width="2"
  48. d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"
  49. ></path>
  50. </svg>
  51. </a>
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. <!-- 菜谱生成模型配置 -->
  57. <div class="border rounded-lg">
  58. <button
  59. @click="isTextConfigExpanded = !isTextConfigExpanded"
  60. class="w-full p-3 md:p-4 flex items-center justify-between text-left hover:bg-gray-50 transition-colors"
  61. >
  62. <h3 class="text-base md:text-lg font-semibold text-gray-800 flex items-center">
  63. <svg class="w-4 h-4 md:w-5 md:h-5 mr-2 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  64. <path
  65. stroke-linecap="round"
  66. stroke-linejoin="round"
  67. stroke-width="2"
  68. 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"
  69. ></path>
  70. </svg>
  71. 菜谱生成模型配置
  72. </h3>
  73. <svg
  74. class="w-5 h-5 text-gray-500 transition-transform"
  75. :class="{ 'rotate-180': isTextConfigExpanded }"
  76. fill="none"
  77. stroke="currentColor"
  78. viewBox="0 0 24 24"
  79. >
  80. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
  81. </svg>
  82. </button>
  83. <div v-show="isTextConfigExpanded" class="px-3 md:px-4 pb-3 md:pb-4">
  84. <div class="space-y-3 md:space-y-4">
  85. <!-- API地址单独一行 -->
  86. <div>
  87. <label class="block text-sm font-medium text-gray-700 mb-1">API地址</label>
  88. <input
  89. v-model="textConfig.baseUrl"
  90. type="text"
  91. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
  92. placeholder="https://api.example.com/v1/"
  93. />
  94. <p class="text-xs text-gray-500 mt-1">基础API地址,系统会自动添加 /chat/completions 路径</p>
  95. </div>
  96. <!-- 其他配置项两列布局 -->
  97. <div class="grid grid-cols-1 md:grid-cols-2 gap-3 md:gap-4">
  98. <div>
  99. <label class="block text-sm font-medium text-gray-700 mb-1">API密钥</label>
  100. <input
  101. v-model="textConfig.apiKey"
  102. type="password"
  103. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
  104. placeholder="输入API密钥"
  105. />
  106. </div>
  107. <div>
  108. <label class="block text-sm font-medium text-gray-700 mb-1">模型名称</label>
  109. <input
  110. v-model="textConfig.model"
  111. type="text"
  112. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
  113. placeholder="yi-lightning"
  114. />
  115. </div>
  116. <div>
  117. <label class="block text-sm font-medium text-gray-700 mb-1">温度参数 (0-1)</label>
  118. <input
  119. v-model.number="textConfig.temperature"
  120. type="number"
  121. min="0"
  122. max="1"
  123. step="0.1"
  124. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
  125. />
  126. <p class="text-xs text-gray-500 mt-1">控制回答的创造性,0.7为推荐值</p>
  127. </div>
  128. <div>
  129. <label class="block text-sm font-medium text-gray-700 mb-1">超时时间 (毫秒)</label>
  130. <input
  131. v-model.number="textConfig.timeout"
  132. type="number"
  133. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
  134. placeholder="300000"
  135. />
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. </div>
  141. <!-- 图片生成模型配置 -->
  142. <div class="border rounded-lg">
  143. <button
  144. @click="isImageConfigExpanded = !isImageConfigExpanded"
  145. class="w-full p-3 md:p-4 flex items-center justify-between text-left hover:bg-gray-50 transition-colors"
  146. >
  147. <h3 class="text-base md:text-lg font-semibold text-gray-800 flex items-center">
  148. <svg class="w-4 h-4 md:w-5 md:h-5 mr-2 text-green-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  149. <path
  150. stroke-linecap="round"
  151. stroke-linejoin="round"
  152. stroke-width="2"
  153. 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"
  154. ></path>
  155. </svg>
  156. 图片生成模型配置
  157. </h3>
  158. <svg
  159. class="w-5 h-5 text-gray-500 transition-transform"
  160. :class="{ 'rotate-180': isImageConfigExpanded }"
  161. fill="none"
  162. stroke="currentColor"
  163. viewBox="0 0 24 24"
  164. >
  165. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
  166. </svg>
  167. </button>
  168. <div v-show="isImageConfigExpanded" class="px-3 md:px-4 pb-3 md:pb-4">
  169. <div class="space-y-3 md:space-y-4">
  170. <!-- API地址单独一行 -->
  171. <div>
  172. <label class="block text-sm font-medium text-gray-700 mb-1">API地址</label>
  173. <input
  174. v-model="imageConfig.baseUrl"
  175. type="text"
  176. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-green-500"
  177. placeholder="https://api.example.com/v4/images/generations"
  178. />
  179. <p class="text-xs text-gray-500 mt-1">图片生成API的完整地址,包含具体的端点路径</p>
  180. </div>
  181. <!-- 其他配置项两列布局 -->
  182. <div class="grid grid-cols-1 md:grid-cols-2 gap-3 md:gap-4">
  183. <div>
  184. <label class="block text-sm font-medium text-gray-700 mb-1">API密钥</label>
  185. <input
  186. v-model="imageConfig.apiKey"
  187. type="password"
  188. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-green-500"
  189. placeholder="输入API密钥"
  190. />
  191. </div>
  192. <div>
  193. <label class="block text-sm font-medium text-gray-700 mb-1">模型名称</label>
  194. <input
  195. v-model="imageConfig.model"
  196. type="text"
  197. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-green-500"
  198. placeholder="cogview-3-flash"
  199. />
  200. </div>
  201. </div>
  202. </div>
  203. </div>
  204. </div>
  205. </div>
  206. </div>
  207. <!-- 固定底部按钮 -->
  208. <div class="flex flex-col md:flex-row justify-end gap-2 md:gap-3 p-4 md:p-6 pt-3 md:pt-4 border-t bg-gray-50 rounded-b-lg">
  209. <button @click="resetToDefault" class="px-4 py-2 text-gray-600 border border-gray-300 rounded-md hover:bg-gray-50 transition-colors text-sm md:text-base">
  210. 恢复默认
  211. </button>
  212. <button @click="closeModal" class="px-4 py-2 text-gray-600 border border-gray-300 rounded-md hover:bg-gray-50 transition-colors text-sm md:text-base">取消</button>
  213. <button @click="saveSettings" class="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 transition-colors text-sm md:text-base">保存设置</button>
  214. </div>
  215. </div>
  216. </div>
  217. </template>
  218. <script setup>
  219. import { ref, reactive, watch } from 'vue'
  220. import { useSettingsStore } from '../stores/settings'
  221. const props = defineProps({
  222. isVisible: {
  223. type: Boolean,
  224. default: false
  225. }
  226. })
  227. const emit = defineEmits(['close', 'save'])
  228. const settingsStore = useSettingsStore()
  229. // 折叠状态
  230. const isTextConfigExpanded = ref(true) // 默认展开菜谱生成模型配置
  231. const isImageConfigExpanded = ref(false)
  232. // 文本生成配置
  233. const textConfig = reactive({
  234. baseUrl: '',
  235. apiKey: '',
  236. model: '',
  237. temperature: 0.7,
  238. timeout: 300000
  239. })
  240. // 图片生成配置
  241. const imageConfig = reactive({
  242. baseUrl: '',
  243. apiKey: '',
  244. model: ''
  245. })
  246. // 监听弹窗显示状态,加载当前配置并控制背景滚动
  247. watch(
  248. () => props.isVisible,
  249. visible => {
  250. if (visible) {
  251. loadCurrentSettings()
  252. // 阻止背景页面滚动
  253. document.body.style.overflow = 'hidden'
  254. } else {
  255. // 恢复背景页面滚动
  256. document.body.style.overflow = ''
  257. }
  258. }
  259. )
  260. // 加载当前设置
  261. const loadCurrentSettings = () => {
  262. const settings = settingsStore.getSettings()
  263. // 加载文本生成配置
  264. textConfig.baseUrl = settings.textGeneration.baseUrl
  265. textConfig.apiKey = settings.textGeneration.apiKey
  266. textConfig.model = settings.textGeneration.model
  267. textConfig.temperature = settings.textGeneration.temperature
  268. textConfig.timeout = settings.textGeneration.timeout
  269. // 加载图片生成配置
  270. imageConfig.baseUrl = settings.imageGeneration.baseUrl
  271. imageConfig.apiKey = settings.imageGeneration.apiKey
  272. imageConfig.model = settings.imageGeneration.model
  273. }
  274. // 保存设置
  275. const saveSettings = () => {
  276. const newSettings = {
  277. textGeneration: {
  278. baseUrl: textConfig.baseUrl,
  279. apiKey: textConfig.apiKey,
  280. model: textConfig.model,
  281. temperature: textConfig.temperature,
  282. timeout: textConfig.timeout
  283. },
  284. imageGeneration: {
  285. baseUrl: imageConfig.baseUrl,
  286. apiKey: imageConfig.apiKey,
  287. model: imageConfig.model
  288. }
  289. }
  290. settingsStore.updateSettings(newSettings)
  291. emit('save')
  292. closeModal()
  293. }
  294. // 恢复默认设置
  295. const resetToDefault = () => {
  296. settingsStore.resetToDefault()
  297. loadCurrentSettings()
  298. }
  299. // 关闭弹窗
  300. const closeModal = () => {
  301. emit('close')
  302. }
  303. </script>