sdk 版本调整

This commit is contained in:
2betop 2020-09-27 12:28:40 +08:00
parent 44d3ac5c53
commit 1fa1a428f4
3 changed files with 67 additions and 20 deletions

View File

@ -313,7 +313,7 @@ if (fis.project.currentMedia() === 'publish') {
env.get('project.ignore').push('sdk/**'); env.get('project.ignore').push('sdk/**');
env.set('project.files', ['examples/sdk-placeholder.html']); env.set('project.files', ['examples/sdk-placeholder.html']);
env.match('/{examples,scss}/(**)', { env.match('/{examples,scss,src}/(**)', {
release: '/$1' release: '/$1'
}); });
@ -354,8 +354,9 @@ if (fis.project.currentMedia() === 'publish') {
rExt: '.js' rExt: '.js'
}); });
env.match('/examples/sdk-mod.js', { env.match('/examples/mod.js', {
isMod: false isMod: false,
optimizer: fis.plugin('uglify-js')
}); });
env.match('*.{js,jsx,ts,tsx}', { env.match('*.{js,jsx,ts,tsx}', {
@ -388,7 +389,10 @@ if (fis.project.currentMedia() === 'publish') {
'!echarts/**', '!echarts/**',
'!papaparse/**', '!papaparse/**',
'!docsearch.js/**', '!docsearch.js/**',
'!monaco-editor/**.css' '!monaco-editor/**.css',
'!src/components/RichText.tsx',
'!src/components/Tinymce.tsx',
'!src/lib/renderers/Form/CityDB.js'
], ],
'rich-text.js': [ 'rich-text.js': [

View File

@ -4,7 +4,6 @@ import ListRadios from '../ListRadios';
import ResultBox from '../ResultBox'; import ResultBox from '../ResultBox';
import {ClassNamesFn, ThemeProps, themeable} from '../../theme'; import {ClassNamesFn, ThemeProps, themeable} from '../../theme';
import {Icon} from '../icons'; import {Icon} from '../icons';
import {find} from 'lodash';
import {findTree, noop} from '../../utils/helper'; import {findTree, noop} from '../../utils/helper';
export interface ConditionFieldProps extends ThemeProps { export interface ConditionFieldProps extends ThemeProps {

View File

@ -1,8 +1,7 @@
import React from 'react'; import React from 'react';
import {FormItem, FormControlProps, FormBaseControl} from './Item'; import {FormItem, FormControlProps, FormBaseControl} from './Item';
import db, {province, city, district} from './CityDB';
import {ClassNamesFn, themeable, ThemeProps} from '../../theme'; import {ClassNamesFn, themeable, ThemeProps} from '../../theme';
import {Select} from '../../components'; import {Select, Spinner} from '../../components';
import {autobind} from '../../utils/helper'; import {autobind} from '../../utils/helper';
import {Option} from './Options'; import {Option} from './Options';
import {localeable, LocaleProps} from '../../locale'; import {localeable, LocaleProps} from '../../locale';
@ -71,6 +70,21 @@ export interface CityPickerState {
district: string; district: string;
districtCode: number; districtCode: number;
street: string; street: string;
db?: {
province: Array<string>;
city: {
[propName: number]: Array<number>;
};
district: {
[propName: number]:
| {
[propName: number]: Array<number>;
}
| Array<number>;
};
[propName: string]: any;
};
} }
export class CityPicker extends React.Component< export class CityPicker extends React.Component<
@ -86,7 +100,7 @@ export class CityPicker extends React.Component<
allowStreet: false allowStreet: false
}; };
state = { state: CityPickerState = {
code: 0, code: 0,
province: '', province: '',
provinceCode: 0, provinceCode: 0,
@ -98,17 +112,38 @@ export class CityPicker extends React.Component<
}; };
componentDidMount() { componentDidMount() {
this.syncIn(); this.loadDb(() => this.syncIn());
} }
componentDidUpdate(prevProps: CityPickerProps) { componentDidUpdate(prevProps: CityPickerProps) {
const props = this.props; const props = this.props;
if (props.value !== prevProps.value) { if (props.value !== prevProps.value) {
this.syncIn(props); this.loadDb(() => this.syncIn(props));
} }
} }
loadDb(callback?: () => void) {
if (this.state.db) {
callback?.();
return;
}
(require as any)(['./CityDB.ts'], (db: any) =>
this.setState(
{
db: {
...db.default,
province: db.province,
city: db.city,
district: db.district
}
},
callback
)
);
}
@autobind @autobind
handleProvinceChange(option: Option) { handleProvinceChange(option: Option) {
this.setState( this.setState(
@ -178,8 +213,13 @@ export class CityPicker extends React.Component<
@autobind @autobind
syncIn(props = this.props) { syncIn(props = this.props) {
const db = this.state.db!;
const {value, delimiter} = props; const {value, delimiter} = props;
if (!db) {
return;
}
const state = { const state = {
code: 0, code: 0,
province: '', province: '',
@ -271,13 +311,13 @@ export class CityPicker extends React.Component<
translate: __ translate: __
} = this.props; } = this.props;
const {provinceCode, cityCode, districtCode, street} = this.state; const {provinceCode, cityCode, districtCode, street, db} = this.state;
return ( return db ? (
<div className={cx('CityPicker', className)}> <div className={cx('CityPicker', className)}>
<Select <Select
disabled={disabled} disabled={disabled}
options={province.map(item => ({ options={db.province.map(item => ({
label: db[item], label: db[item],
value: item value: item
}))} }))}
@ -287,20 +327,22 @@ export class CityPicker extends React.Component<
{provinceCode && {provinceCode &&
allowDistrict && allowDistrict &&
Array.isArray(district[provinceCode]) ? ( Array.isArray(db.district[provinceCode]) ? (
<Select <Select
disabled={disabled} disabled={disabled}
options={(district[provinceCode] as Array<number>).map(item => ({ options={(db.district[provinceCode] as Array<number>).map(item => ({
label: db[item], label: db[item],
value: item value: item
}))} }))}
value={districtCode} value={districtCode}
onChange={this.handleDistrictChange} onChange={this.handleDistrictChange}
/> />
) : allowCity && city[provinceCode] && city[provinceCode].length ? ( ) : allowCity &&
db.city[provinceCode] &&
db.city[provinceCode].length ? (
<Select <Select
disabled={disabled} disabled={disabled}
options={city[provinceCode].map(item => ({ options={db.city[provinceCode].map(item => ({
label: db[item], label: db[item],
value: item value: item
}))} }))}
@ -311,11 +353,11 @@ export class CityPicker extends React.Component<
{cityCode && {cityCode &&
allowDistrict && allowDistrict &&
district[provinceCode] && db.district[provinceCode] &&
district[provinceCode][cityCode] ? ( db.district[provinceCode][cityCode] ? (
<Select <Select
disabled={disabled} disabled={disabled}
options={(district[provinceCode][cityCode] as Array<number>).map( options={(db.district[provinceCode][cityCode] as Array<number>).map(
item => ({ item => ({
label: db[item], label: db[item],
value: item value: item
@ -336,6 +378,8 @@ export class CityPicker extends React.Component<
/> />
) : null} ) : null}
</div> </div>
) : (
<Spinner show size="sm" />
); );
} }
} }