UNPKG

@scenemesh/entity-engine

Version:

一个“元数据驱动 + 组件适配 + 动态关系 + 视图管线”式的实体引擎。以 **Model + View + FieldType + SuiteAdapter + DataSource** 为五大支点,统一 CRUD / 查询 / 引用管理 / 视图渲染 / 扩展注册,支持在运行期无侵入拼装出 **表单、网格、主从、看板、仪表盘、流程/树形视图** 等多形态界面。

145 lines (126 loc) 5.62 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _chunkW3GG22TSjs = require('./chunk-W3GG22TS.js'); // src/modules/build-in/views/auth/auth-view-comp.tsx var _react = require('react'); var _notifications = require('@mantine/notifications'); var _core = require('@mantine/core'); var _jsxruntime = require('react/jsx-runtime'); function AuthViewLoginComp(props) { const { model, baseObjectId, viewData, behavior } = props; const [username, setUsername] = _react.useState.call(void 0, ""); const [password, setPassword] = _react.useState.call(void 0, ""); const [rememberMe, setRememberMe] = _react.useState.call(void 0, false); const [error, setError] = _react.useState.call(void 0, ""); const engine = _chunkW3GG22TSjs.useEntityEngine.call(void 0, ); const { session, sessionRefresh } = _chunkW3GG22TSjs.useEntitySession.call(void 0, ); const { performAction } = _chunkW3GG22TSjs.useMasterDetailViewContainer.call(void 0, ); const getCsrfToken = async () => { const response = await fetch(engine.settings.getUrl("/auth/csrf")); const { csrfToken } = await response.json(); return csrfToken; }; const handleSubmit = async (e) => { e.preventDefault(); const csrfToken = await getCsrfToken(); if (!csrfToken) { setError("Could not retrieve CSRF token."); return; } const body = new URLSearchParams(); body.append("csrfToken", csrfToken); body.append("username", username); body.append("password", password); body.append("remember", rememberMe ? "true" : "false"); body.append("json", "true"); body.append("redirect", "false"); const response = await fetch(engine.settings.getUrl("/auth/callback/credentials"), { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body }); if (response.ok && response.status === 200) { console.log("Login successful", response); _notifications.notifications.show({ title: "\u767B\u5F55\u6210\u529F", message: "\u6B22\u8FCE\u56DE\u6765\uFF0C\u4F60\u5DF2\u6210\u529F\u767B\u5F55\u3002", color: "green", autoClose: 5e3 }); await _optionalChain([sessionRefresh, 'optionalCall', _ => _()]); window.location.reload(); } else { setError("\u90AE\u7BB1\u6216\u5BC6\u7801\u9519\u8BEF."); } }; return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "entity-auth-wrapper", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _core.Paper, { className: "entity-auth-form", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _core.Title, { order: 2, className: "entity-auth-title", children: "\u6B22\u8FCE\u767B\u5F55" }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "form", { onSubmit: handleSubmit, children: [ error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _core.Text, { c: "red", children: error }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _core.TextInput, { label: "\u90AE\u7BB1\u5730\u5740", placeholder: "hello@gmail.com", size: "md", radius: "md", onChange: (e) => setUsername(e.target.value) } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _core.PasswordInput, { label: "\u767B\u5F55\u5BC6\u7801", placeholder: "Your password", mt: "md", size: "md", radius: "md", onChange: (e) => setPassword(e.target.value) } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _core.Checkbox, { label: "\u4FDD\u6301\u767B\u5F55", mt: "xl", size: "md", onChange: (e) => setRememberMe(e.target.checked) } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _core.Button, { fullWidth: true, mt: "xl", size: "md", radius: "md", type: "submit", onClick: handleSubmit, children: "\u767B\u5F55" } ), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _core.Text, { ta: "center", mt: "md", children: [ "\u8FD8\u6CA1\u6709\u5BC6\u7801?", " ", /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _core.Anchor, { href: "#", fw: 500, onClick: (event) => event.preventDefault(), children: "\u6CE8\u518C" }) ] }) ] }) ] }) }); } // src/modules/build-in/views/auth/auth.view.tsx var AuthView = class extends _chunkW3GG22TSjs.EntityView { constructor() { super(...arguments); this.info = { viewName: "auth", displayName: "\u8BA4\u8BC1\u89C6\u56FE", icon: "auth_icon", description: "\u8BA4\u8BC1\u89C6\u56FE, \u5305\u542B\u767B\u5F55\u3001\u6CE8\u518C\u7B49\u529F\u80FD" }; this.Component = (props) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AuthViewLoginComp, { ...props }); } }; var auth_view_default = AuthView; exports.AuthView = AuthView; exports.default = auth_view_default; //# sourceMappingURL=auth.view-BV23IBTV.js.map