1
This commit is contained in:
49
config/config.json
Normal file
49
config/config.json
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"jwtkey": "97856358!@#",
|
||||
"port": {
|
||||
"node": 9096,
|
||||
"web": 9095
|
||||
},
|
||||
"allowUrls": ["/admin_api/sys_user/login", "/admin_api/sys_user/authorityMenus", "/admin_api/sys_user/register", "/api/user/loginByWeixin", "/file/", "/sys_file/"],
|
||||
|
||||
"fileConifg": {
|
||||
"vue": {
|
||||
"api": "../../admin/src/api/",
|
||||
"view": "../../admin/src/view/"
|
||||
},
|
||||
"node": {
|
||||
"controller": "../controller_admin/",
|
||||
"model": "../model/"
|
||||
}
|
||||
},
|
||||
"db": {
|
||||
"database": "platformweb",
|
||||
"username": "platformweb",
|
||||
"password": "BPPypsjfZExHzA7G",
|
||||
"host": "47.98.167.204",
|
||||
"port": 3306,
|
||||
"dialect": "mysql"
|
||||
},
|
||||
|
||||
"wechat": {
|
||||
"appid": "",
|
||||
"secret": "",
|
||||
"mch_id": "",
|
||||
"partner_key": "",
|
||||
"partnerV3_key": "",
|
||||
"notify_url": "",
|
||||
"refund_notify_url": "",
|
||||
"shareUrlQr": ""
|
||||
},
|
||||
"aliyun": {
|
||||
"accessKeyId": "LTAITcmHTshBRPQ4",
|
||||
"accessKeySecret": "TA4j4cLYdRTDIWBc0DGoSNstSDW5CY",
|
||||
"ossUrl": "http://light22600.oss-cn-beijing.aliyuncs.com"
|
||||
},
|
||||
"redis": {
|
||||
"host": "",
|
||||
"port": "",
|
||||
"pwd": "",
|
||||
"opt": {}
|
||||
}
|
||||
}
|
||||
52
config/template/config.ejs
Normal file
52
config/template/config.ejs
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
|
||||
"platformApiUrl": "http://auto.light120.com/api",
|
||||
"project_key": "<%=project_key%>",
|
||||
"jwtkey": "9233358!@#",
|
||||
"port": {
|
||||
"node": 9091,
|
||||
"web": 9090
|
||||
},
|
||||
"allowUrls": ["/admin_api/sys_user/login", "/admin_api/sys_user/authorityMenus", "/admin_api/sys_user/register", "/api/user/loginByWeixin", "/file/", "/sys_file/"],
|
||||
|
||||
"fileConifg": {
|
||||
"vue": {
|
||||
"api": "../../admin/src/api/",
|
||||
"view": "../../admin/src/view/"
|
||||
},
|
||||
"node": {
|
||||
"controller": "../controller_admin/",
|
||||
"model": "../model/"
|
||||
}
|
||||
},
|
||||
"db":{
|
||||
"username": "<%=config.db.username%>",
|
||||
"password": "<%=config.db.password%>",
|
||||
"database": "<%=config.db.database%>",
|
||||
"host": "<%=config.db.host%>",
|
||||
"port": <%=config.db.port%>,
|
||||
"dialect": "<%=config.db.dialect%>"
|
||||
},
|
||||
"wechat":{
|
||||
"appid": "<%=config.wechat.appid%>",
|
||||
"secret": "<%=config.wechat.secret%>",
|
||||
"mch_id": "<%=config.wechat.mch_id%>",
|
||||
"partner_key": "<%=config.wechat.partner_key%>",
|
||||
"partnerV3_key": "<%=config.wechat.partnerV3_key%>",
|
||||
"notify_url": "<%=config.wechat.notify_url%>",
|
||||
"refund_notify_url": "<%=config.wechat.refund_notify_url%>"
|
||||
|
||||
},
|
||||
"aliyun":{
|
||||
"accessKeyId": "<%=config.aliyun.accessKeyId%>",
|
||||
"accessKeySecret": "<%=config.aliyun.accessKeyId%>",
|
||||
"ossUrl": "<%=config.aliyun.accessKeyId%>"
|
||||
} ,
|
||||
"redis":{
|
||||
"host": "<%=config.redis.host%>",
|
||||
"port": "<%=config.redis.port%>",
|
||||
"pwd": "<%=config.redis.pwd%>",
|
||||
"opt": {}
|
||||
|
||||
}
|
||||
}
|
||||
77
config/template/controller.ejs
Normal file
77
config/template/controller.ejs
Normal file
@@ -0,0 +1,77 @@
|
||||
const {<%=table_name%>, op } = require('../../middleware/baseModel');
|
||||
|
||||
module.exports = {
|
||||
'GET /<%=table_name%>/all' : async (ctx, next) => {
|
||||
const res = await <%=table_name%>.findAll();
|
||||
return ctx.success(res);
|
||||
},
|
||||
|
||||
'GET /<%=table_name%>/detail' : async (ctx, next) => {
|
||||
let id = ctx.get('id')
|
||||
const res = await <%=table_name%>.findOne({where:{id:id}});
|
||||
return ctx.success(res);
|
||||
},
|
||||
|
||||
|
||||
"POST /<%=table_name%>/export": async (ctx, next) => {
|
||||
let rows = [];
|
||||
let cols = [];
|
||||
let title='<%=table_name%>';
|
||||
|
||||
let tableAttributes = <%=table_name%>.tableAttributes;
|
||||
let colKeys = Object.keys(tableAttributes);
|
||||
|
||||
colKeys.forEach((key) => {
|
||||
let row = tableAttributes[key];
|
||||
let caption = row.comment ? row.comment : row.fieldName;
|
||||
cols.push({ caption, type: row.type.__proto__.key === "INTEGER" ? "number" : "string", key: row.field });
|
||||
});
|
||||
|
||||
const dbRows = await <%=table_name%>.findAll({});
|
||||
rows = dbRows.map((p) => {
|
||||
let tempRow = p.toJSON();
|
||||
let row = [];
|
||||
cols.forEach((col) => {
|
||||
row.push(tempRow[col.key]);
|
||||
});
|
||||
return row;
|
||||
});
|
||||
|
||||
return ctx.downFile({title, rows, cols });
|
||||
},
|
||||
|
||||
'POST /<%=table_name%>/page' : async (ctx, next) => {
|
||||
let param = ctx.getPageSize()
|
||||
let row = ctx.getBody();
|
||||
let {key,value}=row.seachOption
|
||||
let where={}
|
||||
if(key&&value){
|
||||
where[key]={ [op.like]:'%' +value + '%'}
|
||||
}
|
||||
|
||||
const res = await <%=table_name%>.findAndCountAll({
|
||||
where,
|
||||
order: [["id", "DESC"]],
|
||||
...param,
|
||||
});
|
||||
return ctx.success(res);
|
||||
},
|
||||
|
||||
'POST /<%=table_name%>/add': async (ctx, next) => {
|
||||
let row = ctx.getBody();
|
||||
const res = await <%=table_name%>.create(row);
|
||||
return ctx.success(res);
|
||||
},
|
||||
'POST /<%=table_name%>/edit': async (ctx, next) => {
|
||||
let row = ctx.getBody();
|
||||
let id = ctx.get('id')
|
||||
const res = await <%=table_name%>.update(row, { where: { id: id }, individualHooks: true });
|
||||
return ctx.success(res);
|
||||
},
|
||||
|
||||
'POST /<%=table_name%>/del': async (ctx, next) => {
|
||||
let id = ctx.get('id')
|
||||
const res = await <%=table_name%>.destroy({ where: { id: id }, individualHooks: true });
|
||||
return ctx.success(res);
|
||||
}
|
||||
};
|
||||
168
config/template/db.ejs
Normal file
168
config/template/db.ejs
Normal file
@@ -0,0 +1,168 @@
|
||||
const dayjs = require("dayjs");
|
||||
const Sequelize = require("sequelize");
|
||||
|
||||
const config ={
|
||||
"username": "<%=dbConfig.username%>",
|
||||
"password": "<%=dbConfig.password%>",
|
||||
"database": "<%=dbConfig.database%>",
|
||||
"host": "<%=dbConfig.host%>",
|
||||
"port": <%=dbConfig.port%>,
|
||||
"dialect": "<%=dbConfig.dialect%>"
|
||||
}
|
||||
|
||||
let model = {};
|
||||
|
||||
const logEditField = (oldRow, newRow) => {
|
||||
let str = ``;
|
||||
oldRow = oldRow.toJSON ? oldRow.toJSON() : oldRow;
|
||||
newRow = newRow ? newRow.toJSON() : newRow;
|
||||
|
||||
let keyRows = Object.keys(oldRow);
|
||||
for (let i = 0; i < keyRows.length; i++) {
|
||||
let key = keyRows[i];
|
||||
|
||||
if (key !== "create_time" && key !== "last_modify_time" && oldRow[key] !== newRow[key]) {
|
||||
let oldVal = oldRow[key];
|
||||
if (typeof oldVal === "string") {
|
||||
oldVal = oldVal.replace(/<p>/g, "").replace(/<\/p>/g, "");
|
||||
}
|
||||
|
||||
let newVal = newRow[key];
|
||||
if (typeof newVal === "string") {
|
||||
newVal = newVal.replace(/<p>/g, "").replace(/<\/p>/g, "");
|
||||
}
|
||||
str += ` ${key} 从<span class="bold"> ${oldVal} </span> 变更为 <span class="bold"> ${newVal} </span>,<br>`;
|
||||
}
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
const logCreateField = (oldRow) => {
|
||||
let str = ``;
|
||||
oldRow = oldRow.toJSON ? oldRow.toJSON() : oldRow;
|
||||
let keyRows = Object.keys(oldRow);
|
||||
|
||||
for (let i = 0; i < keyRows.length; i++) {
|
||||
let key = keyRows[i];
|
||||
|
||||
if (key !== "create_time" && key !== "last_modify_time") {
|
||||
let newVal = oldRow[key];
|
||||
if (typeof newVal === "string") {
|
||||
newVal = newVal.replace(/<p>/g, "").replace(/<\/p>/g, "");
|
||||
}
|
||||
|
||||
str += `<span class="bold"> ${key} </span> 为 <span class="bold"> ${newVal} </span>,<br>`;
|
||||
}
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
let sequelize = new Sequelize(config.database, config.username, config.password, {
|
||||
host: config.host,
|
||||
dialect: config.dialect,
|
||||
pool: {
|
||||
max: 5,
|
||||
min: 0,
|
||||
idle: 10000,
|
||||
},
|
||||
dialectOptions: {
|
||||
charset: "utf8mb4",
|
||||
collate: "utf8mb4_unicode_ci",
|
||||
supportBigNumbers: true,
|
||||
bigNumberStrings: true,
|
||||
},
|
||||
});
|
||||
|
||||
const define = (name, attributes) => {
|
||||
let attrs = {};
|
||||
for (let key in attributes) {
|
||||
let value = attributes[key];
|
||||
if (typeof value === "object" && value["type"]) {
|
||||
value.allowNull = value.allowNull || false;
|
||||
attrs[key] = value;
|
||||
} else {
|
||||
attrs[key] = {
|
||||
type: value,
|
||||
allowNull: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
attrs.create_time = {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: sequelize.literal("CURRENT_TIMESTAMP"),
|
||||
comment: "创建时间",
|
||||
get() {
|
||||
return dayjs(this.getDataValue("create_time")).format("YYYY-MM-DD HH:mm:ss");
|
||||
},
|
||||
};
|
||||
|
||||
attrs.last_modify_time = {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
comment: "最后更新时间",
|
||||
defaultValue: sequelize.literal("CURRENT_TIMESTAMP"),
|
||||
get() {
|
||||
return dayjs(this.getDataValue("last_modify_time")).format("YYYY-MM-DD HH:mm:ss");
|
||||
},
|
||||
};
|
||||
|
||||
model[name] = sequelize.define(name, attrs, {
|
||||
tableName: name,
|
||||
timestamps: false,
|
||||
hooks: {
|
||||
beforeValidate: (obj) => {
|
||||
let now = Date.now();
|
||||
if (obj.isNewRecord) {
|
||||
obj.create_time = now;
|
||||
obj.last_modify_time = now;
|
||||
} else {
|
||||
obj.last_modify_time = now;
|
||||
}
|
||||
},
|
||||
afterCreate: async (obj) => {
|
||||
let tableName = obj._modelOptions.tableName;
|
||||
if (tableName !== "sys_log") {
|
||||
let logStr = logCreateField(obj);
|
||||
await model["sys_log"].create({ table_name: tableName, operate: "新增", content: logStr });
|
||||
}
|
||||
},
|
||||
|
||||
afterDestroy: async (obj) => {
|
||||
let id = obj.id;
|
||||
let tableName = obj._modelOptions.tableName;
|
||||
if (tableName !== "sys_log") {
|
||||
await model["sys_log"].create({ table_name: tableName, operate: "删除", content: `用户删除id为 <span class="bold"> ${id} </span>` });
|
||||
}
|
||||
},
|
||||
|
||||
beforeUpdate: async (obj) => {
|
||||
let tableName = obj._modelOptions.tableName;
|
||||
if (tableName !== "sys_log") {
|
||||
let id = obj.id;
|
||||
let tableName = obj._modelOptions.tableName;
|
||||
let updateRow = await model[tableName].findOne({ where: { id } });
|
||||
let logStr = logEditField(updateRow, obj);
|
||||
await model["sys_log"].create({ table_name: tableName, operate: "修改", content: logStr });
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return model[name];
|
||||
};
|
||||
|
||||
let exp = {
|
||||
sequelize,
|
||||
define,
|
||||
sync: () => {
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
sequelize.sync({ force: false });
|
||||
} else {
|
||||
throw new Error("Cannot sync() when NODE_ENV is set to 'production'.");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = exp;
|
||||
68
config/template/dbInit/ddl.db
Normal file
68
config/template/dbInit/ddl.db
Normal file
@@ -0,0 +1,68 @@
|
||||
DROP TABLE IF EXISTS sys_user;
|
||||
CREATE TABLE `sys_user` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(100) NOT NULL DEFAULT '',
|
||||
`password` varchar(100) NOT NULL DEFAULT '',
|
||||
`roleId` int(8) NOT NULL,
|
||||
`create_time` datetime DEFAULT NULL,
|
||||
`last_modify_time` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS sys_role;
|
||||
CREATE TABLE `sys_role` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(100) NOT NULL DEFAULT '',
|
||||
`type` int(1) NOT NULL DEFAULT '0',
|
||||
`menus` json NOT NULL,
|
||||
`create_time` datetime DEFAULT NULL,
|
||||
`last_modify_time` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
|
||||
|
||||
DROP TABLE IF EXISTS sys_menu;
|
||||
CREATE TABLE `sys_menu` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(100) NOT NULL DEFAULT '',
|
||||
`parent_id` int(5) unsigned DEFAULT '0',
|
||||
`model_id` int(11) unsigned DEFAULT NULL,
|
||||
`form_id` int(11) DEFAULT NULL,
|
||||
`icon` varchar(100) NOT NULL DEFAULT '',
|
||||
`path` varchar(255) NOT NULL DEFAULT '',
|
||||
`component` varchar(100) NOT NULL DEFAULT '',
|
||||
`api_path` varchar(100) DEFAULT NULL,
|
||||
`is_show_menu` tinyint(1) NOT NULL DEFAULT '1',
|
||||
`is_show` tinyint(1) NOT NULL DEFAULT '1',
|
||||
`type` enum('菜单','页面','外链','功能') NOT NULL DEFAULT '页面',
|
||||
`sort` int(11) DEFAULT '0',
|
||||
`create_time` datetime DEFAULT NULL,
|
||||
`last_modify_time` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=120 DEFAULT CHARSET=utf8;
|
||||
|
||||
DROP TABLE IF EXISTS sys_log;
|
||||
CREATE TABLE `sys_log` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`table_name` varchar(100) NOT NULL DEFAULT '',
|
||||
`user_id` int(11) unsigned NOT NULL DEFAULT '0',
|
||||
`operate` varchar(100) NOT NULL DEFAULT '',
|
||||
`content` json NOT NULL,
|
||||
`create_time` datetime DEFAULT NULL,
|
||||
`last_modify_time` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1388 DEFAULT CHARSET=utf8;
|
||||
|
||||
DROP TABLE IF EXISTS sys_parameter;
|
||||
CREATE TABLE `sys_parameter` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`key` varchar(100) NOT NULL DEFAULT '',
|
||||
`value` varchar(100) NOT NULL DEFAULT '',
|
||||
`is_modified` int(2) DEFAULT '0',
|
||||
`remark` varchar(500) NOT NULL DEFAULT '',
|
||||
`create_time` datetime DEFAULT NULL,
|
||||
`last_modify_time` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
|
||||
43
config/template/dbInit/insert.db
Normal file
43
config/template/dbInit/insert.db
Normal file
@@ -0,0 +1,43 @@
|
||||
INSERT INTO sys_user
|
||||
(id, name, password, roleId, create_time, last_modify_time)
|
||||
VALUES(1, 'zc', 'd3df61764ee9a26091f714b88958caef', 6, '2022-10-24 05:45:40', '2022-10-24 05:45:40');
|
||||
|
||||
|
||||
|
||||
INSERT INTO sys_user
|
||||
(id, name, password, roleId, create_time, last_modify_time)
|
||||
VALUES(2, 'admin', 'e10adc3949ba59abbe56e057f20f883e', 4, '2022-10-24 05:45:40', '2022-10-24 05:45:40');
|
||||
|
||||
|
||||
|
||||
INSERT INTO sys_role
|
||||
(id, name, `type`, menus, create_time, last_modify_time)
|
||||
VALUES(3, '运营专员', 0, '{"value": "[1,71,77,82,67,68]"}', '2020-03-20 05:22:40', '2020-03-20 05:22:40');
|
||||
|
||||
INSERT INTO sys_role
|
||||
(id, name, `type`, menus, create_time, last_modify_time)
|
||||
VALUES(4, '管理员', 0, '{"value": "[1,71,76,77,78,79,5,11,12,67,68,15]"}', '2020-03-28 17:35:39', '2022-10-28 19:04:40');
|
||||
|
||||
INSERT INTO sys_role
|
||||
(id, name, `type`, menus, create_time, last_modify_time)
|
||||
VALUES(6, '超级管理员', 1, '{"value": "[1,71,80,78,76,77,5,11,12,67,68,15,31,13,26,27]"}', '2020-05-02 08:32:44', '2020-05-02 08:32:44');
|
||||
|
||||
|
||||
INSERT INTO sys_parameter (id, `key`, value, is_modified, remark, create_time, last_modify_time) VALUES(1, 'sys_title', '${demo系统管理}', 0, '系统标题', '2023-11-16 09:28:45', '2023-11-16 09:28:45');
|
||||
INSERT INTO sys_parameter (id, `key`, value, is_modified, remark, create_time, last_modify_time) VALUES(2, 'sys_logo', 'https://light22600.oss-cn-beijing.aliyuncs.com/bgWeb/logo.png', 0, '系统logo', '2021-11-12 14:44:31', '2021-11-12 14:44:31');
|
||||
|
||||
|
||||
INSERT INTO sys_menu (id, name, parent_id, model_id, form_id, icon, `path`, component, api_path, is_show_menu, is_show, `type`, sort, create_time, last_modify_time) VALUES(1, '首页', 0, NULL, NULL, 'md-home', 'home', 'home/index.vue', NULL, 1, 1, '页面', 0, '2021-07-16 11:48:15', '2021-07-16 11:48:15');
|
||||
INSERT INTO sys_menu (id, name, parent_id, model_id, form_id, icon, `path`, component, api_path, is_show_menu, is_show, `type`, sort, create_time, last_modify_time) VALUES(5, '系统管理', 0, NULL, NULL, 'ios-construct', 'system', '', NULL, 1, 1, '菜单', 100, '2021-07-16 12:02:32', '2021-07-16 12:02:32');
|
||||
INSERT INTO sys_menu (id, name, parent_id, model_id, form_id, icon, `path`, component, api_path, is_show_menu, is_show, `type`, sort, create_time, last_modify_time) VALUES(11, '系统用户', 5, NULL, NULL, 'md-bug', 'sys_user', 'system/sys_user.vue', 'system/sys_user_server.js', 1, 1, '页面', 0, '2021-07-16 04:56:54', '2021-07-16 04:56:54');
|
||||
INSERT INTO sys_menu (id, name, parent_id, model_id, form_id, icon, `path`, component, api_path, is_show_menu, is_show, `type`, sort, create_time, last_modify_time) VALUES(12, '角色管理', 5, NULL, NULL, 'md-disc', 'sys_role', 'system/sys_role.vue', 'system/sys_role_server.js', 1, 1, '页面', 0, '2021-07-16 04:57:04', '2021-07-16 04:57:04');
|
||||
INSERT INTO sys_menu (id, name, parent_id, model_id, form_id, icon, `path`, component, api_path, is_show_menu, is_show, `type`, sort, create_time, last_modify_time) VALUES(13, '菜单管理', 5, NULL, NULL, 'ios-people', 'menu', 'system_high/sys_menu.vue', NULL, 1, 1, '页面', 0, '2021-06-17 09:13:37', '2021-06-17 09:13:37');
|
||||
INSERT INTO sys_menu (id, name, parent_id, model_id, form_id, icon, `path`, component, api_path, is_show_menu, is_show, `type`, sort, create_time, last_modify_time) VALUES(15, '参数设定管理', 5, NULL, NULL, 'ios-people', 'sys_param_setup', 'system/sys_param_setup.vue', 'system/sys_param_setup_server.js', 1, 1, '页面', 5, '2021-11-12 06:06:58', '2021-11-12 06:06:58');
|
||||
INSERT INTO sys_menu (id, name, parent_id, model_id, form_id, icon, `path`, component, api_path, is_show_menu, is_show, `type`, sort, create_time, last_modify_time) VALUES(60, '用户管理', 59, 4, NULL, 'md-cloud-upload', 'vip_member', 'vip/vip_member.vue', 'vip/vip_member_server.js', 1, 1, '页面', 1, '2021-07-05 09:55:53', '2021-07-05 09:55:53');
|
||||
INSERT INTO sys_menu (id, name, parent_id, model_id, form_id, icon, `path`, component, api_path, is_show_menu, is_show, `type`, sort, create_time, last_modify_time) VALUES(65, '信息类目管理', 64, 5, NULL, 'md-calculator', 'info_type', 'cote/info_type.vue', 'cote/info_type_server.js', 1, 1, '页面', 1, '2021-09-02 06:25:45', '2021-09-02 06:25:45');
|
||||
INSERT INTO sys_menu (id, name, parent_id, model_id, form_id, icon, `path`, component, api_path, is_show_menu, is_show, `type`, sort, create_time, last_modify_time) VALUES(66, '信息管理', 64, 6, NULL, 'md-color-palette', 'info', 'cote/info.vue', 'cote/info_server.js', 1, 1, '页面', 2, '2021-07-15 09:33:57', '2021-07-15 09:33:57');
|
||||
INSERT INTO sys_menu (id, name, parent_id, model_id, form_id, icon, `path`, component, api_path, is_show_menu, is_show, `type`, sort, create_time, last_modify_time) VALUES(67, '日志管理', 5, 0, NULL, 'md-cash', 'sys_log', 'system/sys_log.vue', 'system/sys_log_server.js', 1, 1, '页面', 1, '2021-07-16 08:44:34', '2021-07-16 08:44:34');
|
||||
INSERT INTO sys_menu (id, name, parent_id, model_id, form_id, icon, `path`, component, api_path, is_show_menu, is_show, `type`, sort, create_time, last_modify_time) VALUES(68, '操作日志', 5, 0, NULL, 'md-female', 'sys_log_operate', 'system/sys_log_operate.vue', 'system/sys_log_operate_server.js', 1, 1, '页面', 1, '2021-07-19 05:49:52', '2021-07-19 05:49:52');
|
||||
|
||||
|
||||
|
||||
25
config/template/model.ejs
Normal file
25
config/template/model.ejs
Normal file
@@ -0,0 +1,25 @@
|
||||
const dayjs = require("dayjs");
|
||||
const Sequelize = require('sequelize');
|
||||
<% if(isProjectDb){%>
|
||||
const db = require('../db.js');
|
||||
<%} else{%>
|
||||
const db = require('../../middleware/db');
|
||||
<%}%>
|
||||
|
||||
module.exports = db.define('<%=table_name%>', {
|
||||
<% columns.forEach(function(col){ %>
|
||||
<%=col.key%>:{
|
||||
comment:'<%=col.name%>',
|
||||
<%if(col.data_type==="DOUBLE") {%>type: Sequelize.<%=col.data_type%>(<%=col.data_length%>,4),<%}
|
||||
else if(col.data_type==='DATE'||col.data_type==='TEXT'||col.data_type==='JSON'){%>type: Sequelize.<%=col.data_type%>(), <%}
|
||||
else {%>type: Sequelize.<%=col.data_type%>(<%=col.data_length%>), <%}%>
|
||||
allowNull: <%=col.allow_null||false%>,
|
||||
<%if(col.data_type==='DATE'){%>defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
|
||||
get() { return dayjs(this.getDataValue("<%=col.key%>")).format("YYYY-MM-DD HH:mm:ss");}<%}
|
||||
else if(col.data_type==='INTEGER'){%>defaultValue: '0'<%}
|
||||
else if(col.data_type==='BOOLEAN'){%>defaultValue: '0'<%}
|
||||
else{%>defaultValue: '<%=col.default_value%>'
|
||||
<%}%>
|
||||
},
|
||||
<%});%>
|
||||
});
|
||||
BIN
config/template/systemWeb.zip
Normal file
BIN
config/template/systemWeb.zip
Normal file
Binary file not shown.
38
config/template/vue_file/apiServer.ejs
Normal file
38
config/template/vue_file/apiServer.ejs
Normal file
@@ -0,0 +1,38 @@
|
||||
import http from '@/libs/http';
|
||||
class <%=fileName%>ClServer {
|
||||
async all(param) {
|
||||
let res= await http.get('/<%=modelName%>/all', param);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
async page(row) {
|
||||
let res= await http.post('/<%=modelName%>/page', row);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
async exportCsv(row) {
|
||||
let res = http.fileExport("/<%=modelName%>/export", row);
|
||||
return res;
|
||||
}
|
||||
|
||||
async add(row) {
|
||||
let res= await http.post('/<%=modelName%>/add', row);
|
||||
return res;
|
||||
}
|
||||
|
||||
async edit(row) {
|
||||
let res= await http.post('/<%=modelName%>/edit', row);
|
||||
return res;
|
||||
}
|
||||
|
||||
async del(row) {
|
||||
let res= await http.post('/<%=modelName%>/del', row);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
const <%=fileName%>Server = new <%=fileName%>ClServer();
|
||||
export default <%=fileName%>Server;
|
||||
|
||||
190
config/template/vue_file/page.ejs
Normal file
190
config/template/vue_file/page.ejs
Normal file
@@ -0,0 +1,190 @@
|
||||
<template>
|
||||
<div class="content-view">
|
||||
<div class="table-head-tool">
|
||||
<Button type="primary" @click="showAddWarp">新增</Button>
|
||||
|
||||
<Form ref="formInline" :model="gridOption.param.seachOption" inline :label-width="80">
|
||||
<FormItem :label-width="20" class="flex">
|
||||
<Select v-model="gridOption.param.seachOption.key" style="width: 120px" :placeholder="seachTypePlaceholder">
|
||||
<Option v-for="item in seachTypes" :value="item.key" :key="item.key">{{ item.value }}</Option>
|
||||
</Select>
|
||||
<Input class="ml10" v-model="gridOption.param.seachOption.value" style="width: 200px" search placeholder="请输入关键字" @on-search="query(1)" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem>
|
||||
<Button type="default" @click="exportCsv">导出</Button>
|
||||
</FormItem>
|
||||
</Form>
|
||||
</div>
|
||||
<div class="table-body">
|
||||
<tables :columns="listColumns" :value="gridOption.data" :pageOption="gridOption.param.pageOption" @changePage="query"></tables>
|
||||
</div>
|
||||
<editModal ref="editModal" :columns="editColumns" :rules="gridOption.rules"> </editModal>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import funTool from '@/libs/funTool'
|
||||
import uiTool from '@/libs/uiTool'
|
||||
import menuServer from '@/api/system_high/menuServer.js'
|
||||
import <%=fileName%>Server from '@/api/<%=api_path%>'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
let rules = {}
|
||||
<%columns.forEach(p=>{%>
|
||||
<%if(p.data_type==="DOUBLE"||p.data_type==="INTEGER") {%>rules["<%=p.key%>"]=[{ required: true,type:"number", message: '请选择<%=p.name%>', trigger: 'change' }];<%}
|
||||
else if(p.control.comType==="Select"||p.control.comType==="Radio"||p.control.comType==="Checkbox") {%>
|
||||
rules["<%=p.key%>"]=[{ required: true, message: '请选择<%=p.name%>', trigger: 'change', }]<%}
|
||||
else if(p.name.indexOf("图")>-1){%>
|
||||
rules["<%=p.key%>"]=[{ required: true, message: '请上传<%=p.name%>', trigger: 'change' }] <%}
|
||||
else if(p.data_type==="BOOLEAN"){%>
|
||||
rules["<%=p.key%>"]=[{ required: true,type:'boolean', message: '请选择<%=p.name%>', trigger: 'change' }] <%}
|
||||
else{%>rules["<%=p.key%>"]=[{ required: true, message: '请填写<%=p.name%>'}];<%}%> <%})%>
|
||||
return {
|
||||
seachTypes:[
|
||||
<%columns.filter(p=>p.is_show_seach===1).forEach(p=>{%> {key:"<%=p.key%>",value:"<%=p.name%>"},<%})%>
|
||||
],
|
||||
gridOption: {
|
||||
param: {
|
||||
seachOption:{key:"",value:""},
|
||||
pageOption:{
|
||||
total: 0,
|
||||
page: 1,
|
||||
pageSize: 20
|
||||
}
|
||||
},
|
||||
rules,
|
||||
columns:[
|
||||
{key:'id',title:'id',width:'80px',is_show_edit:0},
|
||||
<%columns.forEach(p=>{%>
|
||||
<%if(p.control.comType==="Select"||p.control.comType==="Radio"||p.control.comType==="Checkbox"){%>{ key: "<%=p.key%>",title:"<%=p.name%>",
|
||||
com:"<%=p.control.comType%>",
|
||||
source:[<%p.source.forEach(row=>{%>{key:<%=row.key%>,value:"<%=row.value%>"}, <%})%>] ,render:(h,params)=>{
|
||||
let row=params.column.source.find(p=>(p.key)==params.row['<%=p.key%>'] )
|
||||
if(row){ return <span>{row.value}</span>}else { return <span>-</span> }
|
||||
},
|
||||
disabled: <%=p.is_edit_disable?true:false%>,
|
||||
is_show_edit:<%=p.is_show_edit%>,
|
||||
is_show_list:<%=p.is_show_list%>,
|
||||
defaultVal:'<%=p.default_value%>',
|
||||
},
|
||||
<%}else if(p.control.comType==='UploadSingle'){%>{ key: "<%=p.key%>",title:"<%=p.name%>",com:"<%=p.control.comType%>", disabled: <%=p.is_edit_disable?true:false%>, is_show_edit:<%=p.is_show_edit%>,is_show_list:<%=p.is_show_list%>,
|
||||
render:(h,params)=>{ return <img src={params.row['<%=p.key%>']} style={{ width: '100px', height: '100px' }} />} },
|
||||
<%}else if(p.control.comType){%>{ key: "<%=p.key%>",title:"<%=p.name%>",disabled: <%=p.is_edit_disable?true:false%>,is_show_edit:<%=p.is_show_edit%>,is_show_list:<%=p.is_show_list%>%>, <%if(p.data_type==="DOUBLE"||p.data_type==="INTEGER") {%>data_type:"number",<%} else if(p.data_type==="BOOLEAN"){%>data_type:"boolean",<%}%> com:"<%=p.control.comType%>" },<%} else {%>{ key: "<%=p.key%>",title:"<%=p.name%>", is_show_edit:<%=p.is_show_edit%>,is_show_list:<%=p.is_show_list%>,disabled: <%=p.is_edit_disable?true:false%> }, <%}%><%})%>
|
||||
{key:'create_time',title:'创建时间',width:'100px',is_show_edit:0 },
|
||||
{key:'last_modify_time',title:'更新时间',width:'100px',is_show_edit:0 },
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width:'200px',
|
||||
type: 'template',
|
||||
render: (h, params) => {
|
||||
let btns = [
|
||||
{
|
||||
title: '修改',
|
||||
type: 'primary',
|
||||
click: () => {
|
||||
this.showEditWarp(params.row)
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '删除',
|
||||
type: 'primary',
|
||||
click: () => {
|
||||
this.delConfirm(params.row)
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
return uiTool.getBtn(h, btns)
|
||||
},
|
||||
},],
|
||||
data: []
|
||||
},
|
||||
}
|
||||
},
|
||||
computed:{
|
||||
seachTypePlaceholder(){
|
||||
return this.seachTypes.map(p=>p.value).slice(0,3).join('/')
|
||||
},
|
||||
editColumns(){
|
||||
let editTempColumns= this.gridOption.columns.filter(p=>p.is_show_edit===1)
|
||||
return editTempColumns
|
||||
},
|
||||
listColumns(){
|
||||
let listTempColumns= this.gridOption.columns.filter(p=>p.is_show_list!==0)
|
||||
return listTempColumns
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.init()
|
||||
this.initCol()
|
||||
},
|
||||
methods: {
|
||||
init() {
|
||||
this.query(1)
|
||||
},
|
||||
async initCol(){
|
||||
<%if(columns&&columns.length>0){%>
|
||||
let columnRows=[<%columns.forEach(p=>{%> <%if(p.control.interfaceType ==='接口'){%> {key:'<%=p.key%>',modelKey:"<%=p.control.modelKey%>",map_option:{key:"<%=p.control.modelMap.key%>",value:"<%=p.control.modelMap.value%>"}},<%}%><%})%>]
|
||||
let columnKeys=columnRows.map(p=>p.key)
|
||||
let newColumns=this.gridOption.columns.filter(p=>columnKeys.indexOf(p.key) >-1)
|
||||
for(let i=0;i<newColumns.length;i++){
|
||||
let curColumn =newColumns[i]
|
||||
let modelMap=columnRows[i].map_option
|
||||
let res=await menuServer.modelInterface({model_key:columnRows[i].modelKey,map_option:modelMap})
|
||||
curColumn.source=res.data
|
||||
}
|
||||
<%}%>
|
||||
},
|
||||
|
||||
async inquiry() {
|
||||
let res = await <%=fileName%>Server.all(this.gridOption.param)
|
||||
this.gridOption.data = res.data
|
||||
},
|
||||
|
||||
async query(page){
|
||||
if (page) {
|
||||
this.gridOption.param.pageOption.page = page
|
||||
}
|
||||
|
||||
let res = await <%=fileName%>Server.page(this.gridOption.param)
|
||||
this.gridOption.data = res.data.rows
|
||||
this.gridOption.param.pageOption.total = res.data.count
|
||||
|
||||
},
|
||||
async showAddWarp() {
|
||||
this.$refs.editModal.addShow({<%columns.filter(p=>(p.default_value||p.default_value===0)).forEach(p=>{%>'<%=p.key%>':'<%=p.default_value%>',<%})%> }, async (newRow) => {
|
||||
let res = await <%=fileName%>Server.add(newRow)
|
||||
rootVue.$Message.success('新增成功!')
|
||||
this.init()
|
||||
})
|
||||
},
|
||||
async showEditWarp(row) {
|
||||
this.$refs.editModal.editShow(row, async (newRow) => {
|
||||
let valid = await this.$refs['editModal'].$refs['From'].validate()
|
||||
if (valid) {
|
||||
let res = await <%=fileName%>Server.edit(newRow)
|
||||
rootVue.$Message.success('修改成功!')
|
||||
this.init()
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
async delConfirm(row){
|
||||
uiTool.delConfirm(async () => {
|
||||
await <%=fileName%>Server.del(row)
|
||||
rootVue.$Message.success('删除成功!')
|
||||
this.init()
|
||||
})
|
||||
},
|
||||
|
||||
async exportCsv(row){
|
||||
await <%=fileName%>Server.exportCsv(row)
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less"></style>
|
||||
Reference in New Issue
Block a user