From 307db148645230afc780a3d5d16ffb97aa32c189 Mon Sep 17 00:00:00 2001
From: jihongshun <1151753686@qq.com>
Date: 星期四, 03 七月 2025 16:38:58 +0800
Subject: [PATCH] 模型 && 设备相关

---
 src/views/system/device/components/deviceDialog.vue |  110 ++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 77 insertions(+), 33 deletions(-)

diff --git a/src/views/system/device/components/deviceDialog.vue b/src/views/system/device/components/deviceDialog.vue
index cbc2b09..f08cfae 100644
--- a/src/views/system/device/components/deviceDialog.vue
+++ b/src/views/system/device/components/deviceDialog.vue
@@ -4,28 +4,22 @@
     <Modal :title="form.id ? '淇敼璁惧' : '娣诲姞璁惧'" v-model="open">
       <template slot="form">
         <el-form ref="form" :model="form" :rules="rules" label-width="auto">
-          <el-form-item label="璁惧鍚嶇О" prop="name">
-            <el-input v-model="form.name1" placeholder="璇疯緭鍏ヨ澶囧悕绉�" />
+          <el-form-item label="璁惧鍚嶇О" prop="deviceName">
+            <el-input v-model="form.deviceName" placeholder="璇疯緭鍏ヨ澶囧悕绉�" />
           </el-form-item>
-          <el-form-item label="鎵�灞炵嚎璺�" prop="beloneRoad">
-            <el-input v-model="form.name2" placeholder="璇疯緭鍏ユ墍灞炵嚎璺�" />
+          <el-form-item label="鎵�灞炵嚎璺�" prop="belongingRoute">
+            <el-input v-model="form.belongingRoute" placeholder="璇疯緭鍏ユ墍灞炵嚎璺�" />
           </el-form-item>
-          <el-form-item label="閫夋嫨妯″瀷" prop="wellType">
-            <el-select v-model="form.wellType" placeholder="閫夋嫨妯″瀷">
-              <el-option v-for="key in modelListData" :key="key.id" :label="key.modelType"
+          <el-form-item label="閫夋嫨妯″瀷" prop="modelId">
+            <el-select v-model="form.modelId" placeholder="閫夋嫨妯″瀷"  @change="change">
+              <el-option v-for="key in modelListData" :key="key.id" :label="key.modelName"
                 :value="key.id"></el-option>
             </el-select>
           </el-form-item>
-          <el-form-item label="鏈濆悜" prop="direction">
-            <el-input v-model="form.direction" placeholder="璇疯緭鍏ユ湞鍚�"  style="width:90%;"/>
+          <el-form-item label="鏈濆悜" prop="face">
+            <el-input v-model="form.face" placeholder="璇疯緭鍏ユ湞鍚�"  style="width:90%;"/>
             <i class="el-icon-map-location" @click="gettiles3dCam" title="棰勮"></i>
           </el-form-item>
-          <!-- <el-form-item label="妯″瀷绫诲瀷" prop="wellType">
-            <el-select v-model="form.wellType" placeholder="妯″瀷绫诲瀷">
-              <el-option v-for="key in model_type" :key="key.value" :label="key.label"
-                :value="key.value"></el-option>
-            </el-select>
-          </el-form-item> -->
         </el-form>
       </template>
       <template slot="cesium">
@@ -64,16 +58,14 @@
       form: {},
       // 琛ㄥ崟鏍¢獙
       rules: {
-        name: [
-          { required: true, message: '璇疯緭鍏ュ鍚嶇О', trigger: 'blur' }
+        deviceName: [
+          { required: true, message: '璇疯緭鍏ヨ澶囧悕绉�', trigger: 'blur' }
         ],
-        deptId: [
-          { required: true, message: '褰掑睘閮ㄩ棬' } // trigger鐩戝惉涓嶅埌 浣跨敤@input鍗曠嫭鏍¢獙vue-treeSelect琛ㄥ崟椤�
-        ]
       },
       // 閮ㄩ棬鏁版嵁
       deptOptions: null,
-      modelListData:[]
+      modelListData:[],
+      modelUrl:null
     }
   },
   methods: {
@@ -92,6 +84,34 @@
               latitude: +this.form.latitude,
               altitude: +this.form.altitude,
             })
