ソースを参照

feat: 所属工业

chenlei 1 年間 前
コミット
d561a170ec

+ 4 - 0
src/api/index.ts

@@ -17,6 +17,10 @@ export const updatePwd = (data: UpdatePwdRequest) => {
   return requestByPost("/api/sys/user/updatePwd", data);
 };
 
+export const getMetaListApi = () => {
+  return requestByGet("/api/cms/meta/getList");
+};
+
 export * from "./overview";
 export * from "./history";
 export * from "./log";

+ 52 - 0
src/components/CheckboxGroup/index.tsx

@@ -0,0 +1,52 @@
+import { Checkbox, CheckboxOptionType } from "antd";
+import { CheckboxGroupProps } from "antd/lib/checkbox";
+import { isNumber, isObject, merge } from "lodash";
+import { FC, useEffect, useState } from "react";
+
+export interface DageCheckboxGroupProps extends CheckboxGroupProps {
+  /** 最多选择个数 */
+  max?: number;
+}
+
+export const DageCheckboxGroup: FC<DageCheckboxGroupProps> = ({
+  options,
+  max,
+  ...rest
+}) => {
+  const [_options, _setOptions] = useState<CheckboxOptionType[]>([]);
+
+  useEffect(() => {
+    _setOptions(
+      merge(
+        [],
+        options?.map((i) => {
+          if (isObject(i)) return i;
+          return {
+            label: i,
+            value: i,
+          };
+        }),
+        _options
+      )
+    );
+
+    // eslint-disable-next-line react-hooks/exhaustive-deps
+  }, [options]);
+
+  useEffect(() => {
+    const { value } = rest;
+
+    if (!value || !isNumber(max)) return;
+
+    _setOptions((val) => {
+      return val.map((i) => ({
+        ...i,
+        disabled: value.length >= max ? !value.includes(i.value) : false,
+      }));
+    });
+
+    // eslint-disable-next-line react-hooks/exhaustive-deps
+  }, [rest.value, max]);
+
+  return <Checkbox.Group options={_options} {...rest} />;
+};

+ 70 - 4
src/pages/History/create-or-edit/index.tsx

