nsgm-cli 2.1.19 → 2.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/components/Button.tsx +3 -3
- package/client/components/ClientProviders.tsx +12 -12
- package/client/components/LanguageSwitcher.tsx +26 -26
- package/client/components/SSRSafeAntdProvider.tsx +7 -7
- package/client/components/SuppressHydrationWarnings.tsx +30 -30
- package/client/components/__tests__/Button.test.tsx +12 -12
- package/client/layout/index.tsx +124 -124
- package/client/redux/reducers.ts +2 -2
- package/client/redux/store.ts +24 -24
- package/client/redux/template/manage/actions.ts +40 -40
- package/client/redux/template/manage/reducers.ts +32 -32
- package/client/redux/template/manage/types.ts +19 -19
- package/client/service/template/manage.ts +29 -29
- package/client/styled/common.ts +6 -6
- package/client/styled/layout/index.ts +17 -17
- package/client/styled/template/manage.ts +19 -19
- package/client/utils/common.ts +54 -54
- package/client/utils/cookie.ts +30 -30
- package/client/utils/fetch.ts +111 -111
- package/client/utils/i18n.ts +41 -41
- package/client/utils/menu.tsx +12 -12
- package/client/utils/navigation.ts +22 -22
- package/client/utils/sso.ts +124 -124
- package/client/utils/suppressWarnings.ts +17 -17
- package/generation/prettierrc +6 -0
- package/lib/args.js +19 -19
- package/lib/cli/app.d.ts +1 -1
- package/lib/cli/app.js +2 -2
- package/lib/cli/commands/build.d.ts +1 -1
- package/lib/cli/commands/build.js +9 -9
- package/lib/cli/commands/create.d.ts +1 -1
- package/lib/cli/commands/create.js +36 -36
- package/lib/cli/commands/delete.d.ts +1 -1
- package/lib/cli/commands/delete.js +55 -55
- package/lib/cli/commands/export.d.ts +1 -1
- package/lib/cli/commands/export.js +12 -12
- package/lib/cli/commands/help.d.ts +1 -1
- package/lib/cli/commands/help.js +29 -29
- package/lib/cli/commands/init.d.ts +1 -1
- package/lib/cli/commands/init.js +31 -31
- package/lib/cli/commands/server.d.ts +1 -1
- package/lib/cli/commands/server.js +12 -12
- package/lib/cli/commands/upgrade.d.ts +1 -1
- package/lib/cli/commands/upgrade.js +13 -13
- package/lib/cli/commands/version.d.ts +1 -1
- package/lib/cli/commands/version.js +7 -7
- package/lib/cli/index.d.ts +13 -13
- package/lib/cli/parser.d.ts +1 -1
- package/lib/cli/parser.js +12 -12
- package/lib/cli/registry.d.ts +1 -1
- package/lib/cli/types.d.ts +2 -2
- package/lib/cli/utils/console.d.ts +2 -2
- package/lib/cli/utils/console.js +22 -22
- package/lib/cli/utils/index.d.ts +2 -2
- package/lib/cli/utils/prompt.d.ts +1 -1
- package/lib/cli/utils/prompt.js +98 -98
- package/lib/constants.js +28 -28
- package/lib/generate.d.ts +2 -2
- package/lib/generate.js +19 -19
- package/lib/generate_create.d.ts +1 -1
- package/lib/generate_create.js +38 -38
- package/lib/generate_delete.js +63 -63
- package/lib/generate_init.js +94 -94
- package/lib/generators/base-generator.d.ts +1 -1
- package/lib/generators/base-generator.js +23 -23
- package/lib/generators/file-generator.js +15 -15
- package/lib/generators/generator-factory.d.ts +5 -5
- package/lib/generators/i18n-generator.d.ts +1 -1
- package/lib/generators/i18n-generator.js +127 -127
- package/lib/generators/page-generator.d.ts +1 -1
- package/lib/generators/page-generator.js +25 -25
- package/lib/generators/resolver-generator.d.ts +1 -1
- package/lib/generators/resolver-generator.js +27 -27
- package/lib/generators/schema-generator.d.ts +1 -1
- package/lib/generators/schema-generator.js +4 -4
- package/lib/generators/service-generator.d.ts +1 -1
- package/lib/generators/service-generator.js +29 -29
- package/lib/generators/sql-generator.d.ts +1 -1
- package/lib/generators/sql-generator.js +10 -10
- package/lib/index.js +23 -23
- package/lib/server/csrf.d.ts +3 -3
- package/lib/server/csrf.js +20 -20
- package/lib/server/db.d.ts +1 -1
- package/lib/server/db.js +21 -21
- package/lib/server/graphql.js +26 -26
- package/lib/server/plugins/date.d.ts +1 -1
- package/lib/server/plugins/date.js +6 -6
- package/lib/server/utils/graphql-cache.js +5 -5
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/lib/utils/project-config.d.ts +1 -1
- package/lib/utils/project-config.js +20 -20
- package/lib/utils.js +3 -3
- package/package.json +1 -1
- package/pages/_app.tsx +62 -62
- package/pages/_document.tsx +15 -15
- package/pages/_error.tsx +26 -26
- package/pages/index.tsx +48 -48
- package/pages/login.tsx +64 -64
- package/pages/template/manage.tsx +175 -175
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { useState, useEffect } from
|
|
2
|
-
import { ConfigProvider, Modal, Space, Upload, message } from
|
|
1
|
+
import React, { useState, useEffect } from "react";
|
|
2
|
+
import { ConfigProvider, Modal, Space, Upload, message } from "antd";
|
|
3
3
|
import {
|
|
4
4
|
Container,
|
|
5
5
|
SearchRow,
|
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
IconWrapper,
|
|
13
13
|
RoundedButton,
|
|
14
14
|
GlobalStyle,
|
|
15
|
-
} from
|
|
16
|
-
import { useDispatch, useSelector } from
|
|
15
|
+
} from "@/styled/template/manage";
|
|
16
|
+
import { useDispatch, useSelector } from "react-redux";
|
|
17
17
|
import {
|
|
18
18
|
addTemplate,
|
|
19
19
|
modTemplate,
|
|
@@ -21,105 +21,105 @@ import {
|
|
|
21
21
|
updateSSRTemplate,
|
|
22
22
|
searchTemplate,
|
|
23
23
|
batchDelTemplate,
|
|
24
|
-
} from
|
|
25
|
-
import { getTemplateService } from
|
|
26
|
-
import { RootState, AppDispatch } from
|
|
27
|
-
import _ from
|
|
28
|
-
import { useTranslation } from
|
|
29
|
-
import { getAntdLocale } from
|
|
30
|
-
import { useRouter } from
|
|
31
|
-
import { handleXSS, checkModalObj } from
|
|
32
|
-
import { UploadOutlined } from
|
|
33
|
-
import ExcelJS from
|
|
34
|
-
import { saveAs } from
|
|
35
|
-
import { createCSRFUploadProps } from
|
|
36
|
-
|
|
37
|
-
const pageSize = 100
|
|
24
|
+
} from "@/redux/template/manage/actions";
|
|
25
|
+
import { getTemplateService } from "@/service/template/manage";
|
|
26
|
+
import { RootState, AppDispatch } from "@/redux/store";
|
|
27
|
+
import _ from "lodash";
|
|
28
|
+
import { useTranslation } from "next-i18next";
|
|
29
|
+
import { getAntdLocale } from "@/utils/i18n";
|
|
30
|
+
import { useRouter } from "next/router";
|
|
31
|
+
import { handleXSS, checkModalObj } from "@/utils/common";
|
|
32
|
+
import { UploadOutlined } from "@ant-design/icons";
|
|
33
|
+
import ExcelJS from "exceljs";
|
|
34
|
+
import { saveAs } from "file-saver";
|
|
35
|
+
import { createCSRFUploadProps } from "@/utils/fetch";
|
|
36
|
+
|
|
37
|
+
const pageSize = 100;
|
|
38
38
|
|
|
39
39
|
const Page = ({ template }) => {
|
|
40
|
-
const { t } = useTranslation([
|
|
41
|
-
const router = useRouter()
|
|
42
|
-
const antdLocale = getAntdLocale(router.locale ||
|
|
43
|
-
const dispatch = useDispatch<AppDispatch>()
|
|
44
|
-
const [isModalVisiable, setIsModalVisible] = useState(false)
|
|
45
|
-
const [modalId, setModalId] = useState(0)
|
|
46
|
-
const [modalName, setModalName] = useState(
|
|
47
|
-
const [searchName, setSearchName] = useState(
|
|
48
|
-
const [batchDelIds, setBatchDelIds] = useState([])
|
|
40
|
+
const { t } = useTranslation(["common", "template"]);
|
|
41
|
+
const router = useRouter();
|
|
42
|
+
const antdLocale = getAntdLocale(router.locale || "zh-CN");
|
|
43
|
+
const dispatch = useDispatch<AppDispatch>();
|
|
44
|
+
const [isModalVisiable, setIsModalVisible] = useState(false);
|
|
45
|
+
const [modalId, setModalId] = useState(0);
|
|
46
|
+
const [modalName, setModalName] = useState("");
|
|
47
|
+
const [searchName, setSearchName] = useState("");
|
|
48
|
+
const [batchDelIds, setBatchDelIds] = useState([]);
|
|
49
49
|
|
|
50
50
|
const keyTitles = {
|
|
51
|
-
name: t(
|
|
52
|
-
}
|
|
51
|
+
name: t("template:template.fields.name"),
|
|
52
|
+
};
|
|
53
53
|
|
|
54
54
|
useEffect(() => {
|
|
55
|
-
dispatch(updateSSRTemplate(template))
|
|
56
|
-
}, [dispatch])
|
|
55
|
+
dispatch(updateSSRTemplate(template));
|
|
56
|
+
}, [dispatch]);
|
|
57
57
|
|
|
58
58
|
useEffect(() => {
|
|
59
59
|
// 管理弹窗打开时的滚动条显示
|
|
60
60
|
if (isModalVisiable) {
|
|
61
61
|
// 记录原始样式
|
|
62
|
-
const originalStyle = window.getComputedStyle(document.body).overflow
|
|
63
|
-
const originalPaddingRight = window.getComputedStyle(document.body).paddingRight
|
|
62
|
+
const originalStyle = window.getComputedStyle(document.body).overflow;
|
|
63
|
+
const originalPaddingRight = window.getComputedStyle(document.body).paddingRight;
|
|
64
64
|
|
|
65
65
|
// 设置定时器,在 Modal 设置样式后覆盖
|
|
66
66
|
const timer = setTimeout(() => {
|
|
67
|
-
document.body.style.overflow =
|
|
68
|
-
document.body.style.paddingRight =
|
|
69
|
-
}, 0)
|
|
67
|
+
document.body.style.overflow = "auto";
|
|
68
|
+
document.body.style.paddingRight = "0px";
|
|
69
|
+
}, 0);
|
|
70
70
|
|
|
71
71
|
return () => {
|
|
72
|
-
clearTimeout(timer)
|
|
72
|
+
clearTimeout(timer);
|
|
73
73
|
// 清理时恢复原始样式
|
|
74
|
-
document.body.style.overflow = originalStyle
|
|
75
|
-
document.body.style.paddingRight = originalPaddingRight
|
|
76
|
-
}
|
|
74
|
+
document.body.style.overflow = originalStyle;
|
|
75
|
+
document.body.style.paddingRight = originalPaddingRight;
|
|
76
|
+
};
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
// 当弹窗关闭时,不需要清理函数
|
|
80
|
-
return undefined
|
|
81
|
-
}, [isModalVisiable])
|
|
80
|
+
return undefined;
|
|
81
|
+
}, [isModalVisiable]);
|
|
82
82
|
|
|
83
|
-
const templateManage = useSelector((state: RootState) => state.templateManage)
|
|
83
|
+
const templateManage = useSelector((state: RootState) => state.templateManage);
|
|
84
84
|
|
|
85
85
|
if (!templateManage.firstLoadFlag) {
|
|
86
|
-
template = templateManage.template
|
|
86
|
+
template = templateManage.template;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
const { totalCounts, items: templateItems } = _.cloneDeep(template)
|
|
89
|
+
const { totalCounts, items: templateItems } = _.cloneDeep(template);
|
|
90
90
|
|
|
91
91
|
_.each(templateItems, (item) => {
|
|
92
|
-
const { id } = item
|
|
93
|
-
item.key = id
|
|
94
|
-
})
|
|
92
|
+
const { id } = item;
|
|
93
|
+
item.key = id;
|
|
94
|
+
});
|
|
95
95
|
|
|
96
|
-
const dataSource = templateItems
|
|
96
|
+
const dataSource = templateItems;
|
|
97
97
|
const columns: any = [
|
|
98
98
|
{
|
|
99
|
-
title: t(
|
|
100
|
-
dataIndex:
|
|
101
|
-
key:
|
|
99
|
+
title: t("template:template.fields.id"),
|
|
100
|
+
dataIndex: "id",
|
|
101
|
+
key: "id",
|
|
102
102
|
sorter: (a: any, b: any) => a.id - b.id,
|
|
103
|
-
sortDirections: [
|
|
103
|
+
sortDirections: ["descend", "ascend"],
|
|
104
104
|
showSorterTooltip: false,
|
|
105
|
-
width:
|
|
106
|
-
align:
|
|
105
|
+
width: "15%",
|
|
106
|
+
align: "center",
|
|
107
107
|
},
|
|
108
108
|
{
|
|
109
|
-
title: t(
|
|
110
|
-
dataIndex:
|
|
111
|
-
key:
|
|
109
|
+
title: t("template:template.fields.name"),
|
|
110
|
+
dataIndex: "name",
|
|
111
|
+
key: "name",
|
|
112
112
|
sorter: (a: any, b: any) => a.name.length - b.name.length,
|
|
113
|
-
sortDirections: [
|
|
113
|
+
sortDirections: ["descend", "ascend"],
|
|
114
114
|
showSorterTooltip: false,
|
|
115
|
-
width:
|
|
115
|
+
width: "60%",
|
|
116
116
|
ellipsis: true,
|
|
117
117
|
},
|
|
118
118
|
{
|
|
119
|
-
title: t(
|
|
120
|
-
dataIndex:
|
|
121
|
-
width:
|
|
122
|
-
align:
|
|
119
|
+
title: t("template:template.fields.actions"),
|
|
120
|
+
dataIndex: "",
|
|
121
|
+
width: "25%",
|
|
122
|
+
align: "center",
|
|
123
123
|
render: (_: any, record: any) => {
|
|
124
124
|
return (
|
|
125
125
|
<Space size="small">
|
|
@@ -127,268 +127,268 @@ const Page = ({ template }) => {
|
|
|
127
127
|
type="primary"
|
|
128
128
|
size="small"
|
|
129
129
|
onClick={() => {
|
|
130
|
-
updateTemplate(record)
|
|
130
|
+
updateTemplate(record);
|
|
131
131
|
}}
|
|
132
132
|
>
|
|
133
|
-
{t(
|
|
133
|
+
{t("template:template.buttons.edit")}
|
|
134
134
|
</RoundedButton>
|
|
135
135
|
<RoundedButton
|
|
136
136
|
danger
|
|
137
137
|
size="small"
|
|
138
138
|
onClick={() => {
|
|
139
|
-
const { id } = record
|
|
140
|
-
deleteTemplate(id)
|
|
139
|
+
const { id } = record;
|
|
140
|
+
deleteTemplate(id);
|
|
141
141
|
}}
|
|
142
142
|
>
|
|
143
|
-
{t(
|
|
143
|
+
{t("template:template.buttons.delete")}
|
|
144
144
|
</RoundedButton>
|
|
145
145
|
</Space>
|
|
146
|
-
)
|
|
146
|
+
);
|
|
147
147
|
},
|
|
148
148
|
},
|
|
149
|
-
]
|
|
149
|
+
];
|
|
150
150
|
|
|
151
151
|
const rowSelection = {
|
|
152
152
|
onChange: (selectedRowKeys: any) => {
|
|
153
153
|
//
|
|
154
|
-
setBatchDelIds(selectedRowKeys)
|
|
154
|
+
setBatchDelIds(selectedRowKeys);
|
|
155
155
|
},
|
|
156
|
-
}
|
|
156
|
+
};
|
|
157
157
|
|
|
158
158
|
const createTemplate = () => {
|
|
159
|
-
setModalId(0)
|
|
160
|
-
setModalName(
|
|
161
|
-
showModal()
|
|
162
|
-
}
|
|
159
|
+
setModalId(0);
|
|
160
|
+
setModalName("");
|
|
161
|
+
showModal();
|
|
162
|
+
};
|
|
163
163
|
|
|
164
164
|
const updateTemplate = (record: any) => {
|
|
165
|
-
const { id, name } = record
|
|
165
|
+
const { id, name } = record;
|
|
166
166
|
|
|
167
|
-
setModalId(id)
|
|
168
|
-
setModalName(name)
|
|
169
|
-
showModal()
|
|
170
|
-
}
|
|
167
|
+
setModalId(id);
|
|
168
|
+
setModalName(name);
|
|
169
|
+
showModal();
|
|
170
|
+
};
|
|
171
171
|
|
|
172
172
|
const deleteTemplate = (id: number) => {
|
|
173
173
|
Modal.confirm({
|
|
174
|
-
title: t(
|
|
175
|
-
content: t(
|
|
176
|
-
okText: t(
|
|
177
|
-
cancelText: t(
|
|
174
|
+
title: t("common:common.warning"),
|
|
175
|
+
content: t("template:template.messages.confirmDelete"),
|
|
176
|
+
okText: t("template:template.buttons.confirm"),
|
|
177
|
+
cancelText: t("template:template.buttons.cancel"),
|
|
178
178
|
onOk: () => {
|
|
179
|
-
dispatch(delTemplate(id))
|
|
180
|
-
Modal.destroyAll()
|
|
179
|
+
dispatch(delTemplate(id));
|
|
180
|
+
Modal.destroyAll();
|
|
181
181
|
},
|
|
182
|
-
})
|
|
183
|
-
}
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
184
|
|
|
185
185
|
const showModal = () => {
|
|
186
|
-
setIsModalVisible(true)
|
|
187
|
-
}
|
|
186
|
+
setIsModalVisible(true);
|
|
187
|
+
};
|
|
188
188
|
|
|
189
189
|
const getMessageTitle = (key: string) => {
|
|
190
|
-
let result = keyTitles[key]
|
|
191
|
-
if (result == undefined) result = key
|
|
192
|
-
return result
|
|
193
|
-
}
|
|
190
|
+
let result = keyTitles[key];
|
|
191
|
+
if (result == undefined) result = key;
|
|
192
|
+
return result;
|
|
193
|
+
};
|
|
194
194
|
|
|
195
195
|
const handleOk = () => {
|
|
196
196
|
const modalObj = {
|
|
197
197
|
name: handleXSS(modalName),
|
|
198
|
-
}
|
|
198
|
+
};
|
|
199
199
|
//
|
|
200
200
|
|
|
201
|
-
const checkResult = checkModalObj(modalObj)
|
|
201
|
+
const checkResult = checkModalObj(modalObj);
|
|
202
202
|
|
|
203
203
|
if (!checkResult) {
|
|
204
204
|
if (modalId == 0) {
|
|
205
205
|
// 新增
|
|
206
|
-
dispatch(addTemplate(modalObj))
|
|
206
|
+
dispatch(addTemplate(modalObj));
|
|
207
207
|
} else {
|
|
208
|
-
dispatch(modTemplate(modalId, modalObj))
|
|
208
|
+
dispatch(modTemplate(modalId, modalObj));
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
-
setIsModalVisible(false)
|
|
211
|
+
setIsModalVisible(false);
|
|
212
212
|
} else {
|
|
213
|
-
message.info(getMessageTitle(checkResult.key) + checkResult.reason)
|
|
213
|
+
message.info(getMessageTitle(checkResult.key) + checkResult.reason);
|
|
214
214
|
}
|
|
215
|
-
}
|
|
215
|
+
};
|
|
216
216
|
|
|
217
217
|
const handleCancel = () => {
|
|
218
|
-
setIsModalVisible(false)
|
|
219
|
-
}
|
|
218
|
+
setIsModalVisible(false);
|
|
219
|
+
};
|
|
220
220
|
|
|
221
221
|
const doSearch = () => {
|
|
222
|
-
dispatch(searchTemplate(0, pageSize, { name: handleXSS(searchName) }))
|
|
223
|
-
}
|
|
222
|
+
dispatch(searchTemplate(0, pageSize, { name: handleXSS(searchName) }));
|
|
223
|
+
};
|
|
224
224
|
|
|
225
225
|
const exportTemplate = () => {
|
|
226
226
|
if (templateItems.length > 0) {
|
|
227
|
-
const wb = new ExcelJS.Workbook()
|
|
228
|
-
const ws = wb.addWorksheet(
|
|
229
|
-
const jsonData = _.map(templateItems, (item) => _.omit(item, [
|
|
227
|
+
const wb = new ExcelJS.Workbook();
|
|
228
|
+
const ws = wb.addWorksheet("Template");
|
|
229
|
+
const jsonData = _.map(templateItems, (item) => _.omit(item, ["key"]));
|
|
230
230
|
|
|
231
231
|
// 提取表头
|
|
232
|
-
const headers = Object.keys(jsonData[0])
|
|
232
|
+
const headers = Object.keys(jsonData[0]);
|
|
233
233
|
|
|
234
234
|
// 将 JSON 数据转换为二维数组
|
|
235
|
-
const data = [headers, ...jsonData.map((item) => headers.map((header) => item[header]))]
|
|
235
|
+
const data = [headers, ...jsonData.map((item) => headers.map((header) => item[header]))];
|
|
236
236
|
|
|
237
237
|
// 将数据写入工作表
|
|
238
|
-
ws.addRows(data)
|
|
238
|
+
ws.addRows(data);
|
|
239
239
|
|
|
240
240
|
// 设置表头样式加粗
|
|
241
241
|
ws.getRow(1).eachCell((cell) => {
|
|
242
|
-
cell.font = { bold: true }
|
|
243
|
-
})
|
|
242
|
+
cell.font = { bold: true };
|
|
243
|
+
});
|
|
244
244
|
|
|
245
245
|
// 设置列宽
|
|
246
246
|
ws.columns = [
|
|
247
|
-
{ header:
|
|
248
|
-
{ header:
|
|
249
|
-
]
|
|
247
|
+
{ header: "ID", key: "header1", width: 20 },
|
|
248
|
+
{ header: "NAME", key: "header2", width: 30 },
|
|
249
|
+
];
|
|
250
250
|
|
|
251
251
|
wb.xlsx
|
|
252
252
|
.writeBuffer()
|
|
253
253
|
.then((data) => {
|
|
254
|
-
const blob = new Blob([data], { type:
|
|
255
|
-
saveAs(blob,
|
|
254
|
+
const blob = new Blob([data], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
|
|
255
|
+
saveAs(blob, "Template.xlsx");
|
|
256
256
|
})
|
|
257
257
|
.catch(() => {
|
|
258
258
|
// 导出失败
|
|
259
|
-
})
|
|
259
|
+
});
|
|
260
260
|
} else {
|
|
261
|
-
message.info(t(
|
|
261
|
+
message.info(t("template:template.messages.noData"));
|
|
262
262
|
}
|
|
263
|
-
}
|
|
263
|
+
};
|
|
264
264
|
|
|
265
|
-
const uploadProps = createCSRFUploadProps(
|
|
266
|
-
name:
|
|
265
|
+
const uploadProps = createCSRFUploadProps("/rest/template/import", {
|
|
266
|
+
name: "file",
|
|
267
267
|
onSuccess: (fileName) => {
|
|
268
|
-
message.success(`${fileName} ${t(
|
|
269
|
-
window.location.reload()
|
|
268
|
+
message.success(`${fileName} ${t("template:template.messages.uploadSuccess")}`);
|
|
269
|
+
window.location.reload();
|
|
270
270
|
},
|
|
271
271
|
onError: (fileName) => {
|
|
272
|
-
message.error(`${fileName} ${t(
|
|
272
|
+
message.error(`${fileName} ${t("template:template.messages.uploadFailed")}`);
|
|
273
273
|
},
|
|
274
274
|
beforeUpload: (file) => {
|
|
275
275
|
// 可以在这里添加文件类型、大小等验证
|
|
276
276
|
const isExcel =
|
|
277
|
-
file.type ===
|
|
278
|
-
file.type ===
|
|
277
|
+
file.type === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ||
|
|
278
|
+
file.type === "application/vnd.ms-excel";
|
|
279
279
|
if (!isExcel) {
|
|
280
|
-
message.error(t(
|
|
281
|
-
return false
|
|
280
|
+
message.error(t("template:template.messages.onlyExcel"));
|
|
281
|
+
return false;
|
|
282
282
|
}
|
|
283
|
-
const isLt2M = file.size / 1024 / 1024 < 2
|
|
283
|
+
const isLt2M = file.size / 1024 / 1024 < 2;
|
|
284
284
|
if (!isLt2M) {
|
|
285
|
-
message.error(t(
|
|
286
|
-
return false
|
|
285
|
+
message.error(t("template:template.messages.fileSizeLimit"));
|
|
286
|
+
return false;
|
|
287
287
|
}
|
|
288
|
-
return true
|
|
288
|
+
return true;
|
|
289
289
|
},
|
|
290
|
-
})
|
|
290
|
+
});
|
|
291
291
|
|
|
292
292
|
const batchDeleteTemplate = () => {
|
|
293
293
|
if (batchDelIds.length > 0) {
|
|
294
294
|
Modal.confirm({
|
|
295
|
-
title: t(
|
|
296
|
-
content: t(
|
|
297
|
-
okText: t(
|
|
298
|
-
cancelText: t(
|
|
295
|
+
title: t("common:common.warning"),
|
|
296
|
+
content: t("template:template.messages.confirmBatchDelete"),
|
|
297
|
+
okText: t("template:template.buttons.confirm"),
|
|
298
|
+
cancelText: t("template:template.buttons.cancel"),
|
|
299
299
|
onOk: () => {
|
|
300
|
-
dispatch(batchDelTemplate(batchDelIds))
|
|
301
|
-
Modal.destroyAll()
|
|
300
|
+
dispatch(batchDelTemplate(batchDelIds));
|
|
301
|
+
Modal.destroyAll();
|
|
302
302
|
},
|
|
303
|
-
})
|
|
303
|
+
});
|
|
304
304
|
} else {
|
|
305
|
-
message.info(t(
|
|
305
|
+
message.info(t("template:template.messages.noDataBatchDelete"));
|
|
306
306
|
}
|
|
307
|
-
}
|
|
307
|
+
};
|
|
308
308
|
|
|
309
309
|
return (
|
|
310
310
|
<Container>
|
|
311
311
|
<GlobalStyle />
|
|
312
|
-
<div className="page-title">{t(
|
|
312
|
+
<div className="page-title">{t("template:template.title")}</div>
|
|
313
313
|
<ConfigProvider locale={antdLocale}>
|
|
314
314
|
<SearchRow>
|
|
315
315
|
<Space size="middle" wrap>
|
|
316
316
|
<Space size="small">
|
|
317
317
|
<StyledButton type="primary" onClick={createTemplate} $primary>
|
|
318
318
|
<IconWrapper className="fa fa-plus"></IconWrapper>
|
|
319
|
-
{t(
|
|
319
|
+
{t("template:template.buttons.add")}
|
|
320
320
|
</StyledButton>
|
|
321
321
|
<StyledInput
|
|
322
322
|
value={searchName}
|
|
323
|
-
placeholder={t(
|
|
323
|
+
placeholder={t("template:template.placeholders.enterName")}
|
|
324
324
|
allowClear
|
|
325
325
|
onChange={(e) => setSearchName(e.target.value)}
|
|
326
326
|
onPressEnter={doSearch}
|
|
327
327
|
/>
|
|
328
328
|
<StyledButton type="primary" onClick={doSearch} $primary>
|
|
329
329
|
<IconWrapper className="fa fa-search"></IconWrapper>
|
|
330
|
-
{t(
|
|
330
|
+
{t("template:template.buttons.search")}
|
|
331
331
|
</StyledButton>
|
|
332
332
|
</Space>
|
|
333
333
|
<Space size="small">
|
|
334
334
|
<StyledButton onClick={exportTemplate} icon={<UploadOutlined rotate={180} />} $export>
|
|
335
|
-
{t(
|
|
335
|
+
{t("template:template.buttons.export")}
|
|
336
336
|
</StyledButton>
|
|
337
337
|
<Upload {...uploadProps}>
|
|
338
338
|
<StyledButton icon={<UploadOutlined />} $import>
|
|
339
|
-
{t(
|
|
339
|
+
{t("template:template.buttons.import")}
|
|
340
340
|
</StyledButton>
|
|
341
341
|
</Upload>
|
|
342
342
|
<StyledButton danger onClick={batchDeleteTemplate} $danger>
|
|
343
|
-
{t(
|
|
343
|
+
{t("template:template.buttons.batchDelete")}
|
|
344
344
|
</StyledButton>
|
|
345
345
|
</Space>
|
|
346
346
|
</Space>
|
|
347
347
|
</SearchRow>
|
|
348
348
|
<StyledTable
|
|
349
349
|
rowSelection={{
|
|
350
|
-
type:
|
|
350
|
+
type: "checkbox",
|
|
351
351
|
...rowSelection,
|
|
352
352
|
}}
|
|
353
353
|
dataSource={dataSource}
|
|
354
354
|
columns={columns}
|
|
355
355
|
bordered
|
|
356
|
-
rowClassName={(_, index) => (index % 2 === 0 ?
|
|
356
|
+
rowClassName={(_, index) => (index % 2 === 0 ? "table-row-light" : "table-row-dark")}
|
|
357
357
|
pagination={{
|
|
358
358
|
total: totalCounts,
|
|
359
359
|
pageSize: pageSize,
|
|
360
360
|
showSizeChanger: false,
|
|
361
361
|
showQuickJumper: true,
|
|
362
|
-
showTotal: (total) => t(
|
|
362
|
+
showTotal: (total) => t("template:template.pagination.total", { total }),
|
|
363
363
|
onChange: (page, pageSize) => {
|
|
364
|
-
dispatch(searchTemplate(page - 1, pageSize, { name: handleXSS(searchName) }))
|
|
364
|
+
dispatch(searchTemplate(page - 1, pageSize, { name: handleXSS(searchName) }));
|
|
365
365
|
},
|
|
366
|
-
className:
|
|
366
|
+
className: "styled-pagination",
|
|
367
367
|
}}
|
|
368
368
|
/>
|
|
369
369
|
<Modal
|
|
370
370
|
title={
|
|
371
371
|
<ModalTitle>
|
|
372
|
-
{modalId == 0 ? t(
|
|
372
|
+
{modalId == 0 ? t("template:template.modal.addTitle") : t("template:template.modal.editTitle")}
|
|
373
373
|
</ModalTitle>
|
|
374
374
|
}
|
|
375
375
|
open={isModalVisiable}
|
|
376
376
|
onOk={handleOk}
|
|
377
377
|
onCancel={handleCancel}
|
|
378
|
-
okText={t(
|
|
379
|
-
cancelText={t(
|
|
378
|
+
okText={t("template:template.buttons.confirm")}
|
|
379
|
+
cancelText={t("template:template.buttons.cancel")}
|
|
380
380
|
centered
|
|
381
381
|
maskClosable={false}
|
|
382
382
|
destroyOnHidden
|
|
383
|
-
okButtonProps={{ className:
|
|
384
|
-
cancelButtonProps={{ className:
|
|
383
|
+
okButtonProps={{ className: "rounded-button" }}
|
|
384
|
+
cancelButtonProps={{ className: "rounded-button" }}
|
|
385
385
|
>
|
|
386
386
|
<ModalContainer>
|
|
387
387
|
<div className="line">
|
|
388
388
|
<label>{keyTitles.name}:</label>
|
|
389
389
|
<ModalInput
|
|
390
390
|
value={modalName}
|
|
391
|
-
placeholder={t(
|
|
391
|
+
placeholder={t("template:template.placeholders.inputName")}
|
|
392
392
|
allowClear
|
|
393
393
|
autoFocus
|
|
394
394
|
onChange={(e) => setModalName(e.target.value)}
|
|
@@ -398,28 +398,28 @@ const Page = ({ template }) => {
|
|
|
398
398
|
</Modal>
|
|
399
399
|
</ConfigProvider>
|
|
400
400
|
</Container>
|
|
401
|
-
)
|
|
402
|
-
}
|
|
401
|
+
);
|
|
402
|
+
};
|
|
403
403
|
|
|
404
404
|
export async function getServerSideProps(context) {
|
|
405
|
-
const { serverSideTranslations } = await import(
|
|
405
|
+
const { serverSideTranslations } = await import("next-i18next/serverSideTranslations");
|
|
406
406
|
|
|
407
|
-
let template = null
|
|
407
|
+
let template = null;
|
|
408
408
|
|
|
409
409
|
await getTemplateService(0, pageSize).then((res: any) => {
|
|
410
|
-
const { data } = res
|
|
411
|
-
template = data.template
|
|
412
|
-
})
|
|
410
|
+
const { data } = res;
|
|
411
|
+
template = data.template;
|
|
412
|
+
});
|
|
413
413
|
|
|
414
|
-
const { locale } = context
|
|
415
|
-
const translations = await serverSideTranslations(locale ||
|
|
414
|
+
const { locale } = context;
|
|
415
|
+
const translations = await serverSideTranslations(locale || "zh-CN", ["common", "template", "layout", "login"]);
|
|
416
416
|
|
|
417
417
|
return {
|
|
418
418
|
props: {
|
|
419
419
|
template,
|
|
420
420
|
...translations,
|
|
421
421
|
},
|
|
422
|
-
}
|
|
422
|
+
};
|
|
423
423
|
}
|
|
424
424
|
|
|
425
|
-
export default Page
|
|
425
|
+
export default Page;
|