feat: 添加动态配置API基础URL功能

在config.js中添加全局变量__API_BASE__,并在main.js中实现优先使用配置的API基础URL,其次使用location.origin或默认值的逻辑
This commit is contained in:
zhouyonggao 2025-12-03 11:54:33 +08:00
parent 996f4cb2a0
commit 08d0000f3f
3 changed files with 3 additions and 1 deletions

1
web/config.js Normal file
View File

@ -0,0 +1 @@
window.__API_BASE__ = ''

View File

@ -305,6 +305,7 @@
</template>
</el-dialog>
</div>
<script src="./config.js"></script>
<script src="./vendor/vue.global.prod.js"></script>
<script src="./vendor/element-plus.full.min.js"></script>
<script src="./main.js"></script>

View File

@ -37,7 +37,7 @@ const { createApp, reactive } = Vue;
exportTpl: { id: null, filters: {}, main_table: '', fields: [], datasource: '', file_format: '' }
})
const API_BASE = 'http://localhost:8077'
const API_BASE = (window.__API_BASE__ && String(window.__API_BASE__).trim()) ? String(window.__API_BASE__).trim() : (typeof location !== 'undefined' ? location.origin : 'http://localhost:8077')
const getUserId = ()=>{
const sp = new URLSearchParams(window.location.search||'')
const v = sp.get('userId') || sp.get('userid') || sp.get('user_id')