wzyyy 3 лет назад
Родитель
Сommit
28ff2690ee

+ 2 - 2
config/proxy.ts

@@ -15,8 +15,8 @@ export default {
       // target: 'http://120.79.18.123:8844/',
       // ws: 'ws://120.79.18.123:8844/',
       // 测试环境
-      target: 'http://120.77.179.54:8844/',
-      ws: 'ws://120.77.179.54:8844/',
+      target: 'http://192.168.32.65:8844/',
+      ws: 'ws://192.168.32.65:8844/',
       // target: 'http://192.168.66.5:8844/',
       // ws: 'ws://192.168.66.5:8844/',
       //v2环境

+ 11 - 0
config/routes.ts

@@ -42,6 +42,17 @@
       },
     ],
   },
+  {
+    path: '/init-license',
+    layout: false,
+    routes: [
+      {
+        name: '初始化License',
+        path: '/init-license',
+        component: './system/License/init',
+      },
+    ],
+  },
   // {
   //   path: '/analysis',
   //   name: 'analysis',

+ 37 - 4
src/app.tsx

@@ -1,6 +1,6 @@
 import type { Settings as LayoutSettings } from '@ant-design/pro-layout';
 import { PageLoading } from '@ant-design/pro-layout';
-import { notification } from 'antd';
+import { notification, Modal } from 'antd';
 import type { RequestConfig, RunTimeLayoutConfig } from 'umi';
 import { history, Link } from 'umi';
 import RightContent from '@/components/RightContent';
@@ -30,7 +30,9 @@ moment.locale('zh-cn');
 const isDev = process.env.NODE_ENV === 'development';
 const loginPath = '/user/login';
 const bindPath = '/account/center/bind';
+const licensePath = '/init-license';
 let extraRoutes: any[] = [];
