wzyyy 3 роки тому
батько
коміт
d48548e111

+ 3 - 2
src/components/FRuleEditor/Advance/index.tsx

@@ -7,10 +7,11 @@ import Editor from '@/components/FRuleEditor/Editor';
 interface Props {
   model: 'advance' | 'simple';
   onChange: (value: 'advance' | 'simple') => void;
+  virtualRule?: any;
 }
 
 const Advance = (props: Props) => {
-  const { model, onChange } = props;
+  const { model, onChange, virtualRule } = props;
   return (
     <Modal
       maskClosable={false}
@@ -23,7 +24,7 @@ const Advance = (props: Props) => {
       <div className={styles.box}>
         <div className={styles.left}>
           <Editor mode="advance" />
-          <Debug />
+          <Debug virtualRule={virtualRule} />
         </div>
         <div className={styles.right}>
           <Operator />

+ 44 - 7
src/components/FRuleEditor/Debug/index.tsx

@@ -1,7 +1,7 @@
 import styles from './index.less';
 import { createSchemaField, observer } from '@formily/react';
 import { ArrayTable, Form, FormItem, Input, Select } from '@formily/antd';
-import { useMemo } from 'react';
+import { useMemo, useRef, useState } from 'react';
 import type { Field } from '@formily/core';
 import { createForm } from '@formily/core';
 import type { ISchema } from '@formily/json-schema';
@@ -15,7 +15,11 @@ import DB from '@/db';
 import type { PropertyMetadata } from '@/pages/device/Product/typings';
 import { action } from '@formily/reactive';
 
-const Debug = observer(() => {
+interface Props {
+  virtualRule?: any;
+}
+
+const Debug = observer((props: Props) => {
   const SchemaField = createSchemaField({
     components: {
       FormItem,
@@ -40,6 +44,9 @@ const Debug = observer(() => {
   };
 
   const getProperty = async () => DB.getDB().table('properties').toArray();
+  const virtualIdRef = useRef(new Date().getTime());
+  const ws = useRef<any>();
+  const [isBeginning, setIsBeginning] = useState<any>(true);
 
   const schema: ISchema = {
     type: 'object',
@@ -144,20 +151,20 @@ const Debug = observer(() => {
       const _item = propertiesList.find((i) => i.id === item.id);
       return { ...item, type: _item?.valueType?.type };
     });
-    subscribeTopic?.(
+    ws.current = subscribeTopic?.(
       `virtual-property-debug-${State.property}-${new Date().getTime()}`,
       '/virtual-property-debug',
       {
-        virtualId: `${new Date().getTime()}-virtual-id`,
+        virtualId: `${virtualIdRef.current}-virtual-id`,
         property: State.property,
         virtualRule: {
-          type: 'script',
-          script: State.code,
+          ...props.virtualRule,
         },
         properties: _properties || [],
       },
     )?.subscribe((data: WebsocketPayload) => {
       State.log.push({ time: new Date().getTime(), content: JSON.stringify(data.payload) });
+      setIsBeginning(true);
     });
   };
   return (
@@ -169,6 +176,16 @@ const Debug = observer(() => {
               属性赋值
               <div className={styles.description}>请对上方规则使用的属性进行赋值</div>
             </div>
+            {!isBeginning && props.virtualRule?.type === 'window' && (
+              <div
+                className={styles.action}
+                onClick={() => {
+                  runScript();
+                }}
+              >
+                <a>发送数据</a>
+              </div>
+            )}
           </div>
         </div>
         <Form form={form}>
@@ -183,11 +200,31 @@ const Debug = observer(() => {
 
           <div className={styles.action}>
             <div>
-              <a onClick={runScript}>开始运行</a>
+              {isBeginning ? (
+                <a
+                  onClick={() => {
+                    setIsBeginning(false);
+                    runScript();
+                  }}
+                >
+                  开始运行
+                </a>
+              ) : (
+                <a
+                  onClick={() => {
+                    setIsBeginning(true);
+                    // ws.current && ws.current.unsubscribe();
+                  }}
+                >
+                  停止运行
+                </a>
+              )}
             </div>
             <div>
               <a
                 onClick={() => {
+                  // console.log(props.virtualRule, 222222222222)
+                  // console.log(virtualIdRef.current)
                   State.log = [];
                 }}
               >

+ 4 - 1
src/components/FRuleEditor/index.tsx

@@ -23,11 +23,13 @@ interface Props {
   value: string;
   onChange: (value: string) => void;
   property?: string;
+  virtualRule?: any;
 }
 
 const FRuleEditor = observer((props: Props) => {
-  const { value, onChange, property } = props;
+  const { value, onChange, property, virtualRule } = props;
   useEffect(() => {
+    console.log(virtualRule, 111111111);
     State.property = property;
     const subscription = Store.subscribe('rule-editor-value', onChange);
     State.code = value;
@@ -45,6 +47,7 @@ const FRuleEditor = observer((props: Props) => {
       />
       <Advance
         model={State.model}
+        virtualRule={virtualRule}
         onChange={(v) => {
           State.model = v;
         }}

+ 30 - 11
src/pages/account/Center/bind/index.tsx

@@ -14,7 +14,7 @@ const Bind = () => {
   const [form] = Form.useForm();
   const [bindUser, setBindUser] = useState<any>();
   const [user, setUser] = useState<any>();
-  const [code, setCode] = useState<string>('');
+  const [code, setCode] = useState<any>('');
   const [isLogin, setIslogin] = useState<any>('yes');
   const { initialState, setInitialState } = useModel('@@initialState');
   const [captcha, setCaptcha] = useState<{ key?: string; base64?: string }>({});
@@ -25,10 +25,10 @@ const Bind = () => {
   const logo = require('/public/images/bind/jetlinksLogo.png');
 
   const iconMap = new Map();
-  iconMap.set('dingtalk', require('/public/images/notice/dingtalk.png'));
+  iconMap.set('dingtalk-ent-app', require('/public/images/notice/dingtalk.png'));
   iconMap.set('wechat-webapp', require('/public/images/notice/wechat.png'));
 
-  const bindUserInfo = (params: string) => {
+  const bindUserInfo = (params: any) => {
     service.bindUserInfo(params).then((res) => {
       if (res.status === 200) {
         setBindUser(res.result);
@@ -57,10 +57,14 @@ const Bind = () => {
       <div className={styles.topimg}>
         <img src={logo} style={{ width: '50px', height: '50px' }} />
         <img src={Vector} style={{ height: '15px', margin: '0 15px' }} />
-        <img src={iconMap.get(bindUser?.type)} style={{ width: '50px', height: '50px' }} />
+        <img
+          src={iconMap.get(bindUser?.applicationProvider)}
+          style={{ width: '50px', height: '50px' }}
+        />
       </div>
       <div className={styles.topfont}>
-        你已通过{bindUser?.type === 'dingtalk' ? '钉钉' : '微信'}授权,完善以下登录信息即可以完成绑定
+        你已通过{bindUser?.type === 'dingtalk-ent-app' ? '钉钉' : '微信'}
+        授权,完善以下登录信息即可以完成绑定
       </div>
       <div className={styles.form}>
         <Form layout="vertical" form={form}>
@@ -136,8 +140,9 @@ const Bind = () => {
   };
 
   useEffect(() => {
-    const params = window.location.href.split('?')[1].split('&')[1].split('=')[1];
-    // const params = 'b584032923c78d69e6148cf0e9312723'
+    const url = new URLSearchParams(window.location.href);
+    const params = url.get('code');
+    // const params = '5c021c8892d4afffd8fd42439c4e2382'
     setCode(params);
     bindUserInfo(params);
     if (localStorage.getItem('onLogin') === 'yes') {
@@ -146,6 +151,17 @@ const Bind = () => {
     if (localStorage.getItem('onLogin')) {
       setIslogin(localStorage.getItem('onLogin'));
     }
+    service.settingDetail('front').then((res) => {
+      if (res.status === 200) {
+        const ico: any = document.querySelector('link[rel="icon"]');
+        ico.href = res.result.ico;
+        if (res.result.title) {
+          document.title = res.result.title;
+        } else {
+          document.title = '';
+        }
+      }
+    });
   }, []);
   useEffect(getCode, []);
 
@@ -181,7 +197,7 @@ const Bind = () => {
                 >
                   <div className={styles.item}>
                     <div style={{ height: 100, marginTop: 10, marginBottom: 10 }}>
-                      <img src={logo} style={{ height: 70 }} />
+                      <img src={user?.avatar || logo} style={{ height: 70 }} />
                     </div>
                     <p className={styles.fonts}>账号:{user?.username}</p>
                     <p className={styles.fonts}>用户名:{user?.name}</p>
@@ -202,10 +218,13 @@ const Bind = () => {
                 >
                   <div className={styles.item}>
                     <div style={{ height: 100, marginTop: 10, marginBottom: 10 }}>
-                      <img style={{ height: 70 }} src={iconMap.get(bindUser?.type)} />
+                      <img
+                        style={{ height: 70 }}
+                        src={iconMap.get(bindUser?.applicationProvider)}
+                      />
                     </div>
-                    <p className={styles.fonts}>账户:{bindUser?.providerName}</p>
-                    <p className={styles.fonts}>用户名:{bindUser?.result.others.name}</p>
+                    <p className={styles.fonts}>用户名:{bindUser?.result?.username || '-'}</p>
+                    <p className={styles.fonts}>名称:{bindUser?.result?.name || '-'}</p>
                   </div>
                 </Card>
               </>

+ 17 - 14
src/pages/account/Center/index.tsx

@@ -39,11 +39,15 @@ const Center = () => {
   const [bindList, setBindList] = useState<any>([]);
 
   const iconMap = new Map();
-  iconMap.set('dingtalk', require('/public/images/notice/dingtalk.png'));
+  iconMap.set('dingtalk-ent-app', require('/public/images/notice/dingtalk.png'));
   iconMap.set('wechat-webapp', require('/public/images/notice/wechat.png'));
 
+  const nameMap = new Map();
+  nameMap.set('dingtalk-ent-app', '钉钉');
+  nameMap.set('wechat-webapp', '微信');
+
   const bGroundMap = new Map();
-  bGroundMap.set('dingtalk', require('/public/images/notice/dingtalk-background.png'));
+  bGroundMap.set('dingtalk-ent-app', require('/public/images/notice/dingtalk-background.png'));
   bGroundMap.set('wechat-webapp', require('/public/images/notice/wechat-background.png'));
 
   const getDetail = () => {
@@ -109,14 +113,14 @@ const Center = () => {
     });
   };
   const getBindInfo = () => {
-    service.bindInfo().then((res) => {
+    service.getSsoBinds().then((res) => {
       if (res.status === 200) {
         setBindList(res.result);
       }
     });
   };
-  const unBind = (type: string, provider: string) => {
-    service.unbind(type, provider).then((res) => {
+  const unBind = (appId: string) => {
+    service.unbind(appId).then((res) => {
       if (res.status === 200) {
         onlyMessage('解绑成功');
         getBindInfo();
@@ -182,7 +186,6 @@ const Center = () => {
             </Descriptions>
           </div>
           <a>
-            {' '}
             <EditOutlined
               className={styles.action}
               onClick={() => {
@@ -244,17 +247,17 @@ const Center = () => {
       >
         <Row gutter={[24, 24]}>
           {bindList.map((item: any) => (
-            <Col key={item.type}>
+            <Col key={item.id}>
               <Card
                 style={{
-                  background: `url(${bGroundMap.get(item.type)}) no-repeat`,
+                  background: `url(${bGroundMap.get(item.provider)}) no-repeat`,
                   backgroundSize: '100% 100%',
                   width: 415,
                 }}
               >
                 <div className={styles.bind}>
                   <div>
-                    <img style={{ height: 56 }} src={iconMap.get(item.type)} />
+                    <img style={{ height: 56 }} src={iconMap.get(item.provider)} />
                   </div>
                   <div>
                     {item.bound ? (
@@ -272,9 +275,7 @@ const Center = () => {
                         </div>
                       </div>
                     ) : (
-                      <div style={{ fontSize: '22px' }}>{`${
-                        item.type === 'dingtalk' ? '钉钉' : '微信'
-                      }未绑定`}</div>
+                      <div style={{ fontSize: '22px' }}>{nameMap.get(item.provider)}未绑定</div>
                     )}
                   </div>
                   <div>
@@ -282,7 +283,7 @@ const Center = () => {
                       <Popconfirm
                         title="确认解除绑定嘛?"
                         onConfirm={() => {
-                          unBind(item.type, item.provider);
+                          unBind(item.id);
                         }}
                       >
                         <Button>解除绑定</Button>
@@ -291,7 +292,9 @@ const Center = () => {
                       <Button
                         type="primary"
                         onClick={() => {
-                          window.open(`/${SystemConst.API_BASE}/sso/${item.provider}/login`);
+                          window.open(
+                            `/${SystemConst.API_BASE}/application/sso/${item.id}/login?autoCreateUser=false&redirect=/account/center/bind`,
+                          );
                           // window.open(`/#/account/center/bind`);
                           localStorage.setItem('onBind', 'false');
                           localStorage.setItem('onLogin', 'yes');

+ 18 - 5
src/pages/account/Center/service.ts

@@ -45,22 +45,35 @@ class Service extends BaseService<UserItem> {
       data: password,
     });
   bindInfo = (params?: any) =>
-    request(`/${SystemConst.API_BASE}/sso/me/bindings`, {
+    request(`/${SystemConst.API_BASE}/application/sso/me/bindings`, {
       method: 'GET',
       params,
     });
   bindUserInfo = (code: string) =>
-    request(`/${SystemConst.API_BASE}/sso/bind-code/${code}`, {
+    request(`/${SystemConst.API_BASE}/application/sso/bind-code/${code}`, {
       method: 'GET',
     });
   bind = (code: string) =>
-    request(`/${SystemConst.API_BASE}/sso/me/bind/${code}`, {
+    request(`/${SystemConst.API_BASE}/application/sso/me/bind/${code}`, {
       method: 'POST',
     });
-  unbind = (type: string, provider: string) =>
-    request(`/${SystemConst.API_BASE}/sso/me/${type}/${provider}/unbind`, {
+  unbind = (appId: string) =>
+    request(`/${SystemConst.API_BASE}/application/sso/${appId}/unbind/me`, {
       method: 'POST',
     });
+  getSso = (params?: any) =>
+    request(`/${SystemConst.API_BASE}/application/sso/_all`, {
+      method: 'GET',
+      params,
+    });
+  getSsoBinds = () =>
+    request(`/${SystemConst.API_BASE}/application/sso/me/bindings`, {
+      method: 'GET',
+    });
+  settingDetail = (scopes: any) =>
+    request(`/${SystemConst.API_BASE}/system/config/${scopes}`, {
+      method: 'GET',
+    });
 }
 
 export default Service;

+ 4 - 3
src/pages/device/components/Metadata/Base/Edit/index.tsx

@@ -1,7 +1,7 @@
 import { Button, Drawer, message } from 'antd';
 import { createSchemaField, observer } from '@formily/react';
 import MetadataModel from '../model';
-import type { Field, IFieldState } from '@formily/core';
+import { Field, IFieldState } from '@formily/core';
 import {
   createForm,
   onFieldInit,
@@ -493,7 +493,7 @@ const Edit = observer((props: Props) => {
               dependencies: ['..virtualRule.windowType'],
               fulfill: {
                 state: {
-                  value: "{{$self.value?'window':'script'}}",
+                  value: "{{ $self.value?'window':'script'}}",
                 },
               },
             },
@@ -504,13 +504,14 @@ const Edit = observer((props: Props) => {
             'x-visible': false,
             'x-reactions': [
               {
-                dependencies: ['..source', 'id'],
+                dependencies: ['..source', 'id', '..virtualRule'],
                 fulfill: {
                   state: {
                     visible: '{{$deps[0]==="rule"}}',
                   },
                   schema: {
                     'x-component-props.property': '{{$deps[1]}}',
+                    'x-component-props.virtualRule': '{{$deps[2]}}',
                   },
                 },
               },

+ 13 - 9
src/pages/link/Type/Detail/index.tsx

@@ -193,20 +193,24 @@ const Save = observer(() => {
           onFieldReact('grid.cluster.cluster.*.layout2.serverId', async (field, f3) => {
             const value = (field as Field).value;
             const type = (field.query('type').take() as Field).value;
-            const response = await getResourceById(value, type);
-            f3.setFieldState(field.query('.host'), (state) => {
-              state.dataSource = response.map((item) => ({ label: item.host, value: item.host }));
-            });
+            if (value) {
+              const response = await getResourceById(value, type);
+              f3.setFieldState(field.query('.host'), (state) => {
+                state.dataSource = response.map((item) => ({ label: item.host, value: item.host }));
+              });
+            }
           });
           onFieldReact('grid.cluster.cluster.*.layout2.host', async (field, f4) => {
             const host = (field as Field).value;
             const value = (field.query('.serverId').take() as Field)?.value;
             const type = (field.query('type').take() as Field)?.value;
-            const response = await getResourceById(value, type);
-            const _ports = response.find((item) => item.host === host);
-            f4.setFieldState(field.query('.port').take(), async (state) => {
-              state.dataSource = _ports?.ports?.map((i: any) => ({ label: i, value: i }));
-            });
+            if (value) {
+              const response = await getResourceById(value, type);
+              const _ports = response.find((item) => item.host === host);
+              f4.setFieldState(field.query('.port').take(), async (state) => {
+                state.dataSource = _ports?.ports?.map((i: any) => ({ label: i, value: i }));
+              });
+            }
           });
         },
       }),

+ 4 - 0
src/pages/media/Device/Playback/index.tsx

@@ -21,6 +21,7 @@ import {
 } from '@ant-design/icons';
 import TimeLine from './timeLine';
 import { RadioCard } from '@/components';
+import { onlyMessage } from '@/utils/util';
 
 const service = new Service('media');
 
@@ -56,6 +57,9 @@ const IconNode = (props: IconNodeType) => {
         endTime: item.endTime,
       })
       .then((res) => {
+        if (res.status === 200) {
+          onlyMessage('操作成功。上传云端需要一定时间,请稍后查看云端数据');
+        }
         setStatus(res.status === 200 ? 2 : 0);
       });
   };

+ 5 - 3
src/pages/user/Login/index.tsx

@@ -23,7 +23,7 @@ const Login: React.FC = () => {
   const intl = useIntl();
 
   const iconMap = new Map();
-  iconMap.set('dingtalk', require('/public/images/bind/dingtalk.png'));
+  iconMap.set('dingtalk-ent-app', require('/public/images/bind/dingtalk.png'));
   iconMap.set('wechat-webapp', require('/public/images/bind/wechat-webapp.png'));
 
   const fetchUserInfo = async () => {
@@ -266,7 +266,9 @@ const Login: React.FC = () => {
                           onClick={() => {
                             localStorage.setItem('onLogin', 'no');
                             //  window.open(`/#/account/center/bind`);
-                            window.open(`/${SystemConst.API_BASE}/sso/${item.provider}/login`);
+                            window.open(
+                              `/${SystemConst.API_BASE}/application/sso/${item.id}/login?redirect=/account/center/bind`,
+                            );
                             window.onstorage = (e) => {
                               if (e.newValue) {
                                 window.location.href = '/';
@@ -274,7 +276,7 @@ const Login: React.FC = () => {
                             };
                           }}
                         >
-                          <img src={iconMap.get(item.type)} />
+                          <img src={iconMap.get(item.provider)} />
                         </Button>
                       ))}
                     </div>

+ 1 - 1
src/pages/user/Login/service.ts

@@ -53,7 +53,7 @@ const Service = {
       method: 'GET',
     }),
   bindInfo: (params?: any) =>
-    request(`/${SystemConst.API_BASE}/sso/providers`, {
+    request(`/${SystemConst.API_BASE}/application/sso/_all`, {
       method: 'GET',
       params,
     }),