diff --git a/app/event/test.js b/app/chef/event/test.js similarity index 63% rename from app/event/test.js rename to app/chef/event/test.js index de77a3e..98aa8d7 100644 --- a/app/event/test.js +++ b/app/chef/event/test.js @@ -7,4 +7,8 @@ module.exports = { "event2": (args) => { console.log(args || 'event2') }, + //status定义的有限状态机 + "start.ling": (args) => { + console.log(args || 'event2') + }, } diff --git a/app/event/全局事件定义文件 b/app/chef/event/全局事件定义文件 similarity index 100% rename from app/event/全局事件定义文件 rename to app/chef/event/全局事件定义文件 diff --git a/app/chef/status/test.js b/app/chef/status/test.js new file mode 100644 index 0000000..fe8b34d --- /dev/null +++ b/app/chef/status/test.js @@ -0,0 +1,13 @@ +'use strict'; +const Smf = require('bamboo_smf'); +const smf = new Smf() + +// 测试状态 +smf.init('test', 'start') + .push('start', 'start.ling') + .push('ling', 'start.end') + .push('end') + + +module.exports = smf.getSmfData() + diff --git a/app/components/公共函数 b/app/chef/status/状态管理 similarity index 100% rename from app/components/公共函数 rename to app/chef/status/状态管理 diff --git a/app/controller/index.js b/app/cms/controller/index.js similarity index 97% rename from app/controller/index.js rename to app/cms/controller/index.js index ab88c94..9d604e7 100644 --- a/app/controller/index.js +++ b/app/cms/controller/index.js @@ -2,14 +2,14 @@ module.exports = { doc : "默认页面", - path : "/", + path : "cms/index/", method : ["get", "post"], middleware: [], params : { "age": "int?" }, return : {}, - controller: async (ctx, app) => { + fun: async (ctx, app) => { console.log(ctx.request.body); // app.err.ParameterException() // app.event.emit('test.event2') @@ -59,6 +59,7 @@ module.exports = { // }, "save": "" // }, { + "as": "user_info", "table" : "UserInfo", "where" : { "uid": "$as.user_data.id",//根据别名 user_data 返回的结果中的id值作为条件查询 diff --git a/app/init.js b/app/cms/init.js similarity index 100% rename from app/init.js rename to app/cms/init.js diff --git a/app/model/User.js b/app/cms/model/User.js similarity index 79% rename from app/model/User.js rename to app/cms/model/User.js index 43530b4..808aeac 100644 --- a/app/model/User.js +++ b/app/cms/model/User.js @@ -1,8 +1,8 @@ module.exports = { doc : "用户", + api : true,//是否需要生成api接口 model: { uid: {type: "STRING", comment: '用户id'}, age: {type: "INTEGER", comment: '年龄', defaultValue: 0,}, - } } diff --git a/app/model/UserInfo.js b/app/cms/model/UserInfo.js similarity index 100% rename from app/model/UserInfo.js rename to app/cms/model/UserInfo.js diff --git a/app/model/数据库模型 b/app/cms/model/数据库模型 similarity index 100% rename from app/model/数据库模型 rename to app/cms/model/数据库模型 diff --git a/app/middleware/bodyparser.js b/app/middleware/bodyparser.js deleted file mode 100644 index facc9b8..0000000 --- a/app/middleware/bodyparser.js +++ /dev/null @@ -1,4 +0,0 @@ -'use strict'; -const bodyParser = require('koa-bodyparser') -// 错误处理 -module.exports = bodyParser() diff --git a/app/middleware/error.js b/app/middleware/error.js deleted file mode 100644 index 92a17ba..0000000 --- a/app/middleware/error.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; -const error = require('koa-json-error') -// 错误处理 -module.exports = error((err) => { - return { - status : err.status, - message : err.message, - code : err.code, - res : false, - // postFormat: (e, obj) => process.env.NODE_ENV === 'production' ? _.omit(obj, 'stack') : obj - } -}) diff --git a/app/middleware/koaLogger.js b/app/middleware/koaLogger.js deleted file mode 100644 index 49a2327..0000000 --- a/app/middleware/koaLogger.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict'; -const logger = require('koa-logger') -module.exports = logger() diff --git a/app/middleware/time.js b/app/middleware/time.js deleted file mode 100644 index bff09eb..0000000 --- a/app/middleware/time.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; -/*响应时间*/ -module.exports = async (ctx, next, app) => { - // console.log(ctx, next, options); - // const timetaken = `${ctx.request.method}${ctx.request.url} 响应时间` - // console.time(timetaken) - // app.logger.debug("123") - await next() - // console.timeEnd(timetaken) -} diff --git a/app/mkt/营销,推广 b/app/mkt/营销,推广 new file mode 100644 index 0000000..e69de29 diff --git a/app/mps/消息推送 b/app/mps/消息推送 new file mode 100644 index 0000000..e69de29 diff --git a/app/oms/订单管理 b/app/oms/订单管理 new file mode 100644 index 0000000..e69de29 diff --git a/app/sqlite/database.sqlite b/app/sqlite/database.sqlite deleted file mode 100644 index c38eb5c..0000000 Binary files a/app/sqlite/database.sqlite and /dev/null differ diff --git a/components/公共函数 b/components/公共函数 new file mode 100644 index 0000000..e69de29 diff --git a/config/database.js b/config/database.js index 6f44e78..c1a0bda 100644 --- a/config/database.js +++ b/config/database.js @@ -1,6 +1,6 @@ /*数据库配置*/ module.exports = { - mysql: { + mysql : { database: "bamboo", username: "bamboo", password: "bamboo", @@ -46,11 +46,31 @@ module.exports = { }, }, }, - redis:{}, - sqlite:{ + redis : {}, + sqlite: { dialect: 'sqlite', storage: 'app/sqlite/database.sqlite', logging: false, + // model的全局配置 + define : { + // 添加create,update,delete时间戳 + timestamps: true, + // 添加软删除 + paranoid: false, + // 防止修改表名为复数 + freezeTableName: true, + // 防止驼峰式字段被默认转为下划线 + underscored: false, + }, + dialectOptions: { + typeCast(field, next) {// 让读取date类型数据时返回字符串而不是UTC时间 + if (field.type === 'DATETIME') { + // console.log(field); + return field.string(); + } + return next(); + }, + }, }, diff --git a/config/extend.js b/config/extend.js new file mode 100644 index 0000000..87e9f64 --- /dev/null +++ b/config/extend.js @@ -0,0 +1,13 @@ +module.exports = { + dir: { + "event" : "app/*/event/*.js", + "status" : "app/*/status/*.js", + "controller": "app/*/controller/*.js", + "model" : "app/*/model/*.js", + "middleware": "middleware/*.js", + "extend" : "extend/*.js", + "schedule" : "schedule/*.js", + "sqlite" : "sqlite/model/*.js", + "config" : "config/*.js", + } +} diff --git a/config/middleware.js b/config/middleware.js index 7652933..c3d00a9 100644 --- a/config/middleware.js +++ b/config/middleware.js @@ -1,7 +1,4 @@ 'use strict'; module.exports = { - register: ["bodyparser", "error", "time", "koaLogger", "verify"], - time : { - params: '123' - }, + } diff --git a/extend/load/config.js b/extend/load/config.js new file mode 100644 index 0000000..a197a85 --- /dev/null +++ b/extend/load/config.js @@ -0,0 +1,4 @@ +//加载配置文件 +module.exports = (app) => { + +} diff --git a/lib/bamboo/bamboo.js b/lib/bamboo/bamboo.js new file mode 100644 index 0000000..3c94346 --- /dev/null +++ b/lib/bamboo/bamboo.js @@ -0,0 +1,123 @@ +const Koa = require("koa") +const load = require("./load") +const path = require('path') +const xe = require("xe-utils") +const EventEmitter = require('events'); +const Router = require("koa-router"); +const Parameter = require('parameter'); +const error = require('./errorException'); +const log4js = require("log4js"); +const Smf = require('./smf/smf'); + +module.exports = class Bamboo extends Koa { + constructor() { + super(); + this.init() + } + + path(args) { + return this.isPath + '/' + (args || "") + } + + isPath(args) { + return path.resolve('./' + (args || "")) + } + + get xe() { + return xe + } + + async init() { + this.config = {} + await this.loadConfig() + this.event = new EventEmitter() + this.parameter = new Parameter(); + this.error = error; + this.smf = new Smf() + log4js.configure(this.config['log']); + this.logger = log4js.getLogger(); + // await this.loadEvent() + // await this.loadStatus() + // await this.loadMiddleware() + // await this.loadController() + } + + /** + * 加载配置 + */ + async loadConfig() { + this.config = {} + const config = await load(this.isPath(), "config") + config.forEach(item => { + this.config[item.file_name] = item.res + }) + } + // + // /** + // * 加载事件 + // */ + // async loadEvent() { + // const event = await load(this.isPath(), "event") + // event.forEach(item => { + // Object.keys(item.res).forEach(key => { + // this.event.on(key, item.res[key]) + // }) + // }) + // } + // + // /** + // * 加载状态 + // */ + // async loadStatus() { + // const status = await load(this.isPath(), "status") + // const setSmfDataList = [] + // status.forEach(item => { + // setSmfDataList.push(item.res) + // }) + // this.smf.setSmfDataList(setSmfDataList) + // //监听流程变更 + // this.smf.on((e, paras) => { + // this.event.emit(e.currentState, paras) + // }) + // } + // + // /** + // * 加载控制器路由 + // */ + // async loadController() { + // const controller = await load(this.isPath(), "controller") + // const router = new Router(); + // controller.forEach(item => { + // item.res.method.forEach(method => { + // router[method](item.res.path, async (ctx, next) => { + // const validate = this.parameter.validate(item.res.params, ctx.request.body); + // if (validate) { + // console.error(validate); + // this.error.ParameterException(validate); + // } + // else { + // await item.res.fun(ctx, this.application) + // await next(); + // } + // }) + // }) + // }) + // } + // + // /** + // * 加载中间件 + // */ + // async loadMiddleware() { + // const middleware = await load(this.isPath(), "middleware") + // let hashList = xe.toArray(middleware) + // hashList = xe.orderBy(hashList, "fun.sort") + // hashList = hashList.filter(item => item.res.use) + // hashList.forEach(item => { + // this.use(async (ctx, next) => { + // ctx['logger'] = this.logger + // return await item.res.fun(ctx, next, this.application) + // }) + // }) + // } + +} diff --git a/app/err/errorException.js b/lib/bamboo/errorException.js similarity index 63% rename from app/err/errorException.js rename to lib/bamboo/errorException.js index 7fc90da..810a8f5 100644 --- a/app/err/errorException.js +++ b/lib/bamboo/errorException.js @@ -11,7 +11,7 @@ class HttpException extends Error { class ParameterException extends HttpException { constructor(message, code, status) { super() - this.status = status || 402 + this.status = status || 402 this.code = code this.message = message || '参数错误' } @@ -20,7 +20,7 @@ class ParameterException extends HttpException { class NotFound extends HttpException { constructor(message, code, status) { super() - this.status = status || 404 + this.status = status || 404 this.code = 404 this.message = message || '资源未找到' } @@ -29,7 +29,7 @@ class NotFound extends HttpException { class AuthFailed extends HttpException { constructor(message, code, status) { super() - this.status = status || 401 + this.status = status || 401 this.message = message || '授权失败' this.code = 401 } @@ -38,16 +38,16 @@ class AuthFailed extends HttpException { class Forbidden extends HttpException { constructor(message, code, status) { super() - this.status = status || 403 + this.status = status || 403 this.message = message || '禁止访问' this.code = 403 } } module.exports = { - HttpException, - ParameterException, - NotFound, - AuthFailed, - Forbidden, + HttpException: (message, code, status) => {throw new HttpException(message, code, status)}, + ParameterException: (message, code, status) => {throw new ParameterException(message, code, status)}, + NotFound: (message, code, status) => {throw new NotFound(message, code, status)}, + AuthFailed: (message, code, status) => {throw new AuthFailed(message, code, status)}, + Forbidden: (message, code, status) => {throw new Forbidden(message, code, status)}, } diff --git a/lib/bamboo/index.js b/lib/bamboo/index.js index e2be1f6..fc4c10c 100644 --- a/lib/bamboo/index.js +++ b/lib/bamboo/index.js @@ -92,7 +92,7 @@ module.exports = class Bamboo extends Koa { registeredError() { console.log('注册 错误'); this.errorException = {} - const hash = requireDirectory(module, this.path('app/err'), { + const hash = requireDirectory(module, this.path('lib/bamboo/err'), { visit: (obj) => { for (let key of Object.keys(obj)) { this.errorException[key] = (message, code) => { @@ -308,9 +308,8 @@ module.exports = class Bamboo extends Koa { const parse = path.parse(filename); // super.on(parse.name, obj); for (let key of Object.keys(obj)) { - this.event.on(`${parse.name}.${key}`, obj[key]); + this.event.on(`${parse.name}.${key}`, e[key]); } - return obj } }); @@ -338,18 +337,27 @@ module.exports = class Bamboo extends Koa { console.log('注册 middleware'); const hash = requireDirectory(module, this.path('app/middleware'), { visit: (obj, joined, filename) => { - console.log(obj, joined, filename); - const parse = path.parse(filename); - const config = this.config.middleware[parse.name] - // super.use(obj(config || {})) - super.use(async (ctx, next) => { - ctx['logger'] = this.logger - return await obj(ctx, next, this.application) - }) + // console.log(obj, joined, filename); + // const parse = path.parse(filename); + // const config = this.config.middleware[parse.name] + // // super.use(obj(config || {})) + // super.use(async (ctx, next) => { + // ctx['logger'] = this.logger + // return await obj.fun(ctx, next, this.application) + // }) return obj } }); - // console.log(hash); + let hashList = xe.toArray(hash) + hashList = xe.orderBy(hashList,"sort") + hashList = hashList.filter(item=>item.use) + hashList.forEach(item=>{ + super.use(async (ctx, next) => { + ctx['logger'] = this.logger + return await item.fun(ctx, next, this.application) + }) + }) + console.log(hashList); } //注册 utils @@ -938,7 +946,7 @@ module.exports = class Bamboo extends Koa { const tkKeys = Object.keys(tk) for (let key of tkKeys) { if (key === "as") { continue; } - if (key === "where"||key === "data") { + if (key === "where" || key === "data") { const findJsonRes = this.findJsonValue(tk[key], (n) => { if (typeof n === "string") { // console.log(tk[key],n); @@ -996,7 +1004,7 @@ module.exports = class Bamboo extends Koa { } path = path || [] // 获取所有的子节点,并遍历 - if (typeof n ==="object") { + if (typeof n === "object") { const nkeys = Object.keys(n) for (let k of nkeys) { // concat() 方法用于连接两个或多个数组 diff --git a/lib/bamboo/load.js b/lib/bamboo/load.js new file mode 100644 index 0000000..f9aa208 --- /dev/null +++ b/lib/bamboo/load.js @@ -0,0 +1,41 @@ +const glob = require("glob") +const path = require('path') +/** + * 项目文件加载 + */ +const list = { + "event" : "app/*/event/*.js", + "status" : "app/*/status/*.js", + "controller": "app/*/controller/*.js", + "model" : "app/*/model/*.js", + "middleware": "middleware/*.js", + "extend" : "extend/*.js", + "schedule" : "schedule/*.js", + "sqlite" : "sqlite/model/*.js", + "config" : "config/*.js", +} + +module.exports = function load(directory, key) { + return new Promise((resolve, reject) => { + const options = { + root: directory + } + glob(list[key], options, function (er, files) { + if (er) { reject(er) } + console.log(files); + files = files.map(item => { + const parse = path.parse(item); + return { + dir : parse.dir, + file_name: parse.name, + res : require(path.resolve(directory + "/" + item)) + } + }) + resolve(files) + }) + }) +} + + + + diff --git a/lib/bamboo/status.js b/lib/bamboo/status.js new file mode 100644 index 0000000..ac25af2 --- /dev/null +++ b/lib/bamboo/status.js @@ -0,0 +1,227 @@ +const xe = require("xe-utils") +/** + * 状态机-编排复杂的流程状态业务 + * @param {string} listName 列名. + */ +module.exports = class Status { + constructor(listName, status, data) { + this.data = data + this.status = status + this.listName = listName + this.list = [] + } + + /** + * 返回上个状态 + */ + back() { + let index = this.getStatusIndex(this.listName, this.status) + const res = this.getList(this.listName) + if ((index - 1) < 0) { + return null + } + const status = res.status[index - 1] + if (res.listName && status.name) { + this.go(res.listName, status.name) + } + return this + } + + /** + * 下一个状态 + */ + next() { + let index = this.getStatusIndex(this.listName, this.status) + const res = this.getList(this.listName) + if (res.status.length <= (index + 1)) { + return null + } + const status = res.status[index + 1] + if (res.listName && status.name) { + this.go(res.listName, status.name) + } + return this + } + + /** + * 触发成功事件 + */ + success() { + const index = this.getStatusIndex(this.listName, this.status) + const res = this.getList(this.listName) + const status = res.status[index] + if (status.success.event) { this.emitEvent(status.success.event) } + if (status.success.listName && status.success.status) { + this.go(status.success.listName, status.success.status) + } + return this + } + + emitEvent(eventName) { + console.log("emitEvent:", eventName); + } + + fail() { + const index = this.getStatusIndex(this.listName, this.status) + const res = this.getList(this.listName) + const status = res.status[index] + if (status.fail.event) { this.emitEvent(status.fail.event) } + if (status.fail.listName && status.fail.status) { + this.go(status.fail.listName, status.fail.status) + } + return this + } + + go(listName, status) { + this.status = status + this.listName = listName + return this + } + + getStatusIndex(listName, status) { + const res = this.getList(listName) + let index = xe.findKey(res.status, item => item.name === status) + return index ? Number(index) : null + } + + getList(listName) { + const res = this.list.filter(item => item.listName === listName) + if (res.length <= 0) { return false } + return res[0] + } + + push({status, success, fail}) { + const res = this.getList(this.listName) + if (res) { + success = success || {} + success["listName"] = success["listName"] || "" + success["status"] = success["status"] || "" + success["event"] = success["event"] || "" + fail = fail || {} + fail["listName"] = fail["listName"] || "" + fail["status"] = fail["status"] || "" + fail["event"] = fail["event"] || "" + + res.status.push({ + name : status, + success: success, + fail : fail, + }) + } + else {return false} + return this + } + + create(listName) { + if (!listName) { return false } + const res = this.getList(listName) + if (res) { return false } + this.list.push({ + listName: listName, + status : [] + }) + this.listName = listName + return this + } +} +// +// const s = new Status() +// +// s.create("ord") +// .push({ +// status : "start", +// success: { +// listName: "ord", //成功后切换到的listName +// status : "pay", //成功后切换到的status +// event : "ord.start", +// }, +// fail : { +// listName: "", //失败后切换到的listName +// status : "", //失败后切换到的status +// event : "", +// }, +// }) +// .push({ +// status : "pay", +// success: { +// listName: "ord", //成功后切换到的listName +// status : "end", //成功后切换到的status +// event : "ord.pay", +// }, +// fail : { +// listName: "refund", //失败后切换到的listName +// status : "start", //失败后切换到的status +// event : "", +// }, +// }) +// .push({ +// status : "end", +// success: { +// listName: "", //成功后切换到的listName +// status : "", //成功后切换到的status +// event : "ord.end", +// }, +// fail : { +// listName: "", //失败后切换到的listName +// status : "", //失败后切换到的status +// event : "", +// }, +// }) +// s.create("refund") +// .push({ +// status : "start", +// success: { +// listName: "refund", //成功后切换到的listName +// status : "ret", //成功后切换到的status +// event : "refund.start", +// }, +// fail : { +// listName: "", //失败后切换到的listName +// status : "", //失败后切换到的status +// event : "", +// }, +// }) +// .push({ +// status : "ret", +// success: { +// listName: "refund", //成功后切换到的listName +// status : "end", //成功后切换到的status +// event : "refund.ret", +// }, +// fail : { +// listName: "", //失败后切换到的listName +// status : "", //失败后切换到的status +// event : "", +// }, +// }) +// .push({ +// status : "end", +// success: { +// listName: "", //成功后切换到的listName +// status : "", //成功后切换到的status +// event : "refund.end", +// }, +// fail : { +// listName: "", //失败后切换到的listName +// status : "", //失败后切换到的status +// event : "", +// }, +// }) +// // console.log(s); +// +// s.go("ord", "start") +// console.log(s.listName, s.status); +// s.success() +// console.log(s.listName, s.status); +// s.fail() +// console.log(s.listName, s.status); +// s.success() +// console.log(s.listName, s.status); +// s.success() +// console.log(s.listName, s.status); +// s.success() +// console.log(s.listName, s.status); +// s.next() +// console.log(s.listName, s.status); + + diff --git a/lib/main.js b/lib/main.js index ca4290e..e7a9f8c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -13,6 +13,6 @@ require('@babel/register')({ ] }) require('@babel/polyfill') -const bamboo = require('./bamboo/index') +const bamboo = require('./bamboo/bamboo') const app = new bamboo(); // app.listen(3000); diff --git a/middleware/bodyparser.js b/middleware/bodyparser.js new file mode 100644 index 0000000..16e20ec --- /dev/null +++ b/middleware/bodyparser.js @@ -0,0 +1,8 @@ +'use strict'; +const bodyParser = require('koa-bodyparser') +// 错误处理 +module.exports = { + sort: 4, //排序 + use : true, // 是否使用 + fun : bodyParser() +} diff --git a/middleware/error.js b/middleware/error.js new file mode 100644 index 0000000..9709b52 --- /dev/null +++ b/middleware/error.js @@ -0,0 +1,16 @@ +'use strict'; +const error = require('koa-json-error') +// 错误处理 +module.exports = { + sort: 3, //排序 + use : true, // 是否使用 + fun : error((err) => { + return { + status : err.status, + message: err.message, + code : err.code, + res : false, + // postFormat: (e, obj) => process.env.NODE_ENV === 'production' ? _.omit(obj, 'stack') : obj + } + }) +} diff --git a/middleware/koaLogger.js b/middleware/koaLogger.js new file mode 100644 index 0000000..1a3f527 --- /dev/null +++ b/middleware/koaLogger.js @@ -0,0 +1,7 @@ +'use strict'; +const logger = require('koa-logger') +module.exports = { + sort: 2, //排序 + use : true, // 是否使用 + fun : logger() +} diff --git a/middleware/time.js b/middleware/time.js new file mode 100644 index 0000000..4741f8c --- /dev/null +++ b/middleware/time.js @@ -0,0 +1,14 @@ +'use strict'; +/*响应时间*/ +module.exports = { + sort: 1, //排序 + use : true, // 是否使用 + fun : async (ctx, next, app) => { + // console.log(ctx, next, options); + // const timetaken = `${ctx.request.method}${ctx.request.url} 响应时间` + // console.time(timetaken) + // app.logger.debug("123") + await next() + // console.timeEnd(timetaken) + } +} diff --git a/middleware/全局中间件定义文件 b/middleware/全局中间件定义文件 new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json index 7e2ea08..d39ace4 100644 --- a/package.json +++ b/package.json @@ -39,13 +39,16 @@ "dependencies": { "@babel/core": "^7.16.7", "@babel/node": "^7.16.8", + "@babel/plugin-proposal-decorators": "^7.17.9", "@babel/polyfill": "^7.4.4", "@babel/preset-env": "^7.16.8", "@babel/runtime": "^7.5.5", "ajv": "^8.11.0", "babel-loader": "^8.2.3", + "bamboo_smf": "^1.0.5", "clean-webpack-plugin": "^4.0.0", "cross-env": "^7.0.3", + "glob": "^8.0.1", "koa-bodyparser": "^4.3.0", "koa-json-error": "^3.1.2", "koa-logger": "^2.0.1", diff --git a/schedule/pbm.js b/schedule/pbm.js new file mode 100644 index 0000000..b9c3e74 --- /dev/null +++ b/schedule/pbm.js @@ -0,0 +1,12 @@ +'use strict'; +// 定时任务 +module.exports = [ + { + name : "", + time : "*/3 * * * * *", + run : true,//系统启动时立即执行一次 + schedule: (app) => { + // console.log('每3秒我执行一次' + app.utils.VERSION) + } + }, +] diff --git a/app/schedule/test.js b/schedule/test.js similarity index 100% rename from app/schedule/test.js rename to schedule/test.js diff --git a/schedule/定时任务 b/schedule/定时任务 new file mode 100644 index 0000000..e69de29 diff --git a/sqlite/database.sqlite b/sqlite/database.sqlite new file mode 100644 index 0000000..87824de Binary files /dev/null and b/sqlite/database.sqlite differ diff --git a/app/sqlite/model/MysqlMD5.js b/sqlite/model/MysqlMD5.js similarity index 76% rename from app/sqlite/model/MysqlMD5.js rename to sqlite/model/MysqlMD5.js index 43626f5..7a5b60a 100644 --- a/app/sqlite/model/MysqlMD5.js +++ b/sqlite/model/MysqlMD5.js @@ -3,6 +3,5 @@ module.exports = { model: { fileName: {type: "STRING", comment: '文件名称'}, md5 : {type: "TEXT", comment: 'md5记录'}, - md5json : {type: "JSON", comment: 'md5记录'}, } } diff --git a/sqlite/model/PermissionsDatabase.js b/sqlite/model/PermissionsDatabase.js new file mode 100644 index 0000000..2a6cae2 --- /dev/null +++ b/sqlite/model/PermissionsDatabase.js @@ -0,0 +1,25 @@ +module.exports = { + doc : "数据权限表(只在默认api生效)", + model: { + code : {type: "STRING", comment: '角色代码'}, + table: {type: "STRING", comment: '表名'}, + key : {type: "STRING", comment: '表字段'}, + crud: { + type : "ENUM", comment: 'crud权限', + values: [ + "C", // 创建 + "R", // 读取 + "U", // 更新 + "D", // 删除 + ] + }, + value: { + type : "ENUM", comment: '状态', + values: [ + 0, // 禁止 + 1, //通行 + ], + defaultValue: 0, + }, + } +} diff --git a/sqlite/model/PermissionsElement.js b/sqlite/model/PermissionsElement.js new file mode 100644 index 0000000..8f2d20c --- /dev/null +++ b/sqlite/model/PermissionsElement.js @@ -0,0 +1,16 @@ +module.exports = { + doc : "页面元素是否显示权限表", + model: { + code : {type: "STRING", comment: '角色代码'}, + key : {type: "STRING", comment: '元素id', unique: true}, + value: { + type : "ENUM", comment: '状态', + values : [ + //注意,一般页面元素会很多,默认是显示状态 + 0, // 通行 + 1, //禁止 + ], + defaultValue: 0, + }, + } +} diff --git a/sqlite/model/PermissionsPage.js b/sqlite/model/PermissionsPage.js new file mode 100644 index 0000000..9757461 --- /dev/null +++ b/sqlite/model/PermissionsPage.js @@ -0,0 +1,15 @@ +module.exports = { + doc : "页面权限表", + model: { + code : {type: "STRING", comment: '角色代码'}, + key : {type: "STRING", comment: '页面标识,一般是页面url',unique: true}, + value: { + type : "ENUM", comment: '状态', + values: [ + 0, // 禁止 + 1, //通行 + ], + defaultValue: 0, + }, + } +} diff --git a/sqlite/model/Role.js b/sqlite/model/Role.js new file mode 100644 index 0000000..4fd8656 --- /dev/null +++ b/sqlite/model/Role.js @@ -0,0 +1,16 @@ +module.exports = { + doc : "角色", + model: { + cname: {type: "STRING", comment: '角色别名'}, + code : {type: "STRING", comment: '角色代码'}, + super: { + type : "ENUM", comment: '是否为超级管理员(不校验权限)', + values : [ + 0, // api地址 + 1, //url地址 + ], + defaultValue: 0, + }, + doc : {type: "TEXT", comment: '说明'}, + } +} diff --git a/sqlite/model/Rout.js b/sqlite/model/Rout.js new file mode 100644 index 0000000..dc82ca9 --- /dev/null +++ b/sqlite/model/Rout.js @@ -0,0 +1,14 @@ +module.exports = { + doc : "路由表表", + model: { + name: {type: "STRING", comment: '路由名称'}, + key : {type: "STRING", comment: '路由标识,一般是路由url或页面url'}, + type: { + type : "ENUM", comment: '字段类型', + values: [ + 'api', // api地址 + 'url', //url地址 + ] + }, + } +} diff --git a/sqlite/model/Setting.js b/sqlite/model/Setting.js new file mode 100644 index 0000000..3d9068e --- /dev/null +++ b/sqlite/model/Setting.js @@ -0,0 +1,19 @@ +module.exports = { + doc : "系统设置", + model: { + title: {type: "STRING", comment: '字段标题'}, + doc : {type: "TEXT", comment: '字段说明'}, + type : { + type : "ENUM", comment: '字段类型', + values: [ + 'int', // 整数 + 'string', //字符串 + 'json', // json + 'rich' // 富文本 + ], + defaultValue: 'string', + }, + code : {type: "STRING", comment: '字段code'}, + value: {type: "TEXT", comment: '值'}, + } +}