lrf hai 1 ano
pai
achega
30e5cb2274
Modificáronse 3 ficheiros con 14 adicións e 0 borrados
  1. 3 0
      app/controller/.table.js
  2. 10 0
      app/service/table.js
  3. 1 0
      app/z_router/table.js

+ 3 - 0
app/controller/.table.js

@@ -47,4 +47,7 @@ module.exports = {
   getSchema: {
     params: ['!id'],
   },
+  copy: {
+    requestBody: ['!_id', '!project', 'dir'],
+  },
 };

+ 10 - 0
app/service/table.js

@@ -143,6 +143,16 @@ class TableService extends CrudService {
     }
     return data;
   }
+  async copy(data) {
+    // !id:表id;!project:复制到的项目下;dir:复制到的文件夹下
+    let table = await this.model.findById(data);
+    if (!table) return false;
+    table = JSON.parse(JSON.stringify(table));
+    const nt = _.pick(table, ['name', 'name_zh', 'columns', 'sort', 'remark']);
+    nt.project = data.project;
+    if (data.dir) nt.dir = data.dir;
+    await this.model.create(nt);
+  }
 }
 
 module.exports = TableService;

+ 1 - 0
app/z_router/table.js

@@ -5,6 +5,7 @@ module.exports = (app) => {
   const target = 'table';
   const prefix = config.routePrefix;
   const mware = app.middleware.logDb();
+  router.post(target, `${prefix}/${target}/copy`, controller[target].copy);
   router.post(`targetExport`, `${prefix}/${target}/export`, mware, controller[target].toExport);
   router.post(`targetExportTS`, `${prefix}/${target}/exportTS`, controller[target].toExportTS);
   router.resources(target, `${prefix}/${target}`, controller[target]); // index、create、show、destroy