Skip to content

Commit 1be34ff

Browse files
committed
fix: 修复编辑态组件mobile属性渲染错误问题
1 parent 7063746 commit 1be34ff

File tree

7 files changed

+27
-19
lines changed

7 files changed

+27
-19
lines changed

packages/amis-core/src/envOverwrite.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
* @file 用于在移动端或不同语言环境下使用不同配置
33
*/
44

5-
import {JSONValueMap, findObjectsWithKey} from './utils/helper';
5+
import {JSONValueMap} from './utils/helper';
66
import isPlainObject from 'lodash/isPlainObject';
77
const isMobile = (window as any).matchMedia?.('(max-width: 768px)').matches
88
? true
99
: false;
1010

1111
// 这里不能用 addSchemaFilter 是因为还需要更深层的替换,比如 select 里的 options
12-
export const envOverwrite = (schema: any, locale?: string) => {
12+
export const envOverwrite = (schema: any, locale?: string, device?: string) => {
13+
const isMobileDevice = device === 'mobile' || isMobile;
1314
return JSONValueMap(
1415
schema,
1516
(value: any) => {
@@ -21,7 +22,7 @@ export const envOverwrite = (schema: any, locale?: string) => {
2122
const newValue = Object.assign({}, value, value[locale]);
2223
delete newValue[locale];
2324
return newValue;
24-
} else if (isMobile && value.mobile) {
25+
} else if (isMobileDevice && value.mobile) {
2526
const newValue = Object.assign({}, value, value.mobile);
2627
delete newValue.mobile;
2728
return newValue;

packages/amis-core/src/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ function AMISRenderer({
363363

364364
// 根据环境覆盖 schema,这个要在最前面做,不然就无法覆盖 validations
365365
schema = React.useMemo(() => {
366-
schema = envOverwrite(schema, locale);
366+
schema = envOverwrite(schema, locale, env.isMobile() ? 'mobile' : 'pc');
367367
// todo 和 envOverwrite 一起处理,减少循环次数
368368
schema = replaceText(
369369
schema,

packages/amis/src/renderers/CRUD.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -3065,14 +3065,15 @@ export default class CRUD<T extends CRUDProps> extends React.Component<T, any> {
30653065
classnames: cx,
30663066
translate: __,
30673067
testIdBuilder,
3068-
id
3068+
id,
3069+
mobileUI
30693070
} = this.props;
30703071

30713072
return (
30723073
<div
30733074
className={cx('Crud', className, {
30743075
'is-loading': store.loading,
3075-
'is-mobile': isMobile()
3076+
'is-mobile': mobileUI
30763077
})}
30773078
style={style}
30783079
data-id={id}

packages/amis/src/renderers/DropDownButton.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,16 @@ export default class DropDownButton extends React.Component<
264264
classnames: cx,
265265
data,
266266
ignoreConfirm,
267-
testIdBuilder
267+
testIdBuilder,
268+
mobileUI
268269
} = this.props;
269270
index = typeof index === 'number' ? index.toString() : index;
270271

271272
if (typeof button !== 'string' && Array.isArray(button?.children)) {
272273
return (
273274
<div
274275
key={index}
275-
className={cx('DropDown-menu', {'is-mobile': isMobile()})}
276+
className={cx('DropDown-menu', {'is-mobile': mobileUI})}
276277
>
277278
<li key={`${index}/0`} className={cx('DropDown-groupTitle')}>
278279
{button.icon ? (
@@ -345,7 +346,8 @@ export default class DropDownButton extends React.Component<
345346
closeOnOutside,
346347
menuClassName,
347348
overlayPlacement,
348-
trigger
349+
trigger,
350+
mobileUI
349351
} = this.props;
350352

351353
const buttons =
@@ -365,7 +367,7 @@ export default class DropDownButton extends React.Component<
365367
'DropDown-menu-root',
366368
'DropDown-menu',
367369
{
368-
'is-mobile': isMobile()
370+
'is-mobile': mobileUI
369371
},
370372
menuClassName
371373
)}
@@ -442,7 +444,8 @@ export default class DropDownButton extends React.Component<
442444
testIdBuilder,
443445
id,
444446
wrapperCustomStyle,
445-
themeCss
447+
themeCss,
448+
mobileUI
446449
} = this.props;
447450

448451
return (
@@ -454,7 +457,7 @@ export default class DropDownButton extends React.Component<
454457
'DropDown--alignRight': align === 'right',
455458
'is-opened': this.state.isOpened,
456459
'is-actived': isActived,
457-
'is-mobile': isMobile()
460+
'is-mobile': mobileUI
458461
},
459462
className
460463
)}

packages/amis/src/renderers/Form/ConditionBuilder.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export default class ConditionBuilderControl extends React.PureComponent<Conditi
185185
pickerIcon,
186186
env,
187187
popOverContainer,
188+
mobileUI,
188189
...rest
189190
} = this.props;
190191

@@ -203,7 +204,7 @@ export default class ConditionBuilderControl extends React.PureComponent<Conditi
203204
<div
204205
className={cx(
205206
`ConditionBuilderControl`,
206-
{'is-mobile': isMobile()},
207+
{'is-mobile': mobileUI},
207208
className
208209
)}
209210
>

packages/amis/src/renderers/Form/LocationPicker.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ export class LocationControl extends React.Component<LocationControlProps> {
150150
staticSchema,
151151
ak,
152152
coordinatesType,
153-
hideViewControl = false
153+
hideViewControl = false,
154+
mobileUI
154155
} = this.props;
155156
const __ = this.props.translate;
156157

@@ -161,7 +162,7 @@ export class LocationControl extends React.Component<LocationControlProps> {
161162
return (
162163
<div
163164
className={this.props.classnames('LocationControl', {
164-
'is-mobile': isMobile()
165+
'is-mobile': mobileUI
165166
})}
166167
ref={this.domRef}
167168
>
@@ -191,12 +192,12 @@ export class LocationControl extends React.Component<LocationControlProps> {
191192

192193
@supportStatic()
193194
render() {
194-
const {style, env} = this.props;
195+
const {style, env, mobileUI} = this.props;
195196
const ak = filter(this.props.ak, this.props.data) || env.locationPickerAK!;
196197
return (
197198
<div
198199
className={this.props.classnames('LocationControl', {
199-
'is-mobile': isMobile()
200+
'is-mobile': mobileUI
200201
})}
201202
>
202203
<LocationPicker

packages/amis/src/renderers/Form/MatrixCheckboxes.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,14 @@ export default class MatrixCheckbox extends React.Component<
419419
textAlign,
420420
xCheckAll,
421421
yCheckAll,
422-
testIdBuilder
422+
testIdBuilder,
423+
mobileUI
423424
} = this.props;
424425

425426
const value = this.props.value || buildDefaultValue(columns, rows);
426427

427428
return (
428-
<div className={cx('Table m-b-none', {'is-mobile': isMobile()})}>
429+
<div className={cx('Table m-b-none', {'is-mobile': mobileUI})}>
429430
<div className={cx('Table-content')}>
430431
<table className={cx('Table-table')}>
431432
<thead>

0 commit comments

Comments
 (0)