Pārlūkot izejas kodu

系统channel禁止更改

visuddhinanda 2 gadi atpakaļ
vecāks
revīzija
50a2a4e34a
1 mainītis faili ar 72 papildinājumiem un 49 dzēšanām
  1. 72 49
      dashboard/src/components/channel/Edit.tsx

+ 72 - 49
dashboard/src/components/channel/Edit.tsx

@@ -4,13 +4,14 @@ import {
   ProFormText,
   ProFormTextArea,
 } from "@ant-design/pro-components";
-import { message } from "antd";
+import { Alert, message } from "antd";
 
 import { IApiResponseChannel } from "../../components/api/Channel";
 import { get, put } from "../../request";
 import ChannelTypeSelect from "../../components/channel/ChannelTypeSelect";
 import LangSelect from "../../components/general/LangSelect";
 import PublicitySelect from "../../components/studio/PublicitySelect";
+import { useState } from "react";
 
 interface IFormData {
   name: string;
@@ -19,6 +20,7 @@ interface IFormData {
   summary: string;
   status: number;
   studio: string;
+  isSystem: boolean;
 }
 interface IWidget {
   studioName?: string;
@@ -27,57 +29,78 @@ interface IWidget {
 }
 const EditWidget = ({ studioName, channelId, onLoad }: IWidget) => {
   const intl = useIntl();
-
+  const [isSystem, setIsSystem] = useState<Boolean>();
   return (
-    <ProForm<IFormData>
-      onFinish={async (values: IFormData) => {
-        console.log(values);
-        const res = await put(`/v2/channel/${channelId}`, values);
-        console.log(res);
-        message.success(intl.formatMessage({ id: "flashes.success" }));
-      }}
-      formKey="channel_edit"
-      request={async () => {
-        const res = await get<IApiResponseChannel>(`/v2/channel/${channelId}`);
-        if (typeof onLoad !== "undefined") {
-          onLoad(res.data);
-        }
-        return {
-          name: res.data.name,
-          type: res.data.type,
-          lang: res.data.lang,
-          summary: res.data.summary,
-          status: res.data.status,
-          studio: studioName ? studioName : "",
-        };
-      }}
-    >
-      <ProForm.Group>
-        <ProFormText
-          width="md"
-          name="name"
-          required
-          label={intl.formatMessage({ id: "channel.name" })}
-          rules={[
-            {
-              required: true,
-            },
-          ]}
-        />
-      </ProForm.Group>
+    <>
+      {isSystem ? (
+        <Alert type="warning" message={"此版本为系统建立。不能修改,删除。"} />
+      ) : (
+        <></>
+      )}
+      <ProForm<IFormData>
+        submitter={{
+          resetButtonProps: { disabled: isSystem ? true : false },
+          submitButtonProps: { disabled: isSystem ? true : false },
+        }}
+        onFinish={async (values: IFormData) => {
+          console.log(values);
+          const res = await put(`/v2/channel/${channelId}`, values);
+          console.log(res);
+          message.success(intl.formatMessage({ id: "flashes.success" }));
+        }}
+        formKey="channel_edit"
+        request={async () => {
+          const res = await get<IApiResponseChannel>(
+            `/v2/channel/${channelId}`
+          );
+          if (typeof onLoad !== "undefined") {
+            onLoad(res.data);
+          }
+          setIsSystem(res.data.is_system);
+          return {
+            name: res.data.name,
+            type: res.data.type,
+            lang: res.data.lang,
+            summary: res.data.summary,
+            status: res.data.status,
+            studio: studioName ? studioName : "",
+            isSystem: res.data.is_system,
+          };
+        }}
+      >
+        <ProForm.Group>
+          <ProFormText
+            width="md"
+            name="name"
+            readonly={isSystem ? true : false}
+            required
+            label={intl.formatMessage({ id: "channel.name" })}
+            rules={[
+              {
+                required: true,
+              },
+            ]}
+          />
+        </ProForm.Group>
 
-      <ProForm.Group>
-        <ChannelTypeSelect />
-        <LangSelect />
-      </ProForm.Group>
-      <ProForm.Group>
-        <PublicitySelect />
-      </ProForm.Group>
+        <ProForm.Group>
+          <ChannelTypeSelect readonly={isSystem ? true : false} />
+          <LangSelect readonly={isSystem ? true : false} />
+        </ProForm.Group>
+        <ProForm.Group>
+          <PublicitySelect readonly={isSystem ? true : false} />
+        </ProForm.Group>
 
-      <ProForm.Group>
-        <ProFormTextArea width="md" name="summary" label="简介" />
-      </ProForm.Group>
-    </ProForm>
+        <ProForm.Group>
+          <ProFormTextArea
+            readonly={isSystem ? true : false}
+            width="md"
+            name="summary"
+            label="简介"
+          />
+        </ProForm.Group>
+      </ProForm>
+    </>
   );
 };