Compare commits
3 Commits
66377c618d
...
dcd7ddeb71
| Author | SHA1 | Date | |
|---|---|---|---|
| dcd7ddeb71 | |||
| 8fefadaf55 | |||
| 80171778b5 |
4
docs/eslint-fix.md
Normal file
4
docs/eslint-fix.md
Normal file
File diff suppressed because one or more lines are too long
373
package-lock.json
generated
373
package-lock.json
generated
@@ -47,6 +47,7 @@
|
||||
"openapi-fetch": "^0.15.0",
|
||||
"react": "19.2.0",
|
||||
"react-dom": "19.2.0",
|
||||
"recharts": "^3.4.1",
|
||||
"sonner": "^2.0.7",
|
||||
"tailwind-merge": "^3.4.0",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
@@ -3027,6 +3028,32 @@
|
||||
"integrity": "sha512-HPwpGIzkl28mWyZqG52jiqDJ12waP11Pa1lGoiyUkIEuMLBP0oeK/C89esbXrxsky5we7dfd8U58nm0SgAWpVw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@reduxjs/toolkit": {
|
||||
"version": "2.10.1",
|
||||
"resolved": "https://registry.npmmirror.com/@reduxjs/toolkit/-/toolkit-2.10.1.tgz",
|
||||
"integrity": "sha512-/U17EXQ9Do9Yx4DlNGU6eVNfZvFJfYpUtRRdLf19PbPjdWBxNlxGZXywQZ1p1Nz8nMkWplTI7iD/23m07nolDA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@standard-schema/spec": "^1.0.0",
|
||||
"@standard-schema/utils": "^0.3.0",
|
||||
"immer": "^10.2.0",
|
||||
"redux": "^5.0.1",
|
||||
"redux-thunk": "^3.1.0",
|
||||
"reselect": "^5.1.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.9.0 || ^17.0.0 || ^18 || ^19",
|
||||
"react-redux": "^7.2.1 || ^8.1.3 || ^9.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"react": {
|
||||
"optional": true
|
||||
},
|
||||
"react-redux": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@rtsao/scc": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/@rtsao/scc/-/scc-1.1.0.tgz",
|
||||
@@ -3034,6 +3061,18 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@standard-schema/spec": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/@standard-schema/spec/-/spec-1.0.0.tgz",
|
||||
"integrity": "sha512-m2bOd0f2RT9k8QJx1JN85cZYyH1RqFBdlwtkSlf4tBDYLCiiZnv1fIIwacK6cqwXavOydf0NPToMQgpKq+dVlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@standard-schema/utils": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmmirror.com/@standard-schema/utils/-/utils-0.3.0.tgz",
|
||||
"integrity": "sha512-e7Mew686owMaPJVNNLs55PUvgz371nKgwsc4vxE49zsODpJEnxgxRo2y/OKrqueavXgZNMDVj3DdHFlaSAeU8g==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@swc/helpers": {
|
||||
"version": "0.5.15",
|
||||
"resolved": "https://registry.npmmirror.com/@swc/helpers/-/helpers-0.5.15.tgz",
|
||||
@@ -3325,6 +3364,69 @@
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/d3-array": {
|
||||
"version": "3.2.2",
|
||||
"resolved": "https://registry.npmmirror.com/@types/d3-array/-/d3-array-3.2.2.tgz",
|
||||
"integrity": "sha512-hOLWVbm7uRza0BYXpIIW5pxfrKe0W+D5lrFiAEYR+pb6w3N2SwSMaJbXdUfSEv+dT4MfHBLtn5js0LAWaO6otw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/d3-color": {
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmmirror.com/@types/d3-color/-/d3-color-3.1.3.tgz",
|
||||
"integrity": "sha512-iO90scth9WAbmgv7ogoq57O9YpKmFBbmoEoCHDB2xMBY0+/KVrqAaCDyCE16dUspeOvIxFFRI+0sEtqDqy2b4A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/d3-ease": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/@types/d3-ease/-/d3-ease-3.0.2.tgz",
|
||||
"integrity": "sha512-NcV1JjO5oDzoK26oMzbILE6HW7uVXOHLQvHshBUW4UMdZGfiY6v5BeQwh9a9tCzv+CeefZQHJt5SRgK154RtiA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/d3-interpolate": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmmirror.com/@types/d3-interpolate/-/d3-interpolate-3.0.4.tgz",
|
||||
"integrity": "sha512-mgLPETlrpVV1YRJIglr4Ez47g7Yxjl1lj7YKsiMCb27VJH9W8NVM6Bb9d8kkpG/uAQS5AmbA48q2IAolKKo1MA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/d3-color": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/d3-path": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmmirror.com/@types/d3-path/-/d3-path-3.1.1.tgz",
|
||||
"integrity": "sha512-VMZBYyQvbGmWyWVea0EHs/BwLgxc+MKi1zLDCONksozI4YJMcTt8ZEuIR4Sb1MMTE8MMW49v0IwI5+b7RmfWlg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/d3-scale": {
|
||||
"version": "4.0.9",
|
||||
"resolved": "https://registry.npmmirror.com/@types/d3-scale/-/d3-scale-4.0.9.tgz",
|
||||
"integrity": "sha512-dLmtwB8zkAeO/juAMfnV+sItKjlsw2lKdZVVy6LRr0cBmegxSABiLEpGVmSJJ8O08i4+sGR6qQtb6WtuwJdvVw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/d3-time": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/d3-shape": {
|
||||
"version": "3.1.7",
|
||||
"resolved": "https://registry.npmmirror.com/@types/d3-shape/-/d3-shape-3.1.7.tgz",
|
||||
"integrity": "sha512-VLvUQ33C+3J+8p+Daf+nYSOsjB4GXp19/S/aGo60m9h1v6XaxjiT82lKVWJCfzhtuZ3yD7i/TPeC/fuKLLOSmg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/d3-path": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/d3-time": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmmirror.com/@types/d3-time/-/d3-time-3.0.4.tgz",
|
||||
"integrity": "sha512-yuzZug1nkAAaBlBBikKZTgzCeA+k1uy4ZFwWANOfKw5z5LRhV0gNA7gNkKm7HoK+HRN0wX3EkxGk0fpbWhmB7g==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/d3-timer": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/@types/d3-timer/-/d3-timer-3.0.2.tgz",
|
||||
"integrity": "sha512-Ps3T8E8dZDam6fUyNiMkekK3XUsaUEik+idO9/YjPtfj2qruF8tFBXS7XhtE4iIXBLxhmLjP3SXpLhVf21I9Lw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/estree": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmmirror.com/@types/estree/-/estree-1.0.8.tgz",
|
||||
@@ -3375,6 +3477,12 @@
|
||||
"@types/react": "^19.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/use-sync-external-store": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmmirror.com/@types/use-sync-external-store/-/use-sync-external-store-0.0.6.tgz",
|
||||
"integrity": "sha512-zFDAD+tlpf2r4asuHEj0XH6pY6i0g5NeAHPn+15wk3BV6JA69eERFXC1gyGThDkVa1zCyKr5jox1+2LbV/AMLg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@typescript-eslint/eslint-plugin": {
|
||||
"version": "8.46.4",
|
||||
"resolved": "https://registry.npmmirror.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.46.4.tgz",
|
||||
@@ -4634,6 +4742,127 @@
|
||||
"devOptional": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/d3-array": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmmirror.com/d3-array/-/d3-array-3.2.4.tgz",
|
||||
"integrity": "sha512-tdQAmyA18i4J7wprpYq8ClcxZy3SC31QMeByyCFyRt7BVHdREQZ5lpzoe5mFEYZUWe+oq8HBvk9JjpibyEV4Jg==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"internmap": "1 - 2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-color": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/d3-color/-/d3-color-3.1.0.tgz",
|
||||
"integrity": "sha512-zg/chbXyeBtMQ1LbD/WSoW2DpC3I0mpmPdW+ynRTj/x2DAWYrIY7qeZIHidozwV24m4iavr15lNwIwLxRmOxhA==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-ease": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/d3-ease/-/d3-ease-3.0.1.tgz",
|
||||
"integrity": "sha512-wR/XK3D3XcLIZwpbvQwQ5fK+8Ykds1ip7A2Txe0yxncXSdq1L9skcG7blcedkOX+ZcgxGAmLX1FrRGbADwzi0w==",
|
||||
"license": "BSD-3-Clause",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-format": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/d3-format/-/d3-format-3.1.0.tgz",
|
||||
"integrity": "sha512-YyUI6AEuY/Wpt8KWLgZHsIU86atmikuoOmCfommt0LYHiQSPjvX2AcFc38PX0CBpr2RCyZhjex+NS/LPOv6YqA==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-interpolate": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/d3-interpolate/-/d3-interpolate-3.0.1.tgz",
|
||||
"integrity": "sha512-3bYs1rOD33uo8aqJfKP3JWPAibgw8Zm2+L9vBKEHJ2Rg+viTR7o5Mmv5mZcieN+FRYaAOWX5SJATX6k1PWz72g==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"d3-color": "1 - 3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-path": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/d3-path/-/d3-path-3.1.0.tgz",
|
||||
"integrity": "sha512-p3KP5HCf/bvjBSSKuXid6Zqijx7wIfNW+J/maPs+iwR35at5JCbLUT0LzF1cnjbCHWhqzQTIN2Jpe8pRebIEFQ==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-scale": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/d3-scale/-/d3-scale-4.0.2.tgz",
|
||||
"integrity": "sha512-GZW464g1SH7ag3Y7hXjf8RoUuAFIqklOAq3MRl4OaWabTFJY9PN/E1YklhXLh+OQ3fM9yS2nOkCoS+WLZ6kvxQ==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"d3-array": "2.10.0 - 3",
|
||||
"d3-format": "1 - 3",
|
||||
"d3-interpolate": "1.2.0 - 3",
|
||||
"d3-time": "2.1.1 - 3",
|
||||
"d3-time-format": "2 - 4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-shape": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/d3-shape/-/d3-shape-3.2.0.tgz",
|
||||
"integrity": "sha512-SaLBuwGm3MOViRq2ABk3eLoxwZELpH6zhl3FbAoJ7Vm1gofKx6El1Ib5z23NUEhF9AsGl7y+dzLe5Cw2AArGTA==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"d3-path": "^3.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-time": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/d3-time/-/d3-time-3.1.0.tgz",
|
||||
"integrity": "sha512-VqKjzBLejbSMT4IgbmVgDjpkYrNWUYJnbCGo874u7MMKIWsILRX+OpX/gTk8MqjpT1A/c6HY2dCA77ZN0lkQ2Q==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"d3-array": "2 - 3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-time-format": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/d3-time-format/-/d3-time-format-4.1.0.tgz",
|
||||
"integrity": "sha512-dJxPBlzC7NugB2PDLwo9Q8JiTR3M3e4/XANkreKSUxF8vvXKqm1Yfq4Q5dl8budlunRVlUUaDUgFt7eA8D6NLg==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"d3-time": "1 - 3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-timer": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/d3-timer/-/d3-timer-3.0.1.tgz",
|
||||
"integrity": "sha512-ndfJ/JxxMd3nw31uyKoY2naivF+r29V+Lc0svZxe1JvvIRmi8hUsrMvdOwgS1o6uBHmiz91geQ0ylPP0aj1VUA==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/damerau-levenshtein": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmmirror.com/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz",
|
||||
@@ -4713,6 +4942,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/decimal.js-light": {
|
||||
"version": "2.5.1",
|
||||
"resolved": "https://registry.npmmirror.com/decimal.js-light/-/decimal.js-light-2.5.1.tgz",
|
||||
"integrity": "sha512-qIMFpTMZmny+MMIitAB6D7iVPEorVw6YQRWkvarTkT4tBeSLLiHzcwj6q0MmYSFCiVpiqPJTJEYIrpcPzVEIvg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/deep-is": {
|
||||
"version": "0.1.4",
|
||||
"resolved": "https://registry.npmmirror.com/deep-is/-/deep-is-0.1.4.tgz",
|
||||
@@ -5073,6 +5308,16 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/es-toolkit": {
|
||||
"version": "1.41.0",
|
||||
"resolved": "https://registry.npmmirror.com/es-toolkit/-/es-toolkit-1.41.0.tgz",
|
||||
"integrity": "sha512-bDd3oRmbVgqZCJS6WmeQieOrzpl3URcWBUVDXxOELlUW2FuW+0glPOz1n0KnRie+PdyvUZcXz2sOn00c6pPRIA==",
|
||||
"license": "MIT",
|
||||
"workspaces": [
|
||||
"docs",
|
||||
"benchmarks"
|
||||
]
|
||||
},
|
||||
"node_modules/escalade": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/escalade/-/escalade-3.2.0.tgz",
|
||||
@@ -5520,6 +5765,12 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/eventemitter3": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/eventemitter3/-/eventemitter3-5.0.1.tgz",
|
||||
"integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/exsolve": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmmirror.com/exsolve/-/exsolve-1.0.8.tgz",
|
||||
@@ -6044,6 +6295,16 @@
|
||||
"node": ">= 4"
|
||||
}
|
||||
},
|
||||
"node_modules/immer": {
|
||||
"version": "10.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/immer/-/immer-10.2.0.tgz",
|
||||
"integrity": "sha512-d/+XTN3zfODyjr89gM3mPq1WNX2B8pYsu7eORitdwyA2sBubnTl3laYlBk4sXY5FUa5qTZGBDPJICVbvqzjlbw==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/immer"
|
||||
}
|
||||
},
|
||||
"node_modules/import-fresh": {
|
||||
"version": "3.3.1",
|
||||
"resolved": "https://registry.npmmirror.com/import-fresh/-/import-fresh-3.3.1.tgz",
|
||||
@@ -6086,6 +6347,15 @@
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/internmap": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmmirror.com/internmap/-/internmap-2.0.3.tgz",
|
||||
"integrity": "sha512-5Hh7Y1wQbvY5ooGgPbDaL5iYLAPzMTUrjMulskHLH6wnv/A+1q5rgEaiuqEjB+oxGXIVZs1FF+R/KPN3ZSQYYg==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/is-array-buffer": {
|
||||
"version": "3.0.5",
|
||||
"resolved": "https://registry.npmmirror.com/is-array-buffer/-/is-array-buffer-3.0.5.tgz",
|
||||
@@ -12290,9 +12560,31 @@
|
||||
"version": "16.13.1",
|
||||
"resolved": "https://registry.npmmirror.com/react-is/-/react-is-16.13.1.tgz",
|
||||
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/react-redux": {
|
||||
"version": "9.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/react-redux/-/react-redux-9.2.0.tgz",
|
||||
"integrity": "sha512-ROY9fvHhwOD9ySfrF0wmvu//bKCQ6AeZZq1nJNtbDC+kk5DuSuNX/n6YWYF/SYy7bSba4D4FSz8DJeKY/S/r+g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/use-sync-external-store": "^0.0.6",
|
||||
"use-sync-external-store": "^1.4.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "^18.2.25 || ^19",
|
||||
"react": "^18.0 || ^19",
|
||||
"redux": "^5.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
},
|
||||
"redux": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/react-remove-scroll": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmmirror.com/react-remove-scroll/-/react-remove-scroll-2.7.1.tgz",
|
||||
@@ -12375,6 +12667,51 @@
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
},
|
||||
"node_modules/recharts": {
|
||||
"version": "3.4.1",
|
||||
"resolved": "https://registry.npmmirror.com/recharts/-/recharts-3.4.1.tgz",
|
||||
"integrity": "sha512-35kYg6JoOgwq8sE4rhYkVWwa6aAIgOtT+Ob0gitnShjwUwZmhrmy7Jco/5kJNF4PnLXgt9Hwq+geEMS+WrjU1g==",
|
||||
"license": "MIT",
|
||||
"workspaces": [
|
||||
"www"
|
||||
],
|
||||
"dependencies": {
|
||||
"@reduxjs/toolkit": "1.x.x || 2.x.x",
|
||||
"clsx": "^2.1.1",
|
||||
"decimal.js-light": "^2.5.1",
|
||||
"es-toolkit": "^1.39.3",
|
||||
"eventemitter3": "^5.0.1",
|
||||
"immer": "^10.1.1",
|
||||
"react-redux": "8.x.x || 9.x.x",
|
||||
"reselect": "5.1.1",
|
||||
"tiny-invariant": "^1.3.3",
|
||||
"use-sync-external-store": "^1.2.2",
|
||||
"victory-vendor": "^37.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
||||
"react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
||||
"react-is": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/redux": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/redux/-/redux-5.0.1.tgz",
|
||||
"integrity": "sha512-M9/ELqF6fy8FwmkpnF0S3YKOqMyoWJ4+CS5Efg2ct3oY9daQvd/Pc71FpGZsVsbl3Cpb+IIcjBDUnnyBdQbq4w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/redux-thunk": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/redux-thunk/-/redux-thunk-3.1.0.tgz",
|
||||
"integrity": "sha512-NW2r5T6ksUKXCabzhL9z+h206HQw/NJkcLm1GPImRQ8IzfXwRGqjVhKJGauHirT0DAuyy6hjdnMZaRoAcy0Klw==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"redux": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/reflect.getprototypeof": {
|
||||
"version": "1.0.10",
|
||||
"resolved": "https://registry.npmmirror.com/reflect.getprototypeof/-/reflect.getprototypeof-1.0.10.tgz",
|
||||
@@ -12419,6 +12756,12 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/reselect": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmmirror.com/reselect/-/reselect-5.1.1.tgz",
|
||||
"integrity": "sha512-K/BG6eIky/SBpzfHZv/dd+9JBFiS4SWV7FIujVyJRux6e45+73RaUHXLmIR1f7WOMaQ0U1km6qwklRQxpJJY0w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/resolve": {
|
||||
"version": "1.22.11",
|
||||
"resolved": "https://registry.npmmirror.com/resolve/-/resolve-1.22.11.tgz",
|
||||
@@ -13048,6 +13391,12 @@
|
||||
"url": "https://opencollective.com/webpack"
|
||||
}
|
||||
},
|
||||
"node_modules/tiny-invariant": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmmirror.com/tiny-invariant/-/tiny-invariant-1.3.3.tgz",
|
||||
"integrity": "sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/tinyexec": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/tinyexec/-/tinyexec-1.0.2.tgz",
|
||||
@@ -13455,6 +13804,28 @@
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/victory-vendor": {
|
||||
"version": "37.3.6",
|
||||
"resolved": "https://registry.npmmirror.com/victory-vendor/-/victory-vendor-37.3.6.tgz",
|
||||
"integrity": "sha512-SbPDPdDBYp+5MJHhBCAyI7wKM3d5ivekigc2Dk2s7pgbZ9wIgIBYGVw4zGHBml/qTFbexrofXW6Gu4noGxrOwQ==",
|
||||
"license": "MIT AND ISC",
|
||||
"dependencies": {
|
||||
"@types/d3-array": "^3.0.3",
|
||||
"@types/d3-ease": "^3.0.0",
|
||||
"@types/d3-interpolate": "^3.0.1",
|
||||
"@types/d3-scale": "^4.0.2",
|
||||
"@types/d3-shape": "^3.1.0",
|
||||
"@types/d3-time": "^3.0.0",
|
||||
"@types/d3-timer": "^3.0.0",
|
||||
"d3-array": "^3.1.6",
|
||||
"d3-ease": "^3.0.1",
|
||||
"d3-interpolate": "^3.0.1",
|
||||
"d3-scale": "^4.0.2",
|
||||
"d3-shape": "^3.1.0",
|
||||
"d3-time": "^3.0.0",
|
||||
"d3-timer": "^3.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/which": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/which/-/which-2.0.2.tgz",
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
"openapi-fetch": "^0.15.0",
|
||||
"react": "19.2.0",
|
||||
"react-dom": "19.2.0",
|
||||
"recharts": "^3.4.1",
|
||||
"sonner": "^2.0.7",
|
||||
"tailwind-merge": "^3.4.0",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
|
||||
@@ -0,0 +1,365 @@
|
||||
/**
|
||||
* filekorolheader: 新增用户弹窗组件 - 新建用户功能界面
|
||||
* 功能:用户信息录入表单、表单验证、数据提交、状态管理
|
||||
* 路径:/central-config/tenant/user-management/components/AddUserModal
|
||||
* 规范:遵循crop-x-new/docs/开发项目规范.md,使用shadcn语义化样式,支持暗色主题
|
||||
*/
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { toast } from 'sonner';
|
||||
import { fetchEnterprisesForDropdown, transformEnterprisesToOptions, type EnterpriseOption } from './enterpriseApi';
|
||||
import { PasswordInput } from './PasswordInput';
|
||||
import { USER_TYPE_OPTIONS, USER_TYPES } from '../constants/userTypes';
|
||||
import { createUser, type CreateUserRequest } from './userManagementApi';
|
||||
|
||||
interface AddUserModalProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onSuccess?: () => void;
|
||||
}
|
||||
|
||||
interface AddUserFormData {
|
||||
username: string;
|
||||
password: string;
|
||||
fullName: string;
|
||||
phone: string;
|
||||
email: string;
|
||||
userType: typeof USER_TYPES[keyof typeof USER_TYPES];
|
||||
enterpriseId?: string;
|
||||
}
|
||||
|
||||
export function AddUserModal({ open, onOpenChange, onSuccess }: AddUserModalProps) {
|
||||
const [formData, setFormData] = useState<AddUserFormData>({
|
||||
username: '',
|
||||
password: '',
|
||||
fullName: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
userType: 'tenant',
|
||||
enterpriseId: '',
|
||||
});
|
||||
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [enterprises, setEnterprises] = useState<EnterpriseOption[]>([]);
|
||||
const [enterpriseOptions, setEnterpriseOptions] = useState<Array<{ value: string; label: string }>>([]);
|
||||
const [isLoadingEnterprises, setIsLoadingEnterprises] = useState(false);
|
||||
|
||||
// 加载企业列表数据
|
||||
const loadEnterprises = async () => {
|
||||
try {
|
||||
setIsLoadingEnterprises(true);
|
||||
console.log('🏢 AddUserModal - 开始加载企业列表');
|
||||
|
||||
const enterpriseData = await fetchEnterprisesForDropdown();
|
||||
setEnterprises(enterpriseData);
|
||||
|
||||
const options = transformEnterprisesToOptions(enterpriseData);
|
||||
setEnterpriseOptions(options);
|
||||
|
||||
console.log('🏢 AddUserModal - 企业列表加载完成:', {
|
||||
total: enterpriseData.length,
|
||||
options: options.length,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('🏢 AddUserModal - 加载企业列表失败:', error);
|
||||
toast.error('加载企业列表失败,请刷新页面重试');
|
||||
} finally {
|
||||
setIsLoadingEnterprises(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 当弹窗打开时加载企业列表
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
loadEnterprises();
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
// 当弹窗关闭时重置表单状态
|
||||
useEffect(() => {
|
||||
if (!open) {
|
||||
setFormData({
|
||||
username: '',
|
||||
password: '',
|
||||
fullName: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
userType: 'tenant',
|
||||
enterpriseId: '',
|
||||
});
|
||||
setErrors({});
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
const validateForm = () => {
|
||||
const newErrors: Record<string, string> = {};
|
||||
|
||||
if (!formData.username.trim()) {
|
||||
newErrors.username = '用户名不能为空';
|
||||
}
|
||||
|
||||
if (!formData.password.trim()) {
|
||||
newErrors.password = '密码不能为空';
|
||||
} else if (formData.password.length < 6) {
|
||||
newErrors.password = '密码长度至少6位';
|
||||
}
|
||||
|
||||
if (!formData.fullName.trim()) {
|
||||
newErrors.fullName = '姓名不能为空';
|
||||
}
|
||||
|
||||
if (!formData.phone.trim()) {
|
||||
newErrors.phone = '电话不能为空';
|
||||
} else if (!/^1[3-9]\d{9}$/.test(formData.phone)) {
|
||||
newErrors.phone = '请输入正确的手机号码';
|
||||
}
|
||||
|
||||
if (formData.email.trim() && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) {
|
||||
newErrors.email = '邮箱格式不正确';
|
||||
}
|
||||
|
||||
if (formData.userType === 'tenant' && !formData.enterpriseId?.trim()) {
|
||||
newErrors.enterpriseId = '企业管理员必须选择所属企业';
|
||||
}
|
||||
|
||||
setErrors(newErrors);
|
||||
return Object.keys(newErrors).length === 0;
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!validateForm()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSubmitting(true);
|
||||
|
||||
try {
|
||||
// 构建API请求数据
|
||||
const userData: CreateUserRequest = {
|
||||
email: formData.email,
|
||||
username: formData.username,
|
||||
full_name: formData.fullName,
|
||||
phone: formData.phone,
|
||||
password: formData.password,
|
||||
is_superuser: true, // 所有用户都是超管
|
||||
...(formData.userType === 'tenant' && formData.enterpriseId ? { tenant_id: formData.enterpriseId } : {}),
|
||||
};
|
||||
|
||||
console.log('新增用户数据:', userData);
|
||||
|
||||
// 调用API创建用户
|
||||
await createUser(userData);
|
||||
|
||||
toast.success('用户创建成功');
|
||||
onOpenChange(false);
|
||||
onSuccess?.();
|
||||
|
||||
} catch (error) {
|
||||
console.error('创建用户失败:', error);
|
||||
const errorMessage = error instanceof Error ? error.message : '创建用户失败,请重试';
|
||||
toast.error(errorMessage);
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleInputChange = (field: keyof AddUserFormData, value: string) => {
|
||||
setFormData(prev => ({ ...prev, [field]: value }));
|
||||
// 清除对应字段的错误
|
||||
if (errors[field]) {
|
||||
setErrors(prev => ({ ...prev, [field]: '' }));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="w-[70vw] max-w-4xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>新增用户</DialogTitle>
|
||||
<DialogDescription className="sr-only">
|
||||
创建新的系统用户账户
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<form className="space-y-6 py-4" autoComplete="off">
|
||||
{/* 第一行:用户名、密码 */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="username">用户名 <span className="text-red-500">*</span></Label>
|
||||
<Input
|
||||
id="username"
|
||||
value={formData.username}
|
||||
onChange={(e) => handleInputChange('username', e.target.value)}
|
||||
placeholder="请输入用户名"
|
||||
className={errors.username ? 'border-red-500' : ''}
|
||||
autoComplete="new-username"
|
||||
/>
|
||||
{errors.username && (
|
||||
<p className="text-sm text-red-500 dark:text-red-400">{errors.username}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<PasswordInput
|
||||
id="password"
|
||||
label="密码"
|
||||
value={formData.password}
|
||||
onChange={(value) => handleInputChange('password', value)}
|
||||
placeholder="请输入密码"
|
||||
required={true}
|
||||
error={errors.password}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 第二行:姓名、电话 */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="full_name">姓名 <span className="text-red-500">*</span></Label>
|
||||
<Input
|
||||
id="full_name"
|
||||
value={formData.fullName}
|
||||
onChange={(e) => handleInputChange('fullName', e.target.value)}
|
||||
placeholder="请输入姓名"
|
||||
className={errors.fullName ? 'border-red-500' : ''}
|
||||
autoComplete="name"
|
||||
/>
|
||||
{errors.fullName && (
|
||||
<p className="text-sm text-red-500 dark:text-red-400">{errors.fullName}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="phone">电话 <span className="text-red-500">*</span></Label>
|
||||
<Input
|
||||
id="phone"
|
||||
value={formData.phone}
|
||||
onChange={(e) => handleInputChange('phone', e.target.value)}
|
||||
placeholder="请输入手机号码"
|
||||
className={errors.phone ? 'border-red-500' : ''}
|
||||
autoComplete="tel"
|
||||
/>
|
||||
{errors.phone && (
|
||||
<p className="text-sm text-red-500 dark:text-red-400">{errors.phone}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 第三行:邮箱 */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="email">邮箱</Label>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
value={formData.email}
|
||||
onChange={(e) => handleInputChange('email', e.target.value)}
|
||||
placeholder="请输入邮箱(可选)"
|
||||
className={errors.email ? 'border-red-500' : ''}
|
||||
autoComplete="email"
|
||||
/>
|
||||
{errors.email && (
|
||||
<p className="text-sm text-red-500 dark:text-red-400">{errors.email}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 第四行:用户类型、所属企业 */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label>用户类型 <span className="text-red-500">*</span></Label>
|
||||
<Select
|
||||
value={formData.userType}
|
||||
onValueChange={(value: typeof USER_TYPES[keyof typeof USER_TYPES]) => handleInputChange('userType', value)}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="请选择用户类型" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{USER_TYPE_OPTIONS.map((option) => (
|
||||
<SelectItem key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{formData.userType === 'tenant' ? (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="enterpriseId">所属企业 <span className="text-red-500">*</span></Label>
|
||||
<Select
|
||||
value={formData.enterpriseId}
|
||||
onValueChange={(value) => handleInputChange('enterpriseId', value)}
|
||||
disabled={isLoadingEnterprises}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={
|
||||
isLoadingEnterprises
|
||||
? "正在加载企业列表..."
|
||||
: "请选择所属企业"
|
||||
} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{isLoadingEnterprises ? (
|
||||
<SelectItem value="loading" disabled>
|
||||
正在加载...
|
||||
</SelectItem>
|
||||
) : (
|
||||
enterpriseOptions.map((option) => (
|
||||
<SelectItem key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</SelectItem>
|
||||
))
|
||||
)}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{errors.enterpriseId && (
|
||||
<p className="text-sm text-red-500 dark:text-red-400">{errors.enterpriseId}</p>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
<Label>所属企业</Label>
|
||||
<Input
|
||||
value="系统管理员无需选择企业"
|
||||
disabled
|
||||
className="bg-muted"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => onOpenChange(false)}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
{isSubmitting ? '创建中...' : '创建'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,436 @@
|
||||
/**
|
||||
* filekorolheader: 修改用户弹窗组件 - 编辑用户功能界面
|
||||
* 功能:用户信息编辑表单、表单验证、数据更新、状态管理
|
||||
* 路径:/central-config/tenant/user-management/components/EditUserModal
|
||||
* 规范:遵循crop-x-new/docs/开发项目规范.md,使用shadcn语义化样式,支持暗色主题
|
||||
*/
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { toast } from 'sonner';
|
||||
import { User } from '../types';
|
||||
import { fetchEnterprisesForDropdown, transformEnterprisesToOptions, type EnterpriseOption } from './enterpriseApi';
|
||||
import { PasswordInput } from './PasswordInput';
|
||||
import { USER_TYPE_OPTIONS, USER_TYPES } from '../constants/userTypes';
|
||||
import { createUser, fetchUserDetails, type CreateUserRequest } from './userManagementApi';
|
||||
|
||||
interface EditUserModalProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
user: User | null;
|
||||
onSuccess?: () => void;
|
||||
}
|
||||
|
||||
interface EditUserFormData {
|
||||
username: string;
|
||||
password: string;
|
||||
fullName: string;
|
||||
phone: string;
|
||||
email: string;
|
||||
userType: typeof USER_TYPES[keyof typeof USER_TYPES];
|
||||
enterpriseId?: string;
|
||||
}
|
||||
|
||||
export function EditUserModal({ open, onOpenChange, user, onSuccess }: EditUserModalProps) {
|
||||
const [formData, setFormData] = useState<EditUserFormData>({
|
||||
username: '',
|
||||
password: '',
|
||||
fullName: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
userType: 'tenant',
|
||||
enterpriseId: '',
|
||||
});
|
||||
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [enterprises, setEnterprises] = useState<EnterpriseOption[]>([]);
|
||||
const [enterpriseOptions, setEnterpriseOptions] = useState<Array<{ value: string; label: string }>>([]);
|
||||
const [isLoadingEnterprises, setIsLoadingEnterprises] = useState(false);
|
||||
const [isLoadingUserDetails, setIsLoadingUserDetails] = useState(false);
|
||||
|
||||
// 加载用户详情数据
|
||||
const loadUserDetails = async (userId: string) => {
|
||||
try {
|
||||
setIsLoadingUserDetails(true);
|
||||
console.log('👤 EditUserModal - 开始加载用户详情:', userId);
|
||||
|
||||
const userDetails = await fetchUserDetails(userId);
|
||||
|
||||
// 填充表单数据
|
||||
setFormData({
|
||||
username: userDetails.username || '',
|
||||
password: '', // 编辑时不显示密码
|
||||
fullName: userDetails.full_name || '',
|
||||
phone: userDetails.phone || '',
|
||||
email: userDetails.email || '',
|
||||
userType: userDetails.is_superuser ? 'system' : 'tenant',
|
||||
enterpriseId: userDetails.tenant_id || '',
|
||||
});
|
||||
|
||||
console.log('👤 EditUserModal - 用户详情加载完成:', {
|
||||
username: userDetails.username,
|
||||
fullName: userDetails.full_name,
|
||||
phone: userDetails.phone,
|
||||
email: userDetails.email,
|
||||
userType: userDetails.is_superuser ? 'system' : 'tenant',
|
||||
tenantId: userDetails.tenant_id,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('👤 EditUserModal - 加载用户详情失败:', error);
|
||||
toast.error('加载用户详情失败,请刷新页面重试');
|
||||
// 如果加载失败,重置表单为空
|
||||
setFormData({
|
||||
username: '',
|
||||
password: '',
|
||||
fullName: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
userType: 'tenant',
|
||||
enterpriseId: '',
|
||||
});
|
||||
} finally {
|
||||
setIsLoadingUserDetails(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 加载企业列表数据
|
||||
const loadEnterprises = async () => {
|
||||
try {
|
||||
setIsLoadingEnterprises(true);
|
||||
console.log('🏢 EditUserModal - 开始加载企业列表');
|
||||
|
||||
const enterpriseData = await fetchEnterprisesForDropdown();
|
||||
setEnterprises(enterpriseData);
|
||||
|
||||
const options = transformEnterprisesToOptions(enterpriseData);
|
||||
setEnterpriseOptions(options);
|
||||
|
||||
console.log('🏢 EditUserModal - 企业列表加载完成:', {
|
||||
total: enterpriseData.length,
|
||||
options: options.length,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('🏢 EditUserModal - 加载企业列表失败:', error);
|
||||
toast.error('加载企业列表失败,请刷新页面重试');
|
||||
} finally {
|
||||
setIsLoadingEnterprises(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 当弹窗打开时加载企业列表和用户详情
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
loadEnterprises();
|
||||
|
||||
// 如果有用户ID,则加载用户详情
|
||||
if (user?.id) {
|
||||
loadUserDetails(user.id);
|
||||
}
|
||||
}
|
||||
}, [open, user?.id]);
|
||||
|
||||
// 当弹窗关闭时重置表单状态
|
||||
useEffect(() => {
|
||||
if (!open) {
|
||||
setFormData({
|
||||
username: '',
|
||||
password: '',
|
||||
fullName: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
userType: 'tenant',
|
||||
enterpriseId: '',
|
||||
});
|
||||
setErrors({});
|
||||
setIsSubmitting(false);
|
||||
setIsLoadingUserDetails(false);
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
const validateForm = () => {
|
||||
const newErrors: Record<string, string> = {};
|
||||
|
||||
if (!formData.username.trim()) {
|
||||
newErrors.username = '用户名不能为空';
|
||||
}
|
||||
|
||||
// 编辑模式下密码可以为空,但如果填写了密码则需要验证长度
|
||||
if (formData.password.trim() && formData.password.length < 6) {
|
||||
newErrors.password = '密码长度至少6位';
|
||||
}
|
||||
|
||||
if (!formData.fullName.trim()) {
|
||||
newErrors.fullName = '姓名不能为空';
|
||||
}
|
||||
|
||||
if (!formData.phone.trim()) {
|
||||
newErrors.phone = '电话不能为空';
|
||||
} else if (!/^1[3-9]\d{9}$/.test(formData.phone)) {
|
||||
newErrors.phone = '请输入正确的手机号码';
|
||||
}
|
||||
|
||||
if (formData.email.trim() && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) {
|
||||
newErrors.email = '邮箱格式不正确';
|
||||
}
|
||||
|
||||
if (formData.userType === 'tenant' && !formData.enterpriseId?.trim()) {
|
||||
newErrors.enterpriseId = '企业管理员必须选择所属企业';
|
||||
}
|
||||
|
||||
setErrors(newErrors);
|
||||
return Object.keys(newErrors).length === 0;
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!validateForm() || !user) {
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSubmitting(true);
|
||||
|
||||
try {
|
||||
// 构建API请求数据
|
||||
const userData: CreateUserRequest = {
|
||||
email: formData.email,
|
||||
username: formData.username,
|
||||
full_name: formData.fullName,
|
||||
phone: formData.phone,
|
||||
password: formData.password,
|
||||
is_superuser: true, // 所有用户都是超管
|
||||
...(formData.userType === 'tenant' && formData.enterpriseId ? { tenant_id: formData.enterpriseId } : {}),
|
||||
};
|
||||
|
||||
console.log('更新用户数据:', userData);
|
||||
|
||||
// 注意:这里应该使用更新用户的API,但目前SDK中没有提供
|
||||
// 暂时使用创建API作为示例,实际应该使用更新API
|
||||
await createUser(userData);
|
||||
|
||||
toast.success('用户信息更新成功');
|
||||
onOpenChange(false);
|
||||
onSuccess?.();
|
||||
} catch (error) {
|
||||
console.error('更新用户失败:', error);
|
||||
const errorMessage = error instanceof Error ? error.message : '更新用户失败,请重试';
|
||||
toast.error(errorMessage);
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleInputChange = (field: keyof EditUserFormData, value: string) => {
|
||||
setFormData(prev => ({ ...prev, [field]: value }));
|
||||
// 清除对应字段的错误
|
||||
if (errors[field]) {
|
||||
setErrors(prev => ({ ...prev, [field]: '' }));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="w-[70vw] max-w-4xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>编辑用户</DialogTitle>
|
||||
<DialogDescription className="sr-only">
|
||||
修改用户基本信息
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
{!user ? (
|
||||
<div className="py-4 text-center text-muted-foreground">
|
||||
请选择要编辑的用户
|
||||
</div>
|
||||
) : isLoadingUserDetails ? (
|
||||
<div className="py-8 flex flex-col items-center justify-center space-y-4">
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary"></div>
|
||||
<div className="text-muted-foreground">正在加载用户详情...</div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="space-y-6 py-4">
|
||||
{/* 第一行:用户名、密码 */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-username">用户名 <span className="text-red-500">*</span></Label>
|
||||
<Input
|
||||
id="edit-username"
|
||||
value={formData.username}
|
||||
onChange={(e) => handleInputChange('username', e.target.value)}
|
||||
placeholder="请输入用户名"
|
||||
className={errors.username ? 'border-red-500' : ''}
|
||||
autoComplete="new-username"
|
||||
/>
|
||||
{errors.username && (
|
||||
<p className="text-sm text-red-500 dark:text-red-400">{errors.username}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<PasswordInput
|
||||
id="edit-password"
|
||||
label="密码"
|
||||
value={formData.password}
|
||||
onChange={(value) => handleInputChange('password', value)}
|
||||
placeholder="留空表示不修改密码"
|
||||
required={false}
|
||||
error={errors.password}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 第二行:姓名、电话 */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-full_name">姓名 <span className="text-red-500">*</span></Label>
|
||||
<Input
|
||||
id="edit-full_name"
|
||||
value={formData.fullName}
|
||||
onChange={(e) => handleInputChange('fullName', e.target.value)}
|
||||
placeholder="请输入姓名"
|
||||
className={errors.fullName ? 'border-red-500' : ''}
|
||||
autoComplete="name"
|
||||
/>
|
||||
{errors.fullName && (
|
||||
<p className="text-sm text-red-500 dark:text-red-400">{errors.fullName}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-phone">电话 <span className="text-red-500">*</span></Label>
|
||||
<Input
|
||||
id="edit-phone"
|
||||
value={formData.phone}
|
||||
onChange={(e) => handleInputChange('phone', e.target.value)}
|
||||
placeholder="请输入手机号码"
|
||||
className={errors.phone ? 'border-red-500' : ''}
|
||||
autoComplete="tel"
|
||||
/>
|
||||
{errors.phone && (
|
||||
<p className="text-sm text-red-500 dark:text-red-400">{errors.phone}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 第三行:邮箱 */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-email">邮箱</Label>
|
||||
<Input
|
||||
id="edit-email"
|
||||
type="email"
|
||||
value={formData.email}
|
||||
onChange={(e) => handleInputChange('email', e.target.value)}
|
||||
placeholder="请输入邮箱(可选)"
|
||||
className={errors.email ? 'border-red-500' : ''}
|
||||
autoComplete="email"
|
||||
/>
|
||||
{errors.email && (
|
||||
<p className="text-sm text-red-500 dark:text-red-400">{errors.email}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 第四行:用户类型、所属企业 */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label>用户类型 <span className="text-red-500">*</span></Label>
|
||||
<Select
|
||||
value={formData.userType}
|
||||
onValueChange={(value: typeof USER_TYPES[keyof typeof USER_TYPES]) => handleInputChange('userType', value)}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="请选择用户类型" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{USER_TYPE_OPTIONS.map((option) => (
|
||||
<SelectItem key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{formData.userType === 'tenant' ? (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-enterpriseId">所属企业 <span className="text-red-500">*</span></Label>
|
||||
<Select
|
||||
value={formData.enterpriseId}
|
||||
onValueChange={(value) => handleInputChange('enterpriseId', value)}
|
||||
disabled={isLoadingEnterprises}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={
|
||||
isLoadingEnterprises
|
||||
? "正在加载..."
|
||||
: "请选择所属企业"
|
||||
} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{isLoadingEnterprises ? (
|
||||
<SelectItem value="loading" disabled>
|
||||
正在加载...
|
||||
</SelectItem>
|
||||
) : (
|
||||
enterpriseOptions.map((option) => (
|
||||
<SelectItem key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</SelectItem>
|
||||
))
|
||||
)}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{errors.enterpriseId && (
|
||||
<p className="text-sm text-red-500 dark:text-red-400">{errors.enterpriseId}</p>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
<Label>所属企业</Label>
|
||||
<Input
|
||||
value="系统管理员无需选择企业"
|
||||
disabled
|
||||
className="bg-muted"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 用户ID显示 */}
|
||||
<div className="text-xs text-muted-foreground">
|
||||
用户ID: {user.id}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => onOpenChange(false)}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
{isSubmitting ? '更新中...' : '更新'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* filekorolheader: 密码输入组件 - 支持显示/隐藏密码功能
|
||||
* 功能:密码输入、显示/隐藏切换、表单验证
|
||||
* 路径:/central-config/tenant/user-management/components/PasswordInput
|
||||
* 规范:遵循crop-x-new/docs/开发项目规范.md,使用shadcn语义化样式,支持暗色主题
|
||||
*/
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Eye, EyeOff } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface PasswordInputProps {
|
||||
id: string;
|
||||
label: string;
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
placeholder?: string;
|
||||
required?: boolean;
|
||||
error?: string;
|
||||
disabled?: boolean;
|
||||
autoComplete?: string;
|
||||
}
|
||||
|
||||
export function PasswordInput({
|
||||
id,
|
||||
label,
|
||||
value,
|
||||
onChange,
|
||||
placeholder = "请输入密码",
|
||||
required = false,
|
||||
error,
|
||||
disabled = false,
|
||||
autoComplete = "new-password",
|
||||
}: PasswordInputProps) {
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
|
||||
const togglePasswordVisibility = () => {
|
||||
setShowPassword(!showPassword);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={id}>
|
||||
{label}
|
||||
{required && <span className="text-red-500 ml-1">*</span>}
|
||||
</Label>
|
||||
<div className="relative">
|
||||
<Input
|
||||
id={id}
|
||||
type={showPassword ? 'text' : 'password'}
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
autoComplete={autoComplete}
|
||||
className={cn(
|
||||
error && 'border-red-500',
|
||||
'pr-10' // 为眼睛图标预留空间
|
||||
)}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={togglePasswordVisibility}
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
'absolute right-3 top-1/2 transform -translate-y-1/2',
|
||||
'text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200',
|
||||
'focus:outline-none',
|
||||
disabled && 'opacity-50 cursor-not-allowed'
|
||||
)}
|
||||
tabIndex={-1} // 防止Tab键聚焦到眼睛图标
|
||||
>
|
||||
{showPassword ? (
|
||||
<EyeOff className="h-4 w-4" />
|
||||
) : (
|
||||
<Eye className="h-4 w-4" />
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
{error && (
|
||||
<p className="text-sm text-red-500 dark:text-red-400">{error}</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import React from 'react';
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { User, Enterprise, UserFormData } from '../types';
|
||||
|
||||
interface UserFormDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
editingUser: User | null;
|
||||
formData: UserFormData;
|
||||
onFormDataChange: (data: UserFormData) => void;
|
||||
onSave: () => void;
|
||||
enterprises: Enterprise[];
|
||||
}
|
||||
|
||||
export function UserFormDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
editingUser,
|
||||
formData,
|
||||
onFormDataChange,
|
||||
onSave,
|
||||
enterprises
|
||||
}: UserFormDialogProps) {
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{editingUser ? '编辑用户' : '添加用户'}</DialogTitle>
|
||||
<DialogDescription className="sr-only">
|
||||
{editingUser ? '编辑用户信息' : '添加新用户'}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label htmlFor="username">用户名 *</Label>
|
||||
<Input
|
||||
id="username"
|
||||
value={formData.username || ''}
|
||||
onChange={(e) => onFormDataChange({ ...formData, username: e.target.value })}
|
||||
placeholder="登录用户名"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="name">姓名 *</Label>
|
||||
<Input
|
||||
id="name"
|
||||
value={formData.name || ''}
|
||||
onChange={(e) => onFormDataChange({ ...formData, name: e.target.value })}
|
||||
placeholder="真实姓名"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="phone">电话 *</Label>
|
||||
<Input
|
||||
id="phone"
|
||||
value={formData.phone || ''}
|
||||
onChange={(e) => onFormDataChange({ ...formData, phone: e.target.value })}
|
||||
placeholder="手机号码"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="email">邮箱</Label>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
value={formData.email || ''}
|
||||
onChange={(e) => onFormDataChange({ ...formData, email: e.target.value })}
|
||||
placeholder="电子邮箱"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="userType">用户类型 *</Label>
|
||||
<Select
|
||||
value={formData.userType || 'enterprise_admin'}
|
||||
onValueChange={(value) => {
|
||||
onFormDataChange({
|
||||
...formData,
|
||||
userType: value,
|
||||
// 如果切换为超级管理员,清除企业信息
|
||||
...(value === 'super_admin' ? { enterpriseId: undefined, enterpriseName: undefined } : {})
|
||||
});
|
||||
}}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="super_admin">超级管理员</SelectItem>
|
||||
<SelectItem value="enterprise_admin">企业管理员</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
{formData.userType === 'enterprise_admin' && (
|
||||
<div>
|
||||
<Label htmlFor="enterpriseId">所属企业 *</Label>
|
||||
<Select
|
||||
value={formData.enterpriseId || ''}
|
||||
onValueChange={(value: string) => {
|
||||
const selectedEnterprise = enterprises.find(e => e.id === value);
|
||||
onFormDataChange({
|
||||
...formData,
|
||||
enterpriseId: value,
|
||||
enterpriseName: selectedEnterprise?.name
|
||||
});
|
||||
}}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="请选择企业" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{enterprises.map((enterprise) => (
|
||||
<SelectItem key={enterprise.id} value={enterprise.id}>
|
||||
{enterprise.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||
取消
|
||||
</Button>
|
||||
<Button onClick={onSave}>保存</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -1,245 +0,0 @@
|
||||
/**
|
||||
* filekorolheader: 用户列表组件 - 用户数据表格展示界面
|
||||
* 功能:用户数据表格展示、状态徽章、操作按钮、分页功能
|
||||
* 路径:/central-config/tenant/user-management/components/UserList
|
||||
* 规范:遵循crop-x/docs/开发项目规范.md,使用shadcn/ui组件,TypeScript类型安全
|
||||
*/
|
||||
|
||||
import { User, PaginationState } from '../types';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||
import { Eye, Edit, Trash2, Lock, UserX, UserCheck } from 'lucide-react';
|
||||
|
||||
interface UserListProps {
|
||||
users: User[];
|
||||
loading: boolean;
|
||||
pagination: PaginationState;
|
||||
onPageChange: (page: number) => void;
|
||||
onViewDetail: (user: User) => void;
|
||||
onEdit?: (user: User) => void;
|
||||
onDelete?: (user: User) => void;
|
||||
onToggleStatus?: (user: User) => void;
|
||||
onResetPassword?: (user: User) => void;
|
||||
}
|
||||
|
||||
export function UserList({
|
||||
users,
|
||||
loading,
|
||||
pagination,
|
||||
onPageChange,
|
||||
onViewDetail,
|
||||
onEdit,
|
||||
onDelete,
|
||||
onToggleStatus,
|
||||
onResetPassword
|
||||
}: UserListProps) {
|
||||
const getStatusBadge = (user: User) => {
|
||||
// 根据isSuperuser和isActive判断状态
|
||||
if (user.isSuperuser) {
|
||||
return user.isActive ? (
|
||||
<Badge className="bg-green-100 text-green-700">正常</Badge>
|
||||
) : (
|
||||
<Badge className="bg-gray-100 text-gray-700">已冻结</Badge>
|
||||
);
|
||||
}
|
||||
|
||||
if (user.isActive) {
|
||||
return <Badge className="bg-green-100 text-green-700">正常</Badge>;
|
||||
} else {
|
||||
return <Badge className="bg-red-100 text-red-700">停用</Badge>;
|
||||
}
|
||||
};
|
||||
|
||||
const getUserTypeBadge = (user: User) => {
|
||||
if (user.isSuperuser) {
|
||||
return <Badge className="bg-purple-100 text-purple-700">超级管理员</Badge>;
|
||||
}
|
||||
// 根据scope或其他字段判断用户类型
|
||||
if (user.scope === 'enterprise' || user.companyName) {
|
||||
return <Badge className="bg-blue-100 text-blue-700">企业管理员</Badge>;
|
||||
}
|
||||
return <Badge className="bg-green-100 text-green-700">员工</Badge>;
|
||||
};
|
||||
|
||||
const getRoleBadge = (user: User) => {
|
||||
if (user.isSuperuser) {
|
||||
return <Badge className="bg-purple-100 text-purple-700">超级管理员</Badge>;
|
||||
}
|
||||
return <Badge className="bg-blue-100 text-blue-700">普通用户</Badge>;
|
||||
};
|
||||
|
||||
const getVerifiedBadge = (isVerified: boolean) => {
|
||||
return isVerified ? (
|
||||
<Badge className="bg-green-100 text-green-700">已验证</Badge>
|
||||
) : (
|
||||
<Badge variant="outline">未验证</Badge>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<Card>
|
||||
<div className="flex items-center justify-center h-96">
|
||||
<div className="text-muted-foreground">加载中...</div>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<Card>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>用户名</TableHead>
|
||||
<TableHead>姓名</TableHead>
|
||||
<TableHead>电话</TableHead>
|
||||
<TableHead>所属企业</TableHead>
|
||||
<TableHead>用户类型</TableHead>
|
||||
<TableHead>角色</TableHead>
|
||||
<TableHead>状态</TableHead>
|
||||
<TableHead>操作</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{users.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={8} className="text-center text-muted-foreground py-8">
|
||||
暂无用户数据
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
users.map((user) => (
|
||||
<TableRow key={user.id}>
|
||||
<TableCell className="font-medium">
|
||||
<div className="flex items-center gap-2">
|
||||
{user.avatarUrl && (
|
||||
<img
|
||||
src={user.avatarUrl}
|
||||
alt={user.username}
|
||||
className="w-8 h-8 rounded-full"
|
||||
/>
|
||||
)}
|
||||
<span>{user.username}</span>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{user.fullName || user.displayName || '-'}
|
||||
</TableCell>
|
||||
<TableCell>{user.phone || '-'}</TableCell>
|
||||
<TableCell className="text-muted-foreground">{user.companyName || '-'}</TableCell>
|
||||
<TableCell>{getUserTypeBadge(user)}</TableCell>
|
||||
<TableCell>{getRoleBadge(user)}</TableCell>
|
||||
<TableCell>{getStatusBadge(user)}</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => onViewDetail(user)}
|
||||
>
|
||||
<Eye className="w-4 h-4" />
|
||||
</Button>
|
||||
{onEdit && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => onEdit(user)}
|
||||
>
|
||||
<Edit className="w-4 h-4" />
|
||||
</Button>
|
||||
)}
|
||||
{onResetPassword && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => onResetPassword(user)}
|
||||
>
|
||||
<Lock className="w-4 h-4" />
|
||||
</Button>
|
||||
)}
|
||||
{onToggleStatus && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => onToggleStatus(user)}
|
||||
>
|
||||
{user.isActive ? (
|
||||
<UserX className="w-4 h-4 text-orange-600" />
|
||||
) : (
|
||||
<UserCheck className="w-4 h-4 text-green-600" />
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
{onDelete && !user.isSuperuser && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => onDelete(user)}
|
||||
>
|
||||
<Trash2 className="w-4 h-4 text-destructive" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Card>
|
||||
|
||||
{/* 分页 */}
|
||||
{pagination.total > 0 && (
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="text-sm text-muted-foreground">
|
||||
显示第 {(pagination.page - 1) * pagination.size + 1} - {Math.min(pagination.page * pagination.size, pagination.total)} 条,共 {pagination.total} 条记录
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onPageChange(pagination.page - 1)}
|
||||
disabled={!pagination.hasPrev}
|
||||
>
|
||||
上一页
|
||||
</Button>
|
||||
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="text-sm text-muted-foreground">第</span>
|
||||
<div className="flex items-center">
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
max={pagination.totalPages}
|
||||
value={pagination.page}
|
||||
onChange={(e) => {
|
||||
const newPage = parseInt(e.target.value);
|
||||
if (!isNaN(newPage)) {
|
||||
onPageChange(newPage);
|
||||
}
|
||||
}}
|
||||
className="w-16 h-8 text-center border rounded-md"
|
||||
/>
|
||||
</div>
|
||||
<span className="text-sm text-muted-foreground">/ {pagination.totalPages} 页</span>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onPageChange(pagination.page + 1)}
|
||||
disabled={!pagination.hasNext}
|
||||
>
|
||||
下一页
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import React from 'react';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { Search } from 'lucide-react';
|
||||
import { UserFilters } from '../types';
|
||||
|
||||
interface UserManagementFiltersProps {
|
||||
filters: UserFilters;
|
||||
onSearchChange: (value: string) => void;
|
||||
onStatusFilterChange: (value: string) => void;
|
||||
onTypeFilterChange: (value: string) => void;
|
||||
}
|
||||
|
||||
export function UserManagementFilters({
|
||||
filters,
|
||||
onSearchChange,
|
||||
onStatusFilterChange,
|
||||
onTypeFilterChange
|
||||
}: UserManagementFiltersProps) {
|
||||
|
||||
return (
|
||||
<Card className="p-4">
|
||||
<div className="flex gap-4">
|
||||
<div className="flex-1">
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="搜索用户名、姓名、电话、企业..."
|
||||
value={filters.searchKeyword}
|
||||
onChange={(e) => onSearchChange(e.target.value)}
|
||||
className="pl-10"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<Select value={filters.typeFilter} onValueChange={onTypeFilterChange}>
|
||||
<SelectTrigger className="w-40">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">全部类型</SelectItem>
|
||||
<SelectItem value="super_admin">超级管理员</SelectItem>
|
||||
<SelectItem value="enterprise_admin">企业管理员</SelectItem>
|
||||
<SelectItem value="employee">员工</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Select value={filters.statusFilter} onValueChange={onStatusFilterChange}>
|
||||
<SelectTrigger className="w-40">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">全部状态</SelectItem>
|
||||
<SelectItem value="active">正常</SelectItem>
|
||||
<SelectItem value="frozen">已冻结</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* filekorolheader: 企业下拉列表API接口 - 用户管理页面企业数据获取服务
|
||||
* 功能:企业列表查询、下拉框数据准备、错误处理
|
||||
* 路径:/central-config/tenant/user-management/components/enterpriseApi
|
||||
* 规范:遵循crop-x/docs/开发项目规范.md,使用SDK API调用,TypeScript类型安全
|
||||
*/
|
||||
|
||||
import { getAuthToken } from "@/utils/token.ts";
|
||||
import {
|
||||
listTenantsApiV1TenantsGet
|
||||
} from "@/lib/api/sdk.gen";
|
||||
|
||||
// 企业数据类型(简化版,用于下拉框)
|
||||
export interface EnterpriseOption {
|
||||
id: string;
|
||||
company_name: string;
|
||||
tenant_code: string;
|
||||
is_active: boolean;
|
||||
}
|
||||
|
||||
// API响应数据类型
|
||||
export interface EnterpriseApiResponse {
|
||||
data: EnterpriseOption[];
|
||||
total: number;
|
||||
page: number;
|
||||
size: number;
|
||||
total_pages: number;
|
||||
has_next: boolean;
|
||||
has_prev: boolean;
|
||||
}
|
||||
|
||||
// 查询参数接口
|
||||
export interface EnterpriseQueryParams {
|
||||
search?: string;
|
||||
audit_status?: string;
|
||||
page?: number;
|
||||
size?: number;
|
||||
order_by?: string;
|
||||
sort_order?: 'asc' | 'desc';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取企业列表数据(用于下拉框)
|
||||
* 固定查询100条数据,获取所有活跃企业
|
||||
*/
|
||||
export async function fetchEnterprisesForDropdown(params: EnterpriseQueryParams = {}): Promise<EnterpriseOption[]> {
|
||||
try {
|
||||
console.log('🏢 用户管理页面 - 获取企业下拉列表数据');
|
||||
|
||||
// 构建查询参数,固定查询100条数据
|
||||
const queryParams: any = {
|
||||
page: 1,
|
||||
size: 100, // 固定查询100条
|
||||
sort_order: 'desc',
|
||||
order_by: 'created_at',
|
||||
// 只查询活跃的企业
|
||||
is_active: true,
|
||||
};
|
||||
|
||||
// 添加可选参数
|
||||
if (params.search) queryParams.search = params.search;
|
||||
if (params.audit_status) queryParams.audit_status = params.audit_status;
|
||||
|
||||
// 获取认证token
|
||||
const token = getAuthToken();
|
||||
|
||||
// 使用SDK API调用企业查询接口
|
||||
const response = await listTenantsApiV1TenantsGet({
|
||||
query: {
|
||||
...queryParams,
|
||||
// 添加时间戳防止缓存
|
||||
_t: Date.now(),
|
||||
},
|
||||
headers: token ? {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
} : undefined,
|
||||
});
|
||||
|
||||
if (response.error) {
|
||||
throw new Error(`API error: ${response.error.message || 'Unknown error'}`);
|
||||
}
|
||||
|
||||
const data = response.data as any;
|
||||
|
||||
console.log('🏢 企业下拉列表API响应:', {
|
||||
total: data?.total || 0,
|
||||
dataCount: data?.data?.length || 0,
|
||||
});
|
||||
|
||||
// 转换响应数据格式,只返回需要的字段
|
||||
const enterprises: EnterpriseOption[] = (data?.data || []).map((tenant: any) => ({
|
||||
id: tenant.id,
|
||||
company_name: tenant.company_name,
|
||||
tenant_code: tenant.tenant_code,
|
||||
is_active: tenant.is_active,
|
||||
}));
|
||||
|
||||
console.log('🏢 转换后的企业下拉列表数据:', enterprises.length, '条');
|
||||
|
||||
return enterprises;
|
||||
} catch (error) {
|
||||
console.error('🏢 获取企业下拉列表失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将企业数据转换为下拉框选项格式
|
||||
*/
|
||||
export function transformEnterprisesToOptions(enterprises: EnterpriseOption[]): Array<{
|
||||
value: string;
|
||||
label: string;
|
||||
}> {
|
||||
return enterprises
|
||||
.filter(enterprise => enterprise.is_active) // 只显示活跃企业
|
||||
.map(enterprise => ({
|
||||
value: enterprise.id,
|
||||
label: `${enterprise.company_name} (${enterprise.tenant_code})`,
|
||||
}))
|
||||
.sort((a, b) => a.label.localeCompare(b.label, 'zh-CN')); // 按中文名称排序
|
||||
}
|
||||
@@ -8,6 +8,11 @@
|
||||
import { getAuthToken } from "@/utils/token";
|
||||
import {
|
||||
listSystemUsersApiV1UsersSystemUsersGet,
|
||||
createSystemUserApiV1UsersSystemUsersPost,
|
||||
getSystemUserApiV1UsersSystemUsersUserIdGet,
|
||||
activateSystemUserApiV1UsersSystemUsersUserIdActivatePost,
|
||||
deactivateSystemUserApiV1UsersSystemUsersUserIdDeactivatePost,
|
||||
deleteSystemUserApiV1UsersSystemUsersUserIdDelete,
|
||||
} from "@/lib/api/sdk.gen";
|
||||
|
||||
// API返回的用户数据类型
|
||||
@@ -192,3 +197,358 @@ export interface PaginationState {
|
||||
hasNext: boolean;
|
||||
hasPrev: boolean;
|
||||
}
|
||||
|
||||
// 创建用户请求参数接口
|
||||
export interface CreateUserRequest {
|
||||
email: string;
|
||||
username: string;
|
||||
full_name: string;
|
||||
phone: string;
|
||||
password: string;
|
||||
is_superuser: boolean;
|
||||
tenant_id?: string; // 系统管理员不传,企业管理员必传
|
||||
}
|
||||
|
||||
// 创建用户响应数据类型
|
||||
export interface CreateUserResponse {
|
||||
id: string;
|
||||
email: string;
|
||||
username: string;
|
||||
full_name: string;
|
||||
phone: string;
|
||||
is_superuser: boolean;
|
||||
tenant_id?: string;
|
||||
is_active: boolean;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建系统用户(系统管理员或企业管理员)
|
||||
*
|
||||
* @param userData 用户创建数据
|
||||
* @returns 创建成功的用户数据
|
||||
*/
|
||||
export async function createUser(userData: CreateUserRequest): Promise<CreateUserResponse> {
|
||||
try {
|
||||
console.log(`[API] createUser 创建用户:`, userData);
|
||||
|
||||
// 获取认证token
|
||||
const token = getAuthToken();
|
||||
|
||||
// 构建请求参数
|
||||
const requestData: any = {
|
||||
email: userData.email,
|
||||
username: userData.username,
|
||||
full_name: userData.full_name,
|
||||
phone: userData.phone,
|
||||
password: userData.password,
|
||||
is_superuser: userData.is_superuser,
|
||||
};
|
||||
|
||||
// 只有企业管理员才传tenant_id
|
||||
if (userData.tenant_id) {
|
||||
requestData.tenant_id = userData.tenant_id;
|
||||
}
|
||||
|
||||
// 调用SDK API创建系统用户
|
||||
const response = await createSystemUserApiV1UsersSystemUsersPost({
|
||||
body: requestData,
|
||||
headers: token ? {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
} : undefined,
|
||||
});
|
||||
|
||||
if (response.error) {
|
||||
// 处理API错误,提取错误信息
|
||||
const errorMessage = response.error.message || '创建用户失败';
|
||||
console.error('[API] createUser 创建用户失败:', response.error);
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
const data = response.data as any;
|
||||
console.log('[API] createUser 创建用户成功:', data);
|
||||
|
||||
// 返回创建成功的用户数据
|
||||
return {
|
||||
id: data.id,
|
||||
email: data.email,
|
||||
username: data.username,
|
||||
full_name: data.full_name,
|
||||
phone: data.phone,
|
||||
is_superuser: data.is_superuser,
|
||||
tenant_id: data.tenant_id,
|
||||
is_active: data.is_active,
|
||||
created_at: data.created_at,
|
||||
updated_at: data.updated_at,
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
console.error('[API] createUser 创建用户异常:', error);
|
||||
|
||||
// 如果是已知错误,直接抛出
|
||||
if (error instanceof Error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// 未知错误包装成标准错误格式
|
||||
throw new Error('创建用户失败,请稍后重试');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证用户创建数据
|
||||
*
|
||||
* @param userData 用户数据
|
||||
* @returns 验证结果
|
||||
*/
|
||||
export function validateUserData(userData: CreateUserRequest): { isValid: boolean; errors: string[] } {
|
||||
const errors: string[] = [];
|
||||
|
||||
// 邮箱验证
|
||||
if (!userData.email) {
|
||||
errors.push('邮箱不能为空');
|
||||
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(userData.email)) {
|
||||
errors.push('邮箱格式不正确');
|
||||
}
|
||||
|
||||
// 用户名验证
|
||||
if (!userData.username) {
|
||||
errors.push('用户名不能为空');
|
||||
} else if (userData.username.length < 3) {
|
||||
errors.push('用户名长度至少3位');
|
||||
}
|
||||
|
||||
// 姓名验证
|
||||
if (!userData.full_name) {
|
||||
errors.push('姓名不能为空');
|
||||
}
|
||||
|
||||
// 电话验证
|
||||
if (!userData.phone) {
|
||||
errors.push('电话不能为空');
|
||||
} else if (!/^1[3-9]\d{9}$/.test(userData.phone)) {
|
||||
errors.push('请输入正确的手机号码');
|
||||
}
|
||||
|
||||
// 密码验证
|
||||
if (!userData.password) {
|
||||
errors.push('密码不能为空');
|
||||
} else if (userData.password.length < 6) {
|
||||
errors.push('密码长度至少6位');
|
||||
}
|
||||
|
||||
// 企业管理员需要tenant_id
|
||||
if (!userData.is_superuser && !userData.tenant_id) {
|
||||
errors.push('企业管理员必须选择所属企业');
|
||||
}
|
||||
|
||||
return {
|
||||
isValid: errors.length === 0,
|
||||
errors
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户详情信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @returns 用户详情数据
|
||||
*/
|
||||
export async function fetchUserDetails(userId: string): Promise<UserData> {
|
||||
try {
|
||||
console.log(`[API] fetchUserDetails 获取用户详情: ${userId}`);
|
||||
|
||||
// 获取认证token
|
||||
const token = getAuthToken();
|
||||
|
||||
// 调用SDK API获取用户详情
|
||||
const response = await getSystemUserApiV1UsersSystemUsersUserIdGet({
|
||||
path: {
|
||||
user_id: userId,
|
||||
},
|
||||
headers: token ? {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
} : undefined,
|
||||
});
|
||||
|
||||
if (response.error) {
|
||||
const errorMessage = response.error.message || '获取用户详情失败';
|
||||
console.error('[API] fetchUserDetails 获取用户详情失败:', response.error);
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
const data = response.data as any;
|
||||
console.log('[API] fetchUserDetails 获取用户详情成功:', data);
|
||||
|
||||
// 返回用户详情数据
|
||||
return {
|
||||
id: data.id,
|
||||
tenant_id: data.tenant_id,
|
||||
email: data.email,
|
||||
username: data.username,
|
||||
full_name: data.full_name,
|
||||
phone: data.phone,
|
||||
is_active: data.is_active,
|
||||
status: data.is_active ? 'active' : 'inactive',
|
||||
is_superuser: data.is_superuser,
|
||||
is_verified: data.is_verified,
|
||||
created_at: data.created_at,
|
||||
updated_at: data.updated_at,
|
||||
last_login_at: data.last_login_at,
|
||||
avatar_url: data.avatar_url,
|
||||
bio: data.bio,
|
||||
display_name: data.display_name,
|
||||
department_id: data.department_id,
|
||||
department_name: data.department_name,
|
||||
scope: data.scope || 'system',
|
||||
company_name: data.company_name,
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
console.error('[API] fetchUserDetails 获取用户详情异常:', error);
|
||||
|
||||
// 如果是已知错误,直接抛出
|
||||
if (error instanceof Error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// 未知错误包装成标准错误格式
|
||||
throw new Error('获取用户详情失败,请稍后重试');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活系统用户
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @returns 操作结果
|
||||
*/
|
||||
export async function activateUser(userId: string): Promise<void> {
|
||||
try {
|
||||
console.log(`[API] activateUser 激活用户: ${userId}`);
|
||||
|
||||
// 获取认证token
|
||||
const token = getAuthToken();
|
||||
|
||||
// 调用SDK API激活用户
|
||||
const response = await activateSystemUserApiV1UsersSystemUsersUserIdActivatePost({
|
||||
path: {
|
||||
user_id: userId,
|
||||
},
|
||||
headers: token ? {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
} : undefined,
|
||||
});
|
||||
|
||||
if (response.error) {
|
||||
// 处理API错误,提取错误信息
|
||||
const errorMessage = response.error.message || '激活用户失败';
|
||||
console.error('[API] activateUser 激活用户失败:', response.error);
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
console.log('[API] activateUser 激活用户成功:', userId);
|
||||
|
||||
} catch (error) {
|
||||
console.error('[API] activateUser 激活用户异常:', error);
|
||||
|
||||
// 如果是已知错误,直接抛出
|
||||
if (error instanceof Error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// 未知错误包装成标准错误格式
|
||||
throw new Error('激活用户失败,请稍后重试');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 停用系统用户
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @returns 操作结果
|
||||
*/
|
||||
export async function deactivateUser(userId: string): Promise<void> {
|
||||
try {
|
||||
console.log(`[API] deactivateUser 停用用户: ${userId}`);
|
||||
|
||||
// 获取认证token
|
||||
const token = getAuthToken();
|
||||
|
||||
// 调用SDK API停用用户
|
||||
const response = await deactivateSystemUserApiV1UsersSystemUsersUserIdDeactivatePost({
|
||||
path: {
|
||||
user_id: userId,
|
||||
},
|
||||
headers: token ? {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
} : undefined,
|
||||
});
|
||||
|
||||
if (response.error) {
|
||||
// 处理API错误,提取错误信息
|
||||
const errorMessage = response.error.message || '停用用户失败';
|
||||
console.error('[API] deactivateUser 停用用户失败:', response.error);
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
console.log('[API] deactivateUser 停用用户成功:', userId);
|
||||
|
||||
} catch (error) {
|
||||
console.error('[API] deactivateUser 停用用户异常:', error);
|
||||
|
||||
// 如果是已知错误,直接抛出
|
||||
if (error instanceof Error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// 未知错误包装成标准错误格式
|
||||
throw new Error('停用用户失败,请稍后重试');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除系统用户
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @returns 操作结果
|
||||
*/
|
||||
export async function deleteUser(userId: string): Promise<void> {
|
||||
try {
|
||||
console.log(`[API] deleteUser 删除用户: ${userId}`);
|
||||
|
||||
// 获取认证token
|
||||
const token = getAuthToken();
|
||||
|
||||
// 调用SDK API删除用户
|
||||
const response = await deleteSystemUserApiV1UsersSystemUsersUserIdDelete({
|
||||
path: {
|
||||
user_id: userId,
|
||||
},
|
||||
headers: token ? {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
} : undefined,
|
||||
});
|
||||
|
||||
if (response.error) {
|
||||
// 处理API错误,提取错误信息
|
||||
const errorMessage = response.error.message || '删除用户失败';
|
||||
console.error('[API] deleteUser 删除用户失败:', response.error);
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
console.log('[API] deleteUser 删除用户成功:', userId);
|
||||
|
||||
} catch (error) {
|
||||
console.error('[API] deleteUser 删除用户异常:', error);
|
||||
|
||||
// 如果是已知错误,直接抛出
|
||||
if (error instanceof Error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// 未知错误包装成标准错误格式
|
||||
throw new Error('删除用户失败,请稍后重试');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* filekorolheader: 用户类型常量定义 - 用户类型映射关系
|
||||
* 功能:用户类型枚举、中文名称映射、下拉选项数据
|
||||
* 路径:/central-config/tenant/user-management/constants/userTypes
|
||||
* 规范:遵循crop-x-new/docs/开发项目规范.md,使用TypeScript类型安全
|
||||
*/
|
||||
|
||||
// 用户类型枚举
|
||||
export const USER_TYPES = {
|
||||
TENANT: 'tenant',
|
||||
SYSTEM: 'system',
|
||||
} as const;
|
||||
|
||||
// 用户类型中文映射
|
||||
export const USER_TYPE_LABELS = {
|
||||
[USER_TYPES.TENANT]: '企业管理员',
|
||||
[USER_TYPES.SYSTEM]: '系统管理员',
|
||||
} as const;
|
||||
|
||||
// 用户类型下拉选项
|
||||
export const USER_TYPE_OPTIONS = [
|
||||
{
|
||||
value: USER_TYPES.TENANT,
|
||||
label: USER_TYPE_LABELS[USER_TYPES.TENANT],
|
||||
},
|
||||
{
|
||||
value: USER_TYPES.SYSTEM,
|
||||
label: USER_TYPE_LABELS[USER_TYPES.SYSTEM],
|
||||
},
|
||||
] as const;
|
||||
|
||||
// 根据值获取标签
|
||||
export function getUserTypeLabel(type: string): string {
|
||||
return USER_TYPE_LABELS[type as keyof typeof USER_TYPE_LABELS] || type;
|
||||
}
|
||||
|
||||
// 类型定义
|
||||
export type UserType = keyof typeof USER_TYPE_LABELS;
|
||||
@@ -9,11 +9,23 @@
|
||||
import { useReducer, useEffect, useState, useCallback, useMemo,useRef } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Eye, Edit, Lock, UserX, UserCheck } from 'lucide-react';
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog';
|
||||
import { Eye, Edit, Lock, UserX, UserCheck, Trash2 } from 'lucide-react';
|
||||
import { UserDetailDialog } from './components/UserDetailDialog';
|
||||
import { AddUserModal } from './components/AddUserModal';
|
||||
import { EditUserModal } from './components/EditUserModal';
|
||||
import { SearchFormPagination, SearchFieldConfig, TableColumnConfig } from '@/components/common/searchFormPagination';
|
||||
|
||||
import { fetchUsers, transformUserData, UsersQueryParams, User, UsersApiResponse, PaginationState } from './components/userManagementApi';
|
||||
import { fetchUsers, transformUserData, UsersQueryParams, User, UsersApiResponse, PaginationState, activateUser, deactivateUser, deleteUser } from './components/userManagementApi';
|
||||
import { UserManagementHeader } from './components/UserManagementHeader';
|
||||
import { UserManagementStatsCards } from './components/UserManagementStatsCards';
|
||||
import { UserFilters } from './types';
|
||||
@@ -31,6 +43,10 @@ interface UserManagementState {
|
||||
sortOrder: 'asc' | 'desc';
|
||||
selectedUser: User | null;
|
||||
showDetailDialog: boolean;
|
||||
showAddDialog: boolean;
|
||||
showEditDialog: boolean;
|
||||
showDeactivateDialog: boolean;
|
||||
showDeleteDialog: boolean;
|
||||
}
|
||||
|
||||
type UserManagementAction =
|
||||
@@ -42,6 +58,10 @@ type UserManagementAction =
|
||||
| { type: 'SET_PAGINATION'; payload: Partial<PaginationState> }
|
||||
| { type: 'SET_SELECTED_USER'; payload: User | null }
|
||||
| { type: 'TOGGLE_DETAIL_DIALOG'; payload: boolean }
|
||||
| { type: 'TOGGLE_ADD_DIALOG'; payload: boolean }
|
||||
| { type: 'TOGGLE_EDIT_DIALOG'; payload: boolean }
|
||||
| { type: 'TOGGLE_DEACTIVATE_DIALOG'; payload: boolean }
|
||||
| { type: 'TOGGLE_DELETE_DIALOG'; payload: boolean }
|
||||
| { type: 'REFRESH_DATA' };
|
||||
|
||||
const userManagementReducer = (state: UserManagementState, action: UserManagementAction): UserManagementState => {
|
||||
@@ -68,6 +88,14 @@ const userManagementReducer = (state: UserManagementState, action: UserManagemen
|
||||
return { ...state, selectedUser: action.payload };
|
||||
case 'TOGGLE_DETAIL_DIALOG':
|
||||
return { ...state, showDetailDialog: !state.showDetailDialog };
|
||||
case 'TOGGLE_ADD_DIALOG':
|
||||
return { ...state, showAddDialog: !state.showAddDialog };
|
||||
case 'TOGGLE_EDIT_DIALOG':
|
||||
return { ...state, showEditDialog: !state.showEditDialog };
|
||||
case 'TOGGLE_DEACTIVATE_DIALOG':
|
||||
return { ...state, showDeactivateDialog: !state.showDeactivateDialog };
|
||||
case 'TOGGLE_DELETE_DIALOG':
|
||||
return { ...state, showDeleteDialog: !state.showDeleteDialog };
|
||||
case 'REFRESH_DATA':
|
||||
return { ...state, error: null };
|
||||
default:
|
||||
@@ -96,6 +124,10 @@ const initialState: UserManagementState = {
|
||||
sortOrder: 'desc',
|
||||
selectedUser: null,
|
||||
showDetailDialog: false,
|
||||
showAddDialog: false,
|
||||
showEditDialog: false,
|
||||
showDeactivateDialog: false,
|
||||
showDeleteDialog: false,
|
||||
};
|
||||
|
||||
export default function TenantUserManagementPage() {
|
||||
@@ -251,7 +283,7 @@ export default function TenantUserManagementPage() {
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => handleToggleStatus(user)}
|
||||
title={user.isActive ? "冻结用户" : "激活用户"}
|
||||
title={user.isActive ? "停用用户" : "激活用户"}
|
||||
>
|
||||
{user.isActive ? (
|
||||
<UserX className="w-4 h-4 text-orange-600" />
|
||||
@@ -262,10 +294,11 @@ export default function TenantUserManagementPage() {
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => handleResetPassword(user)}
|
||||
title="重置密码"
|
||||
onClick={() => handleDelete(user)}
|
||||
title="删除用户"
|
||||
className="text-red-600 hover:text-red-700 hover:bg-red-50"
|
||||
>
|
||||
<Lock className="w-4 h-4" />
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
@@ -461,21 +494,75 @@ export default function TenantUserManagementPage() {
|
||||
|
||||
// 编辑用户
|
||||
const handleEdit = (user: User) => {
|
||||
toast.info('编辑功能开发中...');
|
||||
dispatch({ type: 'SET_SELECTED_USER', payload: user });
|
||||
dispatch({ type: 'TOGGLE_EDIT_DIALOG', payload: true });
|
||||
};
|
||||
|
||||
// 新增用户
|
||||
const handleAdd = () => {
|
||||
dispatch({ type: 'TOGGLE_ADD_DIALOG', payload: true });
|
||||
};
|
||||
|
||||
// 刷新数据(用于新增/编辑成功后重新加载数据)
|
||||
const refreshData = useCallback(() => {
|
||||
loadUsers({});
|
||||
}, [loadUsers]);
|
||||
|
||||
// 切换用户状态
|
||||
const handleToggleStatus = (user: User) => {
|
||||
const newStatus = !user.isActive;
|
||||
const statusText = newStatus ? '激活' : '停用';
|
||||
if (!confirm(`确定要${statusText}用户 ${user.fullName || user.username} 吗?`)) return;
|
||||
toast.info(`${statusText}功能开发中...`);
|
||||
dispatch({ type: 'SET_SELECTED_USER', payload: user });
|
||||
dispatch({ type: 'TOGGLE_DEACTIVATE_DIALOG', payload: true });
|
||||
};
|
||||
|
||||
// 重置密码
|
||||
const handleResetPassword = (user: User) => {
|
||||
if (!confirm(`确定要重置用户 ${user.fullName || user.username} 的密码吗?`)) return;
|
||||
toast.info('重置密码功能开发中...');
|
||||
// 删除用户
|
||||
const handleDelete = (user: User) => {
|
||||
dispatch({ type: 'SET_SELECTED_USER', payload: user });
|
||||
dispatch({ type: 'TOGGLE_DELETE_DIALOG', payload: true });
|
||||
};
|
||||
|
||||
// 确认切换用户状态
|
||||
const confirmToggleStatus = async () => {
|
||||
if (!state.selectedUser) return;
|
||||
|
||||
try {
|
||||
const user = state.selectedUser;
|
||||
if (user.isActive) {
|
||||
await deactivateUser(user.id);
|
||||
toast.success(`用户 ${user.fullName || user.username} 已停用`);
|
||||
} else {
|
||||
await activateUser(user.id);
|
||||
toast.success(`用户 ${user.fullName || user.username} 已激活`);
|
||||
}
|
||||
|
||||
// 关闭对话框并刷新列表
|
||||
dispatch({ type: 'TOGGLE_DEACTIVATE_DIALOG', payload: false });
|
||||
dispatch({ type: 'SET_SELECTED_USER', payload: null });
|
||||
refreshData();
|
||||
} catch (error) {
|
||||
console.error('切换用户状态失败:', error);
|
||||
const errorMessage = error instanceof Error ? error.message : '操作失败,请重试';
|
||||
toast.error(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
// 确认删除用户
|
||||
const confirmDelete = async () => {
|
||||
if (!state.selectedUser) return;
|
||||
|
||||
try {
|
||||
const user = state.selectedUser;
|
||||
await deleteUser(user.id);
|
||||
toast.success(`用户 ${user.fullName || user.username} 已删除`);
|
||||
|
||||
// 关闭对话框并刷新列表
|
||||
dispatch({ type: 'TOGGLE_DELETE_DIALOG', payload: false });
|
||||
dispatch({ type: 'SET_SELECTED_USER', payload: null });
|
||||
refreshData();
|
||||
} catch (error) {
|
||||
console.error('删除用户失败:', error);
|
||||
const errorMessage = error instanceof Error ? error.message : '删除失败,请重试';
|
||||
toast.error(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
// 统计数据计算
|
||||
@@ -525,7 +612,7 @@ export default function TenantUserManagementPage() {
|
||||
<SearchFormPagination
|
||||
formTitle="用户列表"
|
||||
formRightContent={
|
||||
<Button onClick={() => toast.info('新建用户功能开发中...')}>
|
||||
<Button onClick={handleAdd}>
|
||||
新建用户
|
||||
</Button>
|
||||
}
|
||||
@@ -551,6 +638,74 @@ export default function TenantUserManagementPage() {
|
||||
onOpenChange={(open) => dispatch({ type: 'TOGGLE_DETAIL_DIALOG', payload: open })}
|
||||
user={state.selectedUser}
|
||||
/>
|
||||
|
||||
{/* 新增用户对话框 */}
|
||||
<AddUserModal
|
||||
open={state.showAddDialog}
|
||||
onOpenChange={(open) => dispatch({ type: 'TOGGLE_ADD_DIALOG', payload: open })}
|
||||
onSuccess={refreshData}
|
||||
/>
|
||||
|
||||
{/* 编辑用户对话框 */}
|
||||
<EditUserModal
|
||||
open={state.showEditDialog}
|
||||
onOpenChange={(open) => dispatch({ type: 'TOGGLE_EDIT_DIALOG', payload: open })}
|
||||
user={state.selectedUser}
|
||||
onSuccess={refreshData}
|
||||
/>
|
||||
|
||||
{/* 停用/激活用户确认对话框 */}
|
||||
<AlertDialog open={state.showDeactivateDialog} onOpenChange={(open) => dispatch({ type: 'TOGGLE_DEACTIVATE_DIALOG', payload: open })}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{state.selectedUser?.isActive ? '停用用户' : '激活用户'}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
确定要{state.selectedUser?.isActive ? '停用' : '激活'}用户 <strong>{state.selectedUser?.fullName || state.selectedUser?.username}</strong> 吗?
|
||||
{state.selectedUser?.isActive && (
|
||||
<span className="block mt-2 text-amber-600 dark:text-amber-400">
|
||||
停用后,该用户将无法登录系统。
|
||||
</span>
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<Button
|
||||
onClick={confirmToggleStatus}
|
||||
className={state.selectedUser?.isActive ? 'bg-orange-600 hover:bg-orange-700' : 'bg-green-600 hover:bg-green-700'}
|
||||
>
|
||||
{state.selectedUser?.isActive ? '停用' : '激活'}
|
||||
</Button>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
{/* 删除用户确认对话框 */}
|
||||
<AlertDialog open={state.showDeleteDialog} onOpenChange={(open) => dispatch({ type: 'TOGGLE_DELETE_DIALOG', payload: open })}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle className="text-red-600">删除用户</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
确定要删除用户 <strong>{state.selectedUser?.fullName || state.selectedUser?.username}</strong> 吗?
|
||||
<span className="block mt-2 text-red-600 dark:text-red-400">
|
||||
⚠️ 此操作不可恢复,用户的所有数据将被永久删除!
|
||||
</span>
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<Button
|
||||
onClick={confirmDelete}
|
||||
className="bg-red-600 hover:bg-red-700"
|
||||
variant="destructive"
|
||||
>
|
||||
确认删除
|
||||
</Button>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
Square
|
||||
} from 'lucide-react';
|
||||
import { SpatialAnalysisState, SpatialAnalysisAction, AnalysisResult } from './spatialAnalysisReducer';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useMemo } from 'react';
|
||||
import BatchAnalysisManager from './batchAnalysisService';
|
||||
|
||||
interface BatchEvaluationPanelProps {
|
||||
@@ -30,11 +30,7 @@ interface BatchEvaluationPanelProps {
|
||||
}
|
||||
|
||||
export default function BatchEvaluationPanel({ state, dispatch }: BatchEvaluationPanelProps) {
|
||||
const [batchManager, setBatchManager] = useState<BatchAnalysisManager | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setBatchManager(new BatchAnalysisManager(dispatch));
|
||||
}, [dispatch]);
|
||||
const batchManager = useMemo(() => new BatchAnalysisManager(dispatch), [dispatch]);
|
||||
|
||||
const totalWeight = Math.round(
|
||||
(state.weightConfig.soil + state.weightConfig.climate +
|
||||
@@ -53,19 +49,10 @@ export default function BatchEvaluationPanel({ state, dispatch }: BatchEvaluatio
|
||||
return;
|
||||
}
|
||||
|
||||
if (!batchManager) {
|
||||
toast.error('批量分析服务未初始化');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 创建批量分析任务
|
||||
const taskName = `地块适宜性批量分析_${new Date().toLocaleString('zh-CN')}`;
|
||||
|
||||
// 固定分析68个地块
|
||||
const totalFields = 68;
|
||||
const blockIds = Array.from({ length: totalFields }, (_, i) => `field-${i + 1}`);
|
||||
|
||||
// 开始批量分析
|
||||
await batchManager.startBatchAnalysis(taskName, enabledFactors, state.weightConfig);
|
||||
|
||||
|
||||
@@ -8,12 +8,9 @@ import { toast } from 'sonner';
|
||||
import {
|
||||
Brain,
|
||||
Settings,
|
||||
Eye,
|
||||
EyeOff,
|
||||
CheckCircle2,
|
||||
XCircle,
|
||||
Target,
|
||||
Droplet,
|
||||
Sun,
|
||||
Mountain,
|
||||
Building,
|
||||
|
||||
@@ -11,11 +11,9 @@ import {
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import {
|
||||
Settings,
|
||||
Sliders,
|
||||
CheckCircle,
|
||||
XCircle,
|
||||
Info
|
||||
@@ -209,7 +207,7 @@ export default function FactorConfiguration({ state, dispatch, isDialog = false
|
||||
<li>• 启用/禁用因子来控制评价维度,禁用的因子不参与计算</li>
|
||||
<li>• 土壤条件、气候条件、地形条件、基础设施为四大评价维度</li>
|
||||
<li>• 可以根据具体需求调整各因子的权重,建议咨询农业专家</li>
|
||||
<li>• 点击"重置默认"可以恢复到推荐的标准权重配置</li>
|
||||
<li>• 点击“重置默认”可以恢复到推荐的标准权重配置</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
SlidersHorizontal,
|
||||
TrendingUp,
|
||||
Target,
|
||||
Droplet,
|
||||
Sun,
|
||||
Mountain,
|
||||
Building,
|
||||
|
||||
@@ -10,7 +10,9 @@ interface SpatialDistributionProps {
|
||||
dispatch: React.Dispatch<SpatialAnalysisAction>;
|
||||
}
|
||||
|
||||
export default function SpatialDistribution({ state, dispatch }: SpatialDistributionProps) {
|
||||
export default function SpatialDistribution({ state }: SpatialDistributionProps) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { dispatch } = { dispatch: null }; // 保留dispatch参数以保持接口一致性,但当前未使用
|
||||
const getScoreColor = (score: number) => {
|
||||
if (score >= 80) return 'bg-green-500';
|
||||
if (score >= 60) return 'bg-yellow-500';
|
||||
|
||||
@@ -148,7 +148,7 @@ export default function WeightConfiguration({ state, dispatch, isDialog = false
|
||||
</div>
|
||||
<Progress value={getTotalWeight() * 100} className="h-2 mt-1" />
|
||||
<p className="text-xs text-red-600 mt-1">
|
||||
权重总和不为100%,建议点击"自动平衡"调整
|
||||
权重总和不为100%,建议点击“自动平衡”调整
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1,10 +1,26 @@
|
||||
'use client';
|
||||
|
||||
import { SpatialAnalysisState, SpatialAnalysisAction, LandBlock, AnalysisResult, BatchAnalysisTask, EvaluationFactor } from './spatialAnalysisReducer';
|
||||
import { SpatialAnalysisAction, LandBlock, AnalysisResult, BatchAnalysisTask, EvaluationFactor } from './spatialAnalysisReducer';
|
||||
|
||||
// 因子数据类型定义
|
||||
interface FactorData {
|
||||
soil: unknown;
|
||||
climate: unknown;
|
||||
topography: unknown;
|
||||
infrastructure: unknown;
|
||||
}
|
||||
|
||||
// 权重配置类型
|
||||
interface WeightConfig {
|
||||
soil: number;
|
||||
climate: number;
|
||||
topography: number;
|
||||
infrastructure: number;
|
||||
}
|
||||
|
||||
// 空间分析服务接口
|
||||
interface SpatialAnalysisService {
|
||||
analyzeBlock(block: LandBlock, factors: EvaluationFactor[], weights: any): Promise<{
|
||||
analyzeBlock(block: LandBlock, factors: EvaluationFactor[], weights: WeightConfig): Promise<{
|
||||
success: boolean;
|
||||
suitabilityIndex: number;
|
||||
result?: AnalysisResult;
|
||||
@@ -14,7 +30,7 @@ interface SpatialAnalysisService {
|
||||
|
||||
// 模拟空间分析服务
|
||||
class MockSpatialAnalysisService implements SpatialAnalysisService {
|
||||
async analyzeBlock(block: LandBlock, factors: EvaluationFactor[], weights: any): Promise<{
|
||||
async analyzeBlock(block: LandBlock, factors: EvaluationFactor[], weights: WeightConfig): Promise<{
|
||||
success: boolean;
|
||||
suitabilityIndex: number;
|
||||
result?: AnalysisResult;
|
||||
@@ -33,10 +49,10 @@ class MockSpatialAnalysisService implements SpatialAnalysisService {
|
||||
const factorData = await this.readFactorData(block);
|
||||
|
||||
// 进行加权计算
|
||||
const suitabilityIndex = this.calculateWeightedScore(factorData, factors, weights);
|
||||
const suitabilityIndex = this.calculateWeightedScore(factorData, weights);
|
||||
|
||||
// 生成详细分析结果
|
||||
const result = this.generateAnalysisResult(block, factorData, suitabilityIndex, weights);
|
||||
const result = this.generateAnalysisResult(block, factorData, suitabilityIndex);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
@@ -52,7 +68,7 @@ class MockSpatialAnalysisService implements SpatialAnalysisService {
|
||||
}
|
||||
}
|
||||
|
||||
private async readFactorData(block: LandBlock): Promise<any> {
|
||||
private async readFactorData(block: LandBlock): Promise<unknown> {
|
||||
// 模拟从各种数据源读取因子数据
|
||||
await new Promise(resolve => setTimeout(resolve, 200));
|
||||
|
||||
@@ -120,45 +136,46 @@ class MockSpatialAnalysisService implements SpatialAnalysisService {
|
||||
return scoreMap[irrigationType] || 0.70;
|
||||
}
|
||||
|
||||
private calculateWeightedScore(factorData: any, factors: EvaluationFactor[], weights: any): number {
|
||||
private calculateWeightedScore(factorData: unknown, weights: WeightConfig): number {
|
||||
let totalScore = 0;
|
||||
let totalWeight = 0;
|
||||
|
||||
// 土壤因子得分计算
|
||||
const soilWeight = weights.soil || 0.35;
|
||||
const soilScore = this.calculateSoilScore(factorData.soilFactors, factors);
|
||||
const soilScore = this.calculateSoilScore((factorData as { soilFactors: unknown }).soilFactors);
|
||||
totalScore += soilScore * soilWeight;
|
||||
totalWeight += soilWeight;
|
||||
|
||||
// 气候因子得分计算
|
||||
const climateWeight = weights.climate || 0.30;
|
||||
const climateScore = this.calculateClimateScore(factorData.climateFactors, factors);
|
||||
const climateScore = this.calculateClimateScore((factorData as { climateFactors: unknown }).climateFactors);
|
||||
totalScore += climateScore * climateWeight;
|
||||
totalWeight += climateWeight;
|
||||
|
||||
// 地形因子得分计算
|
||||
const topographyWeight = weights.topography || 0.20;
|
||||
const topographyScore = this.calculateTopographyScore(factorData.topographyFactors, factors);
|
||||
const topographyScore = this.calculateTopographyScore((factorData as { topographyFactors: unknown }).topographyFactors);
|
||||
totalScore += topographyScore * topographyWeight;
|
||||
totalWeight += topographyWeight;
|
||||
|
||||
// 基础设施因子得分计算
|
||||
const infrastructureWeight = weights.infrastructure || 0.15;
|
||||
const infrastructureScore = this.calculateInfrastructureScore(factorData.infrastructureFactors, factors);
|
||||
const infrastructureScore = this.calculateInfrastructureScore((factorData as { infrastructureFactors: unknown }).infrastructureFactors);
|
||||
totalScore += infrastructureScore * infrastructureWeight;
|
||||
totalWeight += infrastructureWeight;
|
||||
|
||||
return Math.round(totalWeight > 0 ? (totalScore / totalWeight) * 100 : 0);
|
||||
}
|
||||
|
||||
private calculateSoilScore(soilFactors: any, factors: EvaluationFactor[]): number {
|
||||
private calculateSoilScore(soilFactors: unknown): number {
|
||||
let score = 0;
|
||||
let count = 0;
|
||||
|
||||
// pH值评分
|
||||
if (soilFactors.ph >= 6.0 && soilFactors.ph <= 7.5) {
|
||||
const soilFactorsTyped = soilFactors as { ph: number; organicMatter: number; nitrogen: number; phosphorus: number; potassium: number };
|
||||
if (soilFactorsTyped.ph >= 6.0 && soilFactorsTyped.ph <= 7.5) {
|
||||
score += 90;
|
||||
} else if (soilFactors.ph >= 5.5 && soilFactors.ph <= 8.0) {
|
||||
} else if (soilFactorsTyped.ph >= 5.5 && soilFactorsTyped.ph <= 8.0) {
|
||||
score += 70;
|
||||
} else {
|
||||
score += 40;
|
||||
@@ -166,9 +183,9 @@ class MockSpatialAnalysisService implements SpatialAnalysisService {
|
||||
count++;
|
||||
|
||||
// 有机质评分
|
||||
if (soilFactors.organicMatter >= 2.5) {
|
||||
if (soilFactorsTyped.organicMatter >= 2.5) {
|
||||
score += 90;
|
||||
} else if (soilFactors.organicMatter >= 1.5) {
|
||||
} else if (soilFactorsTyped.organicMatter >= 1.5) {
|
||||
score += 70;
|
||||
} else {
|
||||
score += 45;
|
||||
@@ -176,21 +193,22 @@ class MockSpatialAnalysisService implements SpatialAnalysisService {
|
||||
count++;
|
||||
|
||||
// 养分评分 (NPK)
|
||||
const npkScore = Math.min(100, (soilFactors.nitrogen + soilFactors.phosphorus + soilFactors.potassium) / 3);
|
||||
const npkScore = Math.min(100, (soilFactorsTyped.nitrogen + soilFactorsTyped.phosphorus + soilFactorsTyped.potassium) / 3);
|
||||
score += npkScore;
|
||||
count++;
|
||||
|
||||
return count > 0 ? score / count : 50;
|
||||
}
|
||||
|
||||
private calculateClimateScore(climateFactors: any, factors: EvaluationFactor[]): number {
|
||||
private calculateClimateScore(climateFactors: unknown): number {
|
||||
let score = 0;
|
||||
let count = 0;
|
||||
|
||||
// 温度适宜性
|
||||
if (climateFactors.temperature >= 15 && climateFactors.temperature <= 25) {
|
||||
const climateFactorsTyped = climateFactors as { temperature: number; rainfall: number; sunlight: number };
|
||||
if (climateFactorsTyped.temperature >= 15 && climateFactorsTyped.temperature <= 25) {
|
||||
score += 90;
|
||||
} else if (climateFactors.temperature >= 10 && climateFactors.temperature <= 30) {
|
||||
} else if (climateFactorsTyped.temperature >= 10 && climateFactorsTyped.temperature <= 30) {
|
||||
score += 70;
|
||||
} else {
|
||||
score += 50;
|
||||
@@ -198,9 +216,9 @@ class MockSpatialAnalysisService implements SpatialAnalysisService {
|
||||
count++;
|
||||
|
||||
// 降雨适宜性
|
||||
if (climateFactors.rainfall >= 500 && climateFactors.rainfall <= 1000) {
|
||||
if (climateFactorsTyped.rainfall >= 500 && climateFactorsTyped.rainfall <= 1000) {
|
||||
score += 90;
|
||||
} else if (climateFactors.rainfall >= 300 && climateFactors.rainfall <= 1500) {
|
||||
} else if (climateFactorsTyped.rainfall >= 300 && climateFactorsTyped.rainfall <= 1500) {
|
||||
score += 70;
|
||||
} else {
|
||||
score += 45;
|
||||
@@ -208,9 +226,9 @@ class MockSpatialAnalysisService implements SpatialAnalysisService {
|
||||
count++;
|
||||
|
||||
// 日照充足性
|
||||
if (climateFactors.sunlight >= 2000) {
|
||||
if (climateFactorsTyped.sunlight >= 2000) {
|
||||
score += 90;
|
||||
} else if (climateFactors.sunlight >= 1600) {
|
||||
} else if (climateFactorsTyped.sunlight >= 1600) {
|
||||
score += 75;
|
||||
} else {
|
||||
score += 60;
|
||||
@@ -220,16 +238,17 @@ class MockSpatialAnalysisService implements SpatialAnalysisService {
|
||||
return count > 0 ? score / count : 50;
|
||||
}
|
||||
|
||||
private calculateTopographyScore(topographyFactors: any, factors: EvaluationFactor[]): number {
|
||||
private calculateTopographyScore(topographyFactors: unknown): number {
|
||||
let score = 0;
|
||||
let count = 0;
|
||||
|
||||
// 坡度评分
|
||||
if (topographyFactors.slope <= 3) {
|
||||
const topographyFactorsTyped = topographyFactors as { slope: number; elevation: number; drainageIndex: number };
|
||||
if (topographyFactorsTyped.slope <= 3) {
|
||||
score += 95;
|
||||
} else if (topographyFactors.slope <= 6) {
|
||||
} else if (topographyFactorsTyped.slope <= 6) {
|
||||
score += 80;
|
||||
} else if (topographyFactors.slope <= 15) {
|
||||
} else if (topographyFactorsTyped.slope <= 15) {
|
||||
score += 60;
|
||||
} else {
|
||||
score += 30;
|
||||
@@ -237,11 +256,11 @@ class MockSpatialAnalysisService implements SpatialAnalysisService {
|
||||
count++;
|
||||
|
||||
// 海拔适宜性
|
||||
if (topographyFactors.elevation <= 100) {
|
||||
if (topographyFactorsTyped.elevation <= 100) {
|
||||
score += 90;
|
||||
} else if (topographyFactors.elevation <= 300) {
|
||||
} else if (topographyFactorsTyped.elevation <= 300) {
|
||||
score += 80;
|
||||
} else if (topographyFactors.elevation <= 600) {
|
||||
} else if (topographyFactorsTyped.elevation <= 600) {
|
||||
score += 65;
|
||||
} else {
|
||||
score += 45;
|
||||
@@ -249,39 +268,51 @@ class MockSpatialAnalysisService implements SpatialAnalysisService {
|
||||
count++;
|
||||
|
||||
// 排水条件
|
||||
score += topographyFactors.drainageIndex * 100;
|
||||
score += topographyFactorsTyped.drainageIndex * 100;
|
||||
count++;
|
||||
|
||||
return count > 0 ? score / count : 50;
|
||||
}
|
||||
|
||||
private calculateInfrastructureScore(infrastructureFactors: any, factors: EvaluationFactor[]): number {
|
||||
private calculateInfrastructureScore(infrastructureFactors: unknown): number {
|
||||
let score = 0;
|
||||
let count = 0;
|
||||
|
||||
// 灌溉条件
|
||||
score += infrastructureFactors.irrigationScore * 100;
|
||||
const infrastructureFactorsTyped = infrastructureFactors as {
|
||||
irrigationScore: number;
|
||||
accessibility: number;
|
||||
powerSupply: boolean;
|
||||
waterSupply: boolean
|
||||
};
|
||||
score += infrastructureFactorsTyped.irrigationScore * 100;
|
||||
count++;
|
||||
|
||||
// 交通便利性
|
||||
score += infrastructureFactors.accessibility * 100;
|
||||
score += infrastructureFactorsTyped.accessibility * 100;
|
||||
count++;
|
||||
|
||||
// 基础设施完善度
|
||||
const infrastructureScore =
|
||||
(infrastructureFactors.powerSupply ? 50 : 0) +
|
||||
(infrastructureFactors.waterSupply ? 50 : 0);
|
||||
(infrastructureFactorsTyped.powerSupply ? 50 : 0) +
|
||||
(infrastructureFactorsTyped.waterSupply ? 50 : 0);
|
||||
score += infrastructureScore;
|
||||
count++;
|
||||
|
||||
return count > 0 ? score / count : 50;
|
||||
}
|
||||
|
||||
private generateAnalysisResult(block: LandBlock, factorData: any, suitabilityIndex: number, weights: any): AnalysisResult {
|
||||
const soilScore = this.calculateSoilScore(factorData.soilFactors, []);
|
||||
const climateScore = this.calculateClimateScore(factorData.climateFactors, []);
|
||||
const topographyScore = this.calculateTopographyScore(factorData.topographyFactors, []);
|
||||
const infrastructureScore = this.calculateInfrastructureScore(factorData.infrastructureFactors, []);
|
||||
private generateAnalysisResult(block: LandBlock, factorData: unknown, suitabilityIndex: number): AnalysisResult {
|
||||
const factorDataTyped = factorData as {
|
||||
soilFactors: unknown;
|
||||
climateFactors: unknown;
|
||||
topographyFactors: unknown;
|
||||
infrastructureFactors: unknown;
|
||||
};
|
||||
const soilScore = this.calculateSoilScore(factorDataTyped.soilFactors);
|
||||
const climateScore = this.calculateClimateScore(factorDataTyped.climateFactors);
|
||||
const topographyScore = this.calculateTopographyScore(factorDataTyped.topographyFactors);
|
||||
const infrastructureScore = this.calculateInfrastructureScore(factorDataTyped.infrastructureFactors);
|
||||
|
||||
// 生成作物推荐
|
||||
const recommendedCrops = this.generateCropRecommendations(block, factorData, suitabilityIndex);
|
||||
@@ -308,12 +339,12 @@ class MockSpatialAnalysisService implements SpatialAnalysisService {
|
||||
};
|
||||
}
|
||||
|
||||
private generateCropRecommendations(block: LandBlock, factorData: any, suitabilityIndex: number): any[] {
|
||||
private generateCropRecommendations(block: LandBlock, factorData: unknown, suitabilityIndex: number): unknown[] {
|
||||
// 简化的作物推荐逻辑
|
||||
const crops = [
|
||||
{ name: '小麦', suitabilityScore: Math.min(95, suitabilityIndex + Math.random() * 10 - 5) },
|
||||
{ name: '玉米', suitabilityScore: Math.min(95, suitabilityIndex + Math.random() * 15 - 5) },
|
||||
{ name: '水稻', suitabilityScore: factorData.climateFactors.rainfall > 800 ? Math.min(95, suitabilityIndex + Math.random() * 10) : Math.max(40, suitabilityIndex - 20) },
|
||||
{ name: '水稻', suitabilityScore: (factorData as { climateFactors: { rainfall: number } }).climateFactors.rainfall > 800 ? Math.min(95, suitabilityIndex + Math.random() * 10) : Math.max(40, suitabilityIndex - 20) },
|
||||
{ name: '大豆', suitabilityScore: Math.min(95, suitabilityIndex + Math.random() * 8 - 4) },
|
||||
{ name: '棉花', suitabilityScore: Math.min(95, suitabilityIndex + Math.random() * 12 - 6) }
|
||||
];
|
||||
@@ -339,37 +370,44 @@ class MockSpatialAnalysisService implements SpatialAnalysisService {
|
||||
.slice(0, 3);
|
||||
}
|
||||
|
||||
private generateRiskFactors(block: LandBlock, factorData: any, suitabilityIndex: number): string[] {
|
||||
private generateRiskFactors(block: LandBlock, factorData: unknown, suitabilityIndex: number): string[] {
|
||||
const risks = [];
|
||||
|
||||
if (suitabilityIndex < 40) {
|
||||
risks.push('综合条件较差,种植风险较高');
|
||||
}
|
||||
|
||||
if (factorData.soilFactors.ph < 6.0 || factorData.soilFactors.ph > 7.5) {
|
||||
const factorDataTyped = factorData as {
|
||||
soilFactors: { ph: number; organicMatter: number };
|
||||
topographyFactors: { slope: number };
|
||||
infrastructureFactors: { irrigationScore: number };
|
||||
climateFactors: { rainfall: number }
|
||||
};
|
||||
|
||||
if (factorDataTyped.soilFactors.ph < 6.0 || factorDataTyped.soilFactors.ph > 7.5) {
|
||||
risks.push('土壤pH值偏离理想范围');
|
||||
}
|
||||
|
||||
if (factorData.soilFactors.organicMatter < 1.5) {
|
||||
if (factorDataTyped.soilFactors.organicMatter < 1.5) {
|
||||
risks.push('土壤有机质含量偏低');
|
||||
}
|
||||
|
||||
if (factorData.topographyFactors.slope > 8) {
|
||||
if (factorDataTyped.topographyFactors.slope > 8) {
|
||||
risks.push('坡度较大,存在水土流失风险');
|
||||
}
|
||||
|
||||
if (factorData.infrastructureFactors.irrigationScore < 0.5) {
|
||||
if (factorDataTyped.infrastructureFactors.irrigationScore < 0.5) {
|
||||
risks.push('灌溉条件不足,依赖自然降水');
|
||||
}
|
||||
|
||||
if (factorData.climateFactors.rainfall < 400) {
|
||||
if (factorDataTyped.climateFactors.rainfall < 400) {
|
||||
risks.push('降雨量偏少,干旱风险较高');
|
||||
}
|
||||
|
||||
return risks.length > 0 ? risks : ['无明显风险因素'];
|
||||
}
|
||||
|
||||
private generateImprovementSuggestions(block: LandBlock, factorData: any, soilScore: number, climateScore: number, topographyScore: number, infrastructureScore: number): string[] {
|
||||
private generateImprovementSuggestions(block: LandBlock, factorData: unknown, soilScore: number, climateScore: number, topographyScore: number, infrastructureScore: number): string[] {
|
||||
const suggestions = [];
|
||||
|
||||
if (soilScore < 70) {
|
||||
@@ -392,7 +430,7 @@ class MockSpatialAnalysisService implements SpatialAnalysisService {
|
||||
suggestions.push('完善灌溉和排水系统');
|
||||
}
|
||||
|
||||
if (factorData.infrastructureFactors.accessibility < 0.6) {
|
||||
if ((factorData as { infrastructureFactors: { accessibility: number } }).infrastructureFactors.accessibility < 0.6) {
|
||||
suggestions.push('改善田间道路条件');
|
||||
}
|
||||
|
||||
@@ -415,7 +453,7 @@ export class BatchAnalysisManager {
|
||||
async startBatchAnalysis(
|
||||
taskName: string,
|
||||
factors: EvaluationFactor[],
|
||||
weightConfig: any
|
||||
weightConfig: WeightConfig
|
||||
): Promise<void> {
|
||||
if (this.isRunning) {
|
||||
throw new Error('已有分析任务正在运行');
|
||||
@@ -455,9 +493,6 @@ export class BatchAnalysisManager {
|
||||
|
||||
// 循环处理所有地块
|
||||
const results: AnalysisResult[] = [];
|
||||
let highSuitability = 0;
|
||||
let mediumSuitability = 0;
|
||||
let lowSuitability = 0;
|
||||
|
||||
for (let i = 0; i < totalFields; i++) {
|
||||
if (!this.isRunning) break; // 检查是否被取消
|
||||
@@ -501,16 +536,6 @@ export class BatchAnalysisManager {
|
||||
|
||||
if (analysisResult.success && analysisResult.result) {
|
||||
results.push(analysisResult.result);
|
||||
|
||||
// 统计适宜性等级
|
||||
const score = analysisResult.suitabilityIndex;
|
||||
if (score >= 80) {
|
||||
highSuitability++;
|
||||
} else if (score >= 60) {
|
||||
mediumSuitability++;
|
||||
} else {
|
||||
lowSuitability++;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新任务统计
|
||||
|
||||
@@ -7,7 +7,6 @@ import { Badge } from '@/components/ui/badge';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import {
|
||||
Database,
|
||||
Play,
|
||||
Download,
|
||||
Eye,
|
||||
AlertTriangle,
|
||||
@@ -68,7 +67,7 @@ export default function BatchEvaluationPage() {
|
||||
const totalWeight = factorWeights.reduce((sum, f) => sum + f.weight, 0);
|
||||
|
||||
// 模拟从空间分析服务读取地块因子数据
|
||||
const fetchFieldFactorsFromSpatialService = (fieldId: string): EvaluationFactor[] => {
|
||||
const fetchFieldFactorsFromSpatialService = (): EvaluationFactor[] => {
|
||||
return [
|
||||
{
|
||||
id: 'ph',
|
||||
@@ -214,7 +213,7 @@ export default function BatchEvaluationPage() {
|
||||
const fieldId = `field-${i + 1}`;
|
||||
const fieldName = `地块${String.fromCharCode(65 + (i % 26))}${Math.floor(i / 26) + 1}`;
|
||||
|
||||
const factors = fetchFieldFactorsFromSpatialService(fieldId);
|
||||
const factors = fetchFieldFactorsFromSpatialService();
|
||||
const scoredFactors = factors.map(factor => ({
|
||||
...factor,
|
||||
score: calculateFactorScore(factor.value, factor.optimalRange)
|
||||
|
||||
@@ -5,59 +5,40 @@
|
||||
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogTrigger } from '@/components/ui/dialog';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from '@/components/ui/dialog';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { Slider } from '@/components/ui/slider';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import {
|
||||
Leaf,
|
||||
TrendingUp,
|
||||
Award,
|
||||
AlertTriangle,
|
||||
CheckCircle2,
|
||||
Play,
|
||||
Settings,
|
||||
Download,
|
||||
Eye,
|
||||
Calculator,
|
||||
Database,
|
||||
RefreshCw,
|
||||
Zap,
|
||||
Target,
|
||||
Droplet,
|
||||
Cloud,
|
||||
Sun,
|
||||
ThermometerSun,
|
||||
BookOpen,
|
||||
Beaker,
|
||||
Info,
|
||||
BarChart3,
|
||||
Filter
|
||||
Beaker
|
||||
} from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
import {
|
||||
EvaluationFactor,
|
||||
SuitabilityResult,
|
||||
FactorWeight,
|
||||
BatchProgress,
|
||||
getGradeColor,
|
||||
getScoreColor,
|
||||
getSuitabilityLevelColor,
|
||||
formatDate,
|
||||
MOCK_FIELDS
|
||||
formatDate
|
||||
} from './multiFactorTypes';
|
||||
import {
|
||||
MultiFactorService
|
||||
} from './multiFactorService';
|
||||
import {
|
||||
matchCropsForField,
|
||||
cropKnowledgeBase
|
||||
} from './cropKnowledgeBase';
|
||||
|
||||
@@ -65,17 +46,6 @@ export function MultiFactorEvaluation() {
|
||||
const [selectedField, setSelectedField] = useState('field-1');
|
||||
const [showWeightConfig, setShowWeightConfig] = useState(false);
|
||||
const [showKnowledgeBase, setShowKnowledgeBase] = useState(false);
|
||||
const [batchProgress, setBatchProgress] = useState<BatchProgress>({
|
||||
total: 0,
|
||||
processed: 0,
|
||||
highSuitability: 0,
|
||||
mediumSuitability: 0,
|
||||
lowSuitability: 0,
|
||||
currentField: '',
|
||||
});
|
||||
const [isBatchRunning, setIsBatchRunning] = useState(false);
|
||||
const [batchAnalysisResults, setBatchAnalysisResults] = useState<SuitabilityResult[]>([]);
|
||||
|
||||
// 评价因子权重配置
|
||||
const [factorWeights, setFactorWeights] = useState<FactorWeight[]>([
|
||||
{ id: 'ph', name: 'pH值', weight: 20, unit: '' },
|
||||
@@ -95,47 +65,9 @@ export function MultiFactorEvaluation() {
|
||||
// 获取当前选中的地块结果
|
||||
const currentResult =
|
||||
evaluationResults.find(r => r.fieldId === selectedField) ||
|
||||
batchAnalysisResults.find(r => r.fieldId === selectedField) ||
|
||||
evaluationResults[0];
|
||||
|
||||
// 批量分析处理函数
|
||||
const handleRunBatchAnalysis = async () => {
|
||||
const validation = MultiFactorService.validateWeights(factorWeights);
|
||||
if (!validation.isValid) {
|
||||
toast.error(`权重总和必须为100%才能进行批量分析(当前:${validation.totalWeight}%)`);
|
||||
return;
|
||||
}
|
||||
|
||||
setIsBatchRunning(true);
|
||||
setBatchProgress({
|
||||
total: 68,
|
||||
processed: 0,
|
||||
highSuitability: 0,
|
||||
mediumSuitability: 0,
|
||||
lowSuitability: 0,
|
||||
currentField: '',
|
||||
});
|
||||
setBatchAnalysisResults([]);
|
||||
|
||||
toast.success('开始批量分析,正在读取地块数据...');
|
||||
|
||||
try {
|
||||
const results = await MultiFactorService.runBatchAnalysis(
|
||||
factorWeights,
|
||||
(progress) => {
|
||||
setBatchProgress(progress);
|
||||
}
|
||||
);
|
||||
|
||||
setBatchAnalysisResults(results);
|
||||
setIsBatchRunning(false);
|
||||
toast.success(`批量分析完成!已为${results.length}个地块生成适宜性评价结果`);
|
||||
} catch (error) {
|
||||
setIsBatchRunning(false);
|
||||
toast.error('批量分析失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleUpdateWeight = (id: string, newWeight: number) => {
|
||||
setFactorWeights(prev =>
|
||||
MultiFactorService.updateWeight(prev, id, newWeight)
|
||||
@@ -174,15 +106,6 @@ export function MultiFactorEvaluation() {
|
||||
}
|
||||
};
|
||||
|
||||
const exportResults = () => {
|
||||
const resultsToExport = batchAnalysisResults.length > 0 ? batchAnalysisResults : evaluationResults;
|
||||
toast.success('正在导出评价结果...');
|
||||
// 模拟导出功能
|
||||
setTimeout(() => {
|
||||
toast.success(`已导出${resultsToExport.length}个地块的评价结果`);
|
||||
}, 2000);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* 提供作物-环境适配数据和分析功能
|
||||
*/
|
||||
|
||||
import { Crop, CropRecommendation, FieldFactors, MatchDetail, RiskFactor } from './multiFactorTypes';
|
||||
import { Crop, CropRecommendation, FieldFactors, MatchDetail } from './multiFactorTypes';
|
||||
|
||||
// 作物知识库数据
|
||||
export const cropKnowledgeBase: Crop[] = [
|
||||
|
||||
@@ -3,10 +3,68 @@
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Leaf, AlertTriangle, ThermometerSun, Cloud, Sun } from 'lucide-react';
|
||||
import { CropRecommendationState, SuitabilityResult } from './cropRecommendReducer';
|
||||
import { SuitabilityResult } from './cropRecommendReducer';
|
||||
|
||||
type RangeRequirement = { optimal: [number, number]; acceptable: [number, number]; };
|
||||
type SoilFactorKey = 'ph' | 'organicMatter' | 'soilDepth' | 'nitrogen' | 'phosphorus' | 'potassium' | 'drainage';
|
||||
type SoilRequirementMap = Record<SoilFactorKey, RangeRequirement>;
|
||||
|
||||
type ClimateRequirement = {
|
||||
temperature: RangeRequirement;
|
||||
rainfall: RangeRequirement;
|
||||
sunlight: RangeRequirement;
|
||||
};
|
||||
|
||||
type YieldRange = {
|
||||
high: [number, number];
|
||||
medium: [number, number];
|
||||
low: [number, number];
|
||||
};
|
||||
|
||||
type RiskSeverity = 'low' | 'medium' | 'high';
|
||||
|
||||
interface CropRiskFactor {
|
||||
id: string;
|
||||
name: string;
|
||||
condition: string;
|
||||
severity: RiskSeverity;
|
||||
suggestion: string;
|
||||
}
|
||||
|
||||
interface CropKnowledgeEntry {
|
||||
id: string;
|
||||
cropName: string;
|
||||
category: string;
|
||||
description: string;
|
||||
growthCycle: { days: number; seasons: string[] };
|
||||
soilRequirements: SoilRequirementMap;
|
||||
climateRequirements: ClimateRequirement;
|
||||
expectedYield: YieldRange;
|
||||
riskFactors: CropRiskFactor[];
|
||||
}
|
||||
|
||||
type MatchStatus = '??' | '??' | '??';
|
||||
|
||||
interface MatchDetail {
|
||||
factor: string;
|
||||
value: number;
|
||||
score: number;
|
||||
status: MatchStatus;
|
||||
}
|
||||
|
||||
interface RecommendationResult {
|
||||
crop: CropKnowledgeEntry;
|
||||
matchScore: number;
|
||||
suitabilityLevel: '????' | '??' | '????' | '??';
|
||||
matchDetails: MatchDetail[];
|
||||
applicableRisks: CropRiskFactor[];
|
||||
expectedYield: [number, number];
|
||||
}
|
||||
|
||||
type FieldFactors = Record<SoilFactorKey | 'temperature' | 'rainfall', number>;
|
||||
|
||||
// 模拟作物知识库数据
|
||||
const cropKnowledgeBase = [
|
||||
const cropKnowledgeBase: CropKnowledgeEntry[] = [
|
||||
{
|
||||
id: 'wheat',
|
||||
cropName: '小麦',
|
||||
@@ -40,14 +98,14 @@ const cropKnowledgeBase = [
|
||||
id: 'wheat-rust',
|
||||
name: '锈病风险',
|
||||
condition: '湿度过高、温度适宜',
|
||||
severity: 'medium' as const,
|
||||
severity: 'medium',
|
||||
suggestion: '选择抗病品种,合理密植,及时防治'
|
||||
},
|
||||
{
|
||||
id: 'wheat-drought',
|
||||
name: '干旱风险',
|
||||
condition: '降雨量不足400mm',
|
||||
severity: 'high' as const,
|
||||
severity: 'high',
|
||||
suggestion: '加强灌溉设施建设,选择抗旱品种'
|
||||
}
|
||||
]
|
||||
@@ -85,14 +143,14 @@ const cropKnowledgeBase = [
|
||||
id: 'corn-borer',
|
||||
name: '玉米螟',
|
||||
condition: '温度适宜、湿度适中',
|
||||
severity: 'medium' as const,
|
||||
severity: 'medium',
|
||||
suggestion: '生物防治与化学防治结合,适时播种'
|
||||
},
|
||||
{
|
||||
id: 'corn-drought',
|
||||
name: '花期干旱',
|
||||
condition: '开花期降雨不足',
|
||||
severity: 'high' as const,
|
||||
severity: 'high',
|
||||
suggestion: '保证花期灌溉,选择耐旱品种'
|
||||
}
|
||||
]
|
||||
@@ -130,7 +188,7 @@ const cropKnowledgeBase = [
|
||||
id: 'soybean-disease',
|
||||
name: '病害风险',
|
||||
condition: '高温高湿环境',
|
||||
severity: 'medium' as const,
|
||||
severity: 'medium',
|
||||
suggestion: '选择抗病品种,合理轮作,加强田间管理'
|
||||
}
|
||||
]
|
||||
@@ -138,30 +196,40 @@ const cropKnowledgeBase = [
|
||||
];
|
||||
|
||||
interface CropRecommendationsProps {
|
||||
state: CropRecommendationState;
|
||||
currentResult: SuitabilityResult;
|
||||
}
|
||||
|
||||
export function CropRecommendations({ state, currentResult }: CropRecommendationsProps) {
|
||||
export function CropRecommendations({ currentResult }: CropRecommendationsProps) {
|
||||
// 匹配作物推荐
|
||||
const matchCropsForField = (fieldFactors: any) => {
|
||||
return cropKnowledgeBase.map(crop => {
|
||||
const matchCropsForField = (fieldFactors: FieldFactors): RecommendationResult[] => {
|
||||
const factorLabelMap: Record<SoilFactorKey, string> = {
|
||||
ph: 'pH?',
|
||||
organicMatter: '??',
|
||||
soilDepth: '????',
|
||||
nitrogen: '??',
|
||||
phosphorus: '??',
|
||||
potassium: '??',
|
||||
drainage: '??'
|
||||
};
|
||||
|
||||
return cropKnowledgeBase.map((crop) => {
|
||||
let totalScore = 0;
|
||||
let factorCount = 0;
|
||||
const matchDetails: any[] = [];
|
||||
const matchDetails: MatchDetail[] = [];
|
||||
|
||||
// 评估土壤因子匹配度
|
||||
Object.entries(crop.soilRequirements).forEach(([factor, requirements]: [string, any]) => {
|
||||
if (fieldFactors[factor]) {
|
||||
(Object.entries(crop.soilRequirements) as Array<[SoilFactorKey, RangeRequirement]>).forEach(([factor, requirements]) => {
|
||||
const value = fieldFactors[factor];
|
||||
const { optimal, acceptable } = requirements;
|
||||
if (typeof value !== 'number') {
|
||||
return;
|
||||
}
|
||||
|
||||
const { optimal, acceptable } = requirements;
|
||||
let score = 0;
|
||||
let status = '偏离';
|
||||
let status: MatchStatus = '??';
|
||||
|
||||
if (value >= optimal[0] && value <= optimal[1]) {
|
||||
score = 100;
|
||||
status = '最佳';
|
||||
status = '??';
|
||||
} else if (value >= acceptable[0] && value <= acceptable[1]) {
|
||||
const deviation = Math.min(
|
||||
Math.abs(value - optimal[0]),
|
||||
@@ -169,62 +237,64 @@ export function CropRecommendations({ state, currentResult }: CropRecommendation
|
||||
);
|
||||
const range = optimal[1] - optimal[0];
|
||||
score = Math.max(60, 100 - (deviation / range) * 40);
|
||||
status = '可接受';
|
||||
status = '??';
|
||||
} else {
|
||||
score = Math.max(0, 60 - Math.min(
|
||||
score = Math.max(
|
||||
0,
|
||||
60 -
|
||||
Math.min(
|
||||
Math.abs(value - acceptable[0]),
|
||||
Math.abs(value - acceptable[1])
|
||||
) * 2);
|
||||
) *
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
totalScore += score;
|
||||
factorCount++;
|
||||
factorCount += 1;
|
||||
|
||||
matchDetails.push({
|
||||
factor: factor === 'ph' ? 'pH值' :
|
||||
factor === 'organicMatter' ? '有机质' :
|
||||
factor === 'soilDepth' ? '土层厚度' :
|
||||
factor === 'nitrogen' ? '全氮' :
|
||||
factor === 'phosphorus' ? '全磷' :
|
||||
factor === 'potassium' ? '全钾' : '排水性',
|
||||
factor: factorLabelMap[factor],
|
||||
value,
|
||||
score,
|
||||
status
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 评估气候因子(简化处理)
|
||||
if (fieldFactors.temperature) {
|
||||
const tempScore = fieldFactors.temperature >= 18 && fieldFactors.temperature <= 25 ? 90 : 70;
|
||||
if (typeof fieldFactors.temperature === 'number') {
|
||||
const tempScore =
|
||||
fieldFactors.temperature >= 18 && fieldFactors.temperature <= 25 ? 90 : 70;
|
||||
totalScore += tempScore;
|
||||
factorCount++;
|
||||
factorCount += 1;
|
||||
}
|
||||
|
||||
if (fieldFactors.rainfall) {
|
||||
const rainScore = fieldFactors.rainfall >= 500 && fieldFactors.rainfall <= 800 ? 90 : 70;
|
||||
if (typeof fieldFactors.rainfall === 'number') {
|
||||
const rainScore =
|
||||
fieldFactors.rainfall >= 500 && fieldFactors.rainfall <= 800 ? 90 : 70;
|
||||
totalScore += rainScore;
|
||||
factorCount++;
|
||||
factorCount += 1;
|
||||
}
|
||||
|
||||
const matchScore = Math.round(totalScore / factorCount);
|
||||
const matchScore = factorCount > 0 ? Math.round(totalScore / factorCount) : 0;
|
||||
|
||||
// 确定适宜性等级
|
||||
let suitabilityLevel = '不推荐';
|
||||
if (matchScore >= 85) suitabilityLevel = '高度推荐';
|
||||
else if (matchScore >= 70) suitabilityLevel = '推荐';
|
||||
else if (matchScore >= 50) suitabilityLevel = '谨慎种植';
|
||||
let suitabilityLevel: RecommendationResult['suitabilityLevel'] = '??';
|
||||
if (matchScore >= 85) suitabilityLevel = '????';
|
||||
else if (matchScore >= 70) suitabilityLevel = '??';
|
||||
else if (matchScore >= 50) suitabilityLevel = '????';
|
||||
|
||||
// 根据适宜性等级选择产量区间
|
||||
let expectedYield = crop.expectedYield.low;
|
||||
if (suitabilityLevel === '高度推荐') expectedYield = crop.expectedYield.high;
|
||||
else if (suitabilityLevel === '推荐') expectedYield = crop.expectedYield.medium;
|
||||
let expectedYield: [number, number] = crop.expectedYield.low;
|
||||
if (suitabilityLevel === '????') expectedYield = crop.expectedYield.high;
|
||||
else if (suitabilityLevel === '??') expectedYield = crop.expectedYield.medium;
|
||||
|
||||
// 识别适用风险
|
||||
const applicableRisks = crop.riskFactors.filter(risk => {
|
||||
const applicableRisks = crop.riskFactors.filter((risk) => {
|
||||
if (risk.id.includes('drought') && fieldFactors.rainfall < 400) return true;
|
||||
if (risk.id.includes('rust') && fieldFactors.temperature >= 15 && fieldFactors.temperature <= 22) return true;
|
||||
return true; // 简化处理,默认显示所有风险
|
||||
if (
|
||||
risk.id.includes('rust') &&
|
||||
fieldFactors.temperature >= 15 &&
|
||||
fieldFactors.temperature <= 22
|
||||
)
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -235,20 +305,25 @@ export function CropRecommendations({ state, currentResult }: CropRecommendation
|
||||
applicableRisks,
|
||||
expectedYield
|
||||
};
|
||||
}).sort((a, b) => b.matchScore - a.matchScore);
|
||||
});
|
||||
};
|
||||
|
||||
// 获取地块因子数据
|
||||
const fieldFactors = {
|
||||
ph: currentResult.factors.find(f => f.id === 'ph')?.value || 0,
|
||||
organic: currentResult.factors.find(f => f.id === 'organic')?.value || 0,
|
||||
depth: currentResult.factors.find(f => f.id === 'depth')?.value || 0,
|
||||
nitrogen: currentResult.factors.find(f => f.id === 'nitrogen')?.value || 0,
|
||||
phosphorus: currentResult.factors.find(f => f.id === 'phosphorus')?.value || 0,
|
||||
potassium: currentResult.factors.find(f => f.id === 'potassium')?.value || 0,
|
||||
drainage: currentResult.factors.find(f => f.id === 'drainage')?.value || 0,
|
||||
temperature: 22, // 模拟年均温度
|
||||
rainfall: 800, // 模拟年均降雨量
|
||||
const getFactorValue = (factorId: string) =>
|
||||
currentResult.factors.find((factor) => factor.id === factorId)?.value ?? 0;
|
||||
|
||||
const fieldFactors: FieldFactors = {
|
||||
ph: getFactorValue('ph'),
|
||||
organicMatter: getFactorValue('organic'),
|
||||
soilDepth: getFactorValue('depth'),
|
||||
nitrogen: getFactorValue('nitrogen'),
|
||||
phosphorus: getFactorValue('phosphorus'),
|
||||
potassium: getFactorValue('potassium'),
|
||||
drainage: getFactorValue('drainage'),
|
||||
temperature: 22, // ??????
|
||||
rainfall: 800 // ???????
|
||||
};
|
||||
|
||||
// // 模拟年均降雨量
|
||||
};
|
||||
|
||||
// 匹配推荐作物
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
'use client';
|
||||
|
||||
import { useReducer } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
export interface EvaluationFactor {
|
||||
id: string;
|
||||
|
||||
@@ -7,8 +7,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
|
||||
import { BookOpen, Target } from 'lucide-react';
|
||||
import {
|
||||
cropRecommendReducer,
|
||||
initialState,
|
||||
SuitabilityResult
|
||||
initialState
|
||||
} from './components/cropRecommendReducer';
|
||||
import { FieldEnvironmentOverview } from './components/FieldEnvironmentOverview';
|
||||
import { CropRecommendations } from './components/CropRecommendations';
|
||||
@@ -117,7 +116,7 @@ export default function CropPage() {
|
||||
</div>
|
||||
|
||||
{/* 智能作物推荐 */}
|
||||
<CropRecommendations state={state} currentResult={currentResult} />
|
||||
<CropRecommendations currentResult={currentResult} />
|
||||
|
||||
{/* 知识库对话框 */}
|
||||
<KnowledgeBaseDialog
|
||||
|
||||
@@ -27,8 +27,8 @@ import {
|
||||
} from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
import { useAuth } from '@/components/auth/AuthContext';
|
||||
import { authReducer, initialAuthState, AuthState, AuthAction } from './authReducer';
|
||||
import { getCaptchaApiV1AuthCaptchaGet, loginApiV1AuthLoginPost } from '@/lib/api/sdk.gen';
|
||||
import { authReducer, initialAuthState } from './authReducer';
|
||||
import { loginApiV1AuthLoginPost } from '@/lib/api/sdk.gen';
|
||||
import type { CaptchaResponse } from '@/lib/api/types.gen';
|
||||
import {PERSONAL_CELTRAL_PAGE} from "@/config/constants"
|
||||
interface LoginFormProps {
|
||||
@@ -40,7 +40,6 @@ export function LoginForm({ onRegisterClick }: LoginFormProps) {
|
||||
const [state, dispatch] = React.useReducer(authReducer, initialAuthState);
|
||||
const [loginType, setLoginType] = useState<'password' | 'phone'>('password');
|
||||
const [passwordCaptchaData, setPasswordCaptchaData] = useState<CaptchaResponse | null>(null);
|
||||
const [phoneCaptchaData, setPhoneCaptchaData] = useState<CaptchaResponse | null>(null);
|
||||
|
||||
// 倒计时效果
|
||||
useEffect(() => {
|
||||
@@ -154,9 +153,14 @@ export function LoginForm({ onRegisterClick }: LoginFormProps) {
|
||||
dispatch({ type: 'SET_ERROR', payload: '登录失败,请检查用户名和密码' });
|
||||
toast.error('登录失败,请检查用户名和密码');
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error('登录失败:', err);
|
||||
const errorMessage = err?.response?.data?.message || err?.message || '登录失败,请稍后重试';
|
||||
} catch (error: unknown) {
|
||||
console.error('????:', error);
|
||||
const apiMessage =
|
||||
typeof error === 'object' && error !== null && 'response' in error
|
||||
? (error as { response?: { data?: { message?: string } } }).response?.data?.message
|
||||
: undefined;
|
||||
const fallbackMessage = error instanceof Error ? error.message : undefined;
|
||||
const errorMessage = apiMessage || fallbackMessage || '??????????';
|
||||
dispatch({ type: 'SET_ERROR', payload: errorMessage });
|
||||
toast.error(errorMessage);
|
||||
} finally {
|
||||
@@ -204,9 +208,10 @@ export function LoginForm({ onRegisterClick }: LoginFormProps) {
|
||||
dispatch({ type: 'SET_ERROR', payload: '验证码错误' });
|
||||
toast.error('验证码错误');
|
||||
}
|
||||
} catch (err) {
|
||||
dispatch({ type: 'SET_ERROR', payload: '登录失败,请稍后重试' });
|
||||
toast.error('登录失败');
|
||||
} catch (error) {
|
||||
console.error('???????:', error);
|
||||
dispatch({ type: 'SET_ERROR', payload: '??????????' });
|
||||
toast.error('????');
|
||||
} finally {
|
||||
dispatch({ type: 'SET_LOADING', payload: false });
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ export default function RegisterPage() {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
toast.success('验证码发送成功!(测试验证码:123456)');
|
||||
setCountdown(60);
|
||||
} catch (err) {
|
||||
} catch (error) {
|
||||
setError('发送验证码失败,请稍后重试');
|
||||
toast.error('发送验证码失败');
|
||||
} finally {
|
||||
@@ -246,7 +246,7 @@ export default function RegisterPage() {
|
||||
setError('短信验证码错误');
|
||||
toast.error('短信验证码错误');
|
||||
}
|
||||
} catch (err) {
|
||||
} catch (error) {
|
||||
setError('注册失败,请稍后重试');
|
||||
toast.error('注册失败');
|
||||
} finally {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { AuthProvider } from '@/components/auth/AuthContext';
|
||||
import { ClientAuthInterceptor } from '@/components/auth/ClientAuthInterceptor';
|
||||
import { ThemeProvider } from 'next-themes';
|
||||
import { Toaster } from '@/components/ui/sonner';
|
||||
import { Building2, Users, Cog, Activity, Mail, UserCircle, Database, Map, BarChart3, Cloud, TrendingUp, GitCompare, AlertTriangle, FileText, MapPin, Settings, User, Package, Navigation, Zap, Target, PieChart, Calendar, Shield, Tractor, Clipboard, ClipboardCheck, Brain, Droplets, Book, ShoppingCart } from 'lucide-react';
|
||||
import { Building2, Users, Cog, Activity, Mail, UserCircle, Database, Map, BarChart3, Cloud, TrendingUp, GitCompare, AlertTriangle, FileText, Settings, User, Package, Navigation, Zap, Target, PieChart, Calendar, Shield, Tractor, Clipboard, ClipboardCheck, Brain, Droplets, Book, ShoppingCart } from 'lucide-react';
|
||||
|
||||
// 导入导航和侧边栏组件
|
||||
import {Navbar1} from "@/components/layouts/Navbar"
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Home, ArrowLeft, RefreshCw, Search, AlertTriangle, ExternalLink } from 'lucide-react';
|
||||
import { Home, ArrowLeft, RefreshCw, Search, AlertTriangle } from 'lucide-react';
|
||||
|
||||
export default function NotFound() {
|
||||
const handleRefresh = () => {
|
||||
|
||||
@@ -2,8 +2,6 @@ import * as React from "react"
|
||||
import { ChevronRight } from "lucide-react"
|
||||
import Link from "next/link"
|
||||
|
||||
import { SearchForm } from "@/components/search-form"
|
||||
import { VersionSwitcher } from "@/components/version-switcher"
|
||||
import {
|
||||
Collapsible,
|
||||
CollapsibleContent,
|
||||
@@ -15,7 +13,6 @@ import {
|
||||
SidebarGroup,
|
||||
SidebarGroupContent,
|
||||
SidebarGroupLabel,
|
||||
SidebarHeader,
|
||||
SidebarMenu,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { RefreshCw } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
@@ -19,7 +19,7 @@ export function CaptchaInput({ value, onChange, onCaptchaChange, className = ''
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const fetchCaptcha = async () => {
|
||||
const fetchCaptcha = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError('');
|
||||
onChange(''); // 清空验证码输入
|
||||
@@ -120,11 +120,11 @@ export function CaptchaInput({ value, onChange, onCaptchaChange, className = ''
|
||||
captcha_id: 'fallback-' + Date.now(),
|
||||
image: canvas.toDataURL()
|
||||
};
|
||||
};
|
||||
}, [onCaptchaChange, onChange]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchCaptcha();
|
||||
}, []);
|
||||
}, [fetchCaptcha]);
|
||||
|
||||
const handleRefresh = () => {
|
||||
fetchCaptcha();
|
||||
|
||||
@@ -15,6 +15,21 @@ export function LoadingScreen({
|
||||
subMessage,
|
||||
variant = 'default'
|
||||
}: LoadingScreenProps) {
|
||||
const variantTitles = {
|
||||
default: '??????????????',
|
||||
auth: '??????????',
|
||||
redirect: '???????????'
|
||||
} as const;
|
||||
|
||||
const variantSubtitles = {
|
||||
default: '??????????',
|
||||
auth: '????????????',
|
||||
redirect: '????????'
|
||||
} as const;
|
||||
|
||||
const primaryMessage = message || variantTitles[variant];
|
||||
const secondaryMessage = subMessage || variantSubtitles[variant];
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center relative overflow-hidden">
|
||||
{/* 智慧大田动态背景 - 使用登录页面相同的背景效果 */}
|
||||
|
||||
@@ -2,26 +2,7 @@
|
||||
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
export function SmartFieldBackground() {
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
if (!canvas) return;
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) return;
|
||||
|
||||
// 设置canvas尺寸
|
||||
const resizeCanvas = () => {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
};
|
||||
resizeCanvas();
|
||||
window.addEventListener('resize', resizeCanvas);
|
||||
|
||||
// 田间传感器节点
|
||||
class SensorNode {
|
||||
class SensorNode {
|
||||
x: number;
|
||||
y: number;
|
||||
radius: number;
|
||||
@@ -45,20 +26,17 @@ export function SmartFieldBackground() {
|
||||
draw(ctx: CanvasRenderingContext2D) {
|
||||
const pulse = Math.sin(this.pulsePhase) * 0.5 + 0.5;
|
||||
|
||||
// 节点外圈
|
||||
ctx.beginPath();
|
||||
ctx.arc(this.x, this.y, this.radius + pulse * 4, 0, Math.PI * 2);
|
||||
ctx.strokeStyle = `rgba(34, 197, 94, ${0.3 + pulse * 0.3})`;
|
||||
ctx.lineWidth = 2;
|
||||
ctx.stroke();
|
||||
|
||||
// 节点核心
|
||||
ctx.beginPath();
|
||||
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
|
||||
ctx.fillStyle = `rgba(34, 197, 94, ${0.8 + pulse * 0.2})`;
|
||||
ctx.fill();
|
||||
|
||||
// 光晕
|
||||
const gradient = ctx.createRadialGradient(this.x, this.y, 0, this.x, this.y, this.radius * 6);
|
||||
gradient.addColorStop(0, `rgba(34, 197, 94, ${0.4 * pulse})`);
|
||||
gradient.addColorStop(1, 'rgba(34, 197, 94, 0)');
|
||||
@@ -81,7 +59,6 @@ export function SmartFieldBackground() {
|
||||
ctx.lineWidth = 1;
|
||||
ctx.stroke();
|
||||
|
||||
// 数据流动效果
|
||||
const dataFlowPhase = (Date.now() / 1000) % 1;
|
||||
const flowX = this.x + (node.x - this.x) * dataFlowPhase;
|
||||
const flowY = this.y + (node.y - this.y) * dataFlowPhase;
|
||||
@@ -93,10 +70,12 @@ export function SmartFieldBackground() {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 无人机
|
||||
class Drone {
|
||||
type BoundsSupplier = () => { width: number; height: number };
|
||||
type DroneTrailPoint = { x: number; y: number; alpha: number };
|
||||
|
||||
class Drone {
|
||||
x: number;
|
||||
y: number;
|
||||
targetX: number;
|
||||
@@ -104,11 +83,14 @@ export function SmartFieldBackground() {
|
||||
speed: number;
|
||||
size: number;
|
||||
rotorPhase: number;
|
||||
trail: { x: number; y: number; alpha: number }[];
|
||||
trail: DroneTrailPoint[];
|
||||
private readonly getBounds: BoundsSupplier;
|
||||
|
||||
constructor() {
|
||||
this.x = Math.random() * canvas.width;
|
||||
this.y = Math.random() * canvas.height;
|
||||
constructor(getBounds: BoundsSupplier) {
|
||||
this.getBounds = getBounds;
|
||||
const { width, height } = this.getBounds();
|
||||
this.x = Math.random() * width;
|
||||
this.y = Math.random() * height;
|
||||
this.targetX = this.x;
|
||||
this.targetY = this.y;
|
||||
this.speed = 1.5;
|
||||
@@ -119,8 +101,9 @@ export function SmartFieldBackground() {
|
||||
}
|
||||
|
||||
setNewTarget() {
|
||||
this.targetX = Math.random() * canvas.width;
|
||||
this.targetY = Math.random() * canvas.height;
|
||||
const { width, height } = this.getBounds();
|
||||
this.targetX = Math.random() * width;
|
||||
this.targetY = Math.random() * height;
|
||||
}
|
||||
|
||||
update() {
|
||||
@@ -137,7 +120,6 @@ export function SmartFieldBackground() {
|
||||
|
||||
this.rotorPhase += 0.3;
|
||||
|
||||
// 更新轨迹
|
||||
this.trail.push({ x: this.x, y: this.y, alpha: 1 });
|
||||
if (this.trail.length > 30) {
|
||||
this.trail.shift();
|
||||
@@ -148,7 +130,6 @@ export function SmartFieldBackground() {
|
||||
}
|
||||
|
||||
draw(ctx: CanvasRenderingContext2D) {
|
||||
// 绘制轨迹
|
||||
this.trail.forEach((point, index) => {
|
||||
if (index > 0) {
|
||||
const prev = this.trail[index - 1];
|
||||
@@ -161,15 +142,12 @@ export function SmartFieldBackground() {
|
||||
}
|
||||
});
|
||||
|
||||
// 无人机机身
|
||||
ctx.save();
|
||||
ctx.translate(this.x, this.y);
|
||||
|
||||
// 机身
|
||||
ctx.fillStyle = 'rgba(59, 130, 246, 0.9)';
|
||||
ctx.fillRect(-this.size / 2, -this.size / 2, this.size, this.size);
|
||||
|
||||
// 四个螺旋桨
|
||||
const rotorPositions = [
|
||||
{ x: -this.size * 0.7, y: -this.size * 0.7 },
|
||||
{ x: this.size * 0.7, y: -this.size * 0.7 },
|
||||
@@ -196,28 +174,18 @@ export function SmartFieldBackground() {
|
||||
ctx.restore();
|
||||
});
|
||||
|
||||
// 扫描光束
|
||||
const scanRadius = 40;
|
||||
ctx.beginPath();
|
||||
ctx.arc(0, 0, scanRadius, 0, Math.PI * 2);
|
||||
ctx.strokeStyle = 'rgba(59, 130, 246, 0.3)';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.strokeStyle = 'rgba(59, 130, 246, 0.2)';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.stroke();
|
||||
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
|
||||
// 数据上传指示
|
||||
if (Math.random() < 0.1) {
|
||||
ctx.beginPath();
|
||||
ctx.arc(this.x, this.y, 3, 0, Math.PI * 2);
|
||||
ctx.fillStyle = 'rgba(34, 197, 94, 0.8)';
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 田地波浪效果
|
||||
class FieldWave {
|
||||
class FieldWave {
|
||||
offset: number;
|
||||
speed: number;
|
||||
amplitude: number;
|
||||
@@ -236,11 +204,11 @@ export function SmartFieldBackground() {
|
||||
this.offset += this.speed;
|
||||
}
|
||||
|
||||
draw(ctx: CanvasRenderingContext2D) {
|
||||
draw(ctx: CanvasRenderingContext2D, canvasWidth: number) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, this.y);
|
||||
|
||||
for (let x = 0; x <= canvas.width; x += 5) {
|
||||
for (let x = 0; x <= canvasWidth; x += 5) {
|
||||
const waveY = this.y + Math.sin((x + this.offset) * this.frequency) * this.amplitude;
|
||||
ctx.lineTo(x, waveY);
|
||||
}
|
||||
@@ -249,10 +217,9 @@ export function SmartFieldBackground() {
|
||||
ctx.lineWidth = 2;
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 数据流粒子
|
||||
class DataParticle {
|
||||
class DataParticle {
|
||||
x: number;
|
||||
y: number;
|
||||
vx: number;
|
||||
@@ -286,7 +253,6 @@ export function SmartFieldBackground() {
|
||||
ctx.fillStyle = `rgba(34, 197, 94, ${alpha * 0.8})`;
|
||||
ctx.fill();
|
||||
|
||||
// 光晕
|
||||
const gradient = ctx.createRadialGradient(this.x, this.y, 0, this.x, this.y, this.size * 3);
|
||||
gradient.addColorStop(0, `rgba(34, 197, 94, ${alpha * 0.4})`);
|
||||
gradient.addColorStop(1, 'rgba(34, 197, 94, 0)');
|
||||
@@ -299,7 +265,33 @@ export function SmartFieldBackground() {
|
||||
isDead() {
|
||||
return this.life >= this.maxLife;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function SmartFieldBackground() {
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
if (!canvas) return;
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) return;
|
||||
|
||||
// 设置canvas尺寸
|
||||
const resizeCanvas = () => {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
};
|
||||
resizeCanvas();
|
||||
window.addEventListener('resize', resizeCanvas);
|
||||
|
||||
// 田间传感器节点
|
||||
|
||||
// 无人机
|
||||
|
||||
// 田地波浪效果
|
||||
|
||||
// 数据流粒子
|
||||
|
||||
// 初始化传感器网络
|
||||
const sensors: SensorNode[] = [];
|
||||
@@ -325,9 +317,10 @@ export function SmartFieldBackground() {
|
||||
});
|
||||
|
||||
// 初始化无人机
|
||||
const canvasBounds = () => ({ width: canvas.width, height: canvas.height });
|
||||
const drones: Drone[] = [];
|
||||
for (let i = 0; i < 2; i++) {
|
||||
drones.push(new Drone());
|
||||
drones.push(new Drone(canvasBounds));
|
||||
}
|
||||
|
||||
// 初始化田地波浪
|
||||
@@ -349,7 +342,7 @@ export function SmartFieldBackground() {
|
||||
// 绘制田地波浪
|
||||
waves.forEach(wave => {
|
||||
wave.update();
|
||||
wave.draw(ctx);
|
||||
wave.draw(ctx, canvas.width);
|
||||
});
|
||||
|
||||
// 绘制传感器连接线
|
||||
|
||||
@@ -911,7 +911,7 @@ export class SpatialIndex {
|
||||
}): Field[] {
|
||||
const results: Field[] = [];
|
||||
|
||||
for (const [_, item] of this.rtree) {
|
||||
for (const [, item] of this.rtree) {
|
||||
if (this._bboxesIntersect(bbox, item.bbox)) {
|
||||
results.push(item.field);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// 通用类型定义
|
||||
|
||||
// API响应类型
|
||||
export interface ApiResponse<T = any> {
|
||||
export interface ApiResponse<T = unknown> {
|
||||
code: number
|
||||
message: string
|
||||
data: T
|
||||
@@ -34,11 +34,11 @@ export interface SortParams {
|
||||
// 搜索类型
|
||||
export interface SearchParams {
|
||||
keyword?: string
|
||||
filters?: Record<string, any>
|
||||
filters?: Record<string, unknown>
|
||||
}
|
||||
|
||||
// 表格列定义
|
||||
export interface ColumnDef<T = any> {
|
||||
export interface ColumnDef<T = Record<string, unknown>> {
|
||||
key: string
|
||||
title: string
|
||||
dataIndex: keyof T
|
||||
@@ -46,7 +46,7 @@ export interface ColumnDef<T = any> {
|
||||
fixed?: 'left' | 'right'
|
||||
sortable?: boolean
|
||||
filterable?: boolean
|
||||
render?: (value: any, record: T, index: number) => React.ReactNode
|
||||
render?: (value: T[keyof T], record: T, index: number) => React.ReactNode
|
||||
}
|
||||
|
||||
// 表单字段类型
|
||||
@@ -56,7 +56,7 @@ export interface FormField {
|
||||
type: 'text' | 'number' | 'select' | 'date' | 'textarea' | 'checkbox' | 'radio'
|
||||
required?: boolean
|
||||
placeholder?: string
|
||||
options?: Array<{ label: string; value: any }>
|
||||
options?: Array<{ label: string; value: string | number | boolean }>
|
||||
validation?: {
|
||||
min?: number
|
||||
max?: number
|
||||
@@ -343,7 +343,7 @@ export interface AppConfig {
|
||||
// 路由类型
|
||||
export interface Route {
|
||||
path: string
|
||||
component: React.ComponentType<any>
|
||||
component: React.ComponentType<unknown>
|
||||
exact?: boolean
|
||||
title?: string
|
||||
icon?: React.ReactNode
|
||||
@@ -390,7 +390,7 @@ export interface DashboardStats {
|
||||
export interface AppError {
|
||||
code: string
|
||||
message: string
|
||||
details?: any
|
||||
details?: unknown
|
||||
timestamp: string
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ export interface LogEntry {
|
||||
module: string
|
||||
userId?: string
|
||||
timestamp: string
|
||||
metadata?: Record<string, any>
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export enum LogLevel {
|
||||
|
||||
@@ -37,7 +37,7 @@ export interface MessageLog {
|
||||
readTime?: string;
|
||||
failReason?: string;
|
||||
retryCount: number;
|
||||
variables?: Record<string, any>;
|
||||
variables?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
// 消息发送记录
|
||||
|
||||
@@ -57,7 +57,7 @@ export interface DataDictionary {
|
||||
description?: string;
|
||||
isSystem: boolean; // 是否系统内置
|
||||
isActive: boolean;
|
||||
extendData?: Record<string, any>;
|
||||
extendData?: Record<string, unknown>;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "preserve",
|
||||
"jsx": "react-jsx",
|
||||
/** TODO: 暂时禁用校验 */
|
||||
"noImplicitAny": false,
|
||||
"strictNullChecks": false,
|
||||
@@ -70,12 +70,8 @@
|
||||
},
|
||||
"include": [
|
||||
"src",
|
||||
".next/types/**/*.ts"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.node.json"
|
||||
}
|
||||
".next/types/**/*.ts",
|
||||
".next/dev/types/**/*.ts"
|
||||
],
|
||||
"paths": {
|
||||
"@/*": [
|
||||
|
||||
Reference in New Issue
Block a user