ソースを参照

修改创建地图组件

HuangKai 2 週間 前
コミット
6708707792
4 ファイル変更58 行追加41 行削除
  1. 1 0
      .gitignore
  2. 9 2
      src/model/AccountAuth.js
  3. 47 0
      src/view/common/CreateMapForm.js
  4. 1 39
      src/view/panes/MapDashboard.js

+ 1 - 0
.gitignore

@@ -20,3 +20,4 @@
 npm-debug.log*
 yarn-debug.log*
 yarn-error.log*
+*.zip

+ 9 - 2
src/model/AccountAuth.js

@@ -208,13 +208,20 @@ class AccountAuth {
             PubSub.publish('body.map.got');
         });        
     }
+    
+    _getIDByTime(){
+        let uuid = "sw" + Date.now().toString(36).slice(-8);
+        console.log(uuid);
+        return uuid;
+    }
 
     cteateMapData(user_id, map_name = 'map'){
         var sql = `INSERT INTO 
                     medba.dat_map 
-                        (map_name, map_data, user_id, update_time, create_time) 
+                        (map_name, map_data, user_id, update_time, create_time, map_uuid) 
                     VALUES 
-                        ('${map_name}', '{ "type": "FeatureCollection", "features": [], "center": { "x": 116.39639, "y": 39.91638 } }', ${user_id}, NOW(), NOW())`;
+                        ('${map_name}', '{ "type": "FeatureCollection", "features": [], "center": { "x": 116.39639, "y": 39.91638 } }', 
+                        ${user_id}, NOW(), NOW(), '${this._getIDByTime()}')`;
         var msg = {
             cmd: "update", // server端要进行判断的
             data: {

+ 47 - 0
src/view/common/CreateMapForm.js

@@ -0,0 +1,47 @@
+import React, { Component } from "react";
+import PubSub from 'pubsub-js';
+import Form from 'react-bootstrap/Form';
+import Button from 'react-bootstrap/Button';
+
+class CreateMapForm extends Component {
+	map_name = '';
+
+    componentDidMount(){
+        PubSub.subscribe('body.map.got', () => {       
+           
+        });
+    }
+
+	createHandle = () => {
+		if(this.map_name !== ''){
+			PubSub.publish('editor.map.create', {id:window.editor_user.id, name: this.map_name});
+		}
+	}
+
+	changeHandle = (e) => {
+		this.map_name = e.target.value;
+	}
+
+	render (){
+		return (
+            <Form>
+				<Form.Group controlId="mapName">
+					<Form.Label>地图名称</Form.Label>
+					<Form.Control 
+						type="text"
+						placeholder=""
+						aria-label="mapName"
+						aria-describedby="mapName"
+						onChange={e => {this.changeHandle(e)}} 
+					/>
+				</Form.Group>
+				<Form.Label style={{color: 'red', fontSize: '12px'}}>请输入地图名称</Form.Label><br/><br/>
+				<Button variant="primary" type="submit" onClick={this.createHandle}>
+					创建
+				</Button>
+			</Form>
+        )
+	}
+}
+
+export default CreateMapForm;

+ 1 - 39
src/view/panes/MapDashboard.js

@@ -14,50 +14,12 @@ import React, { Component } from 'react';
 import Tab from 'react-bootstrap/Tab';
 import Tabs from 'react-bootstrap/Tabs';
 import Container from 'react-bootstrap/Container';
-import Form from 'react-bootstrap/Form';
-import Button from 'react-bootstrap/Button';
 // import Row from 'react-bootstrap/Row';
 // import Col from 'react-bootstrap/Col';
 import MapManageList from '../common/MapManageList'
-import PubSub from 'pubsub-js';
+import CreateMapForm from '../common/CreateMapForm'
 
 
-
-function CreateMapForm(){
-	let name = '';
-
-	function createHandle(){
-		if(name !== ''){
-			PubSub.publish('editor.map.create', {id:window.editor_user.id, name: name});
-		}
-	}
-
-	function changeHandle(e){
-		name = e.target.value;
-	}
-
-	return (
-		<>
-			<Form>
-				<Form.Group controlId="mapName">
-					<Form.Label>地图名称</Form.Label>
-					<Form.Control 
-						type="text"
-						placeholder=""
-						aria-label="mapName"
-						aria-describedby="mapName"
-						onChange={e => {changeHandle(e)}} 
-					/>
-				</Form.Group>
-				<Form.Label style={{color: 'red', fontSize: '12px'}}>请输入地图名称</Form.Label><br/><br/>
-				<Button variant="primary" type="submit" onClick={createHandle}>
-					创建
-				</Button>
-			</Form>
-		</>
-	)
-}
-
 class MapDashboardDialog extends Component {
 	state = {
 		list: null,