From 4fe3e62dc1d031e1e228710abd11a1987c58daff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E6=9C=9D=E4=BC=9F?= <2211960668@qq.com> Date: Tue, 24 Oct 2023 10:27:28 +0800 Subject: [PATCH 1/2] account trigger --- es/triggers/account.d.ts | 5 ++++ es/triggers/account.js | 44 ++++++++++++++++++++++++++++ lib/triggers/account.d.ts | 5 ++++ lib/triggers/account.js | 46 +++++++++++++++++++++++++++++ src/triggers/account.ts | 61 +++++++++++++++++++++++++++++++++++++++ src/triggers/index.ts | 3 ++ 6 files changed, 164 insertions(+) create mode 100644 es/triggers/account.d.ts create mode 100644 es/triggers/account.js create mode 100644 lib/triggers/account.d.ts create mode 100644 lib/triggers/account.js create mode 100644 src/triggers/account.ts diff --git a/es/triggers/account.d.ts b/es/triggers/account.d.ts new file mode 100644 index 000000000..633d784d4 --- /dev/null +++ b/es/triggers/account.d.ts @@ -0,0 +1,5 @@ +import { EntityDict } from '../oak-app-domain/EntityDict'; +import { Trigger } from 'oak-domain/lib/types'; +import { BackendRuntimeContext } from '../context/BackendRuntimeContext'; +declare const triggers: Trigger>[]; +export default triggers; diff --git a/es/triggers/account.js b/es/triggers/account.js new file mode 100644 index 000000000..50e9033e3 --- /dev/null +++ b/es/triggers/account.js @@ -0,0 +1,44 @@ +import { assert } from 'oak-domain/lib/utils/assert'; +import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid'; +const triggers = [ + // 目前先这样授予关系 + { + name: '充值的时候,将用户赋予owner关系', + entity: 'account', + action: 'create', + when: 'before', + fn: async (event, context) => { + const { operation: { data, filter }, } = event; + assert(!(data instanceof Array)); + const accountId = data.id; + const [relation] = await context.select('relation', { + data: { + id: 1, + }, + filter: { + name: 'owner', + entity: 'account', + entityId: { + $exists: false, + } + } + }, { dontCollect: true }); + assert(relation); + const closeRootMode = context.openRootMode(); + await context.operate('userRelation', { + id: await generateNewIdAsync(), + action: 'create', + data: { + id: await generateNewIdAsync(), + relationId: relation.id, + userId: context.getCurrentUserId(), + entity: 'account', + entityId: accountId, + }, + }, {}); + closeRootMode(); + return 1; + }, + }, +]; +export default triggers; diff --git a/lib/triggers/account.d.ts b/lib/triggers/account.d.ts new file mode 100644 index 000000000..633d784d4 --- /dev/null +++ b/lib/triggers/account.d.ts @@ -0,0 +1,5 @@ +import { EntityDict } from '../oak-app-domain/EntityDict'; +import { Trigger } from 'oak-domain/lib/types'; +import { BackendRuntimeContext } from '../context/BackendRuntimeContext'; +declare const triggers: Trigger>[]; +export default triggers; diff --git a/lib/triggers/account.js b/lib/triggers/account.js new file mode 100644 index 000000000..5c034d41b --- /dev/null +++ b/lib/triggers/account.js @@ -0,0 +1,46 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const assert_1 = require("oak-domain/lib/utils/assert"); +const uuid_1 = require("oak-domain/lib/utils/uuid"); +const triggers = [ + // 目前先这样授予关系 + { + name: '充值的时候,将用户赋予owner关系', + entity: 'account', + action: 'create', + when: 'before', + fn: async (event, context) => { + const { operation: { data, filter }, } = event; + (0, assert_1.assert)(!(data instanceof Array)); + const accountId = data.id; + const [relation] = await context.select('relation', { + data: { + id: 1, + }, + filter: { + name: 'owner', + entity: 'account', + entityId: { + $exists: false, + } + } + }, { dontCollect: true }); + (0, assert_1.assert)(relation); + const closeRootMode = context.openRootMode(); + await context.operate('userRelation', { + id: await (0, uuid_1.generateNewIdAsync)(), + action: 'create', + data: { + id: await (0, uuid_1.generateNewIdAsync)(), + relationId: relation.id, + userId: context.getCurrentUserId(), + entity: 'account', + entityId: accountId, + }, + }, {}); + closeRootMode(); + return 1; + }, + }, +]; +exports.default = triggers; diff --git a/src/triggers/account.ts b/src/triggers/account.ts new file mode 100644 index 000000000..2746b67df --- /dev/null +++ b/src/triggers/account.ts @@ -0,0 +1,61 @@ +import { EntityDict } from '../oak-app-domain/EntityDict'; +import { Trigger } from 'oak-domain/lib/types'; +import { BackendRuntimeContext } from '../context/BackendRuntimeContext'; +import { assert } from 'oak-domain/lib/utils/assert'; +import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid'; +import { OakPreConditionUnsetException } from 'oak-domain/lib/types'; +import { RuntimeCxt } from '../types/RuntimeCxt'; + +const triggers: Trigger< + EntityDict, + 'account', + BackendRuntimeContext + >[] = [ + // 目前先这样授予关系 + { + name: '充值的时候,将用户赋予owner关系', + entity: 'account', + action: 'create', + when: 'before', + fn: async (event: any, context: any) => { + const { + operation: { data, filter }, + } = event; + assert(!(data instanceof Array)); + const accountId = data.id!; + const [relation] = await context.select('relation', { + data: { + id: 1, + }, + filter: { + name: 'owner', + entity: 'account', + entityId: { + $exists: false, + } + } + }, { dontCollect: true }); + + assert(relation); + const closeRootMode = context.openRootMode(); + await context.operate( + 'userRelation', + { + id: await generateNewIdAsync(), + action: 'create', + data: { + id: await generateNewIdAsync(), + relationId: relation.id, + userId: context.getCurrentUserId(), + entity: 'account', + entityId: accountId!, + } as EntityDict['userRelation']['CreateSingle']['data'], + }, + {} + ); + closeRootMode(); + return 1; + }, + }, + ]; +export default triggers; diff --git a/src/triggers/index.ts b/src/triggers/index.ts index 0bd0b673f..8002a40bb 100644 --- a/src/triggers/index.ts +++ b/src/triggers/index.ts @@ -14,8 +14,11 @@ import sessionMessageTriggers from './sessionMessage'; import wechatMenuTriggers from './wechatMenu'; import wechatPublicTag from './wechatPublicTag'; +import accountTriggers from './account'; + export default [ + ...accountTriggers, ...applicationTriggers, ...addressTriggers, ...userTriggers, From 2053b5e78c43478e513fffc7f5b167099d576a96 Mon Sep 17 00:00:00 2001 From: qsc <3153284618@qq.com> Date: Tue, 24 Oct 2023 10:38:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?articleMenu=20extraFile=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/components/articleMenu/treeCell/web.pc.js | 42 +++++++++------ lib/components/articleMenu/treeCell/web.pc.js | 40 +++++++++----- .../articleMenu/treeCell/web.pc.tsx | 52 +++++++++++++------ 3 files changed, 90 insertions(+), 44 deletions(-) diff --git a/es/components/articleMenu/treeCell/web.pc.js b/es/components/articleMenu/treeCell/web.pc.js index c1d601940..91ff86b7d 100644 --- a/es/components/articleMenu/treeCell/web.pc.js +++ b/es/components/articleMenu/treeCell/web.pc.js @@ -1,11 +1,12 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { useState, useRef, useEffect } from 'react'; -import { Input, Button, Dropdown, Divider, Modal, Form, Image } from 'antd'; +import { Input, Button, Dropdown, Divider, Modal, Form, Image, Space } from 'antd'; import { EditOutlined, DownOutlined, UpOutlined, MinusOutlined, PlusOutlined, EyeOutlined } from '@ant-design/icons'; import ArticleMenuTreeList from '../treeList'; import ArticleTreeList from '../../article/treeList'; import Styles from './web.pc.module.less'; -import OakGallery from "../../../components/extraFile/gallery"; +import ExtraFileUpload from '../../extraFile/upload'; +import ExtraFileCommit from '../../extraFile/commit'; export default function Render(props) { const { row, allowCreateSubArticle, allowCreateSubMenu, allowRemove, onRemove, onUpdateName, oakFullpath, logo, onChildEditArticleChange, editArticle, show, getBreadcrumbItemsByParent, breadItems, drawerOpen, changeDrawerOpen, selectedArticleId, openArray, getTopInfo, articleId, articleMenuId, getSideInfo, currentArticle, setCurrentArticle } = props.data; const { update, execute, createSubArticle, createSubArticleMenu, setMessage, gotoDoc } = props.methods; @@ -120,24 +121,35 @@ export default function Render(props) { // : _jsxs(_Fragment, { children: [_jsx(Button, { type: "text", icon: _jsx(EditOutlined, {}), size: "small", onClick: () => { setNameEditing(true); - modal.confirm({ + const modalInstance = modal.confirm({ title: '编辑分类', cancelText: '取消', okText: '提交', - content: (_jsxs("div", { children: [_jsx(Form.Item, { label: "\u5206\u7C7B\u540D\u79F0", children: _jsx(Input, { ref: menuNameRef, defaultValue: row.name }) }), _jsx(Form.Item, { label: "LOGO", help: _jsxs("div", { children: [_jsx("span", { children: "\u8BF7\u4E0A\u4F20LOGO\u9AD8\u6E05\u56FE\u7247\uFF0C" }), _jsx("span", { children: "108*108\u50CF\u7D20\uFF0C\u4EC5\u652F\u6301PNG\u3001JPG\u683C\u5F0F\uFF0C\u5927\u5C0F\u4E0D\u8D85\u8FC7300KB\u3002" })] }), children: _jsx(_Fragment, { children: _jsx(OakGallery, { oakPath: oakFullpath + content: (_jsxs("div", { children: [_jsx(Form.Item, { label: "\u5206\u7C7B\u540D\u79F0", children: _jsx(Input, { ref: menuNameRef, defaultValue: row.name, onChange: (val) => update({ name: val.target.value }) }) }), _jsx(Form.Item, { label: "LOGO", help: _jsxs("div", { children: [_jsx("span", { children: "\u8BF7\u4E0A\u4F20LOGO\u9AD8\u6E05\u56FE\u7247\uFF0C" }), _jsx("span", { children: "108*108\u50CF\u7D20\uFF0C\u4EC5\u652F\u6301PNG\u3001JPG\u683C\u5F0F\uFF0C\u5927\u5C0F\u4E0D\u8D85\u8FC7300KB\u3002" })] }), children: _jsx(_Fragment, { children: _jsx(ExtraFileUpload, { oakPath: oakFullpath ? `${oakFullpath}.extraFile$entity$1` : undefined, type: "image", origin: "qiniu", tag1: "logo", entity: "articleMenu", accept: ".PNG, .JPG", maxNumber: 1 }) }) })] })), - onOk: async () => { - if (menuNameRef.current.input.value) { - await onUpdateName(menuNameRef.current.input.value); - } - else { - setMessage({ - type: 'warning', - content: '请输入分类标题', - }); - } - } + // onOk: async () => { + // if (menuNameRef.current!.input!.value) { + // await onUpdateName(menuNameRef.current!.input!.value); + // } else { + // setMessage({ + // type: 'warning', + // content: '请输入分类标题', + // }); + // } + // } + footer: () => _jsxs(Space, { children: [_jsx(ExtraFileCommit, { oakPath: oakFullpath, efPaths: [ + 'extraFile$entity$1', + ], afterCommit: () => { + modalInstance.destroy(); + }, beforeCommit: () => { + if (menuNameRef.current.input.value) { + return true; + } + else { + return false; + } + } }), _jsx(Button, { onClick: () => modalInstance.destroy(), children: "\u53D6\u6D88" })] }) }); }, style: { marginRight: 4 } }), _jsxs("div", { className: Styles.name, children: [logo ? (_jsx(Image, { height: 26, width: 26, src: logo, preview: false })) : null, _jsx("div", { style: { marginLeft: 4, overflow: 'hidden', width: '100px', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, children: row?.name })] })] }) }), _jsx(Divider, { type: "vertical", style: { height: '100%', marginTop: 4, marginBottom: 4 } }), _jsxs("div", { className: Styles.control, children: [!row.parentId && _jsx(Button, { type: "text", onClick: () => { gotoDoc(row?.id); diff --git a/lib/components/articleMenu/treeCell/web.pc.js b/lib/components/articleMenu/treeCell/web.pc.js index 663494e28..6235beb31 100644 --- a/lib/components/articleMenu/treeCell/web.pc.js +++ b/lib/components/articleMenu/treeCell/web.pc.js @@ -8,7 +8,8 @@ const icons_1 = require("@ant-design/icons"); const treeList_1 = tslib_1.__importDefault(require("../treeList")); const treeList_2 = tslib_1.__importDefault(require("../../article/treeList")); const web_pc_module_less_1 = tslib_1.__importDefault(require("./web.pc.module.less")); -const gallery_1 = tslib_1.__importDefault(require("../../../components/extraFile/gallery")); +const upload_1 = tslib_1.__importDefault(require("../../extraFile/upload")); +const commit_1 = tslib_1.__importDefault(require("../../extraFile/commit")); function Render(props) { const { row, allowCreateSubArticle, allowCreateSubMenu, allowRemove, onRemove, onUpdateName, oakFullpath, logo, onChildEditArticleChange, editArticle, show, getBreadcrumbItemsByParent, breadItems, drawerOpen, changeDrawerOpen, selectedArticleId, openArray, getTopInfo, articleId, articleMenuId, getSideInfo, currentArticle, setCurrentArticle } = props.data; const { update, execute, createSubArticle, createSubArticleMenu, setMessage, gotoDoc } = props.methods; @@ -123,24 +124,35 @@ function Render(props) { // : (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(antd_1.Button, { type: "text", icon: (0, jsx_runtime_1.jsx)(icons_1.EditOutlined, {}), size: "small", onClick: () => { setNameEditing(true); - modal.confirm({ + const modalInstance = modal.confirm({ title: '编辑分类', cancelText: '取消', okText: '提交', - content: ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(antd_1.Form.Item, { label: "\u5206\u7C7B\u540D\u79F0", children: (0, jsx_runtime_1.jsx)(antd_1.Input, { ref: menuNameRef, defaultValue: row.name }) }), (0, jsx_runtime_1.jsx)(antd_1.Form.Item, { label: "LOGO", help: (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("span", { children: "\u8BF7\u4E0A\u4F20LOGO\u9AD8\u6E05\u56FE\u7247\uFF0C" }), (0, jsx_runtime_1.jsx)("span", { children: "108*108\u50CF\u7D20\uFF0C\u4EC5\u652F\u6301PNG\u3001JPG\u683C\u5F0F\uFF0C\u5927\u5C0F\u4E0D\u8D85\u8FC7300KB\u3002" })] }), children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(gallery_1.default, { oakPath: oakFullpath + content: ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(antd_1.Form.Item, { label: "\u5206\u7C7B\u540D\u79F0", children: (0, jsx_runtime_1.jsx)(antd_1.Input, { ref: menuNameRef, defaultValue: row.name, onChange: (val) => update({ name: val.target.value }) }) }), (0, jsx_runtime_1.jsx)(antd_1.Form.Item, { label: "LOGO", help: (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("span", { children: "\u8BF7\u4E0A\u4F20LOGO\u9AD8\u6E05\u56FE\u7247\uFF0C" }), (0, jsx_runtime_1.jsx)("span", { children: "108*108\u50CF\u7D20\uFF0C\u4EC5\u652F\u6301PNG\u3001JPG\u683C\u5F0F\uFF0C\u5927\u5C0F\u4E0D\u8D85\u8FC7300KB\u3002" })] }), children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(upload_1.default, { oakPath: oakFullpath ? `${oakFullpath}.extraFile$entity$1` : undefined, type: "image", origin: "qiniu", tag1: "logo", entity: "articleMenu", accept: ".PNG, .JPG", maxNumber: 1 }) }) })] })), - onOk: async () => { - if (menuNameRef.current.input.value) { - await onUpdateName(menuNameRef.current.input.value); - } - else { - setMessage({ - type: 'warning', - content: '请输入分类标题', - }); - } - } + // onOk: async () => { + // if (menuNameRef.current!.input!.value) { + // await onUpdateName(menuNameRef.current!.input!.value); + // } else { + // setMessage({ + // type: 'warning', + // content: '请输入分类标题', + // }); + // } + // } + footer: () => (0, jsx_runtime_1.jsxs)(antd_1.Space, { children: [(0, jsx_runtime_1.jsx)(commit_1.default, { oakPath: oakFullpath, efPaths: [ + 'extraFile$entity$1', + ], afterCommit: () => { + modalInstance.destroy(); + }, beforeCommit: () => { + if (menuNameRef.current.input.value) { + return true; + } + else { + return false; + } + } }), (0, jsx_runtime_1.jsx)(antd_1.Button, { onClick: () => modalInstance.destroy(), children: "\u53D6\u6D88" })] }) }); }, style: { marginRight: 4 } }), (0, jsx_runtime_1.jsxs)("div", { className: web_pc_module_less_1.default.name, children: [logo ? ((0, jsx_runtime_1.jsx)(antd_1.Image, { height: 26, width: 26, src: logo, preview: false })) : null, (0, jsx_runtime_1.jsx)("div", { style: { marginLeft: 4, overflow: 'hidden', width: '100px', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, children: row?.name })] })] }) }), (0, jsx_runtime_1.jsx)(antd_1.Divider, { type: "vertical", style: { height: '100%', marginTop: 4, marginBottom: 4 } }), (0, jsx_runtime_1.jsxs)("div", { className: web_pc_module_less_1.default.control, children: [!row.parentId && (0, jsx_runtime_1.jsx)(antd_1.Button, { type: "text", onClick: () => { gotoDoc(row?.id); diff --git a/src/components/articleMenu/treeCell/web.pc.tsx b/src/components/articleMenu/treeCell/web.pc.tsx index 33aec35a9..3585882f3 100644 --- a/src/components/articleMenu/treeCell/web.pc.tsx +++ b/src/components/articleMenu/treeCell/web.pc.tsx @@ -1,12 +1,13 @@ import React, { useState, useRef, useEffect } from 'react'; -import { Input, Button, MenuProps, Dropdown, Divider, Modal, InputRef, Form, Image } from 'antd'; +import { Input, Button, MenuProps, Dropdown, Divider, Modal, InputRef, Form, Image, Space } from 'antd'; import { EditOutlined, DownOutlined, UpOutlined, RightOutlined, LeftOutlined, MinusOutlined, PlusOutlined, EyeOutlined } from '@ant-design/icons'; import { WebComponentProps } from "oak-frontend-base"; import ArticleMenuTreeList from '../treeList'; import ArticleTreeList from '../../article/treeList'; import { EntityDict } from "../../../oak-app-domain"; import Styles from './web.pc.module.less'; -import OakGallery from "../../../components/extraFile/gallery"; +import ExtraFileUpload from '../../extraFile/upload'; +import ExtraFileCommit from '../../extraFile/commit'; export default function Render(props: WebComponentProps { setNameEditing(true); - modal.confirm({ + const modalInstance = modal.confirm({ title: '编辑分类', cancelText: '取消', okText: '提交', @@ -231,6 +232,7 @@ export default function Render(props: WebComponentProps update({ name: val.target.value })} /> <> - ), - onOk: async () => { - if (menuNameRef.current!.input!.value) { - await onUpdateName(menuNameRef.current!.input!.value); - } else { - setMessage({ - type: 'warning', - content: '请输入分类标题', - }); - } - - } + // onOk: async () => { + // if (menuNameRef.current!.input!.value) { + // await onUpdateName(menuNameRef.current!.input!.value); + // } else { + // setMessage({ + // type: 'warning', + // content: '请输入分类标题', + // }); + // } + // } + footer: () => + { + modalInstance!.destroy() + }} + beforeCommit={() => { + if (menuNameRef.current!.input!.value) { + return true + } else { + return false + } + }} + /> + + }); }} style={{ marginRight: 4 }}