1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date
- * @version
- */
- const path = require('path');
- const fs = require('fs');
- module.exports = app => {
- class TemplateController extends app.BaseController {
- /**
- * 下载 各种模板
- * @param ctx
- * @returns {Promise<void>}
- */
- async download(ctx) {
- const file = ctx.params.file;
- if (file) {
- try {
- let fileName;
- switch (file) {
- case '导入分项清单EXCEL格式.xlsx':
- fileName = path.join(this.app.baseDir, 'app', 'public', 'files', 'template', 'ledger', '导入分项清单EXCEL格式.xlsx');
- break;
- case '导入工程量清单EXCEL格式.xls':
- fileName = path.join(this.app.baseDir, 'app', 'public', 'files', 'template', 'ledger', '导入工程量清单EXCEL格式.xls');
- break;
- case '估概预算示例EXCEL格式.xlsx':
- fileName = path.join(this.app.baseDir, 'app', 'public', 'files', 'template', file);
- break;
- case '控制价示例EXCEL格式.xlsx':
- fileName = path.join(this.app.baseDir, 'app', 'public', 'files', 'template', file);
- break;
- default:
- throw '参数错误'
- }
- ctx.body = await fs.readFileSync(fileName);
- } catch (err) {
- this.log(err);
- if (err.stack) {
- ctx.body = '您下载的示例文件不存在';
- } else {
- ctx.body = err;
- }
- }
- } else {
- ctx.body = '参数错误';
- }
- }
- }
- return TemplateController;
- };
|