Commit 59779442 by sxy

feat: 根据功能生成路由文件

parent 5c47b24d
...@@ -10,42 +10,42 @@ class AppCtl extends CtlBase { ...@@ -10,42 +10,42 @@ class AppCtl extends CtlBase {
constructor() { constructor() {
super("common", CtlBase.getServiceName(AppCtl)); super("common", CtlBase.getServiceName(AppCtl));
this.userCtl = system.getObject("service.auth.userSve"); this.userCtl = system.getObject("service.auth.userSve");
this.comS=system.getObject("service.common.companySve"); this.comS = system.getObject("service.common.companySve");
} }
async findAndCountAll(pobj, qobj, req) { async findAndCountAll(pobj, qobj, req) {
let comtemp=await this.comS.findById(pobj.company_id) let comtemp = await this.comS.findById(pobj.company_id)
pobj.myappstrs=comtemp.appids pobj.myappstrs = comtemp.appids
let rtn=await super.findAndCountAll(pobj,qobj,req) let rtn = await super.findAndCountAll(pobj, qobj, req)
return rtn return rtn
} }
async findAllApps(p, q, req) { async findAllApps(p, q, req) {
var rtns = await this.service.findAllApps(p.userid); var rtns = await this.service.findAllApps(p.userid);
return system.getResult(rtns); return system.getResult(rtns);
} }
async getApp(p,q,req) { async getApp(p, q, req) {
let app= await this.cacheManager["AppCache"].cache(p.appkey, null); let app = await this.cacheManager["AppCache"].cache(p.appkey, null);
return system.getResult({funcJson:JSON.parse(app.functionJSON)}); return system.getResult({ funcJson: JSON.parse(app.functionJSON) });
} }
async buildFrontRouter(p,q,req){ async buildFrontRouter(p, q, req) {
let appkey=p.appkeyForRoute let appkey = p.appkeyForRoute
let app= await this.cacheManager["AppCache"].cache(appkey, null); let app = await this.cacheManager["AppCache"].cache(appkey, null);
let funcJSONOBJ= JSON.parse(app.functionJSON) let funcJSONOBJ = JSON.parse(app.functionJSON)
let rtn=await this.service.buildFrontRouter(funcJSONOBJ) let rtn = await this.service.buildFrontRouter(funcJSONOBJ, app.id)
return system.getResult(rtn) return system.getResult(rtn)
} }
async getFuncs(p,q,req){ async getFuncs(p, q, req) {
let appkey=p.appkey let appkey = p.appkey
let app= await this.cacheManager["AppCache"].cache(appkey, null); let app = await this.cacheManager["AppCache"].cache(appkey, null);
return system.getResult({funcJson:JSON.parse(app.functionJSON)}) return system.getResult({ funcJson: JSON.parse(app.functionJSON) })
//return system.getResult({funcJson:[]}) //return system.getResult({funcJson:[]})
} }
async saveFuncTree(p,q,req){ async saveFuncTree(p, q, req) {
let rtn=await this.service.saveFuncTree(p) let rtn = await this.service.saveFuncTree(p)
return system.getResult(rtn) return system.getResult(rtn)
} }
async create(pobj, queryobj, req) { async create(pobj, queryobj, req) {
......
const system=require("../system"); const system = require("../system");
const settings=require("../../config/settings.js"); const settings = require("../../config/settings.js");
const reclient=system.getObject("util.redisClient"); const reclient = system.getObject("util.redisClient");
const md5 = require("MD5"); const md5 = require("MD5");
//获取平台配置兑换率 //获取平台配置兑换率
//初次登录的赠送数量 //初次登录的赠送数量
//创建一笔交易 //创建一笔交易
//同时增加账户数量,增加系统平台账户 //同时增加账户数量,增加系统平台账户
var dbf=system.getObject("db.common.connection"); var dbf = system.getObject("db.common.connection");
var db=dbf.getCon(); var db = dbf.getCon();
db.sync({force:true}).then(async ()=>{ db.sync({ force: true }).then(async () => {
const apps=await system.getObject("service.common.appSve"); const apps = await system.getObject("service.common.appSve");
const usS=await system.getObject("service.auth.userSve"); const usS = await system.getObject("service.auth.userSve");
let appnew=await apps.create( { let appnew = await apps.create({
"name":"center-app", "name": "center-app",
"domainName":"t9.com", "domainName": "t9.com",
"backend":"192.168.4.1", "backend": "192.168.1.148",
"isSystem":true "isSystem": true,
"title": "center-app"
}); });
let Role=db.models["role"]; let Role = db.models["role"];
await Role.create({code:"ta",name:"租户",isSystem:true,app_id:appnew.id,company_id:settings.pmcompanyid}) await Role.create({ code: "ta", name: "租户", isSystem: true, app_id: appnew.id, company_id: settings.pmcompanyid })
await Role.create({code:"pr",name:"个人",isSystem:true,app_id:appnew.id,company_id:settings.pmcompanyid}) await Role.create({ code: "pr", name: "个人", isSystem: true, app_id: appnew.id, company_id: settings.pmcompanyid })
let usuper=await usS.pmregister({userName:"sm",password:"951753",isSuper:true,isAdmin:true,isSystem:true,isEnabled:true,nickName:"superman",app_id:appnew.id,company_id:settings.id}) let usuper = await usS.pmregister({ userName: "sm", password: "951753", isSuper: true, isAdmin: true, isSystem: true, isEnabled: true, nickName: "superman", app_id: appnew.id, company_id: settings.id })
appnew.creator_id=usuper.user.id appnew.creator_id = usuper.user.id
await appnew.save() await appnew.save()
......
...@@ -2,69 +2,54 @@ const system = require("../../../system"); ...@@ -2,69 +2,54 @@ const system = require("../../../system");
const ServiceBase = require("../../sve.base"); const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings"); const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig(); const appconfig = system.getSysConfig();
const fs=require("fs") const fs = require("fs")
class AppService extends ServiceBase { class AppService extends ServiceBase {
constructor() { constructor() {
super("common", ServiceBase.getDaoName(AppService)); super("common", ServiceBase.getDaoName(AppService));
this.userS = system.getObject("service.auth.userSve"); this.userS = system.getObject("service.auth.userSve");
this.routeDao = system.getObject("db.common.routeDao"); this.routeDao = system.getObject("db.common.routeDao");
this.ossC=system.getObject("util.ossClient"); this.ossC = system.getObject("util.ossClient");
} }
async getApp(p) { async getApp(p) {
let app = this.cacheManager["AppCache"].cache(p.appkey, null); let app = this.cacheManager["AppCache"].cache(p.appkey, null);
return app; return app;
} }
//[{code:root,title:"",children:[]}]
//code->name,title,children
// {
// path: '/',
// name: '_home',
// component: 'replace yours',
// meta: {
// hideInMenu: true,
// title: '快捷面板',
// notCache: false,
// icon: 'replace yours'
// },
// children: []
// }
async makeRoute(cds,parent,results){
cds.forEach(item=>{
let tmpResult={}
tmpResult.name=item.code
tmpResult.path=item.code
tmpResult.component="replace yours"
tmpResult.meta={
hideInMenu:false,
title:item.title,
notCache:false,
icon:'replace yours'
}
results.push(tmpResult)
if(item.children.length>0){
if(!tmpResult["children"]){
tmpResult["children"]=[]
}
this.makeRoute(item.children,item,results)
}else{
} // 组装 前端 路由
}) async makeRoute(cds, parent) {
} let results = [];
async buildFrontRouter(funcJSON,appid){ for (let item of cds) {
let tmpResult = {};
tmpResult.name = item.code;
tmpResult.path = item.code;
tmpResult.component = "replace yours"
tmpResult.meta = {
hideInMenu: false,
title: item.title,
notCache: false,
icon: 'replace yours'
}
if (item.children && item.children.length > 0) {
tmpResult.children = [];
tmpResult.children = await this.makeRoute(item.children, item);
}
results.push(tmpResult);
}
return results
}
async buildFrontRouter(funcJSON, appid) {
var self = this; var self = this;
return this.db.transaction(async function (t) { return this.db.transaction(async function (t) {
let results=[] let results = await self.makeRoute(funcJSON[0].children, null);
await makeRoute(funcJSON.children,null,results) let keyfile = self.getUUID() + ".json"
let keyfile=self.getUUID()+".json" let dirfile = "/tmp/" + keyfile
let dirfile="/tmp/"+keyfile fs.writeFileSync(dirfile, JSON.stringify(results));
fs.writeFileSync(dirfile) let result = await self.ossC.upfile(keyfile, dirfile);
let result =await this.ossC.upfile(key,dirfile); let upurl = result.url
let upurl=result.url let upobj = { id: appid, docUrl: upurl }
let upobj={id:appid,docUrl:upurl}
fs.unlinkSync(dirfile) fs.unlinkSync(dirfile)
await self.db.models.app.update(upobj,{where:{id:appid},transaction:t}) await self.db.models.app.update(upobj, { where: { id: appid }, transaction: t })
return {uprul:upurl} return { uprul: upurl }
}) })
} }
async findAllApps(uid) { async findAllApps(uid) {
...@@ -113,17 +98,17 @@ class AppService extends ServiceBase { ...@@ -113,17 +98,17 @@ class AppService extends ServiceBase {
return this.db.transaction(async function (t) { return this.db.transaction(async function (t) {
var app = await self.dao.create(pobj, t); var app = await self.dao.create(pobj, t);
//创建后台应用服务 //创建后台应用服务
let urltmp="http://" + app.backend let urltmp = "http://" + app.backend
if(app.backport){ if (app.backport) {
urltmp+=":"+app.backport urltmp += ":" + app.backport
} }
let svobj = await self.cjsonregister(AppService.newServiceUrl(), { name: app.name, url: urltmp}) let svobj = await self.cjsonregister(AppService.newServiceUrl(), { name: app.name, url: urltmp })
//添加路由 //添加路由
let ps = ["/web/auth/userCtl/pmgetUserByCode","/web/auth/userCtl/pmlogin", "/web/auth/userCtl/pmregister", "/web/auth/userCtl/pmSendVCode", "/web/auth/userCtl/pmloginByVCode"] let ps = ["/web/auth/userCtl/pmgetUserByCode", "/web/auth/userCtl/pmlogin", "/web/auth/userCtl/pmregister", "/web/auth/userCtl/pmSendVCode", "/web/auth/userCtl/pmloginByVCode"]
let routeobj = await self.cjsonregister(AppService.newRouteUrl(app.name), let routeobj = await self.cjsonregister(AppService.newRouteUrl(app.name),
{ name: app.name, paths: ps, hosts: [app.domainName], strip_path: false }) { name: app.name, paths: ps, hosts: [app.domainName], strip_path: false })
let ps2 = ["/api", "/web"] let ps2 = ["/api", "/web"]
let routeapi = await self.cjsonregister(AppService.newRouteUrl(app.name), { name: app.name + "_api", hosts: [app.domainName], paths: ps2,strip_path: false }) let routeapi = await self.cjsonregister(AppService.newRouteUrl(app.name), { name: app.name + "_api", hosts: [app.domainName], paths: ps2, strip_path: false })
let r1 = await self.routeDao.create({ name: app.name, center_id: routeobj.id, app_id: app.id, shosts: app.domainName, spaths: ps.join(",") }, t); let r1 = await self.routeDao.create({ name: app.name, center_id: routeobj.id, app_id: app.id, shosts: app.domainName, spaths: ps.join(",") }, t);
let r2 = await self.routeDao.create({ name: app.name + "_api", center_id: routeapi.id, app_id: app.id, shosts: app.domainName, spaths: ps2.join(",") }, t); let r2 = await self.routeDao.create({ name: app.name + "_api", center_id: routeapi.id, app_id: app.id, shosts: app.domainName, spaths: ps2.join(",") }, t);
//给api路由启动插件 //给api路由启动插件
...@@ -146,31 +131,31 @@ class AppService extends ServiceBase { ...@@ -146,31 +131,31 @@ class AppService extends ServiceBase {
async translateInitSels(funcobjs) { async translateInitSels(funcobjs) {
funcobjs.forEach((item) => { funcobjs.forEach((item) => {
console.log(item.title) console.log(item.title)
if (item.children && item.children.length>0) { if (item.children && item.children.length > 0) {
this.translateInitSels(item.children) this.translateInitSels(item.children)
} else { } else {
if(item.auths && item.auths.length>0){ if (item.auths && item.auths.length > 0) {
item.sels=[] item.sels = []
} }
} }
}) })
} }
async saveFuncTree(pobj){ async saveFuncTree(pobj) {
var self = this; var self = this;
return this.db.transaction(async function (t) { return this.db.transaction(async function (t) {
//如果存在functionJSON,那么就需要转换,构建编码路径 //如果存在functionJSON,那么就需要转换,构建编码路径
if (pobj.funcJson) { if (pobj.funcJson) {
// let funcobjs = JSON.parse(pobj.functionJSON) // let funcobjs = JSON.parse(pobj.functionJSON)
await self.translateInitSels(pobj.funcJson) await self.translateInitSels(pobj.funcJson)
pobj.functionJSON= JSON.stringify(pobj.funcJson) pobj.functionJSON = JSON.stringify(pobj.funcJson)
} }
let appcache=await self.cacheManager["AppCache"].cache(pobj.appkey); let appcache = await self.cacheManager["AppCache"].cache(pobj.appkey);
let upobj={id:appcache.id,functionJSON:pobj.functionJSON} let upobj = { id: appcache.id, functionJSON: pobj.functionJSON }
await self.dao.update(upobj, t) await self.dao.update(upobj, t)
//令缓存失效 //令缓存失效
await self.cacheManager["AppCache"].invalidate(pobj.appkey); await self.cacheManager["AppCache"].invalidate(pobj.appkey);
let appcache2=await self.dao.model.findById(appcache.id,{transaction:t}); let appcache2 = await self.dao.model.findById(appcache.id, { transaction: t });
return {funcJson:JSON.parse(appcache2.functionJSON)} return { funcJson: JSON.parse(appcache2.functionJSON) }
}) })
} }
//删除应用 //删除应用
...@@ -181,7 +166,7 @@ class AppService extends ServiceBase { ...@@ -181,7 +166,7 @@ class AppService extends ServiceBase {
if (pobj.functionJSON != "") { if (pobj.functionJSON != "") {
let funcobjs = JSON.parse(pobj.functionJSON) let funcobjs = JSON.parse(pobj.functionJSON)
//await self.translateWithBizCode(funcobjs,null) //await self.translateWithBizCode(funcobjs,null)
pobj.functionJSON= JSON.stringify(funcobjs) pobj.functionJSON = JSON.stringify(funcobjs)
} }
await self.dao.update(pobj, t) await self.dao.update(pobj, t)
let upobj = await self.dao.findById(pobj.id) let upobj = await self.dao.findById(pobj.id)
......
var co = require('co'); var co = require('co');
var OSS = require('ali-oss'); var OSS = require('ali-oss');
class OSSClient{ class OSSClient {
constructor(){ constructor() {
this.client=new OSS({ this.client = new OSS({
endpoint: 'https://oss-cn-beijing.aliyuncs.com', endpoint: 'https://oss-cn-beijing.aliyuncs.com',
accessKeyId: 'LTAIyAUK8AD04P5S', accessKeyId: 'LTAI4GC5tSKvqsH2hMqj6pvd',
accessKeySecret: 'DHmRtFlw2Zr3KaRwUFeiu7FWATnmla' accessKeySecret: '3KV9nIwW8qkTGlrPmAe3HnR3fzM6r5'
}); });
this.client.useBucket('gsb-zc'); this.client.useBucket('gsb-zc');
} }
async downfile(key){ async downfile(key) {
var me=this; var me = this;
var result=await co(function* () { var result = await co(function* () {
var result = yield me.client.get(key, '/tmp/'+key); var result = yield me.client.get(key, '/tmp/' + key);
return result; return result;
}); });
return result; return result;
} }
async upfile(key,filepath){ async upfile(key, filepath) {
var me=this; var me = this;
var result=await co(function* () { var result = await co(function* () {
var result = yield me.client.put(key, filepath); var result = yield me.client.put(key, filepath);
return result; return result;
}) })
return result; return result;
} }
async putBuffer (key,buf) { async putBuffer(key, buf) {
try { try {
var result = await this.client.put(key, buf); var result = await this.client.put(key, buf);
console.log(result); console.log(result);
...@@ -36,7 +36,7 @@ class OSSClient{ ...@@ -36,7 +36,7 @@ class OSSClient{
} }
} }
} }
module.exports=OSSClient; module.exports = OSSClient;
// var oss=new OSSClient(); // var oss=new OSSClient();
// var key="netsharp_QSzjD4HdKdTmRR6b5486pEA3AbsW8Pr8.jpg" // var key="netsharp_QSzjD4HdKdTmRR6b5486pEA3AbsW8Pr8.jpg"
// oss.upfile(key,"/usr/devws/OMC/igirl-api/r3.jpg").then(function(result){ // oss.upfile(key,"/usr/devws/OMC/igirl-api/r3.jpg").then(function(result){
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
"description": "h5framework", "description": "h5framework",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"dev": "nodemon main.js",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"author": "jy", "author": "jy",
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
"exif-js": "^2.3.0", "exif-js": "^2.3.0",
"express": "^4.16.2", "express": "^4.16.2",
"express-session": "^1.15.6", "express-session": "^1.15.6",
"glob": "^7.1.6",
"gm": "^1.23.1", "gm": "^1.23.1",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"log4js": "^2.10.0", "log4js": "^2.10.0",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment