@umijs/plugins 4.0.90 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/access.js CHANGED
@@ -80,7 +80,7 @@ export function accessProvider(container) {
80
80
  content: `
81
81
  import React, { PropsWithChildren } from 'react';
82
82
  import { AccessContext } from './context';
83
- import type { IRoute } from 'umi';
83
+ import type { IRoute } from '${api.appData.umi.importSource}';
84
84
 
85
85
  export const useAccess = () => {
86
86
  return React.useContext(AccessContext);
package/dist/dva.js CHANGED
@@ -186,7 +186,7 @@ export { getDvaApp } from './dva';
186
186
  api.writeTmpFile({
187
187
  path: "types.d.ts",
188
188
  tpl: `
189
- import type { History } from 'umi';
189
+ import type { History } from '${api.appData.umi.importSource}';
190
190
 
191
191
  export interface ConnectProps {
192
192
  dispatch?: Dispatch;
package/dist/layout.js CHANGED
@@ -64,6 +64,7 @@ var layout_default = (api) => {
64
64
  antdVersion = require(`${pkgPath2}/package.json`).version;
65
65
  } catch (e) {
66
66
  }
67
+ const packageName = api.pkg.name || "plugin-layout";
67
68
  const isAntd5 = antdVersion.startsWith("5");
68
69
  const layoutFile = isAntd5 ? "Layout.css" : "Layout.less";
69
70
  api.describe({
@@ -129,8 +130,10 @@ ${isFlattedDepsDir ? '/// <reference types="antd" />' : ""}
129
130
  path: "Layout.tsx",
130
131
  content: `
131
132
  ${PKG_TYPE_REFERENCE}
132
- import { Link, useLocation, useNavigate, Outlet, useAppData, useRouteData, matchRoutes } from 'umi';
133
- import type { IRoute } from 'umi';
133
+ import {
134
+ Link, useLocation, useNavigate, Outlet, useAppData, matchRoutes,
135
+ type IRoute
136
+ } from '${api.appData.umi.importSource}';
134
137
  import React, { useMemo } from 'react';
135
138
  import {
136
139
  ProLayout,
@@ -231,7 +234,7 @@ const { formatMessage } = useIntl();
231
234
  <ProLayout
232
235
  route={route}
233
236
  location={location}
234
- title={userConfig.title || 'plugin-layout'}
237
+ title={userConfig.title || '${packageName}'}
235
238
  navTheme="dark"
236
239
  siderWidth={256}
237
240
  onMenuHeaderClick={(e) => {
@@ -435,21 +438,28 @@ export function getRightRenderContent (opts: {
435
438
  );
436
439
  }
437
440
 
438
-
439
- const avatar = (
440
- <span className="umi-plugin-layout-action">
441
- <Avatar
442
- size="small"
443
- className="umi-plugin-layout-avatar"
444
- src={
445
- opts.initialState?.avatar ||
446
- 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png'
447
- }
448
- alt="avatar"
449
- />
450
- <span className="umi-plugin-layout-name">{opts.initialState?.name}</span>
441
+ const showAvatar = opts.initialState?.avatar || opts.initialState?.name || opts.runtimeConfig.logout;
442
+ const disableAvatarImg = opts.initialState?.avatar === false;
443
+ const nameClassName = disableAvatarImg ? 'umi-plugin-layout-name umi-plugin-layout-hide-avatar-img' : 'umi-plugin-layout-name';
444
+ const avatar =
445
+ showAvatar ? (
446
+ <span className="umi-plugin-layout-action">
447
+ {!disableAvatarImg ?
448
+ (
449
+ <Avatar
450
+ size="small"
451
+ className="umi-plugin-layout-avatar"
452
+ src={
453
+ opts.initialState?.avatar ||
454
+ "https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png"
455
+ }
456
+ alt="avatar"
457
+ />
458
+ ) : null}
459
+ <span className={nameClassName}>{opts.initialState?.name}</span>
451
460
  </span>
452
- );
461
+ ) : null;
462
+
453
463
 
454
464
  if (opts.loading) {
455
465
  return (
@@ -459,6 +469,11 @@ export function getRightRenderContent (opts: {
459
469
  );
460
470
  }
461
471
 
472
+ // 如果没有打开Locale,并且头像为空就取消掉这个返回的内容
473
+ {{^Locale}}
474
+ if(!avatar) return null;
475
+ {{/Locale}}
476
+
462
477
  const langMenu = {
463
478
  className: "umi-plugin-layout-menu",
464
479
  selectedKeys: [],
@@ -498,6 +513,7 @@ export function getRightRenderContent (opts: {
498
513
  }
499
514
 
500
515
 
516
+
501
517
  return (
502
518
  <div className="umi-plugin-layout-right anticon">
503
519
  {opts.runtimeConfig.logout ? (
@@ -575,6 +591,9 @@ ${// antd@5里面没有这个样式了
575
591
  .umi-plugin-layout-name {
576
592
  margin-left: 8px;
577
593
  }
594
+ .umi-plugin-layout-name.umi-plugin-layout-hide-avatar-img {
595
+ margin-left: 0;
596
+ }
578
597
  `
579
598
  });
580
599
  api.writeTmpFile({
@@ -677,7 +696,7 @@ export default LogoIcon;
677
696
  path: "Exception.tsx",
678
697
  content: `
679
698
  import React from 'react';
680
- import { history, type IRoute } from 'umi';
699
+ import { history, type IRoute } from '${api.appData.umi.importSource}';
681
700
  import { Result, Button } from 'antd';
682
701
 
683
702
  const Exception: React.FC<{
package/dist/request.js CHANGED
@@ -160,12 +160,13 @@ type RequestError = AxiosError | Error
160
160
  interface IErrorHandler {
161
161
  (error: RequestError, opts: IRequestOptions): void;
162
162
  }
163
- type IRequestInterceptorAxios = (config: RequestOptions) => RequestOptions;
164
- type IRequestInterceptorUmiRequest = (url: string, config : RequestOptions) => { url: string, options: RequestOptions };
163
+ type WithPromise<T> = T | Promise<T>;
164
+ type IRequestInterceptorAxios = (config: IRequestOptions) => WithPromise<IRequestOptions>;
165
+ type IRequestInterceptorUmiRequest = (url: string, config : IRequestOptions) => WithPromise<{ url: string, options: IRequestOptions }>;
165
166
  type IRequestInterceptor = IRequestInterceptorAxios | IRequestInterceptorUmiRequest;
166
167
  type IErrorInterceptor = (error: Error) => Promise<Error>;
167
- type IResponseInterceptor = <T = any>(response : AxiosResponse<T>) => AxiosResponse<T> ;
168
- type IRequestInterceptorTuple = [IRequestInterceptor , IErrorInterceptor] | [ IRequestInterceptor ] | IRequestInterceptor
168
+ type IResponseInterceptor = <T = any>(response : AxiosResponse<T>) => WithPromise<AxiosResponse<T>> ;
169
+ type IRequestInterceptorTuple = [IRequestInterceptor , IErrorInterceptor] | [IRequestInterceptor] | IRequestInterceptor
169
170
  type IResponseInterceptorTuple = [IResponseInterceptor, IErrorInterceptor] | [IResponseInterceptor] | IResponseInterceptor
170
171
 
171
172
  export interface RequestConfig<T = any> extends AxiosRequestConfig {
@@ -196,19 +197,19 @@ const getRequestInstance = (): AxiosInstance => {
196
197
 
197
198
  config?.requestInterceptors?.forEach((interceptor) => {
198
199
  if(interceptor instanceof Array){
199
- requestInstance.interceptors.request.use((config) => {
200
+ requestInstance.interceptors.request.use(async (config) => {
200
201
  const { url } = config;
201
202
  if(interceptor[0].length === 2){
202
- const { url: newUrl, options } = interceptor[0](url, config);
203
+ const { url: newUrl, options } = await interceptor[0](url, config);
203
204
  return { ...options, url: newUrl };
204
205
  }
205
206
  return interceptor[0](config);
206
207
  }, interceptor[1]);
207
208
  } else {
208
- requestInstance.interceptors.request.use((config) => {
209
+ requestInstance.interceptors.request.use(async (config) => {
209
210
  const { url } = config;
210
211
  if(interceptor.length === 2){
211
- const { url: newUrl, options } = interceptor(url, config);
212
+ const { url: newUrl, options } = await interceptor(url, config);
212
213
  return { ...options, url: newUrl };
213
214
  }
214
215
  return interceptor(config);
@@ -239,19 +240,19 @@ const request: IRequest = (url: string, opts: any = { method: 'GET' }) => {
239
240
  const { getResponse = false, requestInterceptors, responseInterceptors } = opts;
240
241
  const requestInterceptorsToEject = requestInterceptors?.map((interceptor) => {
241
242
  if(interceptor instanceof Array){
242
- return requestInstance.interceptors.request.use((config) => {
243
+ return requestInstance.interceptors.request.use(async (config) => {
243
244
  const { url } = config;
244
245
  if(interceptor[0].length === 2){
245
- const { url: newUrl, options } = interceptor[0](url, config);
246
+ const { url: newUrl, options } = await interceptor[0](url, config);
246
247
  return { ...options, url: newUrl };
247
248
  }
248
249
  return interceptor[0](config);
249
250
  }, interceptor[1]);
250
251
  } else {
251
- return requestInstance.interceptors.request.use((config) => {
252
+ return requestInstance.interceptors.request.use(async (config) => {
252
253
  const { url } = config;
253
254
  if(interceptor.length === 2){
254
- const { url: newUrl, options } = interceptor(url, config);
255
+ const { url: newUrl, options } = await interceptor(url, config);
255
256
  return { ...options, url: newUrl };
256
257
  }
257
258
  return interceptor(config);
@@ -308,6 +309,10 @@ export type {
308
309
  AxiosResponse,
309
310
  AxiosError,
310
311
  RequestError,
312
+ IRequestInterceptorAxios as RequestInterceptorAxios,
313
+ IRequestInterceptorUmiRequest as RequestInterceptorUmiRequest,
314
+ IRequestInterceptor as RequestInterceptor,
315
+ IErrorInterceptor as ErrorInterceptor,
311
316
  IResponseInterceptor as ResponseInterceptor,
312
317
  IRequestOptions as RequestOptions,
313
318
  IRequest as Request,
@@ -347,6 +352,10 @@ export type {
347
352
  AxiosResponse,
348
353
  AxiosError,
349
354
  RequestError,
355
+ RequestInterceptorAxios,
356
+ RequestInterceptorUmiRequest,
357
+ RequestInterceptor,
358
+ ErrorInterceptor,
350
359
  ResponseInterceptor,
351
360
  RequestOptions,
352
361
  Request } from './request';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.90",
3
+ "version": "4.1.1",
4
4
  "description": "@umijs/plugins",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/plugins#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -27,7 +27,7 @@
27
27
  "@tanstack/react-query-devtools": "^4.24.10",
28
28
  "antd-dayjs-webpack-plugin": "^1.0.6",
29
29
  "axios": "^0.27.2",
30
- "babel-plugin-import": "^1.13.6",
30
+ "babel-plugin-import": "^1.13.8",
31
31
  "babel-plugin-styled-components": "2.1.4",
32
32
  "dayjs": "^1.11.7",
33
33
  "dva-core": "^2.0.4",
@@ -45,12 +45,12 @@
45
45
  "styled-components": "6.1.1",
46
46
  "tslib": "^2",
47
47
  "warning": "^4.0.3",
48
- "@umijs/bundler-utils": "4.0.90",
48
+ "@umijs/bundler-utils": "4.1.1",
49
49
  "@umijs/valtio": "1.0.4"
50
50
  },
51
51
  "devDependencies": {
52
52
  "antd": "^4.24.1",
53
- "umi": "4.0.90"
53
+ "umi": "4.1.1"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"