tianyunperfect 5 år sedan
förälder
incheckning
11b99afc61

+ 7 - 7
config/config.ts

@@ -56,7 +56,7 @@ export default defineConfig({
           routes: [
             {
               path: '/',
-              redirect: '/modelList',
+              redirect: '/memory',
             },
             // {
             //   path: '/welcome',
@@ -87,16 +87,16 @@ export default defineConfig({
             //   component: './ListTableList',
             // },
             {
-              name: 'list.model-list',
+              name: 'list.memory',
               icon: 'smile',
-              path: '/modelList',
-              component: './ModelList',
+              path: '/memory',
+              component: './Memory',
             },
             {
-              name: 'list.service-list',
+              name: 'list.setting',
               icon: 'smile',
-              path: '/serviceList',
-              component: './ServiceList',
+              path: '/setting',
+              component: './Setting',
             },
             {
               component: './404',

+ 1 - 1
config/proxy.ts

@@ -22,7 +22,7 @@ export default {
   },
   pre: {
     '/api/': {
-      target: 'http://127.0.0.1:9080',
+      target: 'http://www.tianyunperfect.cn:9080',
       changeOrigin: true,
       pathRewrite: { '^': '' },
     },

+ 1 - 0
package.json

@@ -8,6 +8,7 @@
     "build": "umi build",
     "deploy": "npm run site && npm run gh-pages",
     "dev": "npm run start:dev",
+    "pre": "npm run start:pre",
     "fetch:blocks": "pro fetch-blocks --branch=umi@3 && npm run prettier",
     "gh-pages": "cp CNAME ./dist/ && gh-pages -d dist",
     "i18n-remove": "pro i18n-remove --locale=zh-CN --write",

+ 2 - 2
src/locales/zh-CN/menu.ts

@@ -22,8 +22,8 @@ export default {
   'menu.form.step-form.result': '分步表单(完成)',
   'menu.form.advanced-form': '高级表单',
   'menu.list': '列表页',
-  'menu.list.table-list': '查询表格',
-  'menu.list.model-list': '模型列表',
+  'menu.list.memory': '记忆',
+  'menu.list.setting': '设置',
   'menu.list.service-list': '服务列表',
   'menu.list.basic-list': '标准列表',
   'menu.list.card-list': '卡片列表',

+ 1 - 1
src/models/login.ts

@@ -38,7 +38,7 @@ const Model: LoginModelType = {
         payload: response,
       });
       // Login successfully
-      if (response.status === 'ok') {
+      if (response.success) {
         const urlParams = new URL(window.location.href);
         const params = getPageQuery();
         let { redirect } = params as { redirect: string };

+ 0 - 0
src/pages/ModelList/_mock.ts → src/pages/Memory/_mock.ts


+ 0 - 0
src/pages/ModelList/components/CreateForm.tsx → src/pages/Memory/components/CreateForm.tsx


+ 0 - 0
src/pages/ModelList/components/QueryForm.tsx → src/pages/Memory/components/QueryForm.tsx


+ 0 - 0
src/pages/ModelList/components/UpdateForm.tsx → src/pages/Memory/components/UpdateForm.tsx


+ 0 - 0
src/pages/ModelList/data.d.ts → src/pages/Memory/data.d.ts


+ 0 - 0
src/pages/ModelList/index.less → src/pages/Memory/index.less


+ 1 - 1
src/pages/ModelList/index.tsx → src/pages/Memory/index.tsx

@@ -4,7 +4,7 @@ import React, {useRef, useState} from 'react';
 import {PageHeaderWrapper} from '@ant-design/pro-layout';
 import ProTable, {ActionType, ProColumns} from '@ant-design/pro-table';
 import {SorterResult} from 'antd/es/table/interface';
-import QueryForm from '@/pages/ModelList/components/QueryForm';
+import QueryForm from '@/pages/Memory/components/QueryForm';
 import {TableListItem} from './data.d';
 import service from './service';
 

+ 0 - 0
src/pages/ModelList/service.ts → src/pages/Memory/service.ts


+ 60 - 0
src/pages/Setting/_mock.ts

@@ -0,0 +1,60 @@
+// eslint-disable-next-line import/no-extraneous-dependencies
+import { Request, Response } from 'express';
+import { parse } from 'url';
+import { TableListItem, TableListParams } from './data.d';
+
+// mock tableListDataSource
+const genList = (current: number, pageSize: number) => {
+  const tableListDataSource: TableListItem[] = [];
+
+  for (let i = 0; i < pageSize; i += 1) {
+    const index = (current - 1) * 10 + i;
+    tableListDataSource.push({
+      msg: "为学者日益", success: "成功",
+      id: index,
+      serviceIp: `${index}name`,
+      modelName: `${index}name`,
+      modelVersion: `${new Date()}`,
+      currentVersion: `${new Date()}`
+    });
+  }
+  tableListDataSource.reverse();
+  return tableListDataSource;
+};
+
+const tableListDataSource = genList(1, 100);
+
+function getModels(req: Request, res: Response, u: string) {
+  let realUrl = u;
+  if (!realUrl || Object.prototype.toString.call(realUrl) !== '[object String]') {
+    realUrl = req.url;
+  }
+  const { current = 1, pageSize = 10 } = req.query;
+  const params = (parse(realUrl, true).query as unknown) as TableListParams;
+
+  // @ts-ignore
+  const dataSource = [...tableListDataSource].slice((current - 1) * pageSize, current * pageSize);
+
+  const result = {
+    data: dataSource,
+    total: tableListDataSource.length,
+    success: true,
+    pageSize,
+    current: parseInt(`${params.currentPage}`, 10) || 1,
+  };
+
+  return res.json(result);
+}
+
+function success(req: Request, res: Response, u: string) {
+  const result = {
+    data: "ok",
+    success: true,
+  };
+  return res.json(result);
+}
+
+export default {
+  'GET /service/queryList': getModels,
+  'POST /service/forceUpdate': success,
+};

+ 31 - 0
src/pages/Setting/data.d.ts

@@ -0,0 +1,31 @@
+// 表单
+export interface TableListItem {
+  id?: number;
+  serviceIp: string;
+  modelName: string;
+  modelVersion: Date;
+  currentVersion: Date;
+  success:string;
+  msg:string;
+}
+// 分页参数
+export interface TableListPagination {
+  total: number;
+  pageSize: number;
+  current: number;
+}
+// 返回的分页数据
+export interface TableListData {
+  list: TableListItem[];
+  pagination: Partial<TableListPagination>;
+}
+// 查询参数
+export interface TableListParams {
+  sorter?: string;
+  status?: string;
+  name?: string;
+  desc?: string;
+  id?: number;
+  pageSize?: number;
+  currentPage?: number;
+}

+ 6 - 0
src/pages/Setting/index.less

@@ -0,0 +1,6 @@
+.upload {
+  display: inline;
+}
+.red{
+  color: red;
+}

+ 151 - 0
src/pages/Setting/index.tsx

@@ -0,0 +1,151 @@
+import { message, Tooltip, Radio } from 'antd';
+import React, { useRef, useState } from 'react';
+import { PageHeaderWrapper } from '@ant-design/pro-layout';
+import ProTable, { ActionType, ProColumns } from '@ant-design/pro-table';
+import { SorterResult } from 'antd/es/table/interface';
+import { TableListItem } from './data.d';
+import service from './service';
+import styles from './index.less'
+
+/**
+ * 更新节点
+ * @param fields
+ */
+const handleUpdate = async (fields: TableListItem) => {
+  const hide = message.loading('正在配置');
+  try {
+    const data = await service.forceUpdateModel(fields);
+    hide();
+    message.success('配置成功');
+    return data.success;
+  } catch (error) {
+    hide();
+    message.error('配置失败请重试!');
+    return false;
+  }
+};
+
+const TableList: React.FC<{}> = () => {
+  const [sorter, setSorter] = useState<string>('');
+  const actionRef = useRef<ActionType>();
+
+  const columns: ProColumns<TableListItem>[] = [
+    {
+      title: '服务IP',
+      dataIndex: 'serviceIp',
+      width: 150,
+      copyable: true,
+    },
+    {
+      title: '模型名称',
+      dataIndex: 'modelName',
+      width: 150,
+      copyable: true,
+    },
+    {
+      title: '模型版本',
+      dataIndex: 'modelVersion',
+      valueType: 'dateTime',
+      width: 200,
+      hideInSearch: true,
+    },
+    {
+      title: '当前版本',
+      dataIndex: 'currentVersion',
+      valueType: 'dateTime',
+      width: 220,
+      hideInSearch: true,
+      render: (text, row)=>{
+        if (row.currentVersion < row.modelVersion) {
+           return (<div className={styles.red}>{text} :待更新</div>)
+        }
+        return (<div>{text}</div>)
+
+      }
+    },
+    {
+      title: '启动状态',
+      dataIndex: 'success',
+      copyable: true,
+      width: 100,
+      renderFormItem: () => {
+        return (
+          <Radio.Group>
+            <Radio value="成功">成功</Radio>
+            <Radio value="失败">失败</Radio>
+          </Radio.Group>
+        );
+      },
+      valueEnum: {
+        "成功": { text: "成功", status: 'Success' },
+        "失败": { text: "失败", status: 'Error' }
+      },
+    },
+    {
+      title: '启动信息',
+      dataIndex: 'msg',
+      hideInSearch: true,
+      valueType: 'text',
+      width: 200,
+      render: (text, row) => {
+        if (!text) {
+          row.msg = '';
+        }
+
+        return (<>
+          <Tooltip title={row.msg}>
+            <span>{row.msg.substring(0, 10)}</span>
+          </Tooltip>
+        </>);
+      },
+    },
+    {
+      title: '操作',
+      dataIndex: 'option',
+      width: 100,
+      valueType: 'option',
+      render: (_, record,index,action) => (
+        <>
+          <a
+            onClick={async () => {
+              const success = await handleUpdate(record);
+              if (success) {
+                await action.reload();
+              }
+              console.log(record);
+            }}
+          >
+            强制更新
+          </a>
+        </>
+      ),
+    },
+  ];
+
+  return (
+    <PageHeaderWrapper>
+      <ProTable<TableListItem>
+        headerTitle="查询表格"
+        actionRef={actionRef}
+        rowKey="id"
+        onChange={(_, _filter, _sorter) => {
+          const sorterResult = _sorter as SorterResult<TableListItem>;
+          if (sorterResult.field) {
+            setSorter(`${sorterResult.field}_${sorterResult.order}`);
+          }
+        }}
+        pagination={{
+          defaultPageSize: 10,
+        }}
+        params={{
+          sorter,
+        }}
+        request={(params) => service.queryList(params)}
+        columns={columns}
+        rowSelection={{}}
+      />
+    </PageHeaderWrapper>
+  );
+};
+
+export default TableList;

+ 6 - 0
src/pages/Setting/service.ts

@@ -0,0 +1,6 @@
+import api from '@/utils/api';
+
+export default {
+  queryList: api.get('/service/queryList'),
+  forceUpdateModel: api.post('/service/forceUpdate'),
+};

+ 8 - 8
src/pages/user/login/index.tsx

@@ -33,26 +33,26 @@ const Login: React.FC<LoginProps> = (props) => {
   const { userLogin = {}, submitting } = props;
   const { status, type: loginType } = userLogin;
   const [autoLogin, setAutoLogin] = useState(true);
-  const [type, setType] = useState<string>('account');
+  const [identityType, setType] = useState<string>('account');
 
   const handleSubmit = (values: LoginParamsType) => {
     const { dispatch } = props;
     dispatch({
       type: 'login/login',
-      payload: { ...values, type },
+      payload: { ...values, identityType },
     });
   };
   return (
     <div className={styles.main}>
-      <LoginFrom activeKey={type} onTabChange={setType} onSubmit={handleSubmit}>
+      <LoginFrom activeKey={identityType} onTabChange={setType} onSubmit={handleSubmit}>
         <Tab key="account" tab="账户密码登录">
           {status === 'error' && loginType === 'account' && !submitting && (
-            <LoginMessage content="账户或密码错误(admin/ant.design)" />
+            <LoginMessage content="账户或密码错误" />
           )}
 
           <UserName
-            name="userName"
-            placeholder="用户名: admin or user"
+            name="identify"
+            placeholder="用户名"
             rules={[
               {
                 required: true,
@@ -61,8 +61,8 @@ const Login: React.FC<LoginProps> = (props) => {
             ]}
           />
           <Password
-            name="password"
-            placeholder="密码: ant.design"
+            name="credential"
+            placeholder="密码"
             rules={[
               {
                 required: true,

+ 1 - 1
src/services/login.ts

@@ -8,7 +8,7 @@ export interface LoginParamsType {
 }
 
 export async function fakeAccountLogin(params: LoginParamsType) {
-  return request('/api/login/account', {
+  return request('/api/user/login', {
     method: 'POST',
     data: params,
   });