lind 3 лет назад
Родитель
Сommit
c94652dc8d

BIN
public/images/notice/doc/template/weixin-official/02-mini-Program-Appid.png


+ 24 - 2
src/pages/device/components/Metadata/Cat/index.tsx

@@ -3,23 +3,45 @@ import { useEffect, useState } from 'react';
 import { productModel, service } from '@/pages/device/Product';
 import MonacoEditor from 'react-monaco-editor';
 import { observer } from '@formily/react';
+import { InstanceModel } from '@/pages/device/Instance';
+import { useLocation } from 'umi';
+import InstanceService from '@/pages/device/Instance/service';
 
 interface Props {
   visible: boolean;
   close: () => void;
+  type: 'product' | 'device';
 }
 
+const instanceService = new InstanceService('device-instance');
 const Cat = observer((props: Props) => {
+  const location = useLocation<{ id: string }>();
   const [codecs, setCodecs] = useState<{ id: string; name: string }[]>();
-  const metadata = productModel.current?.metadata as string;
+  const metadataMap = {
+    product: productModel.current?.metadata as string,
+    device: InstanceModel.current?.metadata as string, // 有问题
+  };
+  const metadata = metadataMap[props.type];
   const [value, setValue] = useState(metadata);
+  const _path = location.pathname.split('/');
+  const id = _path[_path.length - 1];
   useEffect(() => {
     service.codecs().subscribe({
       next: (data) => {
         setCodecs([{ id: 'jetlinks', name: 'jetlinks' }].concat(data));
       },
     });
-  }, []);
+
+    if (props.type === 'device' && id) {
+      instanceService.detail(id).then((resp) => {
+        if (resp.status === 200) {
+          InstanceModel.current = resp.result;
+          const _metadata = resp.result?.metadata;
+          setValue(_metadata);
+        }
+      });
+    }
+  }, [id]);
 
   const convertMetadata = (key: string) => {
     if (key === 'alink') {

+ 1 - 1
src/pages/device/components/Metadata/index.tsx

@@ -94,7 +94,7 @@ const Metadata = observer((props: Props) => {
         </Tabs.TabPane>
       </Tabs>
       <Import visible={visible} close={() => setVisible(false)} />
-      <Cat visible={cat} close={() => setCat(false)} />
+      <Cat visible={cat} close={() => setCat(false)} type={props.type} />
     </div>
   );
 });

+ 34 - 20
src/pages/notice/Template/Debug/index.tsx

@@ -38,27 +38,32 @@ const Debug = observer(() => {
             }
           });
 
-          onFieldReact('variableDefinitions.*.type', (field) => {
+          onFieldReact('variableDefinitions.*.id', (field) => {
             const value = (field as Field).value;
-            const format = field.query('.value').take() as any;
-            switch (value) {
-              case 'date':
-                format.setComponent(DatePicker);
-                break;
-              case 'string':
-                format.setComponent(Input);
-                break;
-              case 'number':
-                format.setComponent(NumberPicker);
-                break;
-              case 'file':
-                format.setComponent(FUpload, {
-                  type: 'file',
-                });
-                break;
-              case 'other':
-                format.setComponent(Input);
-                break;
+            const format = field.query('.value').take() as Field;
+
+            if (format) {
+              switch (value) {
+                case 'date':
+                  format.setComponent(DatePicker, {
+                    showTime: true,
+                  });
+                  break;
+                case 'string':
+                  format.setComponent(Input);
+                  break;
+                case 'number':
+                  format.setComponent(NumberPicker, {});
+                  break;
+                case 'file':
+                  format.setComponent(FUpload, {
+                    type: 'file',
+                  });
+                  break;
+                case 'other':
+                  format.setComponent(Input);
+                  break;
+              }
             }
           });
         },
@@ -83,6 +88,9 @@ const Debug = observer(() => {
       Select,
       ArrayTable,
       PreviewText,
+      NumberPicker,
+      DatePicker,
+      FUpload,
     },
   });
 
@@ -164,6 +172,12 @@ const Debug = observer(() => {
                   'x-decorator': 'FormItem',
                   'x-component': 'Input',
                 },
+                type: {
+                  'x-hidden': true,
+                  type: 'string',
+                  'x-decorator': 'FormItem',
+                  'x-component': 'Input',
+                },
               },
             },
           },

+ 31 - 14
src/pages/notice/Template/Detail/doc/WeixinApp.tsx

