1、使用Promise,重写red.getJSON /red.post, 解决"回调地狱"问题
2、修改 数据源管理/平台信息管理
This commit is contained in:
@@ -42,9 +42,9 @@ function getServiceDetail({name}, callback) {
|
||||
});
|
||||
}*/
|
||||
const meta = {
|
||||
getPlats: (callback) => {
|
||||
/*getPlats: (callback) => {
|
||||
red.getJSON("/meta/plat_list", {}, json => callback(json));
|
||||
},
|
||||
},*/
|
||||
getTableList(callback) {
|
||||
red.getJSON("/meta/tablelist",{}, json => callback(json));
|
||||
},
|
||||
|
||||
17
root/api/plat.js
Normal file
17
root/api/plat.js
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
const plat = {
|
||||
|
||||
platList(params) { // 平台列表
|
||||
return red.getX('/plat/list', params)
|
||||
},
|
||||
platSave({plat}) {
|
||||
return red.postX('/plat/save', {plat})
|
||||
},
|
||||
|
||||
dbList(params) { // 数据源列表
|
||||
return red.getX('/plat/db_list', params)
|
||||
},
|
||||
dbSave({plat}) {
|
||||
return red.postX('/plat/db_save', {plat})
|
||||
},
|
||||
}
|
||||
@@ -90,6 +90,7 @@
|
||||
<script src="./res/zui/js/zui.js" defer></script>
|
||||
<script src="./res/js/red.js" defer></script>
|
||||
<script src="./api/meta.js" defer></script>
|
||||
<script src="./api/plat.js" defer></script>
|
||||
<script src="./res/zui/lib/sortable/zui.sortable.js" defer></script>
|
||||
<!--<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>-->
|
||||
<script type="module">
|
||||
|
||||
@@ -100,13 +100,14 @@
|
||||
</row>
|
||||
|
||||
<script>
|
||||
let {dbList, dbSave} = plat
|
||||
|
||||
var vm = new Vue({
|
||||
el: ".plat",
|
||||
data: {
|
||||
cfg: {
|
||||
title: "数据中心 管理",
|
||||
cols: [
|
||||
{col: "_id", label: "ID"},
|
||||
{col: "name", label: "数据平台名称"},
|
||||
{col: "url", label: "数据平台连接地址"},
|
||||
{col: "user", label: "用户"},
|
||||
@@ -150,7 +151,11 @@
|
||||
},
|
||||
methods: {
|
||||
findList: function () {
|
||||
var para = {
|
||||
dbList().then(res => {
|
||||
vm.list = res;
|
||||
})
|
||||
|
||||
/*var para = {
|
||||
doc:"db_plat",
|
||||
shows: JSON.stringify(["_id", "name", "url", "user", "pwd", "catalogs", "remark", "status"])
|
||||
};
|
||||
@@ -159,7 +164,7 @@
|
||||
json.rows[i]["pulse"] = "";
|
||||
}
|
||||
vm.list = json;
|
||||
})
|
||||
})*/
|
||||
},
|
||||
update: function (kv, row) {
|
||||
red.post("/meta/save", {
|
||||
@@ -178,14 +183,20 @@
|
||||
$('#myModal').modal({moveable: true});
|
||||
},
|
||||
save: function (row) {
|
||||
red.post("/meta/save", {
|
||||
dbSave({plat: row}).then(() => {
|
||||
red.showMsg({msg: "操作成功"})
|
||||
$('#myModal').modal('hide')
|
||||
vm.findList()
|
||||
})
|
||||
|
||||
/* red.post("/meta/save", {
|
||||
_id: row._id || "db_plat",
|
||||
doc: JSON.stringify(row)
|
||||
}, function (json) {
|
||||
red.showMsg();
|
||||
$('#myModal').modal('hide');
|
||||
vm.findList();
|
||||
});
|
||||
}); */
|
||||
},
|
||||
loadCatalogs: function () {
|
||||
vm.catalogs = [];
|
||||
@@ -198,13 +209,13 @@
|
||||
});
|
||||
},
|
||||
dbPulse: function (row) {
|
||||
row["check"] = true;
|
||||
/*row["check"] = true;
|
||||
$.getJSON("/_db/pulse", {
|
||||
dbPlatId: row._id
|
||||
}, function (json) {
|
||||
row["pulse"] = json.body;
|
||||
row["check"] = false;
|
||||
});
|
||||
});*/
|
||||
}
|
||||
},
|
||||
mounted: function () {
|
||||
|
||||
@@ -76,13 +76,14 @@
|
||||
</row>
|
||||
|
||||
<script>
|
||||
let { platList, platSave } = plat;
|
||||
|
||||
var vm = new Vue({
|
||||
el: ".plat",
|
||||
data: {
|
||||
cfg: {
|
||||
title: "业务平台 管理",
|
||||
cols: [
|
||||
{col: "_id", label: "ID"},
|
||||
{col: "name", label: "业务名称"},
|
||||
{col: "token", label: "Token"},
|
||||
{col: "remark", label: "说明"},
|
||||
@@ -100,15 +101,9 @@
|
||||
|
||||
},
|
||||
methods: {
|
||||
findList: function () {
|
||||
var para = {
|
||||
doc:"sys_plat",
|
||||
shows: JSON.stringify(["_id", "_key", "name", "token","remark", "status"]),
|
||||
filter: JSON.stringify([{col:"status",type:"!=",value:-1}]),
|
||||
};
|
||||
red.getJSON("/meta/find", para, function (json) {
|
||||
vm.list = json;
|
||||
red.setData("sysPlats", json.rows);
|
||||
findList () {
|
||||
platList().then(res => {
|
||||
vm.list = res
|
||||
})
|
||||
},
|
||||
update: function (kv, row) {
|
||||
@@ -127,14 +122,10 @@
|
||||
$('#myModal').modal({moveable: true});
|
||||
},
|
||||
save: function (row) {
|
||||
red.post("/meta/save", {
|
||||
_id: row._id || "sys_plat",
|
||||
doc: JSON.stringify(row)
|
||||
}, function (json) {
|
||||
red.showMsg();
|
||||
$('#myModal').modal('hide');
|
||||
vm.findList();
|
||||
});
|
||||
platSave({plat: row}).then(() => {
|
||||
red.showMsg({msg: "操作成功"})
|
||||
$('#myModal').modal('hide')
|
||||
})
|
||||
}
|
||||
},
|
||||
mounted: function () {
|
||||
|
||||
@@ -51,6 +51,44 @@ var red = {
|
||||
callback(data)
|
||||
})
|
||||
},
|
||||
getX(url, params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(url, params).then(res => {
|
||||
let data = res.data || {}
|
||||
red.loginCheck(data)
|
||||
if (data.code == -1) {
|
||||
red.showMsg({type:"error", msg: data.message})
|
||||
return;
|
||||
}
|
||||
if (data.code == 0) {
|
||||
data = data.body
|
||||
}
|
||||
|
||||
resolve(data)
|
||||
})
|
||||
})
|
||||
},
|
||||
postX(url, params) {
|
||||
return new Promise(resolve => {
|
||||
axios({
|
||||
url,
|
||||
method: 'post',
|
||||
params,
|
||||
|
||||
}).then(res => {
|
||||
let data = res.data || {}
|
||||
red.loginCheck(data)
|
||||
if (data.code == -1) {
|
||||
red.showMsg({type:"error", msg: data.message})
|
||||
return;
|
||||
}
|
||||
if (data.code == 0) {
|
||||
data = data.body
|
||||
}
|
||||
resolve(data)
|
||||
});
|
||||
})
|
||||
},
|
||||
post: function(url, params, callback) {
|
||||
params["platToken"] = red.getPlatToken()
|
||||
axios.post(url, params).then(res => {
|
||||
|
||||
@@ -102,10 +102,11 @@
|
||||
<script src="../res/js/red.js" defer></script>
|
||||
<script src="../res/libs/axios.min.js" defer></script>
|
||||
<script src="../api/meta.js"></script>
|
||||
<script src="../api/plat.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
|
||||
<script type="module">
|
||||
import { login } from '../api/user.js'
|
||||
let { getPlats } = meta;
|
||||
let { platList } = plat;
|
||||
|
||||
var vm = new Vue({
|
||||
el: ".login",
|
||||
@@ -122,14 +123,15 @@
|
||||
loginCheck: function ({username, pwd}) {
|
||||
login({username, pwd}, function (json) {
|
||||
if (json.code == 0) {
|
||||
getPlats(function (json) {
|
||||
platList().then(res => {
|
||||
let rows = res.rows
|
||||
red.showMsg({msg:"请选择业务平台"})
|
||||
|
||||
vm.sysPlats = json;
|
||||
vm.sysPlats = rows;
|
||||
if (!vm.sysPlat) {
|
||||
vm.sysPlat = json[0];
|
||||
vm.sysPlat = rows[0];
|
||||
}
|
||||
red.setData("sysPlats", json);
|
||||
red.setData("sysPlats", rows);
|
||||
setTimeout(function () {
|
||||
vm.choose = true;
|
||||
}, 500);
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.arangodb.ArangoCollection;
|
||||
import com.arangodb.ArangoDBException;
|
||||
import com.arangodb.ArangoDatabase;
|
||||
import com.arangodb.entity.DocumentCreateEntity;
|
||||
import net.tccn.base.PageBean;
|
||||
import org.redkale.source.Flipper;
|
||||
|
||||
import javax.persistence.Table;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -160,7 +162,7 @@ public abstract class Doc<T extends Doc> {
|
||||
this.db = arangoSource.db(table.catalog());
|
||||
this.collection = arangoSource.collection(this);
|
||||
}
|
||||
public final static <T extends Doc> T dao(Class<T> type) {
|
||||
protected final static <T extends Doc> T dao(Class<T> type) {
|
||||
|
||||
if (daos.get(type) == null) {
|
||||
try {
|
||||
@@ -188,6 +190,16 @@ public abstract class Doc<T extends Doc> {
|
||||
collection.updateDocument(this.getKey(), this.toDoc());
|
||||
}
|
||||
|
||||
public <T extends Doc> PageBean<T> findPage(T t, Flipper flipper) {
|
||||
if (flipper == null) {
|
||||
flipper = new Flipper();
|
||||
}
|
||||
|
||||
List<T> list = find(t, flipper.getOffset(), flipper.getLimit());
|
||||
long count = count(t);
|
||||
return PageBean.by(list, count);
|
||||
}
|
||||
|
||||
public T findFirst(T t) {
|
||||
return findFirst(arangoSource.parseAql(t, 0, 1), (Class<T>) t.getClass());
|
||||
}
|
||||
@@ -198,6 +210,9 @@ public abstract class Doc<T extends Doc> {
|
||||
return find(t, 0, 1000);
|
||||
}
|
||||
public <T extends Doc> List<T> find(T t, int offset, int pn) {
|
||||
if (t == null) {
|
||||
t = (T) this;
|
||||
}
|
||||
return find(arangoSource.parseAql(t, offset, pn), (Class<T>)this.getClass());
|
||||
}
|
||||
|
||||
@@ -226,6 +241,9 @@ public abstract class Doc<T extends Doc> {
|
||||
return count(this);
|
||||
}
|
||||
public <T extends Doc> long count(T t) {
|
||||
if (t == null) {
|
||||
t = (T) this;
|
||||
}
|
||||
return db.query(arangoSource.parseAqlCount(t), long.class).first();
|
||||
}
|
||||
//ok
|
||||
|
||||
@@ -15,6 +15,8 @@ public class DbExecutors {
|
||||
|
||||
String[] sqls = PARSER.parse(fBean);
|
||||
|
||||
|
||||
|
||||
return PageBean.by(Arrays.asList(Kv.of("findSql:", sqls[0]).set("countSql", sqls[1]) ), 0);
|
||||
}
|
||||
}
|
||||
|
||||
96
src/main/java/net/tccn/plat/DbPlat.java
Normal file
96
src/main/java/net/tccn/plat/DbPlat.java
Normal file
@@ -0,0 +1,96 @@
|
||||
package net.tccn.plat;
|
||||
|
||||
import net.tccn.base.arango.Doc;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
import javax.persistence.Table;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据库平台
|
||||
* @author: liangxianyou at 2018/11/14 12:58.
|
||||
*/
|
||||
@Table(name = "db_plat", catalog = "db_dev")
|
||||
public class DbPlat extends Doc<DbPlat> {
|
||||
public static DbPlat dao = dao(DbPlat.class);
|
||||
|
||||
private String name; //名称
|
||||
private String cate; //类型 mysql|ArangoDb
|
||||
private String remark; //备注
|
||||
private String url; //数据库连接地址
|
||||
private String user; //账号
|
||||
private String pwd; //密码
|
||||
private List<String> catalogs; //库
|
||||
private Integer status;//状态 1启用, 0 未启用
|
||||
|
||||
//------------- setter/getter ---------------
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getCate() {
|
||||
return cate;
|
||||
}
|
||||
|
||||
public void setCate(String cate) {
|
||||
this.cate = cate;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getPwd() {
|
||||
return pwd;
|
||||
}
|
||||
|
||||
public void setPwd(String pwd) {
|
||||
this.pwd = pwd;
|
||||
}
|
||||
|
||||
public List<String> getCatalogs() {
|
||||
return catalogs;
|
||||
}
|
||||
|
||||
public void setCatalogs(List<String> catalogs) {
|
||||
this.catalogs = catalogs;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
}
|
||||
69
src/main/java/net/tccn/plat/PlatService.java
Normal file
69
src/main/java/net/tccn/plat/PlatService.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package net.tccn.plat;
|
||||
|
||||
import net.tccn.base.JBean;
|
||||
import net.tccn.base.Kv;
|
||||
import net.tccn.base.PageBean;
|
||||
import net.tccn.service.BaseService;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.net.http.RestService;
|
||||
import org.redkale.source.Flipper;
|
||||
import org.redkale.util.Comment;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestService(name = "plat", automapping = true, comment = "业务/数据平台")
|
||||
public class PlatService extends BaseService {
|
||||
|
||||
@RestMapping(name = "list", comment = "平台列表")
|
||||
public JBean list(SysPlat plat, Flipper flipper) {
|
||||
JBean jBean = new JBean();
|
||||
|
||||
PageBean<SysPlat> page = SysPlat.dao.findPage(plat, flipper);
|
||||
|
||||
return jBean.setBody(page);
|
||||
}
|
||||
|
||||
@Comment("平台信息保存")
|
||||
public JBean save(SysPlat plat) {
|
||||
if (plat.getKey() == null) {
|
||||
plat.save();
|
||||
} else {
|
||||
plat.update();
|
||||
}
|
||||
|
||||
return new JBean();
|
||||
}
|
||||
|
||||
@RestMapping(name = "info", comment = "平台详情")
|
||||
public void info(int key) {
|
||||
|
||||
}
|
||||
|
||||
//------------------------
|
||||
|
||||
@RestMapping(name = "db_list", comment = "数据源列表")
|
||||
public JBean dbList(DbPlat plat, Flipper flipper) {
|
||||
JBean jBean = new JBean();
|
||||
|
||||
PageBean<DbPlat> page = DbPlat.dao.findPage(plat, flipper);
|
||||
|
||||
return jBean.setBody(page);
|
||||
}
|
||||
|
||||
@RestMapping(name = "db_save", comment = "数据源信息保存")
|
||||
public JBean dbSave(String plat) {
|
||||
Map map = gson.fromJson(plat, Map.class);
|
||||
DbPlat dbPlat = Kv.toBean(map, DbPlat.class);
|
||||
|
||||
// todo: Kv.toBean 的内部属性深度转换,
|
||||
/*if (dbPlat.getKey() == null) {
|
||||
dbPlat.save();
|
||||
} else {
|
||||
dbPlat.update();
|
||||
}*/
|
||||
|
||||
return new JBean().setBody(dbPlat);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.tccn.dbq.qtask;
|
||||
package net.tccn.plat;
|
||||
|
||||
import net.tccn.base.arango.Doc;
|
||||
|
||||
@@ -4,7 +4,7 @@ import net.tccn.base.JBean;
|
||||
import net.tccn.base.Kv;
|
||||
import net.tccn.dbq.Field;
|
||||
import net.tccn.dbq.jdbc.api.DbAccount;
|
||||
import net.tccn.dbq.qtask.SysPlat;
|
||||
import net.tccn.plat.SysPlat;
|
||||
import net.tccn.meta.MetaKit;
|
||||
import net.tccn.meta.MetaService;
|
||||
import net.tccn.meta.MetaTable;
|
||||
|
||||
@@ -4,7 +4,7 @@ import net.tccn.base.JBean;
|
||||
import net.tccn.base.Kv;
|
||||
import net.tccn.dbq.jdbc.api.DbAccount;
|
||||
import net.tccn.dbq.qtask.Qtask;
|
||||
import net.tccn.dbq.qtask.SysPlat;
|
||||
import net.tccn.plat.SysPlat;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.net.http.RestParam;
|
||||
import org.redkale.net.http.RestService;
|
||||
|
||||
@@ -131,7 +131,7 @@ public class RunTest<T> {
|
||||
}).min().orElseGet(()-> 0);
|
||||
|
||||
System.out.println(xx);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user