Selaa lähdekoodia

fix: 时间选择的问题

lvkun 2 vuotta sitten
vanhempi
commit
fffdc4e510

+ 2 - 3
src/api/iot/model.ts

@@ -263,9 +263,8 @@ export const getModelTemplate = (params: any) => {
 /** 获取产品模型库列表详情 */
 export const getModelTemplateById = (id: string) => {
   return request<IOT.API.MODELTEMPLATE.modelTemplate>({
-    url: '/modelTemplate/page',
-    method: 'GET',
-    params: { id }
+    url: `/modelTemplate/${id}`,
+    method: 'GET'
   })
 }
 

+ 5 - 18
src/pages/Iot/dataServer/history.vue

@@ -25,6 +25,7 @@
         </a-select>
         <span>触发时间: </span>
         <a-range-picker v-model:value="time" :format="['DD/MM/YYYY', 'DD/MM/YYYY']"  />
+        <a-button type="primary"  @click="getHistoryPage">搜索</a-button>
       </a-space>
 
     </a-col>
@@ -114,30 +115,16 @@ const state = reactive<{
 watch(
   () => time.value,
   () => {
-    console.log(dayjs(time.value).format('YYYY/MM/DD') === 'Invalid Date')
-    if (dayjs(time.value).format('YYYY/MM/DD') === 'Invalid Date') {
-      queryParams.startTime = ''
-      queryParams.endTime = ''
-    } else {
+    if (time.value && time.value.length === 2) {
       queryParams.startTime = new Date(dayjs(time.value[0])).getTime()
       queryParams.endTime = new Date(dayjs(time.value[1])).getTime()
+    } else {
+      queryParams.startTime = ''
+      queryParams.endTime = ''
     }
   }
 )
 
-watch(
-  () => queryParams.deviceId,
-  () => getHistoryPage()
-)
-
-watch(
-  () => queryParams.modelId,
-  () => {
-    console.log(queryParams.modelId)
-    getHistoryPage()
-  }
-)
-
 const changePage = ({ current }) => {
   queryParams.page = current
   getHistoryPage()

+ 21 - 5
src/pages/Iot/device/topology.vue

@@ -86,7 +86,7 @@
 
 <script lang="ts" setup >
 import { DeviceContriller, ModelController } from '@/controller'
-import { reactive, onMounted, watch, ref } from 'vue'
+import { reactive, onMounted, watch, ref, onUnmounted, onBeforeUnmount } from 'vue'
 import VueTree from '@ssthouse/vue3-tree-chart'
 import '@ssthouse/vue3-tree-chart/dist/vue3-tree-chart.css'
 import { AppstoreOutlined, ZoomInOutlined, ZoomOutOutlined } from '@ant-design/icons-vue'
@@ -128,25 +128,41 @@ const treeData = reactive({
 
 const zoomIn = () => {
   zoomCount.value += 10
-  vueTreeRef.value.zoomIn()
+
+  try {
+    vueTreeRef.value.zoomIn()
+  } catch (error) {
+
+  }
 }
 
 const zoomOut = () => {
   zoomCount.value -= 10
-  vueTreeRef.value.zoomOut()
+  try {
+    vueTreeRef.value.zoomOut()
+  } catch (error) {
+
+  }
 }
 
 const resetZoom = () => {
   zoomCount.value = 100
 }
 
-window.addEventListener('wheel', function (event) {
-  console.log(event.deltaY)
+const scaleHandle = (event) => {
   if (event.deltaY > 0) {
     zoomOut()
   } else {
     zoomIn()
   }
+}
+
+window.addEventListener('wheel', scaleHandle)
+
+onUnmounted(() => {
+  console.log('removeEventListener:', 'wheel')
+
+  window.removeEventListener('wheel', scaleHandle)
 })
 
 watch(

+ 7 - 1
src/pages/Iot/model/detail.vue

@@ -48,6 +48,7 @@ import Topic from './components/topic.vue'
 const route = useRoute()
 
 const modelId = route.query.id as string
+const modelType = route.query.type as 'model' | 'template'
 
 const state = reactive<{
   model: IOT.API.MODEL.ModelDot | null,
@@ -94,8 +95,13 @@ const getModelById = async () => {
   state.model = await ModelController.detail(modelId)
 }
 
+const getModelTemplateById = async () => {
+  state.model = await ModelController.modelTemplateById(modelId)
+}
+
 onMounted(() => {
-  getModelById()
+  modelType === 'model' ? getModelById() : getModelTemplateById()
+
   getDeviceCount()
 })
 

+ 1 - 1
src/pages/Iot/model/index.vue

@@ -207,7 +207,7 @@ const ok = () => {
 }
 
 const goDetailPage = (id: string) => {
-  router.push({ path: '/product/detail', query: { id } })
+  router.push({ path: '/product/detail', query: { id, type: 'model' } })
 }
 
 const confirmDel = async (id: string) => {

+ 8 - 0
src/pages/Iot/model/models.vue

@@ -25,6 +25,7 @@
         </template>
         <template v-if="column.key === 'action'" >
           <a-space>
+            <a @click="goDetailPage(record.id)" >查看</a>
             <a >详情</a>
           </a-space>
         </template>
@@ -65,6 +66,7 @@ import { LeftSquareOutlined } from '@ant-design/icons-vue'
 import { onMounted, reactive } from 'vue'
 import { Form } from 'ant-design-vue'
 import dayjs from 'dayjs'
+import { useRouter } from 'vue-router'
 
 const columns = [
   {
@@ -94,6 +96,8 @@ const columns = [
   }
 ]
 
+const router = useRouter()
+
 const queryParamsState = reactive({
   page: 1,
   pageSize: 10,
@@ -134,6 +138,10 @@ const openModal = () => {
   getModel()
 }
 
+const goDetailPage = (id: string) => {
+  router.push({ path: '/product/detail', query: { id, type: 'template' } })
+}
+
 const changePage = ({ current }) => {
   queryParamsState.page = current
   getModelsPage()

+ 1 - 0
src/pages/Iot/task/manage.vue

@@ -201,6 +201,7 @@ import { computed, onMounted, reactive, ref, toRefs, watch } from 'vue'
 import { Form } from 'ant-design-vue'
 import { DeviceContriller, ModelAttrController, ModelCmdController, ModelController } from '@/controller'
 import SelectDevice from '@/pages/iot/rule/components/selectDevice.vue'
+import StatisticsTemplate from '@/components/StatisticsTemplate/index.vue'
 
 const columns = [
   {

+ 10 - 7
src/pages/Iot/task/track.vue

@@ -3,7 +3,7 @@
   <a-row>
     <a-space>
      <a-col>
-        <a-range-picker v-model:value="time" :format="['DD/MM/YYYY', 'DD/MM/YYYY']"  />
+        <a-range-picker v-model:value="time" format="YYYY/MM/DD"  />
       </a-col>
       <a-col>
         <a-button type="primary" @click="getTrackTaskList">搜索</a-button>
@@ -81,8 +81,8 @@ const time = ref([])
 const queryParamsState = reactive({
   page: 1,
   pageSize: 10,
-  start: 0,
-  end: 0,
+  start: '',
+  end: '',
   taskId: ''
 })
 
@@ -98,13 +98,16 @@ const state = reactive({
 watch(
   () => time.value,
   () => {
-    if (dayjs(time.value).format('YYYY/MM/DD') === 'Invalid Date') {
-      queryParamsState.start = ''
-      queryParamsState.end = ''
-    } else {
+    if (time.value && time.value.length === 2) {
       queryParamsState.start = new Date(dayjs(time.value[0])).getTime()
       queryParamsState.end = new Date(dayjs(time.value[1])).getTime()
+    } else {
+      queryParamsState.start = ''
+      queryParamsState.end = ''
     }
+  },
+  {
+    deep: true
   }
 )