@@ -2,35 +2,52 @@ import { Image } from 'antd';
 import './index.less';
 
 const WeixinApp = () => {
-  const agentId = require('/public/images/notice/doc/template/weixin-official/01-Agentid.jpg');
-  const appId = require('/public/images/notice/doc/template/weixin-official/02-mini-Program-Appid.jpg');
+  const appId = require('/public/images/notice/doc/template/weixin-official/02-mini-Program-Appid.png');
 
   return (
     <div className="doc">
       <div className="url">
-        微信公众平台:<a href="https://mp.weixin.qq.com/">https://mp.weixin.qq.com/</a>
+        企业微信管理后台:<a href="https://work.weixin.qq.com">https://work.weixin.qq.com</a>
       </div>
       <h1>1. 概述</h1>
       <div>
-        通知配置可以结合通知配置为告警消息通知提供支撑。也可以用于系统中其他自定义模块的调用
+        通知模板结合通知配置为告警消息通知提供支撑。通知模板只能调用同一类型的通知配置服务
       </div>
-      <h1>2.通知配置说明</h1>
+      <h1>2.模板配置说明</h1>
       <div>
-        <h2>1. AppID</h2>
-        <div>微信服务号的唯一专属编号。</div>
-        <div>获取路径:“微信公众平台”管理后台--“设置与开发”--“基本配置”</div>
-        <div className="image">
-          <Image width="100%" src={agentId} />
-        </div>
+        <h2>1. 绑定配置</h2>
+        <div>绑定通知配置</div>
+      </div>
+      <div>
+        <h2>2. 用户标签</h2>
+        <div>以标签的维度通知该标签下所有用户</div>
       </div>
-      <h2>2. AppSecret</h2>
       <div>
-        <div>公众号开发者身份的密码</div>
-        <div>获取路径:“微信公众平台”管理后台--“设置与开发”--“基本配置”</div>
+        <h2>3. 消息模板</h2>
+        <div>微信公众号中配置的消息模板</div>
+      </div>
+      <div>
+        <h2>4. 模板跳转链接</h2>
+        <div>点击消息之后进行页面跳转</div>
+      </div>
+      <div>
+        <h2>5. 跳转小程序Appid</h2>
+        <div>点击消息之后打开对应的小程序</div>
+      </div>
+      <div>
+        <h2>6. 跳转小程序具体路径</h2>
+        <div>点击消息之后跳转到小程序的具体页面</div>
         <div className="image">
           <Image width="100%" src={appId} />
         </div>
       </div>
+      <div>
+        <h2>7. 模板内容</h2>
+        <div>
+          支持填写带变量的动态模板。变量填写规范示例:${name}
+          。填写动态参数后,可对变量的名称、类型、格式进行配置,以便告警通知时填写。
+        </div>
+      </div>
     </div>
   );
 };

+ 17 - 15
src/pages/notice/Template/Detail/index.tsx

@@ -16,7 +16,7 @@ import {
   Switch,
 } from '@formily/antd';
 import type { Field } from '@formily/core';
-import { createForm, onFieldInit, onFieldValueChange } from '@formily/core';
+import { createForm, FormPath, onFieldInit, onFieldReact, onFieldValueChange } from '@formily/core';
 import { createSchemaField, observer } from '@formily/react';
 import type { ISchema } from '@formily/json-schema';
 import styles from './index.less';
