Bläddra i källkod

fix(compiler): fix some bug

lizhiqi 2 år sedan
förälder
incheckning
44b9a87de8

+ 1 - 1
src/app.tsx

@@ -81,7 +81,7 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
     // 自定义 403 页面
     // unAccessible: <div>unAccessible</div>,
     // 增加一个 loading 的状态
-    childrenRender: (children, props) => {
+    childrenRender: (children: any, props: { location: { pathname: string | string[] } }) => {
       // if (initialState?.loading) return <PageLoading />;
       return (
         <>

+ 8 - 8
src/components/RightContent/index.tsx

@@ -1,8 +1,8 @@
-import { QuestionCircleOutlined } from '@ant-design/icons';
+// import { QuestionCircleOutlined } from '@ant-design/icons';
 import { Space } from 'antd';
 import React from 'react';
-import { SelectLang, useModel } from 'umi';
-import HeaderSearch from '../HeaderSearch';
+import { useModel } from 'umi';
+// import HeaderSearch from '../HeaderSearch';
 import Avatar from './AvatarDropdown';
 import styles from './index.less';
 
@@ -23,7 +23,7 @@ const GlobalHeaderRight: React.FC = () => {
   }
   return (
     <Space className={className}>
-      <HeaderSearch
+      {/* <HeaderSearch
         className={`${styles.action} ${styles.search}`}
         placeholder="站内搜索"
         defaultValue="umi ui"
@@ -45,17 +45,17 @@ const GlobalHeaderRight: React.FC = () => {
         // onSearch={value => {
         //   console.log('input', value);
         // }}
-      />
-      <span
+      /> */}
+      {/* <span
         className={styles.action}
         onClick={() => {
           window.open('https://pro.ant.design/docs/getting-started');
         }}
       >
         <QuestionCircleOutlined />
-      </span>
+      </span> */}
       <Avatar />
-      <SelectLang className={styles.action} />
+      {/* <SelectLang className={styles.action} /> */}
     </Space>
   );
 };

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

@@ -4,7 +4,7 @@ export default {
   'pages.login.accountLogin.errorMessage': '错误的用户名和密码',
   'pages.login.failure': '登录失败,请重试!',
   'pages.login.success': '登录成功!',
-  'pages.login.username.placeholder': '请输入用户名',
+  'pages.login.username.placeholder': '请输入手机号',
   'pages.login.username.required': '用户名是必填项!',
   'pages.login.password.placeholder': '请输入密码',
   'pages.login.password.required': '密码是必填项!',

+ 135 - 6
src/pages/Demo/index.tsx

@@ -1,13 +1,23 @@
-import { Card, Tabs, Input, Typography, Space, Form, Button } from 'antd';
-
+import { Card, Tabs, Input, Typography, Space, Form, Button, Table, Tag, Modal } from 'antd';
+import type { ColumnsType } from 'antd/es/table';
 import React from 'react';
 import { useState } from 'react';
 import { postData, getData } from '@/services/demo';
-import { ReloadOutlined, SearchOutlined } from '@ant-design/icons';
+import { ExclamationCircleOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons';
+import moment from 'moment';
 
 const { Text } = Typography;
 const { Search } = Input;
 
+interface DataType {
+  key: string;
+  name: string;
+  age: number;
+  address: string;
+  record_id: string;
+  tags: string[];
+}
+
 const DemoPage: React.FC = () => {
   const [currentKey, setCurrentKey] = useState('1');
   const [tabText1, setTabText1] = useState('Tab1');
@@ -15,14 +25,13 @@ const DemoPage: React.FC = () => {
   const [tabText3, setTabText3] = useState('Tab3');
   const [form] = Form.useForm();
 
+  //  tab标签切换
   const handleOnChange = (key: string) => {
-    console.log('handleOnChange: ' + key);
     setCurrentKey(key);
   };
 
+  //  tab下的搜索
   async function onSearch(text: string) {
-    console.log('Current Key: ', currentKey, ', On Search Text: ', text);
-
     switch (currentKey) {
       case '1': {
         const result = await postData(text);
@@ -48,6 +57,120 @@ const DemoPage: React.FC = () => {
       }
     }
   }
+
+  //  删除
+  const toDelete = (record: DataType) => {
+    Modal.confirm({
+      title: '确认删除吗?',
+      icon: <ExclamationCircleOutlined />,
+      okText: '确认',
+      okType: 'danger',
+      cancelText: '取消',
+      onOk() {
+        console.log('OK');
+      },
+      onCancel() {
+        console.log('Cancel', record);
+      },
+    });
+  };
+
+  const columns: ColumnsType<DataType> = [
+    {
+      title: '序号',
+      align: 'center',
+      key: 'index',
+      render: (_: any, row: any, index: number) => index + 1,
+    },
+    {
+      title: '名称',
+      dataIndex: 'name',
+      key: 'name',
+      render: (
+        text:
+          | boolean
+          | React.ReactChild
+          | React.ReactFragment
+          | React.ReactPortal
+          | null
+          | undefined,
+      ) => <a>{text}</a>,
+    },
+    {
+      title: '数字',
+      dataIndex: 'age',
+      key: 'age',
+    },
+    {
+      title: '地址',
+      dataIndex: 'address',
+      key: 'address',
+    },
+    {
+      title: '日期',
+      dataIndex: 'date',
+      key: 'date',
+      render: (data) => data && moment(data).format('YYYY-MM-DD HH:ss:mm'),
+    },
+    {
+      title: '标签们',
+      key: 'tags',
+      dataIndex: 'tags',
+      render: (_, { tags }) => (
+        <>
+          {tags.map((tag) => {
+            let color = tag.length > 5 ? 'geekblue' : 'green';
+            if (tag === 'loser') {
+              color = 'volcano';
+            }
+            return (
+              <Tag color={color} key={tag}>
+                {tag.toUpperCase()}
+              </Tag>
+            );
+          })}
+        </>
+      ),
+    },
+    {
+      title: '操作',
+      key: 'action',
+      render: (_, record) => (
+        <Space size="middle">
+          <a>编辑</a>
+          <a
+            onClick={() => {
+              toDelete(record);
+            }}
+          >
+            删除
+          </a>
+        </Space>
+      ),
+    },
+  ];
+
+  const data = [
+    {
+      record_id: '1',
+      key: '1',
+      name: '111',
+      age: 31,
+      address: '地址地址地址1',
+      date: '2022-10-07T10:44:21',
+      tags: ['loser', 'xixixi'],
+    },
+    {
+      record_id: '2',
+      key: '2',
+      name: '222',
+      age: 32,
+      address: '地址地址地址2',
+      date: '2022-10-07T10:44:21',
+      tags: ['loser', 'hahaha'],
+    },
+  ];
+
   return (
     <div className="site-card-border-less-wrapper">
       <Card title="demo">
@@ -94,6 +217,12 @@ const DemoPage: React.FC = () => {
             <Text> {tabText3} </Text>
           </Space>
         )}
+        <Table
+          columns={columns}
+          dataSource={data}
+          pagination={false}
+          rowKey={(record) => record.record_id}
+        />
       </Card>
     </div>
   );

+ 57 - 57
src/pages/user/Login/index.tsx

@@ -1,21 +1,21 @@
 import Footer from '@/components/Footer';
 import { login } from '@/services/ant-design-pro/api';
-import { getFakeCaptcha } from '@/services/ant-design-pro/login';
+// import { getFakeCaptcha } from '@/services/ant-design-pro/login';
 import {
   AlipayCircleOutlined,
   LockOutlined,
-  MobileOutlined,
+  // MobileOutlined,
   TaobaoCircleOutlined,
   UserOutlined,
   WeiboCircleOutlined,
 } from '@ant-design/icons';
 import {
   LoginForm,
-  ProFormCaptcha,
+  // ProFormCaptcha,
   ProFormCheckbox,
   ProFormText,
 } from '@ant-design/pro-components';
-import { Alert, message, Tabs } from 'antd';
+import { Alert, message } from 'antd';
 import React, { useState } from 'react';
 import { FormattedMessage, history, SelectLang, useIntl, useModel } from 'umi';
 import styles from './index.less';
@@ -35,7 +35,7 @@ const LoginMessage: React.FC<{
 
 const Login: React.FC = () => {
   const [userLoginState, setUserLoginState] = useState<API.LoginResult>({});
-  const [type, setType] = useState<string>('account');
+  const [type] = useState<string>('account');
   const { initialState, setInitialState } = useModel('@@initialState');
 
   const intl = useIntl();
@@ -108,7 +108,7 @@ const Login: React.FC = () => {
             await handleSubmit(values as API.LoginParams);
           }}
         >
-          <Tabs activeKey={type} onChange={setType}>
+          {/* <Tabs activeKey={type} onChange={setType}>
             <Tabs.TabPane
               key="account"
               tab={intl.formatMessage({
@@ -123,7 +123,7 @@ const Login: React.FC = () => {
                 defaultMessage: '手机号登录',
               })}
             />
-          </Tabs>
+          </Tabs> */}
 
           {status === 'error' && loginType === 'account' && (
             <LoginMessage
@@ -133,56 +133,56 @@ const Login: React.FC = () => {
               })}
             />
           )}
-          {type === 'account' && (
-            <>
-              <ProFormText
-                name="username"
-                fieldProps={{
-                  size: 'large',
-                  prefix: <UserOutlined className={styles.prefixIcon} />,
-                }}
-                placeholder={intl.formatMessage({
-                  id: 'pages.login.username.placeholder',
-                  defaultMessage: '用户名: admin or user',
-                })}
-                rules={[
-                  {
-                    required: true,
-                    message: (
-                      <FormattedMessage
-                        id="pages.login.username.required"
-                        defaultMessage="请输入用户名!"
-                      />
-                    ),
-                  },
-                ]}
-              />
-              <ProFormText.Password
-                name="password"
-                fieldProps={{
-                  size: 'large',
-                  prefix: <LockOutlined className={styles.prefixIcon} />,
-                }}
-                placeholder={intl.formatMessage({
-                  id: 'pages.login.password.placeholder',
-                  defaultMessage: '密码: ant.design',
-                })}
-                rules={[
-                  {
-                    required: true,
-                    message: (
-                      <FormattedMessage
-                        id="pages.login.password.required"
-                        defaultMessage="请输入密码!"
-                      />
-                    ),
-                  },
-                ]}
-              />
-            </>
-          )}
+          {/* {type === 'account' && ( */}
+          <>
+            <ProFormText
+              name="username"
+              fieldProps={{
+                size: 'large',
+                prefix: <UserOutlined className={styles.prefixIcon} />,
+              }}
+              placeholder={intl.formatMessage({
+                id: 'pages.login.username.placeholder',
+                defaultMessage: '手机号: XXX',
+              })}
+              rules={[
+                {
+                  required: true,
+                  message: (
+                    <FormattedMessage
+                      id="pages.login.username.required"
+                      defaultMessage="请输入手机号!"
+                    />
+                  ),
+                },
+              ]}
+            />
+            <ProFormText.Password
+              name="password"
+              fieldProps={{
+                size: 'large',
+                prefix: <LockOutlined className={styles.prefixIcon} />,
+              }}
+              placeholder={intl.formatMessage({
+                id: 'pages.login.password.placeholder',
+                defaultMessage: '密码: ant.design',
+              })}
+              rules={[
+                {
+                  required: true,
+                  message: (
+                    <FormattedMessage
+                      id="pages.login.password.required"
+                      defaultMessage="请输入密码!"
+                    />
+                  ),
+                },
+              ]}
+            />
+          </>
+          {/* )} */}
 
-          {status === 'error' && loginType === 'mobile' && <LoginMessage content="验证码错误" />}
+          {/* {status === 'error' && loginType === 'mobile' && <LoginMessage content="验证码错误" />}
           {type === 'mobile' && (
             <>
               <ProFormText
@@ -263,7 +263,7 @@ const Login: React.FC = () => {
                 }}
               />
             </>
-          )}
+          )} */}
           <div
             style={{
               marginBottom: 24,