From 7d4e475a618860a2d9318689aa5d95122220545e Mon Sep 17 00:00:00 2001 From: MXWXZ Date: Sat, 14 Sep 2024 15:20:26 +0800 Subject: [PATCH] fix oneshell --- Makefile | 1 - plugin/task/frontend/src/app.tsx | 27 +--- plugin/task/frontend/src/common_components | 1 + .../common_components/layout/container.tsx | 35 ----- .../src/common_components/layout/exschema.tsx | 77 ---------- .../src/common_components/layout/index.tsx | 44 ------ .../src/common_components/layout/modal.tsx | 25 --- .../common_components/layout/modalSchema.tsx | 80 ---------- .../src/common_components/layout/rowItem.tsx | 29 ---- .../common_components/layout/table/column.tsx | 124 --------------- .../layout/table/deleteBtn.tsx | 68 -------- .../common_components/layout/table/index.tsx | 81 ---------- .../common_components/layout/table/newBtn.tsx | 26 ---- .../common_components/layout/table/opBtn.tsx | 38 ----- .../common_components/layout/table/style.less | 3 - .../layout/table/tableBtn.tsx | 35 ----- plugin/task/frontend/src/common_locales | 1 + .../task/frontend/src/common_locales/en-US.ts | 32 ---- .../task/frontend/src/common_locales/zh-CN.ts | 32 ---- plugin/task/frontend/src/common_pages | 1 + plugin/task/frontend/src/common_pages/403.tsx | 29 ---- plugin/task/frontend/src/common_pages/404.tsx | 29 ---- plugin/task/frontend/src/utils.ts | 145 +----------------- 23 files changed, 5 insertions(+), 958 deletions(-) mode change 100644 => 120000 plugin/task/frontend/src/app.tsx create mode 120000 plugin/task/frontend/src/common_components delete mode 100644 plugin/task/frontend/src/common_components/layout/container.tsx delete mode 100644 plugin/task/frontend/src/common_components/layout/exschema.tsx delete mode 100644 plugin/task/frontend/src/common_components/layout/index.tsx delete mode 100644 plugin/task/frontend/src/common_components/layout/modal.tsx delete mode 100644 plugin/task/frontend/src/common_components/layout/modalSchema.tsx delete mode 100644 plugin/task/frontend/src/common_components/layout/rowItem.tsx delete mode 100644 plugin/task/frontend/src/common_components/layout/table/column.tsx delete mode 100644 plugin/task/frontend/src/common_components/layout/table/deleteBtn.tsx delete mode 100644 plugin/task/frontend/src/common_components/layout/table/index.tsx delete mode 100644 plugin/task/frontend/src/common_components/layout/table/newBtn.tsx delete mode 100644 plugin/task/frontend/src/common_components/layout/table/opBtn.tsx delete mode 100644 plugin/task/frontend/src/common_components/layout/table/style.less delete mode 100644 plugin/task/frontend/src/common_components/layout/table/tableBtn.tsx create mode 120000 plugin/task/frontend/src/common_locales delete mode 100644 plugin/task/frontend/src/common_locales/en-US.ts delete mode 100644 plugin/task/frontend/src/common_locales/zh-CN.ts create mode 120000 plugin/task/frontend/src/common_pages delete mode 100644 plugin/task/frontend/src/common_pages/403.tsx delete mode 100644 plugin/task/frontend/src/common_pages/404.tsx mode change 100644 => 120000 plugin/task/frontend/src/utils.ts diff --git a/Makefile b/Makefile index 1cf09e6..45e4a67 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,6 @@ else endif endif -.ONESHELL: .PHONY: check build build_release run dev static static_plugin clean help all: help diff --git a/plugin/task/frontend/src/app.tsx b/plugin/task/frontend/src/app.tsx deleted file mode 100644 index 5df7f78..0000000 --- a/plugin/task/frontend/src/app.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { RequestConfig } from '@umijs/max'; -import { message } from 'antd'; -import 'antd/dist/reset.css'; -import { stringify } from 'qs'; - -export const request: RequestConfig = { - baseURL: '/api', - timeout: 10000, - paramsSerializer: function (params) { - return stringify(params, { encodeValuesOnly: true }); - }, - errorConfig: { - errorHandler: (error: any, opts: any) => { - if (opts?.skipErrorHandler) throw error; - if (error.response) { - message.error(`${error.response.status}: ${error.response.statusText}`); - if (error.response.status === 403) - setTimeout(() => { - window.location.href = '/'; - }, 1000); - } else { - message.error('Unknown error'); - } - }, - }, -}; diff --git a/plugin/task/frontend/src/app.tsx b/plugin/task/frontend/src/app.tsx new file mode 120000 index 0000000..a6ef6ba --- /dev/null +++ b/plugin/task/frontend/src/app.tsx @@ -0,0 +1 @@ +../../../common/app.tsx \ No newline at end of file diff --git a/plugin/task/frontend/src/common_components b/plugin/task/frontend/src/common_components new file mode 120000 index 0000000..c208b13 --- /dev/null +++ b/plugin/task/frontend/src/common_components @@ -0,0 +1 @@ +../../../common/components \ No newline at end of file diff --git a/plugin/task/frontend/src/common_components/layout/container.tsx b/plugin/task/frontend/src/common_components/layout/container.tsx deleted file mode 100644 index b502c9a..0000000 --- a/plugin/task/frontend/src/common_components/layout/container.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import { getIntl } from '@/utils'; -import { PageContainer, PageContainerProps } from '@ant-design/pro-layout'; -import { BreadcrumbItemType } from 'antd/es/breadcrumb/Breadcrumb'; - -export interface MainContainerProps { - routes: BreadcrumbItemType[]; -} - -const MainContainer: React.FC = ( - props, -) => { - const intl = getIntl(); - props.routes.forEach((item) => { - if (typeof item.title === 'string') item.title = intl.get(item.title); - }); - return ( - - {props.children} - - ); -}; - -export default MainContainer; diff --git a/plugin/task/frontend/src/common_components/layout/exschema.tsx b/plugin/task/frontend/src/common_components/layout/exschema.tsx deleted file mode 100644 index 415b785..0000000 --- a/plugin/task/frontend/src/common_components/layout/exschema.tsx +++ /dev/null @@ -1,77 +0,0 @@ -import { BetaSchemaForm } from '@ant-design/pro-components'; -import { FormSchema } from '@ant-design/pro-components/node_modules/@ant-design/pro-form/es/components/SchemaForm'; -import { isEqual } from 'lodash'; -import { forwardRef, useImperativeHandle, useRef, useState } from 'react'; - -export interface ExSchemaProps { - perm_disabled?: boolean; - onSubmit: ( - param: Record, - initial: Record, - ) => Promise; -} - -export type ExSchemaHandle = { - enableSubmit: (enable: boolean) => void; - refresh: () => void; -}; - -const ExSchema = forwardRef< - ExSchemaHandle | undefined, - ExSchemaProps & FormSchema ->((props: ExSchemaProps & FormSchema, ref) => { - const { onSubmit, ...rest } = props; - const [changed, setChanged] = useState(false); - const data = useRef<{ [key: string]: any }>({}); - const [seed, setSeed] = useState(0); - - useImperativeHandle( - ref, - () => { - return { - enableSubmit(enable: boolean) { - setChanged(enable); - }, - refresh() { - setSeed(seed + 1); - }, - }; - }, - [seed, changed], - ); - - return ( - setChanged(false), - resetButtonProps: { disabled: props.perm_disabled }, - submitButtonProps: { disabled: props.perm_disabled || !changed }, - render: (_, dom) => [...dom.reverse()], - }} - // BUG: props.initialvalues is undefined - onInit={(v) => { - data.current = v; - setChanged(false); - }} - onValuesChange={(_: any, all: Record) => { - for (let k in all) { - // possible object - if (!isEqual(data.current[k], all[k])) { - setChanged(true); - return; - } - } - setChanged(false); - }} - onFinish={(v) => - onSubmit?.(v, data.current).then((rsp) => { - if (rsp) setSeed(seed + 1); - }) - } - {...rest} - /> - ); -}); - -export default ExSchema; diff --git a/plugin/task/frontend/src/common_components/layout/index.tsx b/plugin/task/frontend/src/common_components/layout/index.tsx deleted file mode 100644 index 36a18c5..0000000 --- a/plugin/task/frontend/src/common_components/layout/index.tsx +++ /dev/null @@ -1,44 +0,0 @@ -import DeniedPage from '@/pages/403'; -import { checkPerm, getIntl, UserPerm } from '@/utils'; -import { Access, Helmet, useModel } from '@umijs/max'; -import React, { PropsWithChildren, ReactNode, useEffect } from 'react'; - -export interface MainLayoutProps { - title?: string; - access?: string; - perm?: UserPerm; -} - -const MainLayout: React.FC> = (props) => { - const { initialState, access } = useModel('@@qiankunStateFromMaster'); - const intl = getIntl(); - - useEffect(() => { - if (!initialState?.signin) window.location.href = '/'; - }, []); - - let children: ReactNode; - if (props.access && props.perm !== undefined) - children = ( - - {props.children} - - ); - else children = props.children; - - return ( - <> - {props.title && ( - - {intl.get(props.title)} - - )} - {children} - - ); -}; - -export default MainLayout; diff --git a/plugin/task/frontend/src/common_components/layout/modal.tsx b/plugin/task/frontend/src/common_components/layout/modal.tsx deleted file mode 100644 index 4cf1cbc..0000000 --- a/plugin/task/frontend/src/common_components/layout/modal.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import { StringIntl } from "@/utils"; -import { ExclamationCircleTwoTone } from "@ant-design/icons"; -import { Modal, ModalFuncProps } from "antd"; - -export interface confirmProps { - title: string; - content: string; - intl: StringIntl; -} - -const confirm = (props: confirmProps & ModalFuncProps) => { - const { title, content, intl, ...rest } = props; - Modal.confirm({ - title: title, - content: content, - icon: , - okType: "danger", - okText: props.intl.get("app.ok"), - cancelText: props.intl.get("app.cancel"), - onCancel() {}, - ...rest, - }); -}; - -export default confirm; diff --git a/plugin/task/frontend/src/common_components/layout/modalSchema.tsx b/plugin/task/frontend/src/common_components/layout/modalSchema.tsx deleted file mode 100644 index 7dee13f..0000000 --- a/plugin/task/frontend/src/common_components/layout/modalSchema.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import { BetaSchemaForm, ProFormInstance } from '@ant-design/pro-form'; -import { FormSchema } from '@ant-design/pro-form/es/components/SchemaForm'; -import { Modal } from 'antd'; -import { isEqual } from 'lodash'; -import React, { useRef, useState } from 'react'; - -export interface ModalSchemaProps { - trigger?: JSX.Element; - title?: React.ReactNode; - width?: string | number; - schemaProps: FormSchema; - changedSubmit?: boolean; -} - -// bug in BetaSchemaForm ModalForm, split manually. -const ModalSchema: React.FC = (props) => { - const formRef = useRef(null); - const [open, setOpen] = useState(false); - const [confirmLoading, setConfirmLoading] = useState(false); - const [changed, setChanged] = useState(false); - const trigger = props.trigger ? ( - React.cloneElement(props.trigger, { - onClick: () => { - setOpen(true); - setChanged(false); // reopen modal will not refresh 'changed' - }, - }) - ) : ( - <> - ); - const ok = () => { - setConfirmLoading(true); - formRef.current - ?.validateFields() - .then(async () => { - if ( - await props.schemaProps?.onFinish?.(formRef.current?.getFieldsValue()) - ) - setOpen(false); - }) - .catch(() => {}) - .finally(() => setConfirmLoading(false)); - }; - - return ( - <> - {trigger} - setOpen(false)} - destroyOnClose={true} - width={props.width} - confirmLoading={confirmLoading} - onOk={ok} - okButtonProps={{ disabled: props.changedSubmit ? !changed : false }} - maskClosable={false} - > - ) => { - if (props.schemaProps.initialValues) - for (let k in all) { - // possible object - if (!isEqual(props.schemaProps.initialValues[k], all[k])) { - setChanged(true); - return; - } - } - setChanged(false); - }} - {...props.schemaProps} - /> - - - ); -}; -export default ModalSchema; diff --git a/plugin/task/frontend/src/common_components/layout/rowItem.tsx b/plugin/task/frontend/src/common_components/layout/rowItem.tsx deleted file mode 100644 index 64a8a49..0000000 --- a/plugin/task/frontend/src/common_components/layout/rowItem.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import { ColSpanType } from '@ant-design/pro-card/es/typing'; -import { Col, Row } from 'antd'; - -export interface SpanType { - xs?: ColSpanType; - md?: ColSpanType; -} - -export interface RowItemProps { - span?: SpanType; - nextSpan?: SpanType; - text: React.ReactNode; - item: React.ReactNode; - nospace?: boolean; -} -const RowItem: React.FC = (props) => { - return ( - - - {props.text} - - - {props.item} - - - ); -}; - -export default RowItem; diff --git a/plugin/task/frontend/src/common_components/layout/table/column.tsx b/plugin/task/frontend/src/common_components/layout/table/column.tsx deleted file mode 100644 index 3bab588..0000000 --- a/plugin/task/frontend/src/common_components/layout/table/column.tsx +++ /dev/null @@ -1,124 +0,0 @@ -import { StringIntl } from '@/utils'; -import { ProFormColumnsType } from '@ant-design/pro-form'; -import { ProColumns } from '@ant-design/pro-table'; -import { Tag } from 'antd'; -import { CustomTagProps } from 'rc-select/es/BaseSelect'; - -export type Columns = (intl: StringIntl) => ProFormColumnsType[]; -export type Column = (intl: StringIntl) => ProFormColumnsType; - -export const IDColumn: (intl: StringIntl) => ProColumns = (intl) => { - return { - title: intl.get('app.table.id'), - ellipsis: true, - dataIndex: 'id', - align: 'center', - copyable: true, - hideInSearch: true, - onCell: () => { - return { - style: { - minWidth: 150, - maxWidth: 150, - }, - }; - }, - }; -}; - -export const SearchColumn: (intl: StringIntl) => ProColumns = (intl) => { - return { - title: intl.get('app.table.searchtext'), - key: 'text', - hideInTable: true, - }; -}; - -export const CreatedAtColumn: (intl: StringIntl) => ProColumns[] = (intl) => [ - { - title: intl.get('app.table.createdat'), - dataIndex: 'created_at', - align: 'center', - valueType: 'dateTime', - sorter: true, - hideInSearch: true, - }, - { - title: intl.get('app.table.createdat'), - dataIndex: 'created_at', - valueType: 'dateRange', - hideInTable: true, - search: { - transform: (value) => { - return { - createdStart: value[0], - createdEnd: value[1], - }; - }, - }, - }, -]; - -export const UpdatedAtColumn: (intl: StringIntl) => ProColumns[] = (intl) => [ - { - title: intl.get('app.table.updatedat'), - dataIndex: 'updated_at', - align: 'center', - valueType: 'dateTime', - sorter: true, - hideInSearch: true, - }, - { - title: intl.get('app.table.updatedat'), - dataIndex: 'updated_at', - valueType: 'dateRange', - hideInTable: true, - search: { - transform: (value) => { - return { - updatedStart: value[0], - updatedEnd: value[1], - }; - }, - }, - }, -]; - -export const StatusColumn: ( - title: string, - index: string, - status: { [Key: number]: { label: string; color: string } }, -) => ProColumns = (title, index, status) => { - return { - title: title, - dataIndex: index, - align: 'center', - valueType: 'select', - fieldProps: { - mode: 'multiple', - tagRender: (props: CustomTagProps) => { - // BUG: rc-select undefined value - if (props.value) - return ( - - {props.label} - - ); - }, - }, - valueEnum: Object.entries(status).reduce( - (p, c) => ({ ...p, [c[0]]: { text: c[1].label } }), - {}, - ), - render: (_, row) => ( - - {status[row[index]].label} - - ), - }; -}; diff --git a/plugin/task/frontend/src/common_components/layout/table/deleteBtn.tsx b/plugin/task/frontend/src/common_components/layout/table/deleteBtn.tsx deleted file mode 100644 index f72f652..0000000 --- a/plugin/task/frontend/src/common_components/layout/table/deleteBtn.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import { deleleAPI, getIntl, StringIntl, UserPerm } from "@/utils"; -import { DeleteOutlined } from "@ant-design/icons"; -import { ActionType } from "@ant-design/pro-table"; -import confirm from "../modal"; -import TableBtn from "./tableBtn"; - -export interface TableDeleteProps { - disabled?: boolean; - perm?: UserPerm; - permName?: string; - tableRef: React.MutableRefObject; - url: string; - confirmTitle: string; - confirmContent?: string; - confirmData?: {}; -} - -const handleDelete = async ( - intl: StringIntl, - ref: React.MutableRefObject, - url: string, - title: string, - content?: string, - data?: any -) => { - confirm({ - title: title, - content: content ? content : intl.get("app.confirm"), - onOk() { - return new Promise((resolve, reject) => { - deleleAPI(url, data ? data : {}).then((rsp) => { - if (rsp && rsp.code === 0) { - ref.current?.reloadAndRest?.(); - resolve(rsp); - } else { - reject(rsp); - } - }); - }); - }, - intl: intl, - }); -}; - -const TableDelete: React.FC = (props) => { - const intl = getIntl(); - return ( - - handleDelete( - intl, - props.tableRef, - props.url, - props.confirmTitle, - props.confirmContent, - props.confirmData - ) - } - /> - ); -}; -export default TableDelete; diff --git a/plugin/task/frontend/src/common_components/layout/table/index.tsx b/plugin/task/frontend/src/common_components/layout/table/index.tsx deleted file mode 100644 index 6d4d6f0..0000000 --- a/plugin/task/frontend/src/common_components/layout/table/index.tsx +++ /dev/null @@ -1,81 +0,0 @@ -import { getIntl } from '@/utils'; -import { LoadingOutlined, ReloadOutlined } from '@ant-design/icons'; -import { ParamsType } from '@ant-design/pro-provider'; -import ProTable, { ProTableProps } from '@ant-design/pro-table'; -import { Button } from 'antd'; -import moment from 'moment'; -import { useState } from 'react'; - -type TableProp = { - poll?: boolean; - action?: React.ReactNode[]; - postRequest?: (data: any[]) => any[]; -} & ProTableProps; - -function Table< - T extends Record, - U extends ParamsType = ParamsType, - ValueType = 'text', ->(props: TableProp) { - const intl = getIntl(); - const [polling, setPolling] = useState(true); - const [time, setTime] = useState(() => Date.now()); - const { postRequest, ...rest } = props; - - return ( - - scroll={{ x: 'auto' }} - polling={props.poll ? (polling ? 2000 : undefined) : undefined} - headerTitle={intl.get('app.table.lastupdate', { - time: moment(time).format('HH:mm:ss'), - })} - postData={(data: any[]) => { - setTime(Date.now()); - if (postRequest) return postRequest(data); - return data; - }} - toolbar={{ - actions: [ - props.poll - ? [ - props.action, - , - ] - : props.action, - ], - }} - cardBordered - bordered - search={{ - defaultCollapsed: false, - collapseRender: false, - }} - pagination={{ - defaultPageSize: 10, - pageSizeOptions: ['5', '10', '20', '50'], - showQuickJumper: true, - }} - options={{ - density: false, - }} - {...rest} - /> - ); -} - -export default Table; diff --git a/plugin/task/frontend/src/common_components/layout/table/newBtn.tsx b/plugin/task/frontend/src/common_components/layout/table/newBtn.tsx deleted file mode 100644 index f25b26d..0000000 --- a/plugin/task/frontend/src/common_components/layout/table/newBtn.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { PlusOutlined } from '@ant-design/icons'; -import { Button } from 'antd'; -import { FormattedMessage } from 'react-intl'; -import { ModalSchemaProps } from '../modalSchema'; -import TableOp, { TableOpProps } from './opBtn'; - -const TableNew: React.FC = (props) => { - return ( - - - - - } - rollback={ - - } - {...props} - /> - ); -}; -export default TableNew; diff --git a/plugin/task/frontend/src/common_components/layout/table/opBtn.tsx b/plugin/task/frontend/src/common_components/layout/table/opBtn.tsx deleted file mode 100644 index 1044a5c..0000000 --- a/plugin/task/frontend/src/common_components/layout/table/opBtn.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import { checkPerm, UserPerm } from "@/utils"; -import { useModel } from "@umijs/max"; -import { ReactElement } from "react"; -import ModalSchema, { ModalSchemaProps } from "../modalSchema"; - -export interface TableOpProps { - disabled?: boolean; - perm?: UserPerm; - permName?: string; - rollback?: ReactElement; -} - -const TableOp: React.FC = (props) => { - const { access } = useModel("@@qiankunStateFromMaster"); - if ( - props.disabled || - (props.perm && - props.permName && - !checkPerm(access, props.permName, props.perm)) - ) - return props.rollback ? props.rollback : <>; - else - return ( - - ); -}; -export default TableOp; diff --git a/plugin/task/frontend/src/common_components/layout/table/style.less b/plugin/task/frontend/src/common_components/layout/table/style.less deleted file mode 100644 index d2411a6..0000000 --- a/plugin/task/frontend/src/common_components/layout/table/style.less +++ /dev/null @@ -1,3 +0,0 @@ -.operation>div { - justify-content: center !important; -} diff --git a/plugin/task/frontend/src/common_components/layout/table/tableBtn.tsx b/plugin/task/frontend/src/common_components/layout/table/tableBtn.tsx deleted file mode 100644 index 3664843..0000000 --- a/plugin/task/frontend/src/common_components/layout/table/tableBtn.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import { checkPerm, UserPerm } from '@/utils'; -import { useModel } from '@umijs/max'; -import { Tooltip } from 'antd'; - -export interface TableBtnProps { - icon: React.ElementType; - tip: string; - onClick?: (event: any) => void; - color?: string; - disabled?: boolean; - perm?: UserPerm; - permName?: string; -} - -const TableBtn: React.FC = (props) => { - const { access } = useModel('@@qiankunStateFromMaster'); - const disabled = - props.disabled || - (props.perm && - props.permName && - !checkPerm(access, props.permName, props.perm)); - return ( - - - - ); -}; -export default TableBtn; diff --git a/plugin/task/frontend/src/common_locales b/plugin/task/frontend/src/common_locales new file mode 120000 index 0000000..64966f7 --- /dev/null +++ b/plugin/task/frontend/src/common_locales @@ -0,0 +1 @@ +../../../common/locales \ No newline at end of file diff --git a/plugin/task/frontend/src/common_locales/en-US.ts b/plugin/task/frontend/src/common_locales/en-US.ts deleted file mode 100644 index 05ff413..0000000 --- a/plugin/task/frontend/src/common_locales/en-US.ts +++ /dev/null @@ -1,32 +0,0 @@ -export default { - 'app.copyright.author': 'imwxz', - 'app.ok': 'OK', - 'app.cancel': 'Cancel', - 'app.confirm': 'This operation cannot be undone!', - 'app.filesize': 'File is too large, should be less than {size}', - - 'app.table.lastupdate': 'Last update: {time}', - 'app.table.polling.start': 'Poll', - 'app.table.polling.stop': 'Stop', - 'app.table.createdat': 'Created At', - 'app.table.updatedat': 'Updated At', - 'app.table.id': 'ID', - 'app.table.searchtext': 'Text', - - 'app.op': 'Operation', - 'app.op.delete': 'Delete', - 'app.op.deleteall': 'Delete All', - 'app.op.add': 'Add', - 'app.op.clone': 'Clone', - 'app.op.update': 'Update', - 'app.op.upload': 'Upload', - - 'titles.403': 'Skynet | 403', - 'titles.404': 'Skynet | 404', - - 'pages.404.text': 'Sorry, the page you visited does not exist.', - 'pages.404.backhome': 'Back Home', - - 'pages.403.text': "Sorry, you don't have access to this page.", - 'pages.403.backhome': 'Back Home', -}; diff --git a/plugin/task/frontend/src/common_locales/zh-CN.ts b/plugin/task/frontend/src/common_locales/zh-CN.ts deleted file mode 100644 index 5d296f0..0000000 --- a/plugin/task/frontend/src/common_locales/zh-CN.ts +++ /dev/null @@ -1,32 +0,0 @@ -export default { - 'app.copyright.author': 'imwxz', - 'app.ok': '确认', - 'app.cancel': '取消', - 'app.confirm': '此操作无法撤销!', - 'app.filesize': '文件过大,限制大小为{size}', - - 'app.table.lastupdate': '最后更新:{time}', - 'app.table.polling.start': '拉取', - 'app.table.polling.stop': '停止', - 'app.table.createdat': '创建时间', - 'app.table.updatedat': '更新时间', - 'app.table.id': 'ID', - 'app.table.searchtext': '搜索文本', - - 'app.op': '操作', - 'app.op.delete': '删除', - 'app.op.deleteall': '删除全部', - 'app.op.add': '添加', - 'app.op.clone': '克隆', - 'app.op.update': '更新', - 'app.op.upload': '上传', - - 'titles.403': 'Skynet | 403', - 'titles.404': 'Skynet | 404', - - 'pages.404.text': '抱歉,您访问的页面不存在。', - 'pages.404.backhome': '返回首页', - - 'pages.403.text': '抱歉,您没有权限访问该页面。', - 'pages.403.backhome': '返回首页', -}; diff --git a/plugin/task/frontend/src/common_pages b/plugin/task/frontend/src/common_pages new file mode 120000 index 0000000..2c02707 --- /dev/null +++ b/plugin/task/frontend/src/common_pages @@ -0,0 +1 @@ +../../../common/pages \ No newline at end of file diff --git a/plugin/task/frontend/src/common_pages/403.tsx b/plugin/task/frontend/src/common_pages/403.tsx deleted file mode 100644 index 0f3fc35..0000000 --- a/plugin/task/frontend/src/common_pages/403.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import { getIntl } from '@/utils'; -import { Helmet, MicroAppLink } from '@umijs/max'; -import { Button, Result } from 'antd'; -import { FormattedMessage } from 'react-intl'; - -const DeniedPage = () => { - const intl = getIntl(); - return ( - <> - - {intl.get('titles.403')} - - - - - } - /> - - ); -}; - -export default DeniedPage; diff --git a/plugin/task/frontend/src/common_pages/404.tsx b/plugin/task/frontend/src/common_pages/404.tsx deleted file mode 100644 index 68d118b..0000000 --- a/plugin/task/frontend/src/common_pages/404.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import { getIntl } from '@/utils'; -import { Helmet, MicroAppLink } from '@umijs/max'; -import { Button, Result } from 'antd'; -import { FormattedMessage } from 'react-intl'; - -const NoFoundPage = () => { - const intl = getIntl(); - return ( - <> - - {intl.get('titles.404')} - - - - - } - /> - - ); -}; - -export default NoFoundPage; diff --git a/plugin/task/frontend/src/utils.ts b/plugin/task/frontend/src/utils.ts deleted file mode 100644 index fe772ed..0000000 --- a/plugin/task/frontend/src/utils.ts +++ /dev/null @@ -1,144 +0,0 @@ -import { getLocale, request, useIntl } from "@umijs/max"; -import { message } from "antd"; -import { SortOrder } from "antd/es/table/interface"; -import { PrimitiveType } from "intl-messageformat"; -import Cookies from "js-cookie"; -import moment from "moment"; -import { IntlShape } from "react-intl"; - -export enum UserPerm { - PermBan = -1, - PermInherit = -1, - PermNone = 0, - PermWrite = 1, - PermRead = 1 << 1, - PermAll = (1 << 2) - 1, -} - -export function checkPerm( - access: { [Key: string]: UserPerm }, - name: string, - perm: UserPerm -) { - if (access["root"] !== undefined) return true; - if (access[name] !== undefined) return (access[name] & perm) === perm; - return false; -} - -export class StringIntl { - intl: IntlShape; - constructor(intl: IntlShape) { - this.intl = intl; - } - get(id: string, values?: Record) { - return this.intl.formatMessage( - { - id: id, - }, - values - ); - } -} - -export function getIntl() { - return new StringIntl(useIntl()); -} - -export function api( - method: string, - url: string, - params?: object, - data?: any, - headers?: any, - showmsg: boolean = false -) { - let obj = { - lang: getLocale(), - }; - if (params === undefined) params = obj; - else Object.assign(params, obj); - return request(url, { - method: method, - params: params, - data: data, - headers: headers, - }).then((rsp) => { - if (rsp) { - if (showmsg) { - if (rsp.code == 0) message.success(rsp.message); - else message.error(rsp.message); - } - return rsp; - } - }); -} - -export function withToken( - method: string, - url: string, - params?: object, - data?: any, - showmsg: boolean = false -) { - return request("/token", { - method: "get", - }).then((rsp) => { - if (rsp) - return api( - method, - url, - params, - data, - { - "X-CSRF-Token": Cookies.get("CSRF_TOKEN"), - }, - showmsg - ); - }); -} - -export function getAPI(url: string, params?: object, showmsg: boolean = false) { - return api("get", url, params, undefined, undefined, showmsg); -} - -export function postAPI(url: string, data: any, showmsg: boolean = true) { - return withToken("post", url, undefined, data, showmsg); -} - -export function putAPI(url: string, data: any, showmsg: boolean = true) { - return withToken("put", url, undefined, data, showmsg); -} - -export function deleleAPI(url: string, data: any, showmsg: boolean = true) { - return withToken("delete", url, undefined, data, showmsg); -} - -export async function checkAPI(ret: Promise) { - return await ret.then((rsp) => { - return rsp && rsp.code === 0; - }); -} - -export function paramSort(v?: SortOrder) { - if (v === "ascend") return "asc"; - else if (v === "descend") return "desc"; - return undefined; -} - -export function paramTime(v?: string, end?: boolean) { - return moment(v || 0).valueOf() + (v && end ? 86400000 : 0) || undefined; -} - -export const fileToBase64 = (file: File | undefined) => - new Promise((resolve: (value: string) => void, reject) => { - if (file === undefined) { - resolve(""); - } else { - const reader = new FileReader(); - reader.readAsDataURL(file); - reader.onload = () => { - resolve(reader.result as string); - }; - reader.onerror = (error) => reject(error); - } - }); diff --git a/plugin/task/frontend/src/utils.ts b/plugin/task/frontend/src/utils.ts new file mode 120000 index 0000000..f1d143e --- /dev/null +++ b/plugin/task/frontend/src/utils.ts @@ -0,0 +1 @@ +../../../common/utils.ts \ No newline at end of file