瀏覽代碼

fix(产品): 新增应用配置

xieyonghong 3 年之前
父節點
當前提交
7626471069

+ 1 - 2
src/app.tsx

@@ -193,7 +193,6 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => {
       }
     },
     menuDataRender: () => {
-      console.log(getMenus(extraRoutes));
       return getMenus(extraRoutes);
     },
     links: isDev
@@ -238,7 +237,7 @@ export function patchRoutes(routes: any) {
 
 export function render(oldRender: any) {
   if (history.location.pathname !== loginPath) {
-    MenuService.queryMenuThree({ paging: false }).then((res) => {
+    MenuService.queryOwnThree({ paging: false }).then((res) => {
       if (res.status === 200) {
         extraRoutes = handleRoutes(res.result);
         saveMenusCache(extraRoutes);

+ 1 - 0
src/locales/zh-CN/pages.ts

@@ -31,6 +31,7 @@ export default {
   'pages.data.option.assets': '资产分配',
   'pages.data.option.invoke': '执行',
   'pages.data.option.cancel': '取消',
+  'pages.data.option.view': '查看',
   'pages.searchTable.new': '新建',
   'pages.searchTable.titleStatus': '状态',
   'pages.searchTable.titleStatus.all': '全部',

+ 24 - 0
src/pages/device/Instance/Detail/index.tsx

@@ -17,11 +17,13 @@ import MetadataAction from '@/pages/device/components/Metadata/DataBaseAction';
 import { Store } from 'jetlinks-store';
 import SystemConst from '@/utils/const';
 import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
+import useSendWebsocketMessage from '@/hooks/websocket/useSendWebsocketMessage';
 
 export const deviceStatus = new Map();
 deviceStatus.set('online', <Badge status="success" text={'在线'} />);
 deviceStatus.set('offline', <Badge status="error" text={'离线'} />);
 deviceStatus.set('notActive', <Badge status="processing" text={'未启用'} />);
+
 const InstanceDetail = observer(() => {
   const intl = useIntl();
   const [tab, setTab] = useState<string>('detail');
@@ -35,6 +37,28 @@ const InstanceDetail = observer(() => {
   };
   const params = useParams<{ id: string }>();
 
+  const [subscribeTopic] = useSendWebsocketMessage();
+
+  useEffect(() => {
+    if (subscribeTopic) {
+      subscribeTopic(
+        `instance-editor-info-status-${params.id}`,
+        `/dashboard/device/status/change/realTime`,
+        {
+          deviceId: params.id,
+        },
+        // @ts-ignore
+      ).subscribe((data: any) => {
+        const payload = data.payload;
+        const state = payload.value.type;
+        InstanceModel.detail.state = {
+          value: state,
+          text: '',
+        };
+      });
+    }
+  }, []);
+
   useEffect(() => {
     Store.subscribe(SystemConst.REFRESH_DEVICE, () => {
       MetadataAction.clean();

+ 4 - 0
src/pages/device/Instance/Save/index.tsx

@@ -17,6 +17,7 @@ interface Props {
 const Save = (props: Props) => {
   const { visible, close, data } = props;
   const [productList, setProductList] = useState<any[]>([]);
+  const [loading, setLoading] = useState(false);
   const [form] = Form.useForm();
 
   useEffect(() => {
@@ -70,7 +71,9 @@ const Save = (props: Props) => {
       if (values.id === '') {
         delete values.id;
       }
+      setLoading(true);
       const resp = (await service.update(values)) as any;
+      setLoading(false);
       if (resp.status === 200) {
         message.success('保存成功');
         if (props.reload) {
@@ -114,6 +117,7 @@ const Save = (props: Props) => {
         id: `pages.data.option.${props.model || 'add'}`,
         defaultMessage: '新增',
       })}
+      confirmLoading={loading}
       onOk={handleSave}
     >
       <Form

+ 34 - 9
src/pages/device/Product/Detail/index.tsx

@@ -1,6 +1,18 @@
 import { PageContainer } from '@ant-design/pro-layout';
 import { history, Link, useParams } from 'umi';
-import { Badge, Card, Descriptions, message, Space, Spin, Switch, Tabs, Tooltip } from 'antd';
+import {
+  Badge,
+  Button,
+  Card,
+  Descriptions,
+  message,
+  Popconfirm,
+  Space,
+  Spin,
+  Switch,
+  Tabs,
+  Tooltip,
+} from 'antd';
 import BaseInfo from '@/pages/device/Product/Detail/BaseInfo';
 import { observer } from '@formily/react';
 import { productModel, service } from '@/pages/device/Product';
@@ -149,14 +161,27 @@ const ProductDetail = observer(() => {
           }}
         />
       }
-      // extra={[
-      //   <Button key="1" type="primary" onClick={() => changeDeploy('deploy')}>
-      //     {intl.formatMessage({
-      //       id: 'pages.device.productDetail.setting',
-      //       defaultMessage: '应用配置',
-      //     })}
-      //   </Button>,
-      // ]}
+      extra={[
+        <Popconfirm title={'确定应用配置?'} key="1" onConfirm={() => changeDeploy('deploy')}>
+          {productModel.current?.state === 0 ? (
+            <Tooltip title={'请先发布产品'}>
+              <Button disabled type="primary">
+                {intl.formatMessage({
+                  id: 'pages.device.productDetail.setting',
+                  defaultMessage: '应用配置',
+                })}
+              </Button>
+            </Tooltip>
+          ) : (
+            <Button key="1" type="primary">
+              {intl.formatMessage({
+                id: 'pages.device.productDetail.setting',
+                defaultMessage: '应用配置',
+              })}
+            </Button>
+          )}
+        </Popconfirm>,
+      ]}
     >
       <Card>
         <Tabs defaultActiveKey="base">

+ 5 - 1
src/pages/device/Product/Save/index.tsx

@@ -1,4 +1,4 @@
-import { useEffect } from 'react';
+import { useEffect, useState } from 'react';
 import { service } from '@/pages/device/Product';
 import type { ProductItem } from '@/pages/device/Product/typings';
 import { useIntl } from '@@/plugin-locale/localeExports';
@@ -19,6 +19,7 @@ const Save = (props: Props) => {
   const { visible, close, data } = props;
   const intl = useIntl();
   const [form] = Form.useForm();
+  const [loading, setLoading] = useState(false);
   const { data: classOptions, run: classRequest } = useRequest(service.category, {
     manual: true,
     formatResult: (response) => {
@@ -76,7 +77,9 @@ const Save = (props: Props) => {
       }
       const { deviceTypeId, ...extraFormData } = formData;
       extraFormData.deviceType = formData.deviceTypeId;
+      setLoading(true);
       const res = await service.update(extraFormData);
+      setLoading(false);
       if (res.status === 200) {
         message.success('保存成功');
         if (props.reload) {
@@ -119,6 +122,7 @@ const Save = (props: Props) => {
         id: `pages.data.option.${props.model || 'add'}`,
         defaultMessage: '新增',
       })}
+      confirmLoading={loading}
       onOk={handleSave}
     >
       <Form

+ 1 - 1
src/pages/system/Department/index.tsx

@@ -185,7 +185,7 @@ export default observer(() => {
         'x-validator': [
           {
             required: true,
-            message: '请输入名称',
+            message: '请选择上级部门',
           },
         ],
         'x-component-props': {

+ 15 - 16
src/pages/system/Menu/Detail/edit.tsx

@@ -9,7 +9,6 @@ import {
   Radio,
   Row,
   Select,
-  Switch,
   Tooltip,
   TreeSelect,
 } from 'antd';
@@ -67,10 +66,10 @@ export default (props: EditProps) => {
   const saveData = async () => {
     const formData = await form.validateFields();
     if (formData) {
-      formData.options = {
-        switch: show,
-      };
-      console.log(formData);
+      // formData.options = {
+      //   switch: show,
+      // };
+
       const response: any = !formData.id
         ? await service.save(formData)
         : await service.update(formData);
@@ -224,17 +223,17 @@ export default (props: EditProps) => {
         <Card style={{ marginTop: 24 }}>
           <Title
             title={'权限配置'}
-            toolbarRender={
-              <Switch
-                disabled={disabled}
-                checkedChildren="开启"
-                unCheckedChildren="关闭"
-                checked={show}
-                onChange={(checked) => {
-                  setShow(checked);
-                }}
-              />
-            }
+            // toolbarRender={
+            //   <Switch
+            //     disabled={disabled}
+            //     checkedChildren="开启"
+            //     unCheckedChildren="关闭"
+            //     checked={show}
+            //     onChange={(checked) => {
+            //       setShow(checked);
+            //     }}
+            //   />
+            // }
           />
           {show && (
             <Row gutter={[0, 10]}>

+ 8 - 10
src/pages/system/Menu/Detail/index.tsx

@@ -68,16 +68,14 @@ export default () => {
       }}
     >
       {tabKey === 'detail' ? (
-        <div style={{ padding: '16px 24px' }}>
-          <BaseDetail
-            data={{
-              ...data,
-              parentId: pId,
-            }}
-            basePath={params.get('basePath')}
-            onLoad={queryDetail}
-          />
-        </div>
+        <BaseDetail
+          data={{
+            ...data,
+            parentId: pId,
+          }}
+          basePath={params.get('basePath')}
+          onLoad={queryDetail}
+        />
       ) : (
         <Buttons data={data} onLoad={queryDetail} />
       )}

+ 6 - 0
src/pages/system/Menu/service.ts

@@ -11,6 +11,12 @@ class Service extends BaseService<MenuItem> {
   queryMenuThree = (data: any) => request(`${this.uri}/_all/tree`, { method: 'POST', data });
 
   /**
+   * 当前用户权限菜单
+   * @param data
+   */
+  queryOwnThree = (data: any) => request(`${this.uri}/user-own/tree`, { method: 'POST', data });
+
+  /**
    * 查询权限管理
    * @param data
    */

+ 2 - 7
src/pages/user/Login/index.tsx

@@ -1,6 +1,6 @@
 import { Checkbox, message, Spin } from 'antd';
 import React, { useEffect, useRef, useState } from 'react';
-import { history, Link } from 'umi';
+import { Link } from 'umi';
 import styles from './index.less';
 import Token from '@/utils/token';
 import Service from '@/pages/user/Login/service';
@@ -42,15 +42,10 @@ const Login: React.FC = () => {
 
   /** 此方法会跳转到 redirect 参数所在的位置 */
   const goto = () => {
-    if (!history) return;
     setTimeout(() => {
-      const { query } = history.location;
-      const { redirect } = query as {
-        redirect: string;
-      };
       // history.push(redirect || '/');
       // 用于触发app中的render,生成路由
-      window.location.href = redirect || '/';
+      window.location.href = '/';
       setLoading(false);
     }, 10);
   };