Skip to content

Commit

Permalink
Feat: 多语言导出增加过滤字段
Browse files Browse the repository at this point in the history
  • Loading branch information
pandaoh committed Nov 13, 2024
1 parent b269b53 commit 090a835
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 8 deletions.
24 changes: 17 additions & 7 deletions bin/xcmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @Author: HxB
* @Date: 2022-04-25 16:27:06
* @LastEditors: DoubleAm
* @LastEditTime: 2024-11-03 16:44:49
* @LastEditTime: 2024-11-13 10:58:05
* @Description: 命令处理文件
* @FilePath: \js-xcmd\bin\xcmd.js
*/
Expand Down Expand Up @@ -34,6 +34,7 @@ const { cmd } = require('../utils/cmd');
const { node2es6, sortJSON, mergeObj, versionUpgrade, isValidJson, jsonToExcel } = require('../utils/tools');
const { extractParamsFromFiles } = require('../utils/ast');
const { downloadTpl } = require('../utils/tpl');
const { FILTER_KEYS } = require('../utils/data');
const nodeCmd = require('node-cmd');
const readline = require('readline');

Expand Down Expand Up @@ -708,15 +709,24 @@ program
});

program
.option('json2excel <projectCode> [jsonFilePath]', 'json2excel <projectCode> [jsonFilePath]')
.command('json2excel <projectCode> [jsonFilePath]')
.option('json2excel <projectCode> [jsonFilePath] [notFilter]', 'json2excel <projectCode> [jsonFilePath] [notFilter]')
.command('json2excel <projectCode> [jsonFilePath] [notFilter]')
.description('将 JSON 数据转化为 Excel')
.action((projectCode, jsonFilePath) => {
.action((projectCode, jsonFilePath, notFilter) => {
notFilter = `${notFilter}` === 'true';
if (!projectCode) {
console.error('请提供 Project Code');
return;
}

const _filterJsonData = (data) => {
if (notFilter) return data;
FILTER_KEYS.forEach((key) => {
delete data[key];
});
return data;
};

if (!jsonFilePath) {
// 如果未提供JSON文件路径,则提示输入JSON内容
const rl = readline.createInterface({
Expand All @@ -727,7 +737,7 @@ program
rl.question('请输入 JSON 数据: \n', (jsonData) => {
rl.close();
if (isValidJson(jsonData)) {
jsonToExcel(projectCode, JSON.parse(jsonData));
jsonToExcel(projectCode, _filterJsonData(JSON.parse(jsonData)));
} else {
console.error('输入的内容不是有效的JSON格式');
}
Expand All @@ -736,7 +746,7 @@ program
const filePath = getResolvePath(jsonFilePath);
const jsonData = getJSONFileObj(filePath);
if (jsonData) {
jsonToExcel(projectCode, jsonData);
jsonToExcel(projectCode, _filterJsonData(jsonData));
} else {
console.error('JSON 文件中的内容不是有效的 JSON 格式');
}
Expand All @@ -751,7 +761,7 @@ program
listData?.forEach((i) => {
jsonData[i] = i;
});
jsonToExcel(projectCode, jsonData);
jsonToExcel(projectCode, _filterJsonData(jsonData));
}
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-xcmd",
"version": "1.5.15",
"version": "1.5.16",
"description": "XCmd library for node.js.",
"main": "main.js",
"bin": {
Expand Down
120 changes: 120 additions & 0 deletions utils/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
const FILTER_KEYS = [
'首页',
'上一步',
'下一步',
'返回',
'上一页',
'下一页',
'跳转',
'文件',
'下载',
'生效',
'失效',
'启用',
'停用',
'禁用',
'是',
'否',
'性别',
'男',
'女',
'开启',
'关闭',
'退出',
'状态',
'国家',
'重置',
'搜索',
'查询',
'查看',
'新增',
'编辑',
'删除',
'批量导入',
'批量导出',
'导入',
'导出',
'导出选中',
'导出全部',
'全部',
'操作完成',
'成功',
'失败',
'请输入',
'请选择',
'确认',
'确定',
'取消',
'保存',
'提交',
'清空',
'详情',
'操作',
'操作人',
'创建人',
'创建时间',
'更新人',
'更新时间',
'日期',
'时间',
'年',
'月',
'日',
'时',
'分',
'小时',
'分钟',
'秒',
'毫秒',
'星期',
'星期一',
'星期二',
'星期三',
'星期四',
'星期五',
'星期六',
'星期日',
'星期天',
'放大',
'缩小',
'最小化',
'最大化',
'排序',
'名称',
'备注',
'选择',
'加载中',
'筛选',
'刷新',
'选择文件',
'处理中',
'继续',
'停止',
'跳过',
'全选',
'反选',
'反馈',
'照片',
'图片',
'请上传',
'基础信息',
'基本信息',
'省',
'州',
'市',
'区',
'城市',
'街道',
'点击上传',
'经度',
'纬度',
'可选',
'已选',
'关联',
'不关联',
'请输入必填项',
'请输入正确的格式',
'数据填写不完整请检查并补充所有必填项'
];

module.exports = { FILTER_KEYS };

0 comments on commit 090a835

Please sign in to comment.