Skip to content

Commit 6f329a7

Browse files
committed
zxt 删除数据,符号时提示是否有关联的地图
1 parent 390f007 commit 6f329a7

5 files changed

Lines changed: 180 additions & 5 deletions

File tree

src/components/Dialog/Dialog.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default class Dialog extends PureComponent {
4444
opacity: any,
4545
opacityStyle: Object,
4646
onlyOneBtn: boolean,
47+
disableBackTouch: boolean,
4748
}
4849

4950
static defaultProps = {
@@ -176,6 +177,11 @@ export default class Dialog extends PureComponent {
176177
}}
177178
>
178179
<TouchableOpacity
180+
disabled={
181+
this.props.disableBackTouch === undefined
182+
? false
183+
: this.props.disableBackTouch
184+
}
179185
onPress={this.cancel}
180186
style={[styles.container, this.props.backgroundStyle]}
181187
>

src/containers/tabs/Friend/Component/SimpleDialog.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export default class SimpleDialog extends PureComponent {
99
props: {
1010
confirmAction: () => {},
1111
cancelAction: () => {},
12+
renderExtra: () => {},
13+
style: Object,
1214
text: String,
15+
disableBackTouch: boolean,
1316
}
1417

1518
constructor(props) {
@@ -19,6 +22,7 @@ export default class SimpleDialog extends PureComponent {
1922
confirmAction: this.confirm,
2023
cancelAction: this.cancel,
2124
text: this.props.text,
25+
renderExtra: props.renderExtra,
2226
}
2327
}
2428

@@ -52,6 +56,10 @@ export default class SimpleDialog extends PureComponent {
5256
this.setState({ text: text })
5357
}
5458

59+
setExtra = renderExtra => {
60+
this.setState({ renderExtra: renderExtra })
61+
}
62+
5563
confirm = () => {
5664
this.props.confirmAction && this.props.confirmAction()
5765
this.setVisible(false)
@@ -73,14 +81,16 @@ export default class SimpleDialog extends PureComponent {
7381
cancelAction={this.state.cancelAction}
7482
opacity={1}
7583
opacityStyle={styles.opacityView}
76-
style={styles.dialogBackground}
84+
style={[styles.dialogBackground, this.props.style]}
85+
disableBackTouch={this.props.disableBackTouch}
7786
>
7887
<View style={styles.dialogHeaderView}>
7988
<Image
8089
source={require('../../../../assets/home/Frenchgrey/icon_prompt.png')}
8190
style={styles.dialogHeaderImg}
8291
/>
8392
<Text style={styles.promptTtile}>{this.state.text}</Text>
93+
{this.state.renderExtra}
8494
</View>
8595
</Dialog>
8696
)

src/containers/tabs/Mine/MyBaseMap/MyBaseMap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export default class MyBaseMap extends Component {
112112
initialNumToRender={20}
113113
ref={ref => (this.ref = ref)}
114114
renderItem={this._renderItem}
115+
keyExtractor={(item, index) => index.toString()}
115116
data={this.curUserBaseMaps}
116117
ItemSeparatorComponent={() => (
117118
<View

src/containers/tabs/Mine/MyData/MyData.js

Lines changed: 160 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Image,
88
NativeModules,
99
RefreshControl,
10+
ScrollView,
1011
} from 'react-native'
1112
import { Container, ListSeparator, TextBtn } from '../../../../components'
1213
import { ConstPath, ConstInfo, Const } from '../../../../constants'
@@ -25,10 +26,11 @@ import {
2526
EngineType,
2627
} from 'imobile_for_reactnative'
2728
import { getLanguage } from '../../../../language/index'
28-
import { MsgConstant } from '../../Friend'
29+
import { MsgConstant, SimpleDialog } from '../../Friend'
2930
import { MineItem, BatchHeadBar } from '../component'
3031
import { getThemeAssets } from '../../../../assets'
3132
import styles from './styles'
33+
import RNFS from 'react-native-fs'
3234
const appUtilsModule = NativeModules.AppUtils
3335

3436
export default class MyLocalData extends Component {
@@ -191,6 +193,95 @@ export default class MyLocalData extends Component {
191193
}
192194
}
193195

196+
/**
197+
* 获取地图信息
198+
*/
199+
getMapsInfo = async () => {
200+
let homePath = await FileTools.appendingHomeDirectory()
201+
let userPath =
202+
homePath +
203+
(this.props.user.currentUser.userType === UserType.PROBATION_USER
204+
? ConstPath.CustomerPath
205+
: ConstPath.UserPath + this.props.user.currentUser.userName + '/')
206+
207+
let mapPath = userPath + ConstPath.RelativePath.Map
208+
let filter = {
209+
extension: 'exp',
210+
type: 'file',
211+
}
212+
let maps = await FileTools.getPathListByFilter(mapPath, filter)
213+
return maps
214+
}
215+
216+
/**
217+
* 数据是否在地图中,返回地图名
218+
*/
219+
getRelatedMapName = async (itemInfo, maps) => {
220+
let mapName = undefined
221+
let itemPath = itemInfo.item.path
222+
let homePath = await FileTools.appendingHomeDirectory()
223+
224+
for (let i in maps) {
225+
let value = await RNFS.readFile(homePath + maps[i].path)
226+
let jsonObj = JSON.parse(value)
227+
if (this.state.title === getLanguage(this.props.language).Profile.DATA) {
228+
for (let n in jsonObj.Datasources) {
229+
if (itemPath === ConstPath.UserPath + jsonObj.Datasources[n].Server) {
230+
mapName = maps[i].name
231+
break
232+
}
233+
}
234+
} else if (
235+
this.state.title === getLanguage(this.props.language).Profile.SYMBOL
236+
) {
237+
if (
238+
itemPath.substr(0, itemPath.lastIndexOf('.')) ===
239+
ConstPath.UserPath + jsonObj.Resources
240+
) {
241+
mapName = maps[i].name
242+
break
243+
}
244+
}
245+
}
246+
return mapName ? mapName.substr(0, mapName.lastIndexOf('.')) : undefined
247+
}
248+
249+
/**
250+
* 获取数据关联的地图
251+
*/
252+
getRelatedMap = async itemInfo => {
253+
let mapName = undefined
254+
if (
255+
this.state.title !== getLanguage(this.props.language).Profile.DATA &&
256+
this.state.title !== getLanguage(this.props.language).Profile.SYMBOL
257+
) {
258+
return mapName
259+
}
260+
261+
let maps = await this.getMapsInfo()
262+
return await this.getRelatedMapName(itemInfo, maps)
263+
}
264+
265+
/**
266+
* 批量获取关联地图
267+
*/
268+
getRelatedMaps = async itemInfos => {
269+
let mapNames = []
270+
if (
271+
this.state.title !== getLanguage(this.props.language).Profile.DATA &&
272+
this.state.title !== getLanguage(this.props.language).Profile.SYMBOL
273+
) {
274+
return mapNames
275+
}
276+
277+
let maps = await this.getMapsInfo()
278+
for (let i in itemInfos) {
279+
let mapName = await this.getRelatedMapName({ item: itemInfos[i] }, maps)
280+
mapName && mapNames.push(mapName)
281+
}
282+
return Array.from(new Set(mapNames))
283+
}
284+
194285
createDatasource = async (
195286
datasourcePath,
196287
datasourceName,
@@ -217,13 +308,26 @@ export default class MyLocalData extends Component {
217308
})
218309
}
219310

220-
_batchDelete = async () => {
311+
_batchDelete = async (forceDelete = false) => {
221312
try {
222313
let deleteArr = this._getSelectedList()
223314
if (deleteArr.length === 0) {
224315
Toast.show(getLanguage(global.language).Prompt.SELECT_AT_LEAST_ONE)
225316
return
226317
}
318+
let relatedMaps = []
319+
if (!forceDelete) {
320+
relatedMaps = await this.getRelatedMaps(deleteArr)
321+
}
322+
if (relatedMaps.length !== 0) {
323+
this.relatedMap = relatedMaps
324+
this.SimpleDialog.setConfirm(() => {
325+
this._batchDelete(true)
326+
})
327+
this.SimpleDialog.setExtra(this.renderRelatedMap(relatedMaps))
328+
this.SimpleDialog.setVisible(true)
329+
return
330+
}
227331
let deleteItem
228332
switch (this.state.title) {
229333
case getLanguage(this.props.language).Profile.MAP:
@@ -821,9 +925,22 @@ export default class MyLocalData extends Component {
821925
}
822926
}
823927

824-
_onDeleteData = async () => {
928+
_onDeleteData = async (forceDelete = false) => {
825929
try {
826930
this._closeModal()
931+
let relatedMap = undefined
932+
if (!forceDelete) {
933+
relatedMap = await this.getRelatedMap(this.itemInfo)
934+
}
935+
if (relatedMap) {
936+
this.relatedMap = relatedMap
937+
this.SimpleDialog.setConfirm(() => {
938+
this._onDeleteData(true)
939+
})
940+
this.SimpleDialog.setExtra(this.renderRelatedMap(relatedMap))
941+
this.SimpleDialog.setVisible(true)
942+
return
943+
}
827944
if (this.itemInfo !== undefined && this.itemInfo !== null) {
828945
this.setLoading(
829946
true,
@@ -1288,7 +1405,7 @@ export default class MyLocalData extends Component {
12881405
<View style={styles.bottomStyle}>
12891406
<TouchableOpacity
12901407
style={styles.bottomItemStyle}
1291-
onPress={this._batchDelete}
1408+
onPress={() => this._batchDelete()}
12921409
>
12931410
<Image
12941411
style={{
@@ -1306,6 +1423,44 @@ export default class MyLocalData extends Component {
13061423
)
13071424
}
13081425

1426+
renderSimpleDialog = () => {
1427+
return (
1428+
<SimpleDialog
1429+
ref={ref => (this.SimpleDialog = ref)}
1430+
style={{ height: scaleSize(370) }}
1431+
text={'删除数据将影响以下地图\n是否继续删除?'}
1432+
disableBackTouch={true}
1433+
/>
1434+
)
1435+
}
1436+
1437+
renderRelatedMap = relatedMap => {
1438+
return (
1439+
<View
1440+
style={{
1441+
marginTop: scaleSize(10),
1442+
marginBottom: scaleSize(45),
1443+
height: scaleSize(150),
1444+
width: '80%',
1445+
}}
1446+
>
1447+
{relatedMap instanceof Array ? (
1448+
<ScrollView showsVerticalScrollIndicator={true}>
1449+
{relatedMap.map((item, index) => {
1450+
return (
1451+
<Text key={index} style={{ fontSize: scaleSize(24) }}>
1452+
{item}
1453+
</Text>
1454+
)
1455+
})}
1456+
</ScrollView>
1457+
) : (
1458+
<Text style={{ fontSize: scaleSize(24) }}>{relatedMap}</Text>
1459+
)}
1460+
</View>
1461+
)
1462+
}
1463+
13091464
render() {
13101465
let sectionData = this.state.sectionData
13111466
return (
@@ -1378,6 +1533,7 @@ export default class MyLocalData extends Component {
13781533
{this._showMyDataPopupModal()}
13791534
{this._showDataPopupModal()}
13801535
{this.state.batchMode && this._renderBottom()}
1536+
{this.renderSimpleDialog()}
13811537
<ModalBtns
13821538
ref={ref => {
13831539
this.ModalBtns = ref

src/containers/tabs/Mine/MyLocalData/OnlineDataItem.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ export default class OnlineDataItem extends Component {
121121
{this.props.item.fileName}
122122
</Text>
123123
<Text
124+
ellipsizeMode={'middle'}
125+
numberOfLines={1}
124126
style={{
125127
marginTop: scaleSize(5),
126128
color: color.fontColorGray,

0 commit comments

Comments
 (0)