From b04c1e5310330fe80261eafb03df5df8cea43167 Mon Sep 17 00:00:00 2001 From: wangwenchen <920960949@qq.com> Date: Tue, 1 Aug 2023 18:23:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=99=9A=E6=8B=9F=E7=99=BB=E9=99=86=20?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E4=BC=81=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/checkers/parasite.js | 18 +++ lib/components/parasite/detail/index.js | 13 ++ lib/components/parasite/detail/web.pc.d.ts | 4 +- lib/components/parasite/detail/web.pc.js | 15 +- lib/components/parasite/list/index.js | 3 + lib/components/parasite/list/web.d.ts | 7 +- lib/components/parasite/list/web.js | 145 +++++++++++++----- lib/context/BackendRuntimeContext.js | 4 +- lib/context/FrontendRuntimeContext.js | 4 +- lib/entities/Parasite.js | 1 + lib/general-app-domain/Parasite/Action.d.ts | 2 +- lib/general-app-domain/Parasite/Action.js | 2 +- .../Parasite/locales/zh_CN.json | 2 +- src/checkers/parasite.ts | 18 +++ src/components/parasite/list/index.ts | 7 +- src/components/parasite/list/web.tsx | 109 ++++++++++++- src/context/BackendRuntimeContext.ts | 7 +- src/context/FrontendRuntimeContext.ts | 8 +- src/entities/Parasite.ts | 3 +- 19 files changed, 309 insertions(+), 63 deletions(-) diff --git a/lib/checkers/parasite.js b/lib/checkers/parasite.js index 1d1493da1..d8255ad52 100644 --- a/lib/checkers/parasite.js +++ b/lib/checkers/parasite.js @@ -50,5 +50,23 @@ var checkers = [ (0, assert_1.default)(data.user && data.user.action === 'create'); }, }, + { + type: 'row', + entity: 'parasite', + action: ['cancel'], + errMsg: '您没有设置失效的权限', + filter: { + expired: false, + }, + }, + { + type: 'row', + entity: 'parasite', + action: ['qrcode'], + errMsg: '您没有查看二维码的权限', + filter: { + expired: false, + }, + }, ]; exports.default = checkers; diff --git a/lib/components/parasite/detail/index.js b/lib/components/parasite/detail/index.js index 02ed13581..f27defdcd 100644 --- a/lib/components/parasite/detail/index.js +++ b/lib/components/parasite/detail/index.js @@ -24,4 +24,17 @@ exports.default = OakComponent({ expiresAt: parasite === null || parasite === void 0 ? void 0 : parasite.expiresAt, }; }, + methods: { + copy: function (text) { + var _this = this; + if (text) { + navigator.clipboard.writeText(text).then(function () { + _this.setMessage({ + content: '复制成功', + type: 'success', + }); + }); + } + }, + } }); diff --git a/lib/components/parasite/detail/web.pc.d.ts b/lib/components/parasite/detail/web.pc.d.ts index 588ab1c33..1b04182de 100644 --- a/lib/components/parasite/detail/web.pc.d.ts +++ b/lib/components/parasite/detail/web.pc.d.ts @@ -6,4 +6,6 @@ export default function Render(props: WebComponentProps): import("react/jsx-runtime").JSX.Element; +}, { + copy: (text: string) => void; +}>): import("react/jsx-runtime").JSX.Element; diff --git a/lib/components/parasite/detail/web.pc.js b/lib/components/parasite/detail/web.pc.js index ff96c4d77..4baa61265 100644 --- a/lib/components/parasite/detail/web.pc.js +++ b/lib/components/parasite/detail/web.pc.js @@ -4,12 +4,25 @@ var tslib_1 = require("tslib"); var jsx_runtime_1 = require("react/jsx-runtime"); var qrCode_1 = tslib_1.__importDefault(require("../../../components/common/qrCode")); var antd_1 = require("antd"); +var icons_1 = require("@ant-design/icons"); function Render(props) { var _a = props.data, url = _a.url, expiresAt = _a.expiresAt, oakLoading = _a.oakLoading; + var copy = props.methods.copy; return oakLoading ? ((0, jsx_runtime_1.jsx)("div", tslib_1.__assign({ style: { display: 'flex', justifyContent: 'center', padding: '48px', - } }, { children: (0, jsx_runtime_1.jsx)(antd_1.Spin, { size: "large" }) }))) : ((0, jsx_runtime_1.jsx)(qrCode_1.default, { url: url, expiresAt: expiresAt })); + } }, { children: (0, jsx_runtime_1.jsx)(antd_1.Spin, { size: "large" }) }))) : ((0, jsx_runtime_1.jsxs)("div", tslib_1.__assign({ style: { + display: 'flex', + flexDirection: 'column', + justifyContent: 'center', + alignItems: 'center', + padding: '48px', + } }, { children: [(0, jsx_runtime_1.jsx)(qrCode_1.default, { url: url, expiresAt: expiresAt }), (0, jsx_runtime_1.jsxs)("div", tslib_1.__assign({ style: { + display: 'flex', + flexDirection: 'row', + justifyContent: 'center', + alignItems: 'center', + } }, { children: [url, (0, jsx_runtime_1.jsx)(antd_1.Button, tslib_1.__assign({ type: "text", icon: (0, jsx_runtime_1.jsx)(icons_1.CopyOutlined, {}), onClick: function () { return copy(url); } }, { children: "\u590D\u5236\u94FE\u63A5" }))] }))] }))); } exports.default = Render; diff --git a/lib/components/parasite/list/index.js b/lib/components/parasite/list/index.js index 52d80191a..b7ac814ce 100644 --- a/lib/components/parasite/list/index.js +++ b/lib/components/parasite/list/index.js @@ -16,6 +16,9 @@ exports.default = OakComponent({ nickname: 1, } }, + actions: [ + 'cancel' + ], properties: { entity: '', entityId: '', diff --git a/lib/components/parasite/list/web.d.ts b/lib/components/parasite/list/web.d.ts index 0c03d81da..0b2adc2c3 100644 --- a/lib/components/parasite/list/web.d.ts +++ b/lib/components/parasite/list/web.d.ts @@ -5,4 +5,9 @@ export default function render(props: WebComponentProps): import("react/jsx-runtime").JSX.Element; + qrCodeUrl: string; + qrCodeExpiresAt: number; +}, { + cancel: () => void; + getQrCode: () => Promise; +}>): import("react/jsx-runtime").JSX.Element; diff --git a/lib/components/parasite/list/web.js b/lib/components/parasite/list/web.js index aac011372..7bae904eb 100644 --- a/lib/components/parasite/list/web.js +++ b/lib/components/parasite/list/web.js @@ -5,50 +5,119 @@ var jsx_runtime_1 = require("react/jsx-runtime"); var antd_1 = require("antd"); var dayjs_1 = tslib_1.__importDefault(require("dayjs")); var web_module_less_1 = tslib_1.__importDefault(require("./web.module.less")); +var actionBtnPanel_1 = tslib_1.__importDefault(require("@oak-frontend-base/components/actionBtnPanel")); +var detail_1 = tslib_1.__importDefault(require("../detail")); +var react_1 = require("react"); function render(props) { - var _a = props.data, oakPagination = _a.oakPagination, oakFullpath = _a.oakFullpath, _b = _a.list, list = _b === void 0 ? [] : _b, oakLoading = _a.oakLoading, variant = _a.variant; + var _this = this; + var _a = props.data, oakPagination = _a.oakPagination, oakFullpath = _a.oakFullpath, _b = _a.list, list = _b === void 0 ? [] : _b, oakLoading = _a.oakLoading, variant = _a.variant, qrCodeUrl = _a.qrCodeUrl, qrCodeExpiresAt = _a.qrCodeExpiresAt; var _c = oakPagination || {}, pageSize = _c.pageSize, total = _c.total, currentPage = _c.currentPage; - var _d = props.methods, t = _d.t, setPageSize = _d.setPageSize, setCurrentPage = _d.setCurrentPage; - return ((0, jsx_runtime_1.jsx)(Container, tslib_1.__assign({ variant: variant }, { children: (0, jsx_runtime_1.jsx)(antd_1.Table, { loading: oakLoading, dataSource: list, rowKey: "id", columns: [ - { - dataIndex: 'id', - title: '#', - render: function (value, record, index) { - return index + 1; + var _d = props.methods, t = _d.t, setPageSize = _d.setPageSize, setCurrentPage = _d.setCurrentPage, updateItem = _d.updateItem, execute = _d.execute, getQrCode = _d.getQrCode; + var _e = tslib_1.__read((0, react_1.useState)(false), 2), qrCodeOpen = _e[0], setQrCodeOpen = _e[1]; + var _f = tslib_1.__read((0, react_1.useState)(''), 2), parasiteId = _f[0], setParasiteId = _f[1]; + return ((0, jsx_runtime_1.jsxs)(Container, tslib_1.__assign({ variant: variant }, { children: [(0, jsx_runtime_1.jsx)(antd_1.Table, { loading: oakLoading, dataSource: list, rowKey: "id", columns: [ + { + dataIndex: 'id', + title: '#', + render: function (value, record, index) { + return index + 1; + }, }, - }, - { - dataIndex: ['user', 'nickname'], - title: '姓名', - render: function (value, record, index) { - return value || '--'; + { + dataIndex: ['user', 'nickname'], + title: '姓名', + render: function (value, record, index) { + return value || '--'; + }, }, - }, - { - dataIndex: '$$createAt$$', - title: '创建时间', - render: function (value, record, index) { - return (0, dayjs_1.default)(value).format('YYYY-MM-DD HH:mm'); + { + dataIndex: '$$createAt$$', + title: '创建时间', + render: function (value, record, index) { + return (0, dayjs_1.default)(value).format('YYYY-MM-DD HH:mm'); + }, }, - }, - { - dataIndex: 'expired', - title: '状态', - render: function (value, record, index) { - return ((0, jsx_runtime_1.jsxs)(antd_1.Typography.Text, tslib_1.__assign({ type: record.expired ? 'danger' : 'success' }, { children: [record.expired ? '失效' : '有效', !record.expired && ((0, jsx_runtime_1.jsxs)(antd_1.Typography.Text, { children: ["\u00A0", (0, dayjs_1.default)(record.expiresAt).format('YYYY-MM-DD HH:mm')] }))] }))); + { + dataIndex: 'expired', + title: '状态', + render: function (value, record, index) { + return ((0, jsx_runtime_1.jsxs)(antd_1.Typography.Text, tslib_1.__assign({ type: record.expired ? 'danger' : 'success' }, { children: [record.expired ? '失效' : '有效', !record.expired && ((0, jsx_runtime_1.jsxs)(antd_1.Typography.Text, { children: ["\u00A0", (0, dayjs_1.default)(record.expiresAt).format('YYYY-MM-DD HH:mm')] }))] }))); + }, }, - }, - ], pagination: { - total: total, - pageSize: pageSize, - current: currentPage, - onShowSizeChange: function (pageSize) { - setPageSize(pageSize); - }, - onChange: function (current) { - setCurrentPage(current); - }, - } }) }))); + // { + // dataIndex: 'op', + // width: 200, + // title: '操作', + // align: 'center', + // render: (value, record, index) => { + // return ( + // <> + // + // + // ); + // }, + // fixed: 'right', + // }, + { + width: 200, + title: '操作', + key: 'action', + align: 'center', + fixed: 'right', + render: function (value, record, rowIndex) { + var _a; + return ((0, jsx_runtime_1.jsx)(actionBtnPanel_1.default, { mode: "table-cell", entity: "parasite", items: [ + { + label: '失效', + action: 'cancel', + // alerted: true, + show: (_a = record['#oakLegalActions']) === null || _a === void 0 ? void 0 : _a.includes('cancel'), + onClick: function () { + updateItem({ expired: true }, record.id, 'cancel'); + execute(); + }, + }, + { + label: '采集码', + // alerted: true, + onClick: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { + return tslib_1.__generator(this, function (_a) { + setParasiteId(record.id); + setQrCodeOpen(true); + return [2 /*return*/]; + }); + }); }, + }, + ] })); + }, + } + ], pagination: { + total: total, + pageSize: pageSize, + current: currentPage, + onShowSizeChange: function (pageSize) { + setPageSize(pageSize); + }, + onChange: function (current) { + setCurrentPage(current); + }, + } }), (0, jsx_runtime_1.jsx)(antd_1.Modal, tslib_1.__assign({ width: 786, open: qrCodeOpen, destroyOnClose: true, onCancel: function () { + setQrCodeOpen(false); + }, footer: null }, { children: (0, jsx_runtime_1.jsx)(detail_1.default, { oakId: parasiteId, oakAutoUnmount: true, oakPath: "$parasite/list-parasite/detail" }) }))] }))); } exports.default = render; function Container(props) { diff --git a/lib/context/BackendRuntimeContext.js b/lib/context/BackendRuntimeContext.js index c6a5e307a..5226e079a 100644 --- a/lib/context/BackendRuntimeContext.js +++ b/lib/context/BackendRuntimeContext.js @@ -342,11 +342,11 @@ var BackendRuntimeContext = /** @class */ (function (_super) { if (userState === 'disabled') { throw new Exception_1.OakUserDisabledException('您的帐号已经被禁用,请联系客服'); } - else if (['shadow', 'merged'].includes(userState)) { + else if (['merged'].includes(userState)) { throw new Exception_1.OakTokenExpiredException('您的登录状态有异常,请重新登录 '); } else { - (0, assert_1.default)(userState === 'normal'); + (0, assert_1.default)(userState === 'normal'|| userState === 'shadow'); } return true; } diff --git a/lib/context/FrontendRuntimeContext.js b/lib/context/FrontendRuntimeContext.js index 24c960748..6ef170ee7 100644 --- a/lib/context/FrontendRuntimeContext.js +++ b/lib/context/FrontendRuntimeContext.js @@ -72,11 +72,11 @@ var FrontendRuntimeContext = /** @class */ (function (_super) { if (userState === 'disabled') { throw new Exception_1.OakUserDisabledException('您的帐号已经被禁用,请联系客服'); } - else if (['shadow', 'merged'].includes(userState)) { + else if (['merged'].includes(userState)) { throw new Exception_1.OakTokenExpiredException('您的登录状态有异常,请重新登录 '); } else { - (0, assert_1.default)(userState === 'normal'); + (0, assert_1.default)(userState === 'normal'|| userState === 'shadow'); } return true; } diff --git a/lib/entities/Parasite.js b/lib/entities/Parasite.js index 4ab3c30d4..4e51eacbb 100644 --- a/lib/entities/Parasite.js +++ b/lib/entities/Parasite.js @@ -18,6 +18,7 @@ var locale = { action: { wakeup: '激活', cancel: '作废', + qrcode: '采集码' }, }, }; diff --git a/lib/general-app-domain/Parasite/Action.d.ts b/lib/general-app-domain/Parasite/Action.d.ts index 8e9ead1eb..8161fa276 100644 --- a/lib/general-app-domain/Parasite/Action.d.ts +++ b/lib/general-app-domain/Parasite/Action.d.ts @@ -1,5 +1,5 @@ import { GenericAction } from "oak-domain/lib/actions/action"; -export declare type IAction = 'wakeup' | 'cancel' | string; +export declare type IAction = 'wakeup' | 'cancel' | 'qrcode' | string; export declare type ParticularAction = IAction; export declare type Action = GenericAction | ParticularAction | string; export declare const actions: string[]; diff --git a/lib/general-app-domain/Parasite/Action.js b/lib/general-app-domain/Parasite/Action.js index 70bc1284b..cb834cb89 100644 --- a/lib/general-app-domain/Parasite/Action.js +++ b/lib/general-app-domain/Parasite/Action.js @@ -1,5 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ActionDefDict = exports.actions = void 0; -exports.actions = ["count", "stat", "download", "select", "aggregate", "create", "remove", "update", "wakeup", "cancel"]; +exports.actions = ["count", "stat", "download", "select", "aggregate", "create", "remove", "update", "wakeup", "cancel", "qrcode"]; exports.ActionDefDict = {}; diff --git a/lib/general-app-domain/Parasite/locales/zh_CN.json b/lib/general-app-domain/Parasite/locales/zh_CN.json index 1c1dfc61a..b435960b9 100644 --- a/lib/general-app-domain/Parasite/locales/zh_CN.json +++ b/lib/general-app-domain/Parasite/locales/zh_CN.json @@ -1 +1 @@ -{ "name": "寄生", "attr": { "user": "用户", "showTip": "提示", "expired": "已过期", "expiresAt": "过期时间", "redirectTo": "重定向页面", "multiple": "允许反复使用", "tokens": "令牌", "entity": "关联对象", "entityId": "关联对象Id", "tokenLifeLength": "令牌生命长度" }, "action": { "wakeup": "激活", "cancel": "作废" } } +{ "name": "寄生", "attr": { "user": "用户", "showTip": "提示", "expired": "已过期", "expiresAt": "过期时间", "redirectTo": "重定向页面", "multiple": "允许反复使用", "tokens": "令牌", "entity": "关联对象", "entityId": "关联对象Id", "tokenLifeLength": "令牌生命长度" }, "action": { "wakeup": "激活", "cancel": "作废", "qrcode": "采集码" } } diff --git a/src/checkers/parasite.ts b/src/checkers/parasite.ts index 0bb39d4ea..0fc7ebb51 100644 --- a/src/checkers/parasite.ts +++ b/src/checkers/parasite.ts @@ -59,6 +59,24 @@ const checkers: Checker[] = [ ); }, }, + { + type: 'row', + entity: 'parasite', + action: ['cancel'], + errMsg: '您没有设置失效的权限', + filter: { + expired: false, + }, + }, + { + type: 'row', + entity: 'parasite', + action: ['qrcode'], + errMsg: '您没有查看二维码的权限', + filter: { + expired: false, + }, + }, ]; export default checkers; diff --git a/src/components/parasite/list/index.ts b/src/components/parasite/list/index.ts index b095e7b9b..2f05ba7e3 100644 --- a/src/components/parasite/list/index.ts +++ b/src/components/parasite/list/index.ts @@ -14,6 +14,10 @@ export default OakComponent({ nickname: 1, } }, + actions: [ + 'cancel', + 'qrcode' + ], properties: { entity: '', entityId: '', @@ -47,5 +51,6 @@ export default OakComponent({ data: { open: false, }, - methods: {}, + methods: { + }, }); diff --git a/src/components/parasite/list/web.tsx b/src/components/parasite/list/web.tsx index a8e377023..43f6b9dfd 100644 --- a/src/components/parasite/list/web.tsx +++ b/src/components/parasite/list/web.tsx @@ -1,10 +1,12 @@ import * as React from 'react'; -import { Table, Space, Typography } from 'antd'; +import { Table, Button, Typography, Modal } from 'antd'; import dayjs from 'dayjs'; import { WebComponentProps } from 'oak-frontend-base'; import { EntityDict } from '../../../general-app-domain'; import Style from './web.module.less'; - +import ActionBtnPanel from '@oak-frontend-base/components/actionBtnPanel'; +import ParasiteDetail from '../detail'; +import { useState } from 'react'; export default function render( props: WebComponentProps< EntityDict, @@ -15,8 +17,13 @@ export default function render( list: EntityDict['userEntityGrant']['Schema'][]; showBack: boolean; variant?: 'inline' | 'alone' | 'dialog'; + qrCodeUrl: string; + qrCodeExpiresAt: number; }, - {} + { + cancel: () => void; + getQrCode: () => Promise; + } > ) { const { @@ -25,12 +32,16 @@ export default function render( list = [], oakLoading, variant, + qrCodeUrl, + qrCodeExpiresAt, } = props.data; + const { pageSize, total, currentPage } = oakPagination || {}; - const { t, setPageSize, setCurrentPage } = props.methods; - + const { t, setPageSize, setCurrentPage, updateItem, execute, getQrCode } = props.methods; + const [qrCodeOpen, setQrCodeOpen] = useState(false); + const [parasiteId, setParasiteId] = useState(''); return ( { + // return ( + // <> + // + // + // ); + // }, + // fixed: 'right', + // }, + { + width: 200, + title: '操作', + key: 'action', + align: 'center', + fixed: 'right', + render: (value, record, rowIndex) => { + return ( + { + updateItem( + { expired: true }, + record.id!, + 'cancel' + ); + execute(); + }, + }, + { + label: '采集码', + action: 'qrcode', + show: record[ + '#oakLegalActions' + ]?.includes('qrcode'), + // alerted: true, + onClick: async () => { + setParasiteId(record.id!) + setQrCodeOpen(true); + }, + }, + ]} + /> + ); + }, + } ]} pagination={{ total, @@ -93,6 +177,21 @@ export default function render( }, }} /> + { + setQrCodeOpen(false); + }} + footer={null} + > + + ); } diff --git a/src/context/BackendRuntimeContext.ts b/src/context/BackendRuntimeContext.ts index 63b8bc152..cad718b83 100644 --- a/src/context/BackendRuntimeContext.ts +++ b/src/context/BackendRuntimeContext.ts @@ -21,8 +21,7 @@ import { getMpUnlimitWxaCode } from '../aspects/wechatQrCode'; */ export class BackendRuntimeContext extends AsyncContext - implements RuntimeContext -{ + implements RuntimeContext { protected application?: Partial; protected token?: Partial; protected amIRoot?: boolean; @@ -299,12 +298,12 @@ export class BackendRuntimeContext throw new OakUserDisabledException( '您的帐号已经被禁用,请联系客服' ); - } else if (['shadow', 'merged'].includes(userState!)) { + } else if (['merged'].includes(userState!)) { throw new OakTokenExpiredException( '您的登录状态有异常,请重新登录 ' ); } else { - assert(userState === 'normal'); + assert(userState === 'normal' || userState === 'shadow'); } return true; } diff --git a/src/context/FrontendRuntimeContext.ts b/src/context/FrontendRuntimeContext.ts index 0f2cd1273..b24d881c3 100644 --- a/src/context/FrontendRuntimeContext.ts +++ b/src/context/FrontendRuntimeContext.ts @@ -23,7 +23,7 @@ export class FrontendRuntimeContext< ED extends EntityDict, Cxt extends BackendRuntimeContext, AD extends AspectDict - > extends SyncContext implements RuntimeContext { +> extends SyncContext implements RuntimeContext { private application?: Application; private token?: Token; constructor(store: SyncRowStore>, application?: Application, AD>, token?: Token, AD>) { @@ -57,7 +57,7 @@ export class FrontendRuntimeContext< return this.token?.getUserId(allowUnloggedIn, this); } - toString(): string{ + toString(): string { const data = { }; const a = this.application?.getApplicationId(); @@ -90,11 +90,11 @@ export class FrontendRuntimeContext< if (userState === 'disabled') { throw new OakUserDisabledException('您的帐号已经被禁用,请联系客服'); } - else if (['shadow', 'merged'].includes(userState!)) { + else if (['merged'].includes(userState!)) { throw new OakTokenExpiredException('您的登录状态有异常,请重新登录 '); } else { - assert(userState === 'normal'); + assert(userState === 'normal' || userState === 'shadow'); } return true; } diff --git a/src/entities/Parasite.ts b/src/entities/Parasite.ts index eb72c761e..7d76f6643 100644 --- a/src/entities/Parasite.ts +++ b/src/entities/Parasite.ts @@ -30,7 +30,7 @@ export interface Schema extends EntityShape { tokens: Token[]; } -type IAction = 'wakeup' | 'cancel'; +type IAction = 'wakeup' | 'cancel' | 'qrcode'; type Action = IAction; const locale: LocaleDef = { @@ -51,6 +51,7 @@ const locale: LocaleDef = { action: { wakeup: '激活', cancel: '作废', + qrcode: '采集码' }, }, };