feat: 整合请求地址

This commit is contained in:
RISE
2026-05-21 15:07:46 +08:00
parent fa321e5083
commit c1337cbd80
3 changed files with 31 additions and 3 deletions

View File

@@ -20,6 +20,8 @@
</template> </template>
<script> <script>
import CONFIG from '../../utils/config.js';
export default { export default {
data() { data() {
return { return {
@@ -81,7 +83,7 @@
const self = this const self = this
const token = wx.getStorageSync('token'); const token = wx.getStorageSync('token');
wx.connectSocket({ wx.connectSocket({
url: 'wss://ai-api.aitools666.com/chat', url: CONFIG.getWsUrl(CONFIG.api.chat),
header: { header: {
'authorization': token 'authorization': token
} }
@@ -135,7 +137,7 @@
} }
this.shareBtnLoading = true this.shareBtnLoading = true
wx.downloadFile({ wx.downloadFile({
url: 'https://ai-api.aitools666.com/generate-post?record_id=' + this.recordId, url: CONFIG.getHttpUrl(CONFIG.api.generatePost) + '?record_id=' + this.recordId,
success: (res) => { success: (res) => {
this.shareBtnLoading = false this.shareBtnLoading = false
wx.showShareImageMenu({ wx.showShareImageMenu({

View File

@@ -38,6 +38,8 @@
</template> </template>
<script> <script>
import CONFIG from '../../utils/config.js';
export default { export default {
data() { data() {
return { return {
@@ -72,7 +74,7 @@
const userInfo = res.userInfo; const userInfo = res.userInfo;
// 将 code 和 userInfo 发送给后台服务器 // 将 code 和 userInfo 发送给后台服务器
wx.request({ wx.request({
url: 'https://ai-api.aitools666.com/login', url: CONFIG.getHttpUrl(CONFIG.api.login),
method: 'get', method: 'get',
data: { data: {
code: code code: code

24
utils/config.js Normal file
View File

@@ -0,0 +1,24 @@
// 后端 API 地址配置
const CONFIG = {
// 基础域名(生产环境请替换为你的后端地址)
baseUrl: "https://ai-api.aitools666.com",
// 接口地址
api: {
login: "/login",
chat: "/chat",
generatePost: "/generate-post",
},
// 获取完整 HTTP URL
getHttpUrl(path) {
return this.baseUrl + path;
},
// 获取完整 WebSocket URL
getWsUrl(path) {
return this.baseUrl.replace(/^https?:/, "wss:") + path;
},
};
module.exports = CONFIG;