77 Image ,
88 NativeModules ,
99 RefreshControl ,
10+ ScrollView ,
1011} from 'react-native'
1112import { Container , ListSeparator , TextBtn } from '../../../../components'
1213import { ConstPath , ConstInfo , Const } from '../../../../constants'
@@ -25,10 +26,11 @@ import {
2526 EngineType ,
2627} from 'imobile_for_reactnative'
2728import { getLanguage } from '../../../../language/index'
28- import { MsgConstant } from '../../Friend'
29+ import { MsgConstant , SimpleDialog } from '../../Friend'
2930import { MineItem , BatchHeadBar } from '../component'
3031import { getThemeAssets } from '../../../../assets'
3132import styles from './styles'
33+ import RNFS from 'react-native-fs'
3234const appUtilsModule = NativeModules . AppUtils
3335
3436export 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
0 commit comments