tanghc 6 years ago
parent b3d15cb326
commit d1f33d4e19
  1. 31
      sop-admin/sop-admin-front/assets/js/ApiUtil.js
  2. 136
      sop-admin/sop-admin-front/assets/lib/easyopen/index.html
  3. 293
      sop-admin/sop-admin-front/assets/lib/easyopen/sdk.js
  4. 6
      sop-admin/sop-admin-server/pom.xml
  5. 14
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/ConfigListApi.java
  6. 13
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/RouteListApi.java
  7. 38
      sop-admin/sop-admin-server/src/main/resources/application-dev.properties
  8. 39
      sop-admin/sop-admin-server/src/main/resources/application.properties

@ -0,0 +1,31 @@
/**
* 请求工具
*/
var ApiUtil = (function () {
// 接口URL,更改此处即可
var url = 'http://localhost:8082/api';
var URI_CHAR = '/';
function formatUri(uri) {
if (uri.substring(0, 1) !== URI_CHAR) {
uri = URI_CHAR + uri;
}
if (uri.substring(uri.length - 1) !== URI_CHAR) {
uri = uri + URI_CHAR;
}
return uri;
}
return {
post: function (uri, params, callback) {
uri = formatUri(uri);
sdk.post({
url: url + uri
, data: params // 请求参数
, callback: function (resp) { // 成功回调
callback(resp);
}
});
}
}
})();

@ -0,0 +1,136 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>sdk</title>
<script type="text/javascript" src="sdk.js"></script>
<script type="text/javascript">
//需要发布到服务器上运行,并且server端需要处理跨域
//在IndexController.java上加@CrossOrigin(origins={"*"})
// 初始化配置,执行一次即可
sdk.config({
url : 'http://localhost:8080/api'
,app_key : 'test'
,secret : '123456'
});
sdk.get({
name : 'goods.get' // 接口名
// ,version:'1.0'
// ,access_token:''
,data : {'goods_name':'iphone'} // 请求参数
,callback:function(resp) { // 成功回调
console.log(resp)
}
});
</script>
</head>
<body>
<h1>打开F12查看效果</h1>
<fieldset>
<legend>GET/POST</legend>
<button onclick="getTest()">GET</button>
<button onclick="postTest()">POST</button>
</fieldset>
<hr>
<fieldset>
<legend>上传文件demo</legend>
<form id="frm">
头像图片:<input type="file" name="headImg"/> <br><br>
身份证图片:<input type="file" name="idcardImg"/>
</form>
<br>
<button onclick="uploadTest()">上传文件请求</button>
</fieldset>
<pre>
//需要发布到服务器上运行,并且server端需要处理跨域
//在IndexController.java上加@CrossOrigin(origins={"*"})
sdk.config({
url : 'http://localhost:8080/api'
,app_key : 'test'
,secret : '123456'
});
sdk.get({
name : 'goods.get' // 接口名
,data : {'goods_name':'iphone'} // 请求参数
,callback:function(resp) { // 成功回调
console.log(resp)
}
}); // get方式不支持上传
sdk.post({
name : 'goods.get' // 接口名
,data : {'goods_name':'iphone'} // 请求参数
,callback:function(resp) { // 成功回调
console.log(resp)
}
});
/* ****************上传文件**************** */
&lt;form id=&quot;frm&quot;&gt;
上传文件1:&lt;input type=&quot;file&quot; name=&quot;headImg&quot;/&gt;
上传文件2:&lt;input type=&quot;file&quot; name=&quot;idcardImg&quot;/&gt;
&lt;/form&gt;
function uploadTest() {
sdk.get({
name : 'file.upload' // 接口名
,data : {'goods_name':'iphone'} // 请求参数
,form : document.getElementById('frm')
,callback:function(resp) { // 成功回调
if(resp.code == '0') {
alert('上传成功,' + resp.msg);
} else {
alert('上传失败,' + resp.msg)
}
}
});
}
</pre>
<script type="text/javascript">
function uploadTest() {
sdk.post({
name : 'file.upload' // 接口名
,data : {'goods_name':'iphone'} // 请求参数
,form : document.getElementById('frm')
,callback:function(resp) { // 成功回调
if(resp.code == '0') {
alert('上传成功,' + resp.data);
} else {
alert('上传失败,' + resp.msg)
}
}
});
}
function getTest() {
sdk.get({
name : 'goods.get' // 接口名
,data : {'goods_name':'iphone'} // 请求参数
,callback:function(resp) { // 成功回调
console.log(resp);
}
});
}
function postTest() {
sdk.post({
name : 'goods.get' // 接口名
,data : {'goods_name':'iphone'} // 请求参数
,callback:function(resp) { // 成功回调
console.log(resp);
}
});
}
</script>
</body>
</html>

