diff --git a/eslint.config.js b/eslint.config.js
new file mode 100644
index 0000000..62711d3
--- /dev/null
+++ b/eslint.config.js
@@ -0,0 +1,49 @@
+import antfu from "@antfu/eslint-config";
+
+export default antfu({
+ formatters: {
+ html: false,
+ css: true,
+ },
+ test: false,
+ typescript: true,
+ react: true,
+ vue: false,
+ markdown: false,
+ stylistic: {
+ semi: true,
+ quotes: "double",
+ },
+ overrides: {
+ react: {
+ "react/no-comment-textnodes": "off",
+ "react/no-implicit-key": "off",
+ "react-hooks-extra/no-unnecessary-use-prefix": "off",
+ "react-hooks-extra/prefer-use-state-lazy-initialization": "off",
+ "react-hooks/exhaustive-deps": "off",
+ },
+ javascript: {
+ "no-console": ["warn", { allow: ["warn", "error"] }],
+ "no-debugger": "error",
+ "no-alert": "error",
+ "no-restricted-syntax": [
+ "error",
+ {
+ selector: "VariableDeclarator[id.name='pd']",
+ message: "不允许使用 pd,请改用有语义化的变量名",
+ },
+ {
+ selector: "ObjectExpression > Property[key.name='pd']",
+ message: "不允许使用 pd,请改用有语义化的变量名",
+ },
+ ],
+ "no-unused-vars": ["error", { varsIgnorePattern: "^React$" }],
+ },
+ },
+ rules: {
+ "antfu/top-level-function": "off",
+ "node/prefer-global/process": "off",
+ "dot-notation": "off",
+ "linebreak-style": ["off", "windows"],
+ },
+});
diff --git a/package.json b/package.json
index 2218b3f..bdd4e2f 100644
--- a/package.json
+++ b/package.json
@@ -46,15 +46,22 @@
"use-antd-resizable-header": "^3.2.2"
},
"devDependencies": {
+ "@antfu/eslint-config": "^5.4.1",
"@babel/core": "^7.28.5",
"@babel/preset-react": "^7.28.5",
+ "@eslint-react/eslint-plugin": "^2.2.2",
"@rollup/plugin-babel": "^6.1.0",
"@rollup/plugin-commonjs": "^29.0.0",
"@rollup/plugin-image": "^3.0.3",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^16.0.3",
"@rollup/plugin-terser": "^0.4.4",
+ "eslint": "^9.37.0",
+ "eslint-plugin-format": "^1.0.2",
+ "eslint-plugin-react-hooks": "^7.0.0",
+ "eslint-plugin-react-refresh": "^0.4.23",
"glob": "^13.0.0",
- "rollup": "^4.54.0"
+ "rollup": "^4.54.0",
+ "typescript": "^5.9.3"
}
}
diff --git a/src/components/Cascader/Basic/index.js b/src/components/Cascader/Basic/index.js
index 2a5dc88..30a90f0 100644
--- a/src/components/Cascader/Basic/index.js
+++ b/src/components/Cascader/Basic/index.js
@@ -33,11 +33,11 @@ function BasicCascader(props) {
const processedData = useMemo(() => {
return level
? processTreeDataByLevel({
- data,
- level,
- childrenKey,
- currentLevel: 1,
- })
+ data,
+ level,
+ childrenKey,
+ currentLevel: 1,
+ })
: data;
}, [data, level, childrenKey]);
diff --git a/src/components/HiddenInfo/gwj/index.js b/src/components/HiddenInfo/gwj/index.js
index 4818754..ab499d7 100644
--- a/src/components/HiddenInfo/gwj/index.js
+++ b/src/components/HiddenInfo/gwj/index.js
@@ -342,7 +342,7 @@ function HiddenInfo(props) {
? [
...(item.disposalPlan ? [{ label: "处置方案", children: item.disposalPlan }] : []),
...(
- item.disposalFile
+ item.disposalFile
? [{
label: "处置方案附件",
children: (
diff --git a/src/components/LeftTree/Department/Gwj/index.d.ts b/src/components/LeftTree/Department/Gwj/index.d.ts
index 04c7fe8..73b2375 100644
--- a/src/components/LeftTree/Department/Gwj/index.d.ts
+++ b/src/components/LeftTree/Department/Gwj/index.d.ts
@@ -1,6 +1,6 @@
import type { FC } from "react";
-import type { BasicLeftTreeProps } from "../../Basic";
import type { DepartmentSelectTreeProps } from "../../../SelectTree/Department/Gwj";
+import type { BasicLeftTreeProps } from "../../Basic";
/**
* 组件属性
diff --git a/src/components/Map/CesiumMap.js b/src/components/Map/CesiumMap.js
index 3931c5c..214d938 100644
--- a/src/components/Map/CesiumMap.js
+++ b/src/components/Map/CesiumMap.js
@@ -1,4 +1,4 @@
-import billboardImage from './h.png';
+import billboardImage from "./h.png";
export default class CesiumMap {
viewer;
diff --git a/src/components/Page/index.js b/src/components/Page/index.js
index 5bf1127..ca75dca 100644
--- a/src/components/Page/index.js
+++ b/src/components/Page/index.js
@@ -18,7 +18,7 @@ function Page(props) {
contentPadding = "20px",
customActionButtons,
extraActionButtons,
- children
+ children,
} = props;
const [pageWidth, setPageWidth] = useState(window.innerWidth);
diff --git a/src/components/Select/Personnel/Gwj/index.js b/src/components/Select/Personnel/Gwj/index.js
index e07b44d..93bcde7 100644
--- a/src/components/Select/Personnel/Gwj/index.js
+++ b/src/components/Select/Personnel/Gwj/index.js
@@ -35,11 +35,11 @@ function PersonnelSelect(props) {
}
// 根据参数决定是否发送请求
- if (isNeedCorpInfoId && (!params.corpinfoId || typeof params.corpinfoId !== 'string'))
+ if (isNeedCorpInfoId && (!params.corpinfoId || typeof params.corpinfoId !== "string"))
return;
- if (isNeedDepartmentId && (!params.departmentId || typeof params.departmentId !== 'string'))
+ if (isNeedDepartmentId && (!params.departmentId || typeof params.departmentId !== "string"))
return;
- if (isNeedPostId && (!params.postId || typeof params.postId !== 'string'))
+ if (isNeedPostId && (!params.postId || typeof params.postId !== "string"))
return;
const actualExtraParams = { ...defaultExtraParams, ...extraParams };
diff --git a/src/components/SelectTree/Basic/index.js b/src/components/SelectTree/Basic/index.js
index 0972eca..7346e45 100644
--- a/src/components/SelectTree/Basic/index.js
+++ b/src/components/SelectTree/Basic/index.js
@@ -35,11 +35,11 @@ function BasicSelectTree(props) {
// 根据 level 处理树数据
let result = level
? processTreeDataByLevel({
- data: treeData,
- level,
- childrenKey,
- currentLevel: 1,
- })
+ data: treeData,
+ level,
+ childrenKey,
+ currentLevel: 1,
+ })
: treeData;
// 根据 onlyLastLevel 处理树数据
diff --git a/src/components/Signature/index.js b/src/components/Signature/index.js
index c2bd005..da16f29 100644
--- a/src/components/Signature/index.js
+++ b/src/components/Signature/index.js
@@ -52,8 +52,8 @@ function Signature(props) {
{base64 && (
-
-
+
+
)}
{
-
const { files = [], params = {} } = options;
const formData = new FormData();
diff --git a/src/hooks/useTable/index.js b/src/hooks/useTable/index.js
index e9ad30f..54c0448 100644
--- a/src/hooks/useTable/index.js
+++ b/src/hooks/useTable/index.js
@@ -24,7 +24,7 @@ function getService(service, getExtraParams = {}, transform, usePermission) {
pageSize,
...transformedFormData,
...extraParams,
- }
+ };
if (usePermission)
params.menuPath = window.location.pathname;
diff --git a/src/utils/index.js b/src/utils/index.js
index 2d46aa0..62155a5 100644
--- a/src/utils/index.js
+++ b/src/utils/index.js
@@ -1,5 +1,5 @@
-import { ID_NUMBER } from "../regular";
import dayjs from "dayjs";
+import { ID_NUMBER } from "../regular";
/**
* 计算序号
@@ -20,10 +20,7 @@ export function toArrayString(value) {
* 判断文件后缀名是否符合
*/
export function interceptTheSuffix(name, suffix) {
- return (
- name.substring(name.lastIndexOf("."), name.length).toLowerCase()
- === suffix.toLowerCase()
- );
+ return name.substring(name.lastIndexOf("."), name.length).toLowerCase() === suffix.toLowerCase();
}
/**
@@ -54,10 +51,10 @@ export function image2Base642(file) {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = (e) => {
- resolve(e.target.result); // 返回 base64
+ resolve(e.target.result);
};
reader.onerror = (error) => {
- reject(error); // 处理错误
+ reject(error);
};
});
}
@@ -65,10 +62,10 @@ export function image2Base642(file) {
/**
base64转File对象
*/
-export function base642File(base64, filename = 'file') {
+export function base642File(base64, filename = "file") {
const arr = base64.split(",");
const mime = arr[0].match(/:(.*?);/)[1];
- const ext = mime.split('/')[1];
+ const ext = mime.split("/")[1];
const bstr = atob(arr[1]);
let n = bstr.length;
const u8arr = new Uint8Array(n);
@@ -157,18 +154,15 @@ export function numFormat(num) {
const arr = numArr[0].split("").reverse();
let res = [];
for (let i = 0; i < arr.length; i++) {
- if (i % 3 === 0 && i !== 0) {
+ if (i % 3 === 0 && i !== 0)
res.push(",");
- }
res.push(arr[i]);
}
res.reverse();
- if (numArr[1]) {
+ if (numArr[1])
res = res.join("").concat(`.${numArr[1]}`);
- }
- else {
+ else
res = res.join("");
- }
return res;
}
}
@@ -201,12 +195,7 @@ export function getUrlParam(key) {
*/
export function paging(options) {
const { list, currentPage, pageSize } = options;
- return list.filter((item, index) => {
- return (
- index < +currentPage * +pageSize
- && index >= (+currentPage - 1) * +pageSize
- );
- });
+ return list.filter((item, index) => index < +currentPage * +pageSize && index >= (+currentPage - 1) * +pageSize);
}
/**
@@ -252,19 +241,17 @@ export function readTxtDocument(filePah) {
export function secondConversion(second) {
if (!second)
return 0;
- const h = Number.parseInt(second / 60 / 60, 10);
- const m = Number.parseInt((second / 60) % 60, 10);
- const s = Number.parseInt(second % 60, 10);
+ const h = Number.parseInt((second / 60 / 60).toString(), 10);
+ const m = Number.parseInt(((second / 60) % 60).toString(), 10);
+ const s = Number.parseInt((second % 60).toString(), 10);
if (h) {
return `${h}小时${m}分钟${s}秒`;
}
else {
- if (m) {
+ if (m)
return `${m}分钟${s}秒`;
- }
- else {
+ else
return `${s}秒`;
- }
}
}
@@ -274,11 +261,7 @@ export function secondConversion(second) {
export function addingPrefixToFile(list, options = {}) {
if (!list)
return [];
- const {
- pathKey = "filePath",
- nameKey = "fileName",
- idKey = "id",
- } = options;
+ const { pathKey = "filePath", nameKey = "fileName", idKey = "id" } = options;
const FILE_URL = getFileUrl();
for (let i = 0; i < list.length; i++) {
list[i].url = FILE_URL + list[i][pathKey];
@@ -294,9 +277,8 @@ export function addingPrefixToFile(list, options = {}) {
export function getLabelName(options) {
const { status, list, idKey = "bianma", nameKey = "name" } = options;
for (let i = 0; i < list.length; i++) {
- if (status?.toString() === list[i][idKey]?.toString()) {
+ if (status?.toString() === list[i][idKey]?.toString())
return list[i][nameKey];
- }
}
}
@@ -304,10 +286,7 @@ export function getLabelName(options) {
* 计算文件大小
*/
export function calculateFileSize(size) {
- return size > 1024
- ? `${(`${size / 1024}`).substring(0, (`${size / 1024}`).lastIndexOf(".") + 3)
- }MB`
- : `${size}KB`;
+ return size > 1024 ? `${(`${size / 1024}`).substring(0, (`${size / 1024}`).lastIndexOf(".") + 3)}MB` : `${size}KB`;
}
/**
@@ -319,12 +298,7 @@ export function idCardGetDateAndGender(idCard) {
if (ID_NUMBER.test(idCard)) {
const org_birthday = idCard.substring(6, 14);
const org_gender = idCard.substring(16, 17);
- const birthday
- = `${org_birthday.substring(0, 4)
- }-${
- org_birthday.substring(4, 6)
- }-${
- org_birthday.substring(6, 8)}`;
+ const birthday = `${org_birthday.substring(0, 4)}-${org_birthday.substring(4, 6)}-${org_birthday.substring(6, 8)}`;
const birthdays = new Date(birthday.replace(/-/g, "/"));
const Month = birthdays.getMonth() + 1;
let MonthDate;
@@ -390,11 +364,7 @@ export function listTransTree(options) {
*/
export function isEmptyToWhether(value, options = {}) {
const { yesText = "是", noText = "否", yesValue = "1" } = options;
- return !isEmpty(value)
- ? value.toString() === yesValue.toString()
- ? yesText
- : noText
- : "";
+ return !isEmpty(value) ? (value.toString() === yesValue.toString() ? yesText : noText) : "";
}
/**
@@ -448,9 +418,8 @@ export function getTreeNodePaths(options) {
path: newPath,
isIncludeOneself,
});
- if (result) {
+ if (result)
return result;
- }
}
}
@@ -508,9 +477,8 @@ export const processTreeDataForOnlyLastLevel = (options) => {
};
// 递归处理子节点
- if (hasChildren) {
+ if (hasChildren)
processedItem[childrenKey] = processTreeDataForOnlyLastLevel({ data: item[childrenKey], childrenKey, onlyLastLevel });
- }
return processedItem;
});
@@ -522,15 +490,13 @@ export const processTreeDataForOnlyLastLevel = (options) => {
export const validatorEndTime = (timeStart, message = "结束时间不能早于开始时间") => {
return {
validator: (_, value) => {
- if (value && timeStart && value < timeStart) {
+ if (value && timeStart && value < timeStart)
return Promise.reject(message);
- }
- else {
+ else
return Promise.resolve();
- }
},
- }
-}
+ };
+};
/**
* 验证时间是否大于等于当前时间
@@ -538,15 +504,13 @@ export const validatorEndTime = (timeStart, message = "结束时间不能早于
export const validatorTimeGTCurrentDay = (message = "需要大于当前时间") => {
return {
validator: (_, value) => {
- if (value && value <= dayjs().format("YYYY-MM-DD HH:mm:ss")) {
+ if (value && value <= dayjs().format("YYYY-MM-DD HH:mm:ss"))
return Promise.reject(message);
- }
- else {
+ else
return Promise.resolve();
- }
},
- }
-}
+ };
+};
/**
* 动态加载js资源