sun-chaochao 3 лет назад
Родитель
Сommit
ff3691acf1

+ 14 - 8
src/components/SearchComponent/index.tsx

@@ -64,7 +64,11 @@ interface Props<T> {
    *         ]}
    * */
   defaultParam?: SearchTermsServer | Term[];
-  // pattern?: 'simple' | 'advance';
+  /**
+   * @name "搜索组件模式"
+   * simple 限制只支持一组搜索条件,用于小弹窗搜索时使用
+   */
+  model?: 'simple' | 'advance';
   enableSave?: boolean;
   initParam?: SearchTermsServer;
 }
@@ -138,7 +142,7 @@ const sortField = (field: ProColumns[]) => {
 // 默认六组搜索条件。根据字段index排序
 
 const SearchComponent = <T extends Record<string, any>>(props: Props<T>) => {
-  const { field, target, onSearch, defaultParam, enableSave = true, initParam } = props;
+  const { field, target, onSearch, defaultParam, enableSave = true, initParam, model } = props;
 
   /**
    * 过滤不参与搜索的数据 ?
@@ -633,12 +637,14 @@ const SearchComponent = <T extends Record<string, any>>(props: Props<T>) => {
                 重置
               </Button>
             </Space>
-            <div className={classnames(styles.more, !expand ? styles.simple : styles.advance)}>
-              <Button type="link" onClick={handleExpand}>
-                更多筛选
-                <DoubleRightOutlined style={{ marginLeft: 32 }} rotate={expand ? 90 : -90} />
-              </Button>
-            </div>
+            {model !== 'simple' && (
+              <div className={classnames(styles.more, !expand ? styles.simple : styles.advance)}>
+                <Button type="link" onClick={handleExpand}>
+                  更多筛选
+                  <DoubleRightOutlined style={{ marginLeft: 32 }} rotate={expand ? 90 : -90} />
+                </Button>
+              </div>
+            )}
           </div>
         </div>
       </Form>

+ 4 - 0
src/pages/home/comprehensive /index.tsx

@@ -0,0 +1,4 @@
+const Comprehensive = () => {
+  return <div>综合管理视图</div>;
+};
+export default Comprehensive;

+ 25 - 15
src/pages/home/index.tsx

@@ -1,24 +1,34 @@
 import { PageContainer } from '@ant-design/pro-layout';
-import { Button } from 'antd';
-import { useState } from 'react';
+import { useEffect, useState } from 'react';
+import Comprehensive from './comprehensive  ';
 import Device from './device';
 import Init from './init';
 import Ops from './ops';
+import Service from './service';
 
-const ViewMap = {
-  init: <Init />,
-  device: <Device />,
-  ops: <Ops />,
-};
-
+export const service = new Service();
 const Home = () => {
-  const [current, setCurrent] = useState<'init' | 'device' | 'ops'>('init');
+  type ViewType = keyof typeof ViewMap;
+  const [current, setCurrent] = useState<ViewType>('init');
+
+  const ViewMap = {
+    init: <Init changeView={(value: ViewType) => setCurrent(value)} />,
+    device: <Device />,
+    ops: <Ops />,
+    comprehensive: <Comprehensive />,
+  };
 
-  return (
-    <PageContainer>
-      <Button onClick={() => setCurrent('device')}>切换视图</Button>
-      {ViewMap[current]}
-    </PageContainer>
-  );
+  useEffect(() => {
+    service.queryView().then((resp) => {
+      if (resp.status === 200) {
+        if (resp.result.length == 0) {
+          setCurrent('init');
+        } else {
+          setCurrent(resp.result[0]?.content);
+        }
+      }
+    });
+  }, []);
+  return <PageContainer>{ViewMap[current]}</PageContainer>;
 };
 export default Home;

+ 45 - 2
src/pages/home/init/index.tsx

@@ -1,4 +1,47 @@
-const Init = () => {
-  return <div>初始化视图</div>;
+import { Button, Radio } from 'antd';
+import { useState } from 'react';
+import { service } from '..';
+
+interface Props {
+  changeView: (view: any) => void;
+}
+
+const Init = (props: Props) => {
+  const options = [
+    { label: '设备接入视图', value: 'device' },
+    { label: '运维管理视图', value: 'ops' },
+    { label: '综合管理视图', value: 'comprehensive' },
+  ];
+
+  const [value, setValue] = useState<string>('device');
+
+  return (
+    <div>
+      <Radio.Group
+        options={options}
+        value={value}
+        onChange={(e) => setValue(e.target.value)}
+        optionType="button"
+      />
+      <div>
+        <Button
+          onClick={() => {
+            service
+              .setView({
+                name: 'view',
+                content: value,
+              })
+              .then((resp) => {
+                if (resp.status === 200) {
+                  props.changeView(value);
+                }
+              });
+          }}
+        >
+          确定
+        </Button>
+      </div>
+    </div>
+  );
 };
 export default Init;

+ 17 - 0
src/pages/home/service.ts

@@ -0,0 +1,17 @@
+import { request } from 'umi';
+import SystemConst from '@/utils/const';
+
+class Service {
+  public queryView = () =>
+    request(`/${SystemConst.API_BASE}/user/settings/view`, {
+      method: 'GET',
+    });
+
+  public setView = (data: Record<string, any>) =>
+    request(`/${SystemConst.API_BASE}/user/settings/view`, {
+      method: 'POST',
+      data,
+    });
+}
+
+export default Service;

+ 1 - 1
src/pages/rule-engine/Scene/Save/action/device/deviceModal.tsx

@@ -134,7 +134,7 @@ export default (props: DeviceModelProps) => {
           <SearchComponent<DeviceItem>
             field={columns}
             enableSave={false}
-            // pattern={'simple'}
+            model={'simple'}
             onSearch={async (data) => {
               actionRef.current?.reset?.();
               setSearchParam(data);

+ 1 - 1
src/pages/rule-engine/Scene/TriggerTerm/index.tsx

@@ -219,7 +219,7 @@ const TriggerTerm = (props: Props, ref: any) => {
     const data = props.value;
     data?.trigger?.map((item: { terms: any[] }) =>
       item.terms?.map((j) => {
-        if (typeof j.value.value === 'string') {
+        if (typeof j.value.value !== 'object') {
           j.value.value = [j.value.value];
         }
         return j;