File diff suppressed because one or more lines are too long

@ -36,6 +36,12 @@
<artifactId>easyopen-spring-boot-starter</artifactId>
<version>1.16.0</version>
</dependency>
<!-- zookeeper客户端 -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

@ -0,0 +1,14 @@
package com.gitee.sop.adminserver.api;
import com.gitee.easyopen.annotation.ApiService;
import com.gitee.easyopen.doc.annotation.ApiDoc;
/**
* @author tanghc
*/
@ApiService
@ApiDoc("配置列表")
public class ConfigListApi {
// public
}

@ -0,0 +1,13 @@
package com.gitee.sop.adminserver.api;
import com.gitee.easyopen.annotation.ApiService;
import com.gitee.easyopen.doc.annotation.ApiDoc;
/**
* @author tanghc
*/
@ApiService
@ApiDoc("路由列表")
public class RouteListApi {
}

@ -0,0 +1,38 @@
server.port=8082
#################easyopen基础配置#################
# 显示文档
easyopen.show-doc=true
# 本地秘钥
easyopen.app-secret.test=123456
# 关闭跨域,默认开启
#easyopen.cors=false
# 开启webflux
easyopen.mono=false
## 拦截器
#easyopen.interceptors[0]=com.gitee.easyopen.support.LimitInterceptor
#easyopen.interceptors[1]=com.gitee.easyopen.support.PermissionInterceptor
# 配置中心,config-server-port对应easyopen-config中的netty.server.port
#easyopen.app-name=app-normal
#easyopen.config-server-ip=127.0.0.1
#easyopen.config-server-port=8071
#easyopen.doc-url=http://127.0.0.1:8081/api/doc
#################redis基础配置#################
spring.redis.database=1
spring.redis.host=10.1.11.48
spring.redis.password=0987654321rfvujmtgbyhn
spring.redis.port=6379
# 连接超时时间 单位 ms(毫秒)
spring.redis.timeout=3000
logging.file=D:/logs/server/server
logging.level.com.gitee=debug

@ -1,38 +1 @@
server.port=8082
#################easyopen基础配置#################
# 显示文档
easyopen.show-doc=true
# 本地秘钥
easyopen.app-secret.test=123456
# 关闭跨域,默认开启
#easyopen.cors=false
# 开启webflux
easyopen.mono=false
## 拦截器
#easyopen.interceptors[0]=com.gitee.easyopen.support.LimitInterceptor
#easyopen.interceptors[1]=com.gitee.easyopen.support.PermissionInterceptor
# 配置中心,config-server-port对应easyopen-config中的netty.server.port
#easyopen.app-name=app-normal
#easyopen.config-server-ip=127.0.0.1
#easyopen.config-server-port=8071
#easyopen.doc-url=http://127.0.0.1:8081/api/doc
#################redis基础配置#################
spring.redis.database=1
spring.redis.host=10.1.11.48
spring.redis.password=0987654321rfvujmtgbyhn
spring.redis.port=6379
# 连接超时时间 单位 ms(毫秒)
spring.redis.timeout=3000
logging.file=D:/logs/server/server
logging.level.com.gitee=debug
spring.profiles.active=dev
Loading…
Cancel
Save