SettingsModal.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <template>
  2. <div v-if="isVisible" class="fixed inset-0 bg-black bg-opacity-50 z-50">
  3. <!-- 轻提示 -->
  4. <div
  5. v-if="toast.show"
  6. class="fixed top-4 left-1/2 transform -translate-x-1/2 z-60 bg-white border border-gray-200 rounded-lg shadow-lg px-4 py-3 flex items-center gap-2 transition-all duration-300"
  7. >
  8. <svg v-if="toast.type === 'success'" class="w-5 h-5 text-green-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  9. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
  10. </svg>
  11. <svg v-if="toast.type === 'info'" class="w-5 h-5 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  12. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
  13. </svg>
  14. <span class="text-sm text-gray-700">{{ toast.message }}</span>
  15. </div>
  16. <div class="bg-white w-full h-full flex flex-col md:flex-row">
  17. <!-- 移动端:显示全局头部 -->
  18. <div class="md:hidden flex justify-between items-center px-4 py-3 border-b border-gray-200 bg-white flex-shrink-0">
  19. <h2 class="text-lg font-semibold text-gray-800">模型配置</h2>
  20. <button @click="closeModal" class="text-gray-400 hover:text-gray-600 p-1">
  21. <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  22. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
  23. </svg>
  24. </button>
  25. </div>
  26. <!-- 主要内容区域 -->
  27. <div class="flex-1 md:flex md:h-full overflow-hidden">
  28. <!-- 移动端:垂直滚动布局,PC端:左右布局 -->
  29. <div class="h-full md:flex md:w-full md:overflow-hidden">
  30. <!-- 移动端和PC端的统一滚动容器 -->
  31. <div class="h-full overflow-y-auto md:flex md:w-full md:h-full">
  32. <!-- 左侧:推荐广告区域 -->
  33. <div class="md:w-1/3 bg-gradient-to-br from-indigo-600 via-purple-600 to-pink-500 p-4 md:p-6 border-b md:border-b-0 md:border-r border-purple-300 md:flex-shrink-0 md:h-full relative overflow-hidden">
  34. <!-- 背景装饰 -->
  35. <div class="absolute inset-0 bg-gradient-to-br from-white/10 to-transparent"></div>
  36. <div class="absolute -top-10 -right-10 w-32 h-32 bg-white/5 rounded-full"></div>
  37. <div class="absolute -bottom-6 -left-6 w-24 h-24 bg-white/5 rounded-full"></div>
  38. <div class="relative z-10 md:h-full md:flex md:flex-col md:justify-center">
  39. <div class="text-center text-white">
  40. <!-- Logo区域 -->
  41. <div class="mb-4 md:mb-6">
  42. <div class="w-16 h-16 md:w-24 md:h-24 mx-auto mb-3 bg-white/20 backdrop-blur-sm rounded-2xl flex items-center justify-center border border-white/30 shadow-xl">
  43. <img src="/logo.svg" alt="302.AI Logo" class="w-12 h-12 md:w-16 md:h-16" />
  44. </div>
  45. <div class="inline-flex items-center gap-2 bg-white/20 backdrop-blur-sm px-3 py-1 rounded-full border border-white/30">
  46. <div class="w-2 h-2 bg-green-400 rounded-full animate-pulse"></div>
  47. <span class="text-xs font-medium">企业级AI资源平台</span>
  48. </div>
  49. </div>
  50. <!-- 主标题 -->
  51. <h3 class="text-lg md:text-2xl font-bold mb-2 md:mb-3">
  52. <span class="bg-gradient-to-r from-yellow-300 to-orange-300 bg-clip-text text-transparent">
  53. 🚀 推荐API服务商
  54. </span>
  55. </h3>
  56. <!-- 描述文字 -->
  57. <div class="mb-4 md:mb-6">
  58. <p class="text-sm md:text-base text-white/90 mb-3 leading-relaxed ">
  59. <strong class="text-yellow-300">302.AI</strong> 是一个按用量付费的企业级AI资源平台,提供市场上最新、最全面的AI模型和API,以及多种开箱即用的在线AI应用
  60. </p>
  61. <!-- 特色标签 -->
  62. <div class="flex flex-wrap gap-2 justify-center mb-4">
  63. <span class="bg-gradient-to-r from-green-400 to-emerald-500 text-white text-xs px-3 py-1 rounded-full font-medium shadow-lg">
  64. ✨ 最新模型
  65. </span>
  66. <span class="bg-gradient-to-r from-blue-400 to-cyan-500 text-white text-xs px-3 py-1 rounded-full font-medium shadow-lg">
  67. 💰 按量付费
  68. </span>
  69. <span class="bg-gradient-to-r from-purple-400 to-pink-500 text-white text-xs px-3 py-1 rounded-full font-medium shadow-lg">
  70. 🛡️ 企业级
  71. </span>
  72. </div>
  73. </div>
  74. <!-- 优势列表 -->
  75. <div class="hidden md:block mb-6">
  76. <div class="bg-white/10 backdrop-blur-sm rounded-xl p-4 border border-white/20">
  77. <div class="grid grid-cols-1 gap-3 text-left">
  78. <div class="flex items-center gap-3">
  79. <div class="w-6 h-6 bg-green-400 rounded-full flex items-center justify-center flex-shrink-0">
  80. <svg class="w-3 h-3 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  81. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"></path>
  82. </svg>
  83. </div>
  84. <span class="text-sm text-white/90">支持GPT、Claude、Gemini等主流模型</span>
  85. </div>
  86. <div class="flex items-center gap-3">
  87. <div class="w-6 h-6 bg-blue-400 rounded-full flex items-center justify-center flex-shrink-0">
  88. <svg class="w-3 h-3 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  89. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"></path>
  90. </svg>
  91. </div>
  92. <span class="text-sm text-white/90">0月费和按用量付费模式</span>
  93. </div>
  94. <div class="flex items-center gap-3">
  95. <div class="w-6 h-6 bg-purple-400 rounded-full flex items-center justify-center flex-shrink-0">
  96. <svg class="w-3 h-3 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  97. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"></path>
  98. </svg>
  99. </div>
  100. <span class="text-sm text-white/90">最新、最全面的AI模型和API</span>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. <!-- CTA按钮 -->
  106. <a
  107. href="https://share.302.AI/DymMSI"
  108. target="_blank"
  109. class="group inline-flex items-center gap-2 bg-gradient-to-r from-yellow-400 to-orange-500 hover:from-yellow-500 hover:to-orange-600 text-gray-900 px-6 py-3 md:px-8 md:py-4 rounded-xl font-bold transition-all duration-300 transform hover:scale-105 shadow-xl hover:shadow-2xl"
  110. >
  111. <span class="text-sm md:text-base">🎯 立即体验</span>
  112. <svg class="w-4 h-4 group-hover:translate-x-1 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  113. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 7l5 5m0 0l-5 5m5-5H6"></path>
  114. </svg>
  115. </a>
  116. <!-- 优惠提示 -->
  117. <div class="mt-3 md:mt-4">
  118. <div class="inline-flex items-center gap-2 bg-red-500/20 backdrop-blur-sm px-3 py-1 rounded-full border border-red-400/30">
  119. <span class="text-xs text-red-200 animate-pulse">🔥</span>
  120. <span class="text-xs text-red-200 font-medium">新用户专享优惠</span>
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. </div>
  126. <!-- 右侧:配置表单区域 -->
  127. <div class="md:flex-1 md:h-full md:flex md:flex-col p-4 md:p-0">
  128. <!-- PC端:右侧头部 -->
  129. <div class="hidden md:flex justify-between items-center px-6 py-4 border-b border-gray-200 bg-white flex-shrink-0">
  130. <h2 class="text-xl font-semibold text-gray-800">模型配置</h2>
  131. <button @click="closeModal" class="text-gray-400 hover:text-gray-600 p-1">
  132. <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  133. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
  134. </svg>
  135. </button>
  136. </div>
  137. <!-- 配置内容区域 - 可滚动 -->
  138. <div class="w-full space-y-6 md:flex-1 md:overflow-y-auto md:px-6 md:py-4 md:pr-8">
  139. <!-- 菜谱生成模型配置 -->
  140. <div class="bg-white border border-gray-200 rounded-lg p-4 md:p-6">
  141. <h3 class="text-lg font-semibold text-gray-800 flex items-center mb-4">
  142. <svg class="w-5 h-5 mr-3 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  143. <path
  144. stroke-linecap="round"
  145. stroke-linejoin="round"
  146. stroke-width="2"
  147. 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"
  148. ></path>
  149. </svg>
  150. 菜谱生成模型配置
  151. </h3>
  152. <div class="space-y-4">
  153. <!-- API地址 -->
  154. <div>
  155. <label class="block text-sm font-medium text-gray-700 mb-2">API地址</label>
  156. <input
  157. v-model="textConfig.baseUrl"
  158. type="text"
  159. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 text-sm"
  160. placeholder="https://api.example.com/v1/"
  161. />
  162. <p class="text-xs text-gray-500 mt-1">基础API地址,系统会自动添加 /chat/completions 路径</p>
  163. </div>
  164. <!-- 配置项网格 -->
  165. <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
  166. <div>
  167. <label class="block text-sm font-medium text-gray-700 mb-2">API密钥</label>
  168. <input
  169. v-model="textConfig.apiKey"
  170. type="password"
  171. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 text-sm"
  172. placeholder="输入API密钥"
  173. />
  174. </div>
  175. <div>
  176. <label class="block text-sm font-medium text-gray-700 mb-2">模型名称</label>
  177. <input
  178. v-model="textConfig.model"
  179. type="text"
  180. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 text-sm"
  181. placeholder="yi-lightning"
  182. />
  183. </div>
  184. <div>
  185. <label class="block text-sm font-medium text-gray-700 mb-2">温度参数 (0-1)</label>
  186. <input
  187. v-model.number="textConfig.temperature"
  188. type="number"
  189. min="0"
  190. max="1"
  191. step="0.1"
  192. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 text-sm"
  193. />
  194. <p class="text-xs text-gray-500 mt-1">控制回答的创造性,0.7为推荐值</p>
  195. </div>
  196. <div>
  197. <label class="block text-sm font-medium text-gray-700 mb-2">超时时间 (毫秒)</label>
  198. <input
  199. v-model.number="textConfig.timeout"
  200. type="number"
  201. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 text-sm"
  202. placeholder="300000"
  203. />
  204. </div>
  205. </div>
  206. </div>
  207. </div>
  208. <!-- 图片生成模型配置 -->
  209. <div class="bg-white border border-gray-200 rounded-lg p-4 md:p-6">
  210. <h3 class="text-lg font-semibold text-gray-800 flex items-center mb-4">
  211. <svg class="w-5 h-5 mr-3 text-green-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  212. <path
  213. stroke-linecap="round"
  214. stroke-linejoin="round"
  215. stroke-width="2"
  216. 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"
  217. ></path>
  218. </svg>
  219. 图片生成模型配置
  220. </h3>
  221. <div class="space-y-4">
  222. <!-- API地址 -->
  223. <div>
  224. <label class="block text-sm font-medium text-gray-700 mb-2">API地址</label>
  225. <input
  226. v-model="imageConfig.baseUrl"
  227. type="text"
  228. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-green-500 text-sm"
  229. placeholder="https://api.example.com/v4/images/generations"
  230. />
  231. <p class="text-xs text-gray-500 mt-1">图片生成API的完整地址,包含具体的端点路径</p>
  232. </div>
  233. <!-- 配置项网格 -->
  234. <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
  235. <div>
  236. <label class="block text-sm font-medium text-gray-700 mb-2">API密钥</label>
  237. <input
  238. v-model="imageConfig.apiKey"
  239. type="password"
  240. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-green-500 text-sm"
  241. placeholder="输入API密钥"
  242. />
  243. </div>
  244. <div>
  245. <label class="block text-sm font-medium text-gray-700 mb-2">模型名称</label>
  246. <input
  247. v-model="imageConfig.model"
  248. type="text"
  249. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-green-500 text-sm"
  250. placeholder="cogview-3-flash"
  251. />
  252. </div>
  253. </div>
  254. </div>
  255. </div>
  256. </div>
  257. <!-- PC端:右侧区域底部按钮 -->
  258. <div class="hidden md:flex justify-end gap-3 px-6 py-4 border-t border-gray-200 bg-gray-50 flex-shrink-0">
  259. <button @click="resetToDefault" class="px-4 py-2 text-gray-600 border border-gray-300 rounded hover:bg-gray-100 transition-colors text-sm">恢复默认</button>
  260. <button @click="saveSettings" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors text-sm">保存设置</button>
  261. </div>
  262. </div>
  263. </div>
  264. </div>
  265. </div>
  266. <!-- 移动端:固定底部按钮 -->
  267. <div class="md:hidden flex justify-end gap-3 px-4 py-3 border-t border-gray-200 bg-gray-50 flex-shrink-0">
  268. <button @click="resetToDefault" class="px-4 py-2 text-gray-600 border border-gray-300 rounded hover:bg-gray-100 transition-colors text-sm">恢复默认</button>
  269. <button @click="saveSettings" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors text-sm">保存设置</button>
  270. </div>
  271. </div>
  272. </div>
  273. </template>
  274. <script setup>
  275. import { ref, reactive, watch } from 'vue'
  276. import { useSettingsStore } from '../stores/settings'
  277. const props = defineProps({
  278. isVisible: {
  279. type: Boolean,
  280. default: false
  281. }
  282. })
  283. const emit = defineEmits(['close', 'save'])
  284. const settingsStore = useSettingsStore()
  285. // 配置状态管理
  286. // 轻提示状态
  287. const toast = reactive({
  288. show: false,
  289. message: '',
  290. type: 'success' // 'success' | 'info'
  291. })
  292. // 显示提示
  293. const showToast = (message, type = 'success') => {
  294. toast.message = message
  295. toast.type = type
  296. toast.show = true
  297. // 2秒后自动隐藏
  298. setTimeout(() => {
  299. toast.show = false
  300. }, 2000)
  301. }
  302. // 文本生成配置
  303. const textConfig = reactive({
  304. baseUrl: '',
  305. apiKey: '',
  306. model: '',
  307. temperature: 0.7,
  308. timeout: 300000
  309. })
  310. // 图片生成配置
  311. const imageConfig = reactive({
  312. baseUrl: '',
  313. apiKey: '',
  314. model: ''
  315. })
  316. // 监听弹窗显示状态,加载当前配置并控制背景滚动
  317. watch(
  318. () => props.isVisible,
  319. visible => {
  320. if (visible) {
  321. loadCurrentSettings()
  322. // 阻止背景页面滚动
  323. document.body.style.overflow = 'hidden'
  324. } else {
  325. // 恢复背景页面滚动
  326. document.body.style.overflow = ''
  327. }
  328. }
  329. )
  330. // 加载当前设置
  331. const loadCurrentSettings = () => {
  332. const settings = settingsStore.getSettings()
  333. // 加载文本生成配置
  334. textConfig.baseUrl = settings.textGeneration.baseUrl
  335. textConfig.apiKey = settings.textGeneration.apiKey
  336. textConfig.model = settings.textGeneration.model
  337. textConfig.temperature = settings.textGeneration.temperature
  338. textConfig.timeout = settings.textGeneration.timeout
  339. // 加载图片生成配置
  340. imageConfig.baseUrl = settings.imageGeneration.baseUrl
  341. imageConfig.apiKey = settings.imageGeneration.apiKey
  342. imageConfig.model = settings.imageGeneration.model
  343. }
  344. // 保存设置
  345. const saveSettings = () => {
  346. const newSettings = {
  347. textGeneration: {
  348. baseUrl: textConfig.baseUrl,
  349. apiKey: textConfig.apiKey,
  350. model: textConfig.model,
  351. temperature: textConfig.temperature,
  352. timeout: textConfig.timeout
  353. },
  354. imageGeneration: {
  355. baseUrl: imageConfig.baseUrl,
  356. apiKey: imageConfig.apiKey,
  357. model: imageConfig.model
  358. }
  359. }
  360. settingsStore.updateSettings(newSettings)
  361. showToast('设置已保存', 'success')
  362. emit('save')
  363. // 延迟关闭弹窗,让用户看到提示
  364. setTimeout(() => {
  365. closeModal()
  366. }, 500)
  367. }
  368. // 恢复默认设置
  369. const resetToDefault = () => {
  370. settingsStore.resetToDefault()
  371. loadCurrentSettings()
  372. showToast('已恢复默认设置', 'info')
  373. }
  374. // 关闭弹窗
  375. const closeModal = () => {
  376. emit('close')
  377. }
  378. </script>