Bläddra i källkod

支持readonly

visuddhinanda 1 år sedan
förälder
incheckning
d5ee2de546

+ 7 - 1
dashboard/src/components/dict/SelectCase.tsx

@@ -9,9 +9,14 @@ interface CascaderOption {
 }
 interface IWidget {
   value?: string | null;
+  readonly?: boolean;
   onCaseChange?: Function;
 }
-const SelectCaseWidget = ({ value, onCaseChange }: IWidget) => {
+const SelectCaseWidget = ({
+  value,
+  readonly = false,
+  onCaseChange,
+}: IWidget) => {
   const intl = useIntl();
   const [currValue, setCurrValue] = useState<(string | number)[]>();
 
@@ -339,6 +344,7 @@ const SelectCaseWidget = ({ value, onCaseChange }: IWidget) => {
   ];
   return (
     <Cascader
+      disabled={readonly}
       value={currValue}
       options={options}
       placeholder="Please select case"

+ 3 - 0
dashboard/src/components/template/SentEdit.tsx

@@ -94,6 +94,7 @@ export interface IWidgetSentEditInner {
   compact?: boolean;
   mode?: ArticleMode;
   wbwProgress?: boolean;
+  readonly?: boolean;
 }
 export const SentEditInner = ({
   id,
@@ -115,6 +116,7 @@ export const SentEditInner = ({
   compact = false,
   mode,
   wbwProgress = false,
+  readonly = false,
 }: IWidgetSentEditInner) => {
   const [wbwData, setWbwData] = useState<IWbw[]>();
   const [magicDict, setMagicDict] = useState<string>();
@@ -204,6 +206,7 @@ export const SentEditInner = ({
         compact={isCompact}
         mode={articleMode}
         wbwProgress={wbwProgress}
+        readonly={readonly}
         onWbwChange={(data: IWbw[]) => {
           setWbwData(data);
         }}

+ 3 - 0
dashboard/src/components/template/SentEdit/SentContent.tsx

@@ -31,6 +31,7 @@ interface IWidgetSentContent {
   compact?: boolean;
   mode?: ArticleMode;
   wbwProgress?: boolean;
+  readonly?: boolean;
   onWbwChange?: Function;
   onMagicDictDone?: Function;
 }
@@ -48,6 +49,7 @@ const SentContentWidget = ({
   mode,
   magicDict,
   wbwProgress = false,
+  readonly = false,
   onWbwChange,
   onMagicDictDone,
 }: IWidgetSentContent) => {
@@ -163,6 +165,7 @@ const SentContentWidget = ({
                 answer={answer ? JSON.parse(answer.content ?? "") : undefined}
                 mode={mode}
                 wbwProgress={wbwProgress}
+                readonly={readonly}
                 onChange={(data: IWbw[]) => {
                   if (typeof onWbwChange !== "undefined") {
                     onWbwChange(data);

+ 5 - 1
dashboard/src/components/template/SentEdit/SentWbw.tsx

@@ -37,7 +37,10 @@ const SentWbwWidget = ({
 
   const myCourse = useAppSelector(courseUser);
 
-  const isCourse = myCourse && course;
+  let isCourse: boolean = false;
+  if (myCourse && course) {
+    isCourse = true;
+  }
 
   const load = () => {
     let url = `/v2/wbw-sentence?view=sent-can-read`;
@@ -139,6 +142,7 @@ const SentWbwWidget = ({
           <List.Item key={index}>
             <SentEditInner
               {...item}
+              readonly={isCourse}
               answer={answer}
               wbwProgress={wbwProgress}
             />

+ 4 - 0
dashboard/src/components/template/Wbw/WbwDetail.tsx

@@ -36,6 +36,7 @@ interface IWidget {
   data: IWbw;
   visible?: boolean;
   popIsTop?: boolean;
+  readonly?: boolean;
   onClose?: Function;
   onSave?: Function;
   onAttachmentSelectOpen?: Function;
@@ -45,6 +46,7 @@ const WbwDetailWidget = ({
   data,
   visible = true,
   popIsTop = false,
+  readonly = false,
   onClose,
   onSave,
   onAttachmentSelectOpen,
@@ -185,6 +187,7 @@ const WbwDetailWidget = ({
               <WbwDetailBasic
                 visible={visible && tabKey === "basic"}
                 data={currWbwData}
+                readonly={readonly}
                 onChange={(e: IWbwField) => {
                   console.debug("WbwDetailBasic onchange", e);
                   fieldChanged(e.field, e.value);
@@ -306,6 +309,7 @@ const WbwDetailWidget = ({
           </Button>
         </div>
         <Dropdown.Button
+          disabled={readonly}
           style={{ width: "unset" }}
           type="primary"
           menu={{

+ 9 - 2
dashboard/src/components/template/Wbw/WbwDetailBasic.tsx

@@ -29,6 +29,7 @@ interface IWidget {
   data: IWbw;
   visible?: boolean;
   showRelation?: boolean;
+  readonly?: boolean;
   onChange?: Function;
   onRelationAdd?: Function;
 }
@@ -36,6 +37,7 @@ const WbwDetailBasicWidget = ({
   data,
   visible,
   showRelation = true,
+  readonly = false,
   onChange,
   onRelationAdd,
 }: IWidget) => {
@@ -87,6 +89,7 @@ const WbwDetailBasicWidget = ({
           <div style={{ display: "flex" }}>
             <div style={{ display: "flex", width: "100%" }}>
               <Input
+                disabled={readonly}
                 value={_meaning}
                 allowClear
                 placeholder="请输入"
@@ -110,18 +113,18 @@ const WbwDetailBasicWidget = ({
                     }}
                   />
                 }
+                trigger={readonly ? "" : "click"}
                 overlayStyle={{ width: 500 }}
                 placement="bottom"
-                trigger="click"
                 open={openCreate}
                 onOpenChange={(open: boolean) => {
                   setOpenCreate(open);
                 }}
               >
                 <Button
+                  disabled={readonly}
                   type="text"
                   icon={<MoreOutlined />}
-                  onClick={() => {}}
                 />
               </Popover>
             </div>
@@ -141,6 +144,7 @@ const WbwDetailBasicWidget = ({
         >
           <div style={{ display: "flex" }}>
             <WbwDetailFactor
+              readonly={readonly}
               data={data}
               onChange={(value: string) => {
                 setFactors(value.split("+"));
@@ -170,6 +174,7 @@ const WbwDetailBasicWidget = ({
           <div style={{ display: "flex" }}>
             <WbwDetailFm
               factors={factors}
+              readonly={readonly}
               value={data.factorMeaning?.value?.split("+")}
               onChange={(value: string[]) => {
                 console.log("fm change", value);
@@ -198,6 +203,7 @@ const WbwDetailBasicWidget = ({
         >
           <div style={{ display: "flex" }}>
             <WbwDetailCase
+              readonly={readonly}
               data={data}
               onChange={(value: string) => {
                 if (typeof onChange !== "undefined") {
@@ -225,6 +231,7 @@ const WbwDetailBasicWidget = ({
         >
           <div style={{ display: "flex" }}>
             <WbwDetailParent
+              readonly={readonly}
               data={data}
               onChange={(value: string) => {
                 if (typeof onChange !== "undefined") {

+ 3 - 1
dashboard/src/components/template/Wbw/WbwDetailCase.tsx

@@ -13,15 +13,17 @@ import { useIntl } from "react-intl";
 
 interface IWidget {
   data: IWbw;
+  readonly?: boolean;
   onChange?: Function;
 }
-const WbwDetailCaseWidget = ({ data, onChange }: IWidget) => {
+const WbwDetailCaseWidget = ({ data, readonly = false, onChange }: IWidget) => {
   const inlineDict = useAppSelector(_inlineDict);
   const intl = useIntl();
 
   return (
     <div style={{ display: "flex", width: "100%" }}>
       <SelectCase
+        readonly={readonly}
         value={data.case?.value}
         onCaseChange={(value: string) => {
           if (typeof onChange !== "undefined") {

+ 8 - 2
dashboard/src/components/template/Wbw/WbwDetailFactor.tsx

@@ -20,9 +20,14 @@ interface ValueType {
 }
 interface IWidget {
   data: IWbw;
+  readonly?: boolean;
   onChange?: Function;
 }
-const WbwDetailFactorWidget = ({ data, onChange }: IWidget) => {
+const WbwDetailFactorWidget = ({
+  data,
+  readonly = false,
+  onChange,
+}: IWidget) => {
   const [factorOptions, setFactorOptions] = useState<ValueType[]>([]);
   const inlineDict = useAppSelector(_inlineDict);
   const inlineWordIndex = useAppSelector(wordIndex);
@@ -77,6 +82,7 @@ const WbwDetailFactorWidget = ({ data, onChange }: IWidget) => {
 
   return (
     <AutoComplete
+      disabled={readonly}
       options={factorOptions}
       value={data.factors?.value}
       onChange={(value: string) => {
@@ -85,7 +91,7 @@ const WbwDetailFactorWidget = ({ data, onChange }: IWidget) => {
         }
       }}
     >
-      <Input placeholder="请输入" allowClear />
+      <Input disabled={readonly} placeholder="请输入" allowClear />
     </AutoComplete>
   );
 };

+ 9 - 1
dashboard/src/components/template/Wbw/WbwDetailFm.tsx

@@ -21,9 +21,15 @@ import { MergeIcon } from "../../../assets/icon";
 interface IWFMI {
   pali: string;
   meaning?: string;
+  readonly?: boolean;
   onChange?: Function;
 }
-const WbwFactorMeaningItem = ({ pali, meaning = "", onChange }: IWFMI) => {
+const WbwFactorMeaningItem = ({
+  pali,
+  readonly = false,
+  meaning = "",
+  onChange,
+}: IWFMI) => {
   const intl = useIntl();
   console.debug("WbwFactorMeaningItem meaning", meaning);
   const defaultMenu: ItemType[] = [
@@ -190,12 +196,14 @@ const resizeArray = (input: string[], factors: string[]) => {
 interface IWidget {
   factors?: string[];
   value?: string[];
+  readonly?: boolean;
   onChange?: Function;
   onJoin?: Function;
 }
 const WbwDetailFmWidget = ({
   factors = [],
   value = [],
+  readonly = false,
   onChange,
   onJoin,
 }: IWidget) => {

+ 8 - 2
dashboard/src/components/template/Wbw/WbwDetailParent.tsx

@@ -39,9 +39,14 @@ interface ValueType {
 }
 interface IWidget {
   data: IWbw;
+  readonly?: boolean;
   onChange?: Function;
 }
-const WbwDetailParentWidget = ({ data, onChange }: IWidget) => {
+const WbwDetailParentWidget = ({
+  data,
+  readonly = false,
+  onChange,
+}: IWidget) => {
   const [parentOptions, setParentOptions] = useState<ValueType[]>([]);
   const inlineDict = useAppSelector(_inlineDict);
 
@@ -75,6 +80,7 @@ const WbwDetailParentWidget = ({ data, onChange }: IWidget) => {
 
   return (
     <AutoComplete
+      disabled={readonly}
       options={parentOptions}
       value={data.parent?.value}
       onChange={(value: any, option: ValueType | ValueType[]) => {
@@ -84,7 +90,7 @@ const WbwDetailParentWidget = ({ data, onChange }: IWidget) => {
         }
       }}
     >
-      <Input allowClear placeholder="请输入" />
+      <Input disabled={readonly} allowClear placeholder="请输入" />
     </AutoComplete>
   );
 };

+ 3 - 0
dashboard/src/components/template/Wbw/WbwPali.tsx

@@ -58,6 +58,7 @@ interface IWidget {
   channelId: string;
   display?: TWbwDisplayMode;
   mode?: ArticleMode;
+  readonly?: boolean;
   onSave?: Function;
 }
 const WbwPaliWidget = ({
@@ -66,6 +67,7 @@ const WbwPaliWidget = ({
   mode,
   display,
   studio,
+  readonly = false,
   onSave,
 }: IWidget) => {
   const [popOpen, setPopOpen] = useState(false);
@@ -198,6 +200,7 @@ const WbwPaliWidget = ({
       data={data}
       visible={popOpen}
       popIsTop={popOnTop}
+      readonly={readonly}
       onClose={() => {
         setPaliColor("unset");
         setPopOpen(false);

+ 3 - 0
dashboard/src/components/template/Wbw/WbwWord.tsx

@@ -111,6 +111,7 @@ interface IWidget {
   mode?: ArticleMode;
   wordDark?: boolean;
   studio?: IStudio;
+  readonly?: boolean;
   onChange?: Function;
   onSplit?: Function;
 }
@@ -129,6 +130,7 @@ const WbwWordWidget = ({
     case: true,
   },
   wordDark = false,
+  readonly = false,
   studio,
   onChange,
   onSplit,
@@ -255,6 +257,7 @@ const WbwWordWidget = ({
           mode={mode}
           display={display}
           studio={studio}
+          readonly={readonly}
           onSave={(e: IWbw, isPublish: boolean, isPublic: boolean) => {
             const newData: IWbw = JSON.parse(JSON.stringify(e));
             setWordData(newData);

+ 3 - 0
dashboard/src/components/template/WbwSent.tsx

@@ -151,6 +151,7 @@ interface IWidget {
   mode?: ArticleMode;
   wbwProgress?: boolean;
   studio?: IStudio;
+  readonly?: boolean;
   onMagicDictDone?: Function;
   onChange?: Function;
 }
@@ -170,6 +171,7 @@ export const WbwSentCtl = ({
   mode,
   refreshable = false,
   wbwProgress = false,
+  readonly = false,
   studio,
   onChange,
   onMagicDictDone,
@@ -549,6 +551,7 @@ export const WbwSentCtl = ({
         display={wbwMode}
         fields={fieldDisplay}
         studio={studio}
+        readonly={readonly}
         onChange={(e: IWbw, isPublish: boolean, isPublic: boolean) => {
           let newData = [...wordData];
           newData.forEach((value, index, array) => {