Skip to content

Commit 1751d72

Browse files
committed
新增服务器代理解决跨域问题
1 parent 978bdf9 commit 1751d72

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,16 @@
9393
<a style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(true, 0)">数据库类型Database: {{ database || '点击设置' }}</a>
9494
<a style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(true, 1)">数据库模式Schema: {{ schema || '点击设置' }}</a>
9595
<a style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(true, 2)">生成代码(封装,解析): {{ language || '点击设置' }}</a>
96+
<a style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(! isDelegateEnabled, 9)">{{ isDelegateEnabled ? '关闭' : '开启' }}托管服务器代理: {{ isDelegateEnabled ? '代理中' : '直接访问' }}</a>
97+
<a v-show="User.id == null || User.id <= 0" style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(true, 7)">使用的请求类型: {{ types == null || types.length <= 0 ? '点击设置' : types.join() }}</a>
9698
<a style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(StringUtil.isEmpty(host, true), 3)">{{ StringUtil.isEmpty(host, true) ? '隐藏(固定)URL Host: 可用空格隔开' : '显示(编辑)URL Host: \n' + host }}</a>
9799
<a style="border-bottom: #DDD 1px solid;width: 100%;display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; overflow: hidden;" href="javascript:void(0)" @click="showConfig(! isRandomShow, 5)">{{ isRandomShow ? '隐藏(固定)随机测试 Random Test' : '显示(编辑)随机测试 Random Test' }}</a>
98100
<a style="border-bottom: #DDD 1px solid;width: 100%;display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; overflow: hidden;" href="javascript:void(0)" @click="showConfig(! isHeaderShow, 4)">{{ isHeaderShow ? '隐藏(固定)请求头 Request Header' : '显示(编辑)请求头 Request Header' }}</a>
99-
<a v-show="User.id == null || User.id <= 0" style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(true, 7)">使用的请求类型: {{ types == null || types.length <= 0 ? '点击设置' : types.join() }}</a>
100101
<a v-show="User.id == null || User.id <= 0" style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(true, 6)">托管服务器地址URL: {{ server || '点击设置' }}</a>
101102
<a v-show="User.id != null && User.id > 0" style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(true, 8)">导入Swagger文档: {{ swagger || '点击设置' }}</a>
102-
<li v-show="User.id != null && User.id > 0" style="border-bottom: #DDD 1px solid;width: 100%; display: inline-block;text-align: center;" >
103-
<div style="margin-top: 5px;margin-bottom: 0px">微信扫码<br />请作者喝咖啡~</div>
103+
<li v-show="User.id != null && User.id > 0" style="padding: 0px;margin: 0px; border-bottom: #DDD 1px solid;width: 100%; display: inline-block;text-align: center;" >
104104
<img style="padding: 0px;margin: 0px" src="img/wechat_collect.jpg" />
105+
<div style="padding: 0px;margin: 0px">微信扫码,请作者喝咖啡~</div>
105106
</li>
106107
</ul>
107108
</span>

js/main.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@
530530
isExportRemote: false,
531531
isRegister: false,
532532
isMLEnabled: false,
533+
isDelegateEnabled: false,
533534
isLocalShow: false,
534535
exTxt: {
535536
name: 'APIJSON测试',
@@ -926,6 +927,10 @@
926927
App.isRandomShow = show
927928
App.saveCache('', 'isRandomShow', show)
928929
break
930+
case 9:
931+
App.isDelegateEnabled = show
932+
App.saveCache('', 'isDelegateEnabled', show)
933+
break
929934
}
930935
}
931936
else if (index == 3) {
@@ -944,6 +949,10 @@
944949
App.isRandomShow = show
945950
App.saveCache('', 'isRandomShow', show)
946951
}
952+
else if (index == 9) {
953+
App.isDelegateEnabled = show
954+
App.saveCache('', 'isDelegateEnabled', show)
955+
}
947956
},
948957

949958
// 显示删除弹窗
@@ -2255,7 +2264,7 @@
22552264
// axios.defaults.withcredentials = true
22562265
axios({
22572266
method: (type == REQUEST_TYPE_PARAM ? 'get' : 'post'),
2258-
url: StringUtil.noBlank(url),
2267+
url: (isAdminOperation == false && this.isDelegateEnabled ? (this.server + '/delegate?$_delegate_url=') : '' ) + StringUtil.noBlank(url),
22592268
params: (type == REQUEST_TYPE_JSON ? null : req),
22602269
data: (type == REQUEST_TYPE_JSON ? req : null),
22612270
headers: header,
@@ -2868,11 +2877,11 @@
28682877
},
28692878

28702879
enableML: function (enable) {
2871-
App.isMLEnabled = enable
2872-
App.testProcess = enable ? '机器学习:已开启' : '机器学习:已关闭'
2873-
App.saveCache(App.server, 'isMLEnabled', enable)
2874-
App.remotes = null
2875-
App.showTestCase(true, false)
2880+
this.isMLEnabled = enable
2881+
this.testProcess = enable ? '机器学习:已开启' : '机器学习:已关闭'
2882+
this.saveCache(App.server, 'isMLEnabled', enable)
2883+
this.remotes = null
2884+
this.showTestCase(true, false)
28762885
},
28772886

28782887
/**随机测试,动态替换键值对
@@ -3569,8 +3578,9 @@
35693578

35703579
this.locals = this.getCache('', 'locals') || []
35713580

3572-
this.isHeaderShow = (this.getCache('', 'isHeaderShow')) || false
3573-
this.isRandomShow = (this.getCache('', 'isRandomShow')) || false
3581+
this.isDelegateEnabled = this.getCache('', 'isDelegateEnabled') || this.isDelegateEnabled
3582+
this.isHeaderShow = this.getCache('', 'isHeaderShow') || this.isHeaderShow
3583+
this.isRandomShow = this.getCache('', 'isRandomShow') || this.isRandomShow
35743584
} catch (e) {
35753585
console.log('created try { ' +
35763586
'\nvar url = this.getCache(, url) ...' +
@@ -3590,7 +3600,7 @@
35903600

35913601
try { //可能URL_BASE是const类型,不允许改,这里是初始化,不能出错
35923602
this.User = this.getCache(this.server, 'User') || {}
3593-
this.isMLEnabled = this.getCache(this.server, 'isMLEnabled')
3603+
this.isMLEnabled = this.getCache(this.server, 'isMLEnabled') || this.isMLEnabled
35943604
this.testProcess = this.isMLEnabled ? '机器学习:已开启' : '机器学习:已关闭'
35953605
} catch (e) {
35963606
console.log('created try { ' +

0 commit comments

Comments
 (0)