Преглед изворни кода

Merge pull request #2027 from visuddhinanda/agile

article 编辑 支持cancel 按钮
visuddhinanda пре 2 година
родитељ
комит
af833a2ee1

+ 21 - 0
dashboard/src/assets/icon/index.tsx

@@ -690,6 +690,23 @@ const AdminSvg = () => (
     ></path>
     ></path>
   </svg>
   </svg>
 );
 );
+
+const TabSvg = () => (
+  <svg
+    viewBox="0 0 1024 1024"
+    version="1.1"
+    xmlns="http://www.w3.org/2000/svg"
+    p-id="4260"
+    width="1em"
+    height="1em"
+  >
+    <path
+      d="M810.666667 810.666667 213.333333 810.666667 213.333333 213.333333 512 213.333333 512 384 810.666667 384M810.666667 128 213.333333 128C166.4 128 128 166.4 128 213.333333L128 810.666667C128 857.6 166.4 896 213.333333 896L810.666667 896C857.6 896 896 857.6 896 810.666667L896 213.333333C896 165.973333 857.6 128 810.666667 128Z"
+      fill="currentColor"
+      p-id="4261"
+    ></path>
+  </svg>
+);
 export const DictIcon = (props: Partial<CustomIconComponentProps>) => (
 export const DictIcon = (props: Partial<CustomIconComponentProps>) => (
   <Icon component={DictSvg} {...props} />
   <Icon component={DictSvg} {...props} />
 );
 );