+// const { permission: userPermission } = usePermissions('system/License');
 
 /** 获取用户信息比较慢的时候会展示一个 loading */
 export const initialStateConfig = {
@@ -73,7 +75,11 @@ export async function getInitialState(): Promise<{
   };
 
   // 如果是登录页面,不执行
-  if (history.location.pathname !== loginPath && history.location.pathname !== bindPath) {
+  if (
+    history.location.pathname !== loginPath &&
+    history.location.pathname !== bindPath &&
+    history.location.pathname !== licensePath
+  ) {
     const currentUser = await fetchUserInfo();
     const settings = await getSettings();
     return {
@@ -191,6 +197,32 @@ export const request: RequestConfig = {
               key: 'error',
               message: JSON.parse(resp || '{}').message || '服务器内部错误!',
             });
+            if (JSON.parse(resp || '{}').code === 'license required') {
+              //判读按钮权限
+              let buttons = {};
+              const buttonString = localStorage.getItem('MENUS_BUTTONS_CACHE');
+              buttons = JSON.parse(buttonString || '{}');
+              // console.log(buttons['system/License'].includes('update'))
+              Modal.error({
+                title: 'License已到期或者错误',
+                content: (
+                  <>
+                    {buttons['system/License'].includes('update') ? (
+                      <a
+                        onClick={() => {
+                          Modal.destroyAll();
+                          window.location.href = '/#/init-license';
+                        }}
+                      >
+                        请更新License
+                      </a>
+                    ) : (
+                      '请联系管理员更新license'
+                    )}
+                  </>
+                ),
+              });
+            }
           } else {
             response
               .clone()
@@ -286,7 +318,8 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => {
       if (
         !initialState?.currentUser &&
         location.pathname !== loginPath &&
-        location.pathname !== bindPath
+        location.pathname !== bindPath &&
+        location.pathname !== licensePath
       ) {
         history.push(loginPath);
       }
@@ -368,7 +401,7 @@ export function patchRoutes(routes: any) {
 }
 
 export function render(oldRender: any) {
-  if (![loginPath, bindPath].includes(history.location.pathname)) {
+  if (![loginPath, bindPath, licensePath].includes(history.location.pathname)) {
     //过滤非集成的菜单
     const params = [
       {

+ 97 - 0
src/pages/system/License/index.tsx

@@ -0,0 +1,97 @@
+import PermissionButton from "@/components/PermissionButton";
+import TitleComponent from "@/components/TitleComponent";
+import { useDomFullHeight } from "@/hooks";
+import usePermissions from "@/hooks/permission";
+import { onlyMessage } from "@/utils/util";
+import { PageContainer } from "@ant-design/pro-layout";
+import { Card, Descriptions, Input } from "antd";
+import { useEffect, useState } from "react";
+import Service from './service';
+
+
+const License = () => {
+    const { minHeight } = useDomFullHeight(`.license`);
+    const service = new Service('license');
+    const [info, setInfo] = useState<any>([])
+    const [license, setLicens] = useState<any>()
+    const [value, setValue] = useState<any>()
+    const { permission: userPermission } = usePermissions('system/License');
+
+    const getInfo = async () => {
+        const res = await service.getModule()
+        if (res.status === 200) {
+            setInfo(res.result)
+        }
+    }
+
+    const getLicense = async () => {
+        const res = await service.getLicense()
+        if (res.status === 200) {
+            setLicens(res.result)
+            setValue(res.result?.license)
+        }
+    }
+
+    const save = async (data: any) => {
+        const res: any = await service.save(data)
+        if (res.status === 200) {
+            onlyMessage('配置成功')
+            getLicense()
+        }
+    }
+
+    useEffect(() => {
+        getInfo()
+        getLicense()
+    }, [])
+
+    return (
+        <PageContainer>
+            <Card className="license" style={{ minHeight }}>
+                <TitleComponent data={'基础信息'} />
+                <div >
+                    <Descriptions bordered column={4}>
+                        {info.map((item: any) => (
+                            <>
+                                <Descriptions.Item label="IP" span={2}>{item.ip}</Descriptions.Item>
+                                <Descriptions.Item label="mac" span={2}>{item.mac}</Descriptions.Item>
+                            </>)
+                        )}
+                    </Descriptions>
+
+                </div>
+                <div style={{ display: 'flex', marginTop: 10, alignItems: 'center' }}>
+                    <TitleComponent data={'License'} style={{ marginTop: 10 }} />
+                    <div style={{ width: 200 }}>到期时间:{license?.expire}</div>
+                </div>
+
+                <Input.TextArea
+                    placeholder="请输入License"
+                    rows={10}
+                    // style={{ width: 900 }}
+                    value={value}
+                    onChange={(e) => {
+                        setValue(e.target.value)
+                    }}
+                />
+                <PermissionButton
+                    type="primary"
+                    key="save"
+                    style={{ marginTop: 20 }}
+                    onClick={() => {
+                        // save();
+                        if (value) {
+                            save(value)
+                        } else {
+                            onlyMessage('请配置License', 'warning')
+                        }
+                    }}
+                    isPermission={userPermission.update}
+                >
+                    保存
+                </PermissionButton>
+            </Card>
+        </PageContainer>
+    )
+}
+export default License;

+ 87 - 0
src/pages/system/License/init/index.tsx

@@ -0,0 +1,87 @@
+import PermissionButton from "@/components/PermissionButton";
+import TitleComponent from "@/components/TitleComponent";
+import { useDomFullHeight } from "@/hooks";
+import { onlyMessage } from "@/utils/util";
+import { Card, Descriptions, Input } from "antd";
+import { useEffect, useState } from "react";
+import Service from '../service';
+
+
+const Init = () => {
+    const { minHeight } = useDomFullHeight(`.license`);
+    const service = new Service('license');
+    const [info, setInfo] = useState<any>([])
+    const [value, setValue] = useState<any>()
+
+    const getInfo = async () => {
+        const res = await service.getModule()
+        if (res.status === 200) {
+            setInfo(res.result)
+        }
+    }
+
+    const save = async (data: any) => {
+        const res: any = await service.licenseInit(data)
+        if (res.status === 200) {
+            onlyMessage('配置成功')
+            const resp = await service.initPage()
+            if (resp.status === 200 && !resp.result.length) {
+                window.location.href = '/#/init-home';
+              }else{
+                window.location.href='/'
+              }
+        }
+    }
+
+    useEffect(() => {
+        document.title = '';
+        getInfo()
+    }, [])
+
+    return (
+            <Card className="license" style={{ minHeight }}>
+                <TitleComponent data={'基础信息'} />
+                <div >
+                    <Descriptions bordered column={4}>
+                        {info.map((item: any) => (
+                            <>
+                                <Descriptions.Item label="IP" span={2}>{item.ip}</Descriptions.Item>
+                                <Descriptions.Item label="mac" span={2}>{item.mac}</Descriptions.Item>
+                            </>)
+                        )}
+                    </Descriptions>
+
+                </div>
+                <div style={{ display: 'flex', marginTop: 10, alignItems: 'center' }}>
+                    <TitleComponent data={'License'} style={{ marginTop: 10 }} />
+                </div>
+
+                <Input.TextArea
+                    placeholder="请输入License"
+                    rows={10}
+                    // style={{ width: 900 }}
+                    value={value}
+                    onChange={(e) => {
+                        setValue(e.target.value)
+                    }}
+                />
+                <PermissionButton
+                    type="primary"
+                    key="save"
+                    style={{ marginTop: 20 }}
+                    onClick={() => {
+                        // save();
+                        if (value) {
+                            save(value)
+                        } else {
+                            onlyMessage('请配置License', 'warning')
+                        }
+                    }}
+                    isPermission={true}
+                >
+                    保存
+                </PermissionButton>
+            </Card>
+    )
+}
+export default Init;

+ 22 - 0
src/pages/system/License/service.ts

@@ -0,0 +1,22 @@
+import BaseService from '@/utils/BaseService';
+import { request } from 'umi';
+import SystemConst from '@/utils/const';
+
+class Service extends BaseService<any> {
+    licenseInit = (data?: any) =>
+        request(`/${SystemConst.API_BASE}/license/init`, {
+            method: 'POST',
+            data,
+        });
+    getModule = () =>
+        request(`/${SystemConst.API_BASE}/license/module`, {
+            method: 'GET',
+        });
+    getLicense = () =>
+        request(`/${SystemConst.API_BASE}/license`, {
+            method: 'GET',
+        });
+    initPage = () => request(`/${SystemConst.API_BASE}/user/settings/init`, { method: 'GET' })
+}
+
+export default Service;

+ 38 - 0
src/pages/system/Menu/Setting/baseMenu.ts

@@ -1761,6 +1761,44 @@ export default [
           },
         ],
       },
+      {
+        code: 'system/License',
+        name: 'License管理',
+        owner: 'iot',
+        parentId: '3',
+        id: '3-11',
+        sortIndex: 11,
+        url: '/system/License',
+        icon: 'icon-zidingyiguize',
+        permissions: [],
+        buttons: [
+          {
+            id: 'update',
+            name: '编辑',
+            description: null,
+            permissions: [
+              {
+                permission: 'license',
+                actions: ['query', 'save'],
+              },
+            ],
+            options: null,
+          },
+
+          {
+            id: 'view',
+            name: '查看',
+            description: null,
+            permissions: [
+              {
+                permission: 'license"',
+                actions: ['query'],
+              },
+            ],
+            options: null,
+          },
+        ],
+      },
     ],
   },
 ];

+ 1 - 0
src/utils/menu/router.ts

@@ -133,6 +133,7 @@ export enum MENUS_CODE {
   'system/Apply' = 'system/Apply',
   'system/Apply/Api' = 'system/Apply/Api',
   'system/Apply/View' = 'system/Apply/View',
+  'system/License' = 'system/License',
 }
 
 export type MENUS_CODE_TYPE = keyof typeof MENUS_CODE | string;