fix: 修改移动端模板
This commit is contained in:
parent
633df2ee02
commit
8c399e6aaf
33
.eslintrc.js
33
.eslintrc.js
@ -12,25 +12,28 @@ module.exports = {
|
||||
ecmaVersion: 2020,
|
||||
},
|
||||
"env": {
|
||||
// 您的环境变量(包含多个预定义的全局变量)
|
||||
// Your environments (which contains several predefined global variables)
|
||||
//
|
||||
// browser: true,
|
||||
// node: true,
|
||||
// mocha: true,
|
||||
// jest: true,
|
||||
// jquery: true
|
||||
// 您的环境变量(包含多个预定义的全局变量)
|
||||
// Your environments (which contains several predefined global variables)
|
||||
//
|
||||
// browser: true,
|
||||
// node: true,
|
||||
// mocha: true,
|
||||
// jest: true,
|
||||
// jquery: true
|
||||
},
|
||||
"globals": {
|
||||
// 您的全局变量(设置为 false 表示它不允许被重新赋值)
|
||||
// Your global variables (setting to false means it's not allowed to be reassigned)
|
||||
//
|
||||
// myGlobal: false
|
||||
// 您的全局变量(设置为 false 表示它不允许被重新赋值)
|
||||
// Your global variables (setting to false means it's not allowed to be reassigned)
|
||||
//
|
||||
// myGlobal: false
|
||||
},
|
||||
"rules": {
|
||||
// 自定义您的规则
|
||||
// Customize your rules
|
||||
// 自定义您的规则
|
||||
// Customize your rules
|
||||
"react/jsx-no-useless-fragment": 0,
|
||||
"@typescript-eslint/no-require-imports": 0
|
||||
"@typescript-eslint/no-require-imports": 0,
|
||||
"no-constant-binary-expression": 0,
|
||||
"no-unused-private-class-members": 0,
|
||||
"prefer-object-has-own": 0
|
||||
}
|
||||
};
|
||||
|
34
.umirc.ts
34
.umirc.ts
@ -8,13 +8,17 @@ export default defineConfig({
|
||||
immer: true,
|
||||
hmr: false,
|
||||
},
|
||||
antd: {
|
||||
mobile: false,
|
||||
},
|
||||
publicPath: '/',
|
||||
webpack5: {},
|
||||
mfsu: {},
|
||||
fastRefresh: {},
|
||||
// webpack5: {},
|
||||
// mfsu: {},
|
||||
dynamicImport: {
|
||||
loading: '@/components/PageLoading/index',
|
||||
},
|
||||
extraPostCSSPlugins: [px2rem({ remUnit: 66.7, exclude: /node_modules/i })],
|
||||
extraPostCSSPlugins: [px2rem({ remUnit: 37.5, exclude: /node_modules/i })],
|
||||
routes: [
|
||||
{
|
||||
path: '/',
|
||||
@ -25,8 +29,8 @@ export default defineConfig({
|
||||
{
|
||||
path: '/',
|
||||
component: '@/pages/index',
|
||||
name: '一级菜单',
|
||||
title: '一级菜单',
|
||||
name: '首页',
|
||||
title: '首页',
|
||||
icon: 'EntranceOutlined',
|
||||
},
|
||||
],
|
||||
@ -79,14 +83,14 @@ export default defineConfig({
|
||||
targets: {
|
||||
ie: 10,
|
||||
},
|
||||
extraBabelPlugins: [
|
||||
[
|
||||
'import',
|
||||
{
|
||||
libraryName: 'antd-mobile',
|
||||
libraryDirectory: 'es/components',
|
||||
style: false,
|
||||
},
|
||||
],
|
||||
],
|
||||
// extraBabelPlugins: [
|
||||
// [
|
||||
// 'import',
|
||||
// {
|
||||
// libraryName: 'antd-mobile',
|
||||
// libraryDirectory: 'es/components',
|
||||
// style: false,
|
||||
// },
|
||||
// ],
|
||||
// ],
|
||||
});
|
||||
|
77
.vscode/react.code-snippets
vendored
Normal file
77
.vscode/react.code-snippets
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
{
|
||||
"函数组件模板": {
|
||||
"prefix": "tsx",
|
||||
"body": [
|
||||
"// $CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE - by dev",
|
||||
"\n",
|
||||
"import { } from 'react'",
|
||||
"import { connect, ConnectProps } from 'umi'",
|
||||
"import {} from 'antd-mobile'",
|
||||
"import styles from './index.less'",
|
||||
"\n",
|
||||
"interface I$1 extends ConnectProps {",
|
||||
"}",
|
||||
"\n",
|
||||
"export default connect(({}: {}) => ({",
|
||||
"}))((props: I$1) => {",
|
||||
" return (",
|
||||
" <div className={styles.$1}>$1</div>",
|
||||
" )",
|
||||
"})",
|
||||
],
|
||||
"description": "umi 函数组件模板"
|
||||
},
|
||||
"model模板": {
|
||||
"prefix": "mts",
|
||||
"body": [
|
||||
"import { ImmerReducer, Effect } from 'umi';",
|
||||
"import { SubscriptionsMapObject } from 'dva';",
|
||||
"import { } from './serve';",
|
||||
"\n",
|
||||
"export interface $1ModelState {",
|
||||
"}",
|
||||
"\n",
|
||||
"export interface $1ModelType {",
|
||||
" namespace: '$1';",
|
||||
" state: $1ModelState;",
|
||||
" effects: {",
|
||||
" };",
|
||||
" reducers: {",
|
||||
" save: ImmerReducer<$1ModelState>;",
|
||||
" reset: ImmerReducer<$1ModelState>;",
|
||||
" };",
|
||||
" subscriptions: SubscriptionsMapObject;",
|
||||
"}",
|
||||
"\n",
|
||||
"const initialState: $1ModelState = {",
|
||||
"}",
|
||||
"\n",
|
||||
"const $1Model: $1ModelType = {",
|
||||
" namespace: '$1',",
|
||||
" state: initialState,",
|
||||
" effects: {",
|
||||
" // *getFormList({ payload }, { call, put }) {",
|
||||
" // const response = yield call(getCaseForm, payload);",
|
||||
" // yield put({",
|
||||
" // type: 'save',",
|
||||
" // payload: response,",
|
||||
" // });",
|
||||
" //},",
|
||||
" },",
|
||||
" reducers: {",
|
||||
" save(state, { payload }: any) {",
|
||||
" return { ...state, ...payload }",
|
||||
" },",
|
||||
" reset(state, { payload }: any) {",
|
||||
" return { ...initialState }",
|
||||
" }",
|
||||
" },",
|
||||
" subscriptions: {}",
|
||||
"};",
|
||||
"\n",
|
||||
|
||||
"export default $1Model;"
|
||||
]
|
||||
|
||||
}
|
||||
}
|
@ -42,8 +42,8 @@
|
||||
"@ant-design/pro-layout": "^6.15.4",
|
||||
"@nicecode/tools": "^0.2.12",
|
||||
"antd-mobile": "^5.12.6",
|
||||
"amfe-flexible": "^2.2.1",
|
||||
"antd-mobile-icons": "^0.2.2",
|
||||
"axios": "^0.19.2",
|
||||
"classnames": "^2.2.6",
|
||||
"js-cookie": "^2.2.1",
|
||||
"react": "^17.0.1",
|
||||
|
12
src/app.ts
12
src/app.ts
@ -1,4 +1,14 @@
|
||||
import '@/utils/flexible';
|
||||
import 'amfe-flexible';
|
||||
import eruda from 'eruda'
|
||||
import 'antd-mobile/es/global';
|
||||
import '@/styles/index.less';
|
||||
import '@/styles/reset.less';
|
||||
|
||||
if (process.env.UMI_ENV !== 'production') {
|
||||
eruda.init();
|
||||
}
|
||||
|
||||
// 初始化,可以通过 useModel 调用
|
||||
export function getInitialState() {
|
||||
return {}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
.home {
|
||||
padding: 12px;
|
||||
}
|
||||
.title {
|
||||
margin: 100px auto;
|
||||
font-size: 16px;
|
||||
font-size: 24px;
|
||||
text-align: center;
|
||||
// background: rgb(121, 242, 157);
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
import { Button } from 'antd-mobile'
|
||||
import styles from './index.less';
|
||||
|
||||
export default function () {
|
||||
return (
|
||||
<div>
|
||||
<div className={styles.home}>
|
||||
<h1 className={styles.title}>welcome! there is nicecode!</h1>
|
||||
<Button color='primary' fill='solid' block>
|
||||
你好
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -1,15 +1,32 @@
|
||||
@import 'var.less';
|
||||
|
||||
.ant-picker {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ant-pagination {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
width: 100%;
|
||||
|
||||
&-total-text {
|
||||
flex: 1;
|
||||
}
|
||||
:root {
|
||||
--adm-radius-s: 4px;
|
||||
--adm-radius-m: 8px;
|
||||
--adm-radius-l: 12px;
|
||||
--adm-font-size-1: 9px;
|
||||
--adm-font-size-2: 10px;
|
||||
--adm-font-size-3: 11px;
|
||||
--adm-font-size-4: 12px;
|
||||
--adm-font-size-5: 13px;
|
||||
--adm-font-size-6: 14px;
|
||||
--adm-font-size-7: 15px;
|
||||
--adm-font-size-8: 16px;
|
||||
--adm-font-size-9: 17px;
|
||||
--adm-font-size-10: 18px;
|
||||
--adm-color-primary: #1677ff;
|
||||
--adm-color-success: #00b578;
|
||||
--adm-color-warning: #ff8f1f;
|
||||
--adm-color-danger: #ff3141;
|
||||
--adm-color-white: #ffffff;
|
||||
--adm-color-text: #333333;
|
||||
--adm-color-text-secondary: #666666;
|
||||
--adm-color-weak: #999999;
|
||||
--adm-color-light: #cccccc;
|
||||
--adm-color-border: #eeeeee;
|
||||
--adm-color-box: #f5f5f5;
|
||||
--adm-color-background: #ffffff;
|
||||
--adm-font-size-main: var(--adm-font-size-5);
|
||||
--adm-font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, segoe ui,
|
||||
arial, roboto, 'PingFang SC', 'miui', 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif;
|
||||
--adm-border-color: var(--adm-color-border);
|
||||
}
|
||||
|
@ -1,72 +1,54 @@
|
||||
import axios from 'axios';
|
||||
import { extend } from 'umi-request';
|
||||
import { Toast } from 'antd-mobile';
|
||||
import CodeMsg from '@/assets/data/code';
|
||||
import { BaseResponse } from '@/interfaces/base';
|
||||
|
||||
export const DEFAULT_TIP_MESSAGE = '请求失败,请刷新重试';
|
||||
|
||||
/**
|
||||
* 错误处理
|
||||
* @param data {Object} 请求返回的信息
|
||||
*/
|
||||
export function handleError(data: BaseResponse): void {
|
||||
const msg = CodeMsg[data.code] || data.msg || DEFAULT_TIP_MESSAGE;
|
||||
export function handleError(data: BaseResponse) {
|
||||
const msg = CodeMsg[data.code] || data.msg || CodeMsg['DEFAULT_TIP_MESSAGE'];
|
||||
Toast.show({
|
||||
content: msg,
|
||||
})
|
||||
}
|
||||
|
||||
// create an axios instance
|
||||
const service = axios.create({
|
||||
const service = extend({
|
||||
baseURL: process.env.BASE_API, // api的base_url
|
||||
// timeout: 5000, // request timeout
|
||||
timeout: 1000,
|
||||
mode: 'cors',
|
||||
errorHandler: (error: any) => handleError(error),
|
||||
});
|
||||
|
||||
// request interceptor
|
||||
service.interceptors.request.use(
|
||||
config => {
|
||||
(url: string, config: any) => {
|
||||
// 防止 GET 请求缓存GET
|
||||
if (config.method === 'get') {
|
||||
if (config.method === 'GET') {
|
||||
const t = new Date().getTime();
|
||||
config.params = config.params ? { ...config.params, t } : { t };
|
||||
}
|
||||
return config;
|
||||
},
|
||||
error => {
|
||||
// Do something with request error
|
||||
if (error.status === '504') {
|
||||
Toast.show({
|
||||
content: '网关超时,请重试!',
|
||||
})
|
||||
} else {
|
||||
Toast.show({
|
||||
content: `网络异常[-${error.status}]`,
|
||||
})
|
||||
console.log(error); // for debug
|
||||
}
|
||||
Promise.reject(error);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
// response interceptor
|
||||
service.interceptors.response.use(
|
||||
response => {
|
||||
const res = response.data;
|
||||
if (!res.success) {
|
||||
if (res.code === '1007') {
|
||||
async (response: any) => {
|
||||
const res = await response.clone().json();
|
||||
if (Number(res.code) !== 200) {
|
||||
if (Number(res.code) === 1007) {
|
||||
// 登录失效
|
||||
window.location.href = '/';
|
||||
return;
|
||||
return Promise.resolve();
|
||||
}
|
||||
handleError(res);
|
||||
return Promise.resolve();
|
||||
}
|
||||
return res;
|
||||
},
|
||||
error => {
|
||||
handleError(error);
|
||||
console.log(`err${error}`); // for debug
|
||||
return Promise.reject(error);
|
||||
},
|
||||
return res.data;
|
||||
}
|
||||
);
|
||||
|
||||
export default service;
|
||||
|
Loading…
Reference in New Issue
Block a user