@@ -822,3 +839,7 @@ export const MergeIcon2 = (props: Partial<CustomIconComponentProps>) => (
 export const AdminIcon = (props: Partial<CustomIconComponentProps>) => (
 export const AdminIcon = (props: Partial<CustomIconComponentProps>) => (
   <Icon component={AdminSvg} {...props} />
   <Icon component={AdminSvg} {...props} />
 );
 );
+
+export const TabIcon = (props: Partial<CustomIconComponentProps>) => (
+  <Icon component={TabSvg} {...props} />
+);

+ 38 - 0
dashboard/src/components/article/ArticleEdit.tsx

@@ -40,18 +40,24 @@ interface IWidget {
   studioName?: string;
   studioName?: string;
   articleId?: string;
   articleId?: string;
   anthologyId?: string;
   anthologyId?: string;
+  resetButton?: "reset" | "cancel";
   onReady?: Function;
   onReady?: Function;
   onLoad?: Function;
   onLoad?: Function;
   onChange?: Function;
   onChange?: Function;
+  onCancel?: Function;
+  onSubmit?: Function;
 }
 }
 
 
 const ArticleEditWidget = ({
 const ArticleEditWidget = ({
   studioName,
   studioName,
   articleId,
   articleId,
   anthologyId,
   anthologyId,
+  resetButton = "reset",
   onReady,
   onReady,
   onLoad,
   onLoad,
   onChange,
   onChange,
+  onCancel,
+  onSubmit,
 }: IWidget) => {
 }: IWidget) => {
   const intl = useIntl();
   const intl = useIntl();
   const [unauthorized, setUnauthorized] = useState(false);
   const [unauthorized, setUnauthorized] = useState(false);
@@ -92,6 +98,35 @@ const ArticleEditWidget = ({
       </div>
       </div>
       <ProForm<IFormData>
       <ProForm<IFormData>
         formRef={formRef}
         formRef={formRef}
+        submitter={{
+          // 完全自定义整个区域
+          render: (props, doms) => {
+            console.log(props);
+            return [
+              <Button
+                key="rest"
+                onClick={() => {
+                  if (resetButton === "reset") {
+                    props.form?.resetFields();
+                  } else {
+                    if (typeof onCancel !== "undefined") {
+                      onCancel();
+                    }
+                  }
+                }}
+              >
+                {resetButton === "reset" ? "重置" : "取消"}
+              </Button>,
+              <Button
+                type="primary"
+                key="submit"
+                onClick={() => props.form?.submit?.()}
+              >
+                提交
+              </Button>,
+            ];
+          },
+        }}
         onFinish={async (values: IFormData) => {
         onFinish={async (values: IFormData) => {
           const request: IArticleDataRequest = {
           const request: IArticleDataRequest = {
             uid: articleId ? articleId : "",
             uid: articleId ? articleId : "",
@@ -114,6 +149,9 @@ const ArticleEditWidget = ({
                 if (typeof onChange !== "undefined") {
                 if (typeof onChange !== "undefined") {
                   onChange(res.data);
                   onChange(res.data);
                 }
                 }
+                if (typeof onSubmit !== "undefined") {
+                  onSubmit(res.data);
+                }
                 formRef.current?.setFieldValue("content", res.data.content);
                 formRef.current?.setFieldValue("content", res.data.content);
                 message.success(intl.formatMessage({ id: "flashes.success" }));
                 message.success(intl.formatMessage({ id: "flashes.success" }));
               } else {
               } else {

+ 15 - 16
dashboard/src/components/article/TypeArticle.tsx

@@ -1,6 +1,6 @@
 import { useState } from "react";
 import { useState } from "react";
-import { Alert, Button } from "antd";
-
+import { Alert, Button, Modal } from "antd";
+import { ExclamationCircleOutlined } from "@ant-design/icons";
 import { IArticleDataResponse } from "../api/Article";
 import { IArticleDataResponse } from "../api/Article";
 import { ArticleMode, ArticleType } from "./Article";
 import { ArticleMode, ArticleType } from "./Article";
 import TypeArticleReader from "./TypeArticleReader";
 import TypeArticleReader from "./TypeArticleReader";
@@ -36,29 +36,29 @@ const TypeArticleWidget = ({
   onAnthologySelect,
   onAnthologySelect,
   onArticleEdit,
   onArticleEdit,
 }: IWidget) => {
 }: IWidget) => {
-  const [articleData, setArticleData] = useState<IArticleDataResponse>();
   const [edit, setEdit] = useState(false);
   const [edit, setEdit] = useState(false);
   return (
   return (
     <div>
     <div>
-      <div>
-        {articleData?.role && articleData?.role !== "reader" && edit ? (
-          <Alert
-            message={"请在提交修改后点完成按钮"}
-            type="info"
-            action={<Button onClick={() => setEdit(!edit)}>{"完成"}</Button>}
-          />
-        ) : (
-          <></>
-        )}
-      </div>
       {edit ? (
       {edit ? (
         <ArticleEdit
         <ArticleEdit
           anthologyId={anthologyId ? anthologyId : undefined}
           anthologyId={anthologyId ? anthologyId : undefined}
           articleId={articleId}
           articleId={articleId}
-          onChange={(value: IArticleDataResponse) => {
+          resetButton="cancel"
+          onSubmit={(value: IArticleDataResponse) => {
             if (typeof onArticleEdit !== "undefined") {
             if (typeof onArticleEdit !== "undefined") {
               onArticleEdit(value);
               onArticleEdit(value);
             }
             }
+            setEdit(false);
+          }}
+          onCancel={() => {
+            Modal.confirm({
+              icon: <ExclamationCircleOutlined />,
+              content: "放弃修改吗?",
+              okType: "danger",
+              onOk() {
+                setEdit(false);
+              },
+            });
           }}
           }}
         />
         />
       ) : (
       ) : (
@@ -77,7 +77,6 @@ const TypeArticleWidget = ({
             }
             }
           }}
           }}
           onLoad={(data: IArticleDataResponse) => {
           onLoad={(data: IArticleDataResponse) => {
-            setArticleData(data);
             if (typeof onLoad !== "undefined") {
             if (typeof onLoad !== "undefined") {
               onLoad(data);
               onLoad(data);
             }
             }

+ 15 - 0
dashboard/src/components/article/TypeArticleReaderToolbar.tsx

@@ -17,6 +17,7 @@ import { ArticleTplModal } from "../template/Builder/ArticleTpl";
 import AnthologiesAtArticle from "./AnthologiesAtArticle";
 import AnthologiesAtArticle from "./AnthologiesAtArticle";
 import { TRole } from "../api/Auth";
 import { TRole } from "../api/Auth";
 import { useIntl } from "react-intl";
 import { useIntl } from "react-intl";
+import { TabIcon } from "../../assets/icon";
 
 
 interface IWidget {
 interface IWidget {
   articleId?: string;
   articleId?: string;
@@ -69,6 +70,7 @@ const TypeArticleReaderToolbarWidget = ({
             <Button
             <Button
               type="link"
               type="link"
               size="small"
               size="small"
+              disabled={!editable}
               icon={<EditOutlined />}
               icon={<EditOutlined />}
               onClick={() => {
               onClick={() => {
                 if (typeof onEdit !== "undefined") {
                 if (typeof onEdit !== "undefined") {
@@ -81,6 +83,13 @@ const TypeArticleReaderToolbarWidget = ({
           <Dropdown
           <Dropdown
             menu={{
             menu={{
               items: [
               items: [
+                {
+                  label: intl.formatMessage({
+                    id: "buttons.open.in.new.tab",
+                  }),
+                  key: "open_in_tab",
+                  icon: <TabIcon />,
+                },
                 {
                 {
                   label: intl.formatMessage({
                   label: intl.formatMessage({
                     id: "buttons.add_to_anthology",
                     id: "buttons.add_to_anthology",
@@ -120,6 +129,12 @@ const TypeArticleReaderToolbarWidget = ({
               onClick: ({ key }) => {
               onClick: ({ key }) => {
                 console.log(`Click on item ${key}`);
                 console.log(`Click on item ${key}`);
                 switch (key) {
                 switch (key) {
+                  case "open_in_tab":
+                    window.open(
+                      fullUrl(`/article/article/${articleId}`),
+                      "_blank"
+                    );
+                    break;
                   case "add_to_anthology":
                   case "add_to_anthology":
                     setAddToAnthologyOpen(true);
                     setAddToAnthologyOpen(true);
                     break;
                     break;