+            let url = this.modelListData.filter(item=>item.id == this.form.modelId)[0].modelRoute
+            this.modelUrl = url
+            const position = Cesium.Cartesian3.fromDegrees(this.form.longitude, this.form.latitude, this.form.altitude);
+            // 璁剧疆妯″瀷鏂瑰悜锛堝彲閫夛級
+            let model = viewer.entities.getById("MyModel");
+            const heading = Cesium.Math.toRadians(this.form.face); // 鏈濅笢鍗楁柟鍚�
+            const pitch = 0;
+            const roll = 0;
+            const orientation = Cesium.Transforms.headingPitchRollQuaternion(
+              position,
+              new Cesium.HeadingPitchRoll(heading, pitch, roll)
+            );
+            if(!model) {
+              // 鍔犺浇 glTF 妯″瀷
+              const entity = viewer.entities.add({
+                id: "MyModel",
+                name: "MyModel",
+                position: position,
+                orientation: orientation,
+                model: {
+                  uri:this.modelUrl, // 鏇挎崲鎴愪綘鐨勬ā鍨嬭矾寰�
+                  scale: 1000,
+                },
+              });
+              viewer.flyTo(entity)
+            }else {
+              model.orientation = orientation
+            }
           })
         })
       } else {
@@ -113,13 +133,17 @@
     submitForm() {
       this.$refs["form"].validate(valid => {
         console.log(this.form)
-        // if (valid) {
-        //   this.$api.save('work/tower/', 'id', Object.assign({}, this.form)).then(res => {
-        //     this.form = {}
-        //     this.$emit('on-submit')
-        //     this.open = false
-        //   })
-        // }
+        this.form.longitude = Number(this.form.longitude)
+        this.form.latitude = Number(this.form.latitude)
+        this.form.altitude = Number(this.form.altitude)
+        this.form.face = Number(this.form.face)
+        if (valid) {
+          this.$api.save('tower/device/', 'id', Object.assign({}, this.form)).then(res => {
+            this.form = {}
+            this.$emit('on-submit')
+            this.open = false
+          })
+        }
       });
     },
     cancel() {
@@ -136,14 +160,36 @@
         this.modelListData = res.rows || []
       })
     },    
+    change(id){
+      console.log(id)
+      let url = this.modelListData.filter(item=>item.id == id)[0].modelRoute
+      console.log(url)
+      this.modelUrl = url
+    },  
     gettiles3dCam(){
       console.log(this.form)
+      if(!this.form.face) {
+        return this.$message.error('璇疯緭鍏ユ湞鍚�')
+      }
+      if (!this.form.longitude) {
+        this.$message.error("璇疯緭鍏ョ粡搴�");
+        return;
+      }
+      if (!this.form.latitude) {
+        this.$message.error("璇疯緭鍏ョ含搴�");
+        return;
+      }
+      if (!this.form.altitude) {
+        this.$message.error("璇疯緭鍏ラ珮搴�");
+        return;
+      }
       //鍔ㄦ�佺粡绾害鏈濆悜 鍔犺浇妯″瀷浣嶇疆棰勮
-      const position = Cesium.Cartesian3.fromDegrees(0, 0, 0);
+      // const position = Cesium.Cartesian3.fromDegrees(0, 0, 0);
+      const position = Cesium.Cartesian3.fromDegrees(this.form.longitude, this.form.latitude, this.form.altitude);
       // 璁剧疆妯″瀷鏂瑰悜锛堝彲閫夛級
       // const heading = Cesium.Math.toRadians(135); // 鏈濅笢鍗楁柟鍚�
       let model = viewer.entities.getById("MyModel");
-      const heading = Cesium.Math.toRadians(this.form.direction); // 鏈濅笢鍗楁柟鍚�
+      const heading = Cesium.Math.toRadians(this.form.face); // 鏈濅笢鍗楁柟鍚�
       const pitch = 0;
       const roll = 0;
       const orientation = Cesium.Transforms.headingPitchRollQuaternion(
@@ -158,7 +204,7 @@
           position: position,
           orientation: orientation,
           model: {
-            uri: "/Model/tower.glb", // 鏇挎崲鎴愪綘鐨勬ā鍨嬭矾寰�
+            uri:  this.modelUrl, // 鏇挎崲鎴愪綘鐨勬ā鍨嬭矾寰�
             scale: 1000,
           },
         });
@@ -166,8 +212,6 @@
       }else {
         model.orientation = orientation
       }
-      
-
     }
   },
   mounted() {

--
Gitblit v1.9.3