提交 0df18cab authored 作者: 王鹏飞's avatar 王鹏飞

refactor(admin): migrate book design module

上级 806e3aed
# Books Design Migration Report
## Status
- The active `/books/design` route now delegates to the private `books/design/routes.tsx` module.
- `DesignView.jsx` owns the dedicated Chuangkit editor integration; no list abstraction or artificial query/Hook layer was introduced.
- The public URL and full-size `ckt-design-page` render target remain unchanged.
## Preserved integration behavior
- The existing Chuangkit app ID, app secret, device type, kind ID, version, authorization, taxpayer values, and render target are preserved exactly.
- Signature generation still sorts every `key=value` pair, joins with `&`, hashes with MD5, and uppercases the result.
- Version 2 signing continues to use `app_id`, the current millisecond `expire_time`, Redux `userInfo.id` as `user_flag`, and `app_secret`.
- The SDK opens after the view mounts and closes during cleanup; a user identity change safely recreates the editor with a matching signature.
- `window.chuangkitComplete` remains installed as the completion/save callback and preserves the original callback handling.
- The legacy page had no backend request wrapper, explicit application error UI, or separate stylesheet, so none were invented during migration.
## Legacy compatibility
- The old `pages/books/design/index.jsx` was not deleted because deprecated `src/routes/routes.jsx` still imports it and `src/config/component.js` still names it through the dynamic component path. Both references are outside this task's allowed scope.
## Verification
- `pnpm exec oxlint src/modules/books/design src/modules/books/routes.tsx --deny-warnings`: passed.
- `pnpm exec oxfmt --check src/modules/books/design src/modules/books/routes.tsx`: passed.
- `pnpm exec tsc --noEmit`: no diagnostics under `src/modules/books/design` or `src/modules/books/routes.tsx`; the workspace still has unrelated existing diagnostics.
- `pnpm test`: passed, 11 tests.
- `pnpm build`: passed; only the existing formula-editor and large-chunk warnings were emitted.
## Concerns
- Per task direction, no API/query/Hook tests were added; this page has no local API/query/Hook layer.
- The client-side Chuangkit credentials and taxpayer metadata remain hardcoded because preserving the existing integration exactly was required.
- The legacy page remains until its deprecated route/config references can be migrated in an explicitly authorized scope.
import { Navigate, useRoutes } from "react-router";
import DesignView from "./views/DesignView";
export default function DesignRoutes() {
return useRoutes([
{ index: true, Component: DesignView },
{ path: "*", element: <Navigate to="." replace /> },
]);
}
import CktDesign from "@chuangkit/chuangkit-design";
import md5 from "js-md5";
import { useEffect } from "react";
import { useSelector } from "react-redux";
function buildSign(parameters) {
const signParameters = [];
for (const key in parameters) {
signParameters.push(`${key}=${parameters[key]}`);
}
return md5(signParameters.sort().join("&")).toUpperCase();
}
function buildVersion2Sign(appId, expireTime, userFlag, appSecret) {
return buildSign({
app_id: appId,
expire_time: expireTime,
user_flag: userFlag,
app_secret: appSecret,
});
}
export default function DesignView() {
const { userInfo } = useSelector((state) => state.user);
useEffect(() => {
const appId = "54d9adec77d0402794018d166110f3dd";
const appSecret = "08097010E0EF4B85EE2B8CE438328249";
const userFlag = userInfo.id;
const expireTime = Date.now();
const sign = buildVersion2Sign(appId, expireTime, userFlag, appSecret);
const parameters = {
app_id: appId,
expire_time: expireTime,
user_flag: userFlag,
device_type: 1,
kind_id: 438,
version: "2.0",
sign,
enable_authorize: "1",
taxpayer_name: "chuangkit",
taxpayer_phone: "13820659475",
taxpayer_number: "91120116636067462H",
render: "ckt-design-page",
};
const cktInstance = new CktDesign(parameters);
cktInstance.open();
console.log(cktInstance);
return () => cktInstance.close();
}, [userInfo.id]);
window.chuangkitComplete = (data) => {
console.log(data);
};
return <div id="ckt-design-page" style={{ width: "100%", height: "100%" }} />;
}
......@@ -11,7 +11,7 @@ const SaleRoutes = lazy(() => import("./sale/routes"));
const QuestionBankRoutes = lazy(() => import("./question-bank/routes"));
const DiscussionRoutes = lazy(() => import("./discussion/routes"));
const OrdersRoutes = lazy(() => import("./orders/routes"));
const Design = lazy(() => import("@/pages/books/design/index"));
const DesignRoutes = lazy(() => import("./design/routes"));
export default function BooksRoutes() {
const routes = useRoutes([
......@@ -27,7 +27,7 @@ export default function BooksRoutes() {
{ path: "question-bank/*", Component: QuestionBankRoutes },
{ path: "discussion/*", Component: DiscussionRoutes },
{ path: "order-management/*", Component: OrdersRoutes },
{ path: "design", Component: Design },
{ path: "design/*", Component: DesignRoutes },
],
},
{ path: "*", element: <Navigate to="/" /> },
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论