@@ -1,4 +1,4 @@
-import { historyApi } from "@/api";
+import { getMetaListApi, historyApi, overviewApi } from "@/api";
 import {
   DageUpload,
   DageUploadConsumer,
@@ -9,6 +9,7 @@ import { HistoryDictItem } from "@/types";
 import { Form, FormInstance, Input, Select } from "antd";
 import { useCallback, useEffect, useRef, useState } from "react";
 import { useLocation, useNavigate, useParams } from "react-router-dom";
+import { DageCheckboxGroup } from "@/components/CheckboxGroup";
 
 export default function HistoryCreateOrEdit() {
   const navigate = useNavigate();
@@ -18,13 +19,53 @@ export default function HistoryCreateOrEdit() {
   const formRef = useRef<FormInstance>(null);
   const [loading, setLoading] = useState(false);
   const [dictList, setDictList] = useState<HistoryDictItem[]>([]);
+  const [metaList, setMetaList] = useState([]);
+  const [companyList, setCompanyList] = useState<
+    {
+      label: string;
+      value: number;
+    }[]
+  >([]);
+
+  const getCompanyList = async () => {
+    const data = await overviewApi.getList({
+      pageNum: 1,
+      pageSize: 999,
+    });
+    setCompanyList(
+      data.records.map((i) => ({
+        label: i.name,
+        value: i.id,
+      }))
+    );
+  };
+
+  const getMetaList = async () => {
+    const data = await getMetaListApi();
+    setMetaList(
+      data.map((i: any) => ({
+        label: i.name,
+        value: i.id,
+      }))
+    );
+  };
+
+  useEffect(() => {
+    getMetaList();
+    getCompanyList();
+  }, []);
 
   const getDetail = useCallback(async () => {
     setLoading(true);
     try {
-      const { entity, file } = await historyApi.getDetail(params.id as string);
+      const {
+        entity: { mateIds, companyId, ...rest },
+        file,
+      } = await historyApi.getDetail(params.id as string);
       formRef.current?.setFieldsValue({
-        ...entity,
+        ...rest,
+        companyId: companyId ? Number(companyId) : null,
+        mateIds: mateIds ? mateIds.split(",").map((i) => Number(i)) : [],
         fileIds: file.map((i) => ({
           uid: i.id + "",
           url: `${process.env.REACT_APP_API_URL}${i.filePath}`,
@@ -48,7 +89,11 @@ export default function HistoryCreateOrEdit() {
   const handleSubmit = useCallback(async () => {
     if (!(await formRef.current?.validateFields())) return;
 
-    const { fileIds = [], ...rest } = formRef.current?.getFieldsValue();
+    const {
+      fileIds = [],
+      mateIds = [],
+      ...rest
+    } = formRef.current?.getFieldsValue();
 
     if (params.id) {
       rest.id = params.id;
@@ -56,6 +101,7 @@ export default function HistoryCreateOrEdit() {
 
     await historyApi.add({
       ...rest,
+      mateIds: mateIds.join(","),
       fileIds: fileIds
         .map((i: any) => (!!i.response ? i.response.id : i.uid))
         .join(),
@@ -108,6 +154,19 @@ export default function HistoryCreateOrEdit() {
                     disabled={readonly.current}
                   />
                 </Form.Item>
+                <Form.Item label="所属企业" name="companyId">
+                  <Select
+                    allowClear
+                    showSearch
+                    style={{ width: 200 }}
+                    placeholder="请选择"
+                    options={companyList}
+                    disabled={readonly.current}
+                    filterOption={(input, option) =>
+                      (option?.label ?? "").includes(input)
+                    }
+                  />
+                </Form.Item>
                 <Form.Item label="企业" name="companyName">
                   <Input.TextArea
                     className="w450"
@@ -117,6 +176,13 @@ export default function HistoryCreateOrEdit() {
                     readOnly={readonly.current}
                   />
                 </Form.Item>
+                <Form.Item label="所属工业" name="mateIds">
+                  <DageCheckboxGroup
+                    max={3}
+                    options={metaList}
+                    style={{ width: 650 }}
+                  />
+                </Form.Item>
                 <Form.Item label="简介" name="description">
                   <Input.TextArea
                     className="w450"

+ 29 - 2
src/pages/Overview/create-or-edit/index.tsx

@@ -12,8 +12,9 @@ import {
 import { MemoSpinLoding, FormPageFooter } from "@/components";
 import { useCallback, useEffect, useRef, useState } from "react";
 import { useLocation, useNavigate, useParams } from "react-router-dom";
-import { overviewApi } from "@/api";
+import { getMetaListApi, overviewApi } from "@/api";
 import { formatDate } from "@/utils/date";
+import { DageCheckboxGroup } from "@/components/CheckboxGroup";
 
 const disabledDate: RangePickerProps["disabledDate"] = (current) => {
   return current && current > dayjs().endOf("day");
@@ -27,20 +28,36 @@ export default function OverviewCreateOrEdit() {
   const dageMapRef = useRef<DageMapMethods>(null);
   const readonly = useRef(location.pathname.split("/")[2].indexOf("view") > -1);
   const [loading, setLoading] = useState(false);
+  const [metaList, setMetaList] = useState([]);
 
   const [position, setPosition] = useState([121.473581, 31.230536]);
   const [address, setAddress] = useState("上海市人民政府");
 
+  const getMetaList = async () => {
+    const data = await getMetaListApi();
+    setMetaList(
+      data.map((i: any) => ({
+        label: i.name,
+        value: i.id,
+      }))
+    );
+  };
+
+  useEffect(() => {
+    getMetaList();
+  }, []);
+
   const getDetail = useCallback(async () => {
     setLoading(true);
     try {
       const {
-        entity: { createDay, longitude, latitude, address, ...rest },
+        entity: { createDay, mateIds, longitude, latitude, address, ...rest },
         file,
       } = await overviewApi.getDetail(params.id as string);
       formRef.current?.setFieldsValue({
         ...rest,
         address,
+        mateIds: mateIds ? mateIds.split(",").map((i) => Number(i)) : [],
         createDay: dayjs(createDay),
         fileIds: file.map((i: any) => ({
           uid: i.id + "",
@@ -66,6 +83,7 @@ export default function OverviewCreateOrEdit() {
 
     const {
       createDay,
+      mateIds = [],
       fileIds = [],
       ...rest
     } = formRef.current?.getFieldsValue();
@@ -80,6 +98,7 @@ export default function OverviewCreateOrEdit() {
       latitude: position[1],
       longitude: position[0],
       address,
+      mateIds: mateIds.join(","),
       fileIds: fileIds
         .map((i: any) => (!!i.response ? i.response.id : i.uid))
         .join(),
@@ -143,6 +162,14 @@ export default function OverviewCreateOrEdit() {
                       action="/api/cms/history/upload"
                     />
                   </Form.Item>
+                  <Form.Item label="所属工业" name="mateIds">
+                    <DageCheckboxGroup
+                      max={3}
+                      disabled={readonly.current}
+                      options={metaList}
+                      style={{ width: 650 }}
+                    />
+                  </Form.Item>
                   <Form.Item label="企业类型" name="type">
                     <Input
                       readOnly={readonly.current}

+ 31 - 3
src/pages/Weapon/create-or-edit/index.tsx

@@ -1,4 +1,4 @@
-import { weaponApi } from "@/api";
+import { getMetaListApi, weaponApi } from "@/api";
 import { FormPageFooter, MemoSpinLoding } from "@/components";
 import {
   DageFileCheckbox,
@@ -12,6 +12,7 @@ import { HistoryDictItem } from "@/types";
 import { Form, FormInstance, Input, Select } from "antd";
 import { useCallback, useEffect, useRef, useState } from "react";
 import { useLocation, useNavigate, useParams } from "react-router-dom";
+import { DageCheckboxGroup } from "@/components/CheckboxGroup";
 
 export default function HistoryCreateOrEdit() {
   const navigate = useNavigate();
@@ -23,12 +24,27 @@ export default function HistoryCreateOrEdit() {
   const [loading, setLoading] = useState(false);
   const [dictList, setDictList] = useState<HistoryDictItem[]>([]);
   const [fileList, setFileList] = useState<DageFileResponseType[]>([]);
+  const [metaList, setMetaList] = useState([]);
+
+  const getMetaList = async () => {
+    const data = await getMetaListApi();
+    setMetaList(
+      data.map((i: any) => ({
+        label: i.name,
+        value: i.id,
+      }))
+    );
+  };
+
+  useEffect(() => {
+    getMetaList();
+  }, []);
 
   const getDetail = useCallback(async () => {
     setLoading(true);
     try {
       const {
-        entity: { thumb, ...rest },
+        entity: { thumb, mateIds, ...rest },
         file,
       } = await weaponApi.getDetail(params.id as string);
 
@@ -43,6 +59,9 @@ export default function HistoryCreateOrEdit() {
         ];
       }
       formRef.current?.setFieldsValue({
+        mateIds: mateIds
+          ? mateIds.split(",").map((i: string) => Number(i))
+          : [],
         ...rest,
       });
       dageFileCheckboxRef.current?.setFileList(
@@ -72,7 +91,7 @@ export default function HistoryCreateOrEdit() {
   const handleSubmit = useCallback(async () => {
     if (!(await formRef.current?.validateFields())) return;
 
-    const { thumb, ...rest } = formRef.current?.getFieldsValue();
+    const { thumb, mateIds = [], ...rest } = formRef.current?.getFieldsValue();
 
     if (params.id) {
       rest.id = params.id;
@@ -86,6 +105,7 @@ export default function HistoryCreateOrEdit() {
 
     await weaponApi.add({
       ...rest,
+      mateIds: mateIds.join(","),
       thumb: thumb
         .map((i: any) => (!!i.response ? i.response.filePath : i.uid))
         .join(),
@@ -163,6 +183,14 @@ export default function HistoryCreateOrEdit() {
                     readOnly={readonly.current}
                   />
                 </Form.Item>
+                <Form.Item label="所属工业" name="mateIds">
+                  <DageCheckboxGroup
+                    max={3}
+                    options={metaList}
+                    style={{ width: 650 }}
+                    disabled={readonly.current}
+                  />
+                </Form.Item>
                 <Form.Item label="生产厂家" name="company">
                   <Input
                     className="w450"

+ 2 - 0
src/types/history.ts

@@ -10,6 +10,8 @@ export interface GetHistoryListResponse {
 }
 export interface HistoryItem extends Required<AddHistoryParams> {
   id: number;
+  mateIds: string;
+  companyId: string;
 }
 
 export interface HistoryDictItem {

+ 1 - 0
src/types/overview.ts

@@ -15,6 +15,7 @@ export interface OverviewParams {
   createDay: string;
   latitude: number;
   longitude: number;
+  mateIds: string;
 }
 
 export interface GetOverviewListResponse {