@@ -60,7 +60,7 @@ export const docMap = {
 
 const Detail = observer(() => {
   const { id } = useParams<{ id: string }>();
-  const [provider, setProvider] = useState<string>();
+  const [provider, setProvider] = useState<string>('embedded');
   // 正则提取${}里面的值
   const pattern = /(?<=\$\{).*?(?=\})/g;
 
@@ -227,9 +227,17 @@ const Detail = observer(() => {
               form1.setValuesIn('variableDefinitions', idList);
             }
           });
-          onFieldValueChange('variableDefinitions.*.type', (field) => {
+          onFieldReact('variableDefinitions.*.type', (field) => {
             const value = (field as Field).value;
-            const format = field.query('.format').take() as any;
+            const formatPath = FormPath.transform(
+              field.path,
+              /\d+/,
+              (index) => `variableDefinitions.${parseInt(index)}.format`,
+            );
+            const format = field.query(formatPath).take() as any;
+
+            console.log(format, 'format', value);
+            if (!format) return;
             switch (value) {
               case 'date':
                 format.setComponent(Select);
@@ -243,8 +251,9 @@ const Detail = observer(() => {
                 format.setValue('string');
                 break;
               case 'string':
+                console.log('string');
                 format.setComponent(PreviewText.Input);
-                format.setValue('--');
+                format.setValue('%s');
                 break;
               case 'number':
                 format.setComponent(Input);
@@ -473,15 +482,6 @@ const Detail = observer(() => {
               officialMessage: {
                 type: 'void',
                 properties: {
-                  agentId: {
-                    title: 'AgentId',
-                    type: 'string',
-                    'x-decorator': 'FormItem',
-                    'x-component': 'Input',
-                    'x-component-props': {
-                      placeholder: '请输入AgentId',
-                    },
-                  },
                   tagid: {
                     title: '用户标签',
                     type: 'string',
@@ -1000,9 +1000,11 @@ const Detail = observer(() => {
           fulfill: {
             state: {
               hidden: '{{$deps[0]==="aliyun"}}',
+              disabled: '{{["aliyunSms","aliyun"].includes($deps[0])}}',
             },
           },
         },
+
         'x-component-props': {
           rows: 5,
           placeholder: '变量格式:${name};\n 示例:尊敬的${name},${time}有设备触发告警,请注意处理',
@@ -1070,7 +1072,7 @@ const Detail = observer(() => {
             column4: {
               type: 'void',
               'x-component': 'ArrayTable.Column',
-              'x-component-props': { title: '格式', width: '150px' },
+              'x-component-props': { title: '格式', width: '300px' },
               required: true,
               properties: {
                 format: {

+ 27 - 4
src/pages/notice/Template/Log/index.tsx

@@ -1,4 +1,4 @@
-import { Modal } from 'antd';
+import { Badge, Modal } from 'antd';
 import { observer } from '@formily/react';
 import { service, state } from '..';
 import ProTable, { ActionType, ProColumns } from '@jetlinks/pro-table';
@@ -15,6 +15,7 @@ const Log = observer(() => {
     {
       dataIndex: 'id',
       title: 'id',
+      width: 200,
     },
     {
       dataIndex: 'sendTime',
@@ -23,6 +24,30 @@ const Log = observer(() => {
     {
       dataIndex: 'state',
       title: '状态',
+      renderText: (text: { value: string; text: string }, record) => {
+        return (
+          <>
+            <Badge status={text.value === 'success' ? 'success' : 'error'} text={text.text} />
+            {text.value !== 'success' && (
+              <a
+                key="info"
+                onClick={() => {
+                  Modal.info({
+                    title: '错误信息',
+                    width: '30vw',
+                    content: (
+                      <div style={{ height: '300px', overflowY: 'auto' }}>{record.errorStack}</div>
+                    ),
+                    onOk() {},
+                  });
+                }}
+              >
+                <InfoCircleOutlined />
+              </a>
+            )}
+          </>
+        );
+      },
     },
     {
       dataIndex: 'action',
@@ -34,9 +59,7 @@ const Log = observer(() => {
             Modal.info({
               title: '详情信息',
               width: '30vw',
-              content: (
-                <div style={{ height: '300px', overflowY: 'auto' }}>{record.errorStack}</div>
-              ),
+              content: <div style={{ height: '300px', overflowY: 'auto' }}>{record.message}</div>,
               onOk() {},
             });
           }}

+ 1 - 0
src/pages/notice/Template/index.tsx

@@ -315,6 +315,7 @@ const Template = observer(() => {
                     actionRef.current?.reset?.();
                   },
                 }}
+                isPermission={templatePermission.delete}
                 key="delete"
               >
                 <DeleteOutlined />

+ 1 - 0
src/pages/notice/Template/typings.d.ts

@@ -16,4 +16,5 @@ type LogItem = {
   sendTime: number;
   state: string;
   errorStack?: string;
+  message?: string;
 };

+ 2 - 3
src/pages/system/User/ResetPassword/index.tsx

@@ -107,7 +107,7 @@ const ResetPassword = (props: Props) => {
     },
   };
 
-  const form = useMemo(() => createForm({}), []);
+  const form = useMemo(() => createForm({}), [props.visible]);
   return (
     <Modal
       title="重置密码"
@@ -120,9 +120,8 @@ const ResetPassword = (props: Props) => {
           if (resp.status === 200) {
             message.success('操作成功');
           }
-        } else {
-          props.close();
         }
+        props.close();
       }}
     >
       <Form form={form} layout="vertical">