Bladeren bron

feta: 增加场景和组态的绑定,解绑,查询

yanglzh 1 jaar geleden
bovenliggende
commit
1cb9abc31c

+ 5 - 5
src/views/iot/projects/detail/index.vue

@@ -9,11 +9,11 @@
           <SceneVue :resourcesTypes="4"></SceneVue>
         </el-tab-pane>
         <el-tab-pane label="组态应用" name="2" lazy>
-          <TopoVue></TopoVue>
-        </el-tab-pane>
-        <el-tab-pane label="视频监控" name="3" lazy>
-          <VideoVue></VideoVue>
+          <TopoVue :resourcesTypes="2"></TopoVue>
         </el-tab-pane>
+        <!-- <el-tab-pane label="视频监控" name="3" lazy>
+          <VideoVue :resourcesTypes="3"></VideoVue>
+        </el-tab-pane> -->
       </el-tabs>
     </el-card>
   </div>
@@ -21,7 +21,7 @@
 
 <script lang="ts" setup>
 import TopoVue from './topo.vue'
-import VideoVue from './video.vue'
+// import VideoVue from './video.vue'
 import DeviceVue from './device.vue'
 import SceneVue from './scene.vue'
 

+ 0 - 3
src/views/iot/projects/detail/scene.vue

@@ -53,14 +53,11 @@ import api from '/@/api/projects';
 import { useSearch } from '/@/hooks/useCommon';
 import { useRoute } from 'vue-router';
 import { ElMessage, ElMessageBox } from 'element-plus';
-import { stat } from 'fs';
-import { pa } from 'element-plus/es/locale';
 const route = useRoute();
 
 const props = defineProps({ resourcesTypes: Number })
 const isShowDialog = ref(false)
 const options = ref<any[]>([])
-const deviceList = ref<any[]>([])
 const resourcesTypes = props.resourcesTypes
 const projectsCode = route.params.id
 

+ 130 - 2
src/views/iot/projects/detail/topo.vue

@@ -1,9 +1,137 @@
 <template>
-  <div class="tab-content">
-    组态应用
+  <div class="tab-content h-full">
+    <div class="subtitle"><span></span> <el-button type="primary" size="small" @click="addDevice()">添加组态</el-button></div>
+    <el-table :data="tableData" style="width: 100%" v-loading="loading" max-height="calc(100vh - 280px)">
+      <el-table-column prop="id" label="ID" width="100" show-overflow-tooltip></el-table-column>
+      <el-table-column prop="name" label="组态图名称" show-overflow-tooltip></el-table-column>
+      <el-table-column prop="createdAt" label="创建时间" min-width="100" align="center"></el-table-column>
+      <el-table-column prop="updatedAt" label="更新时间" min-width="100" align="center"></el-table-column>
+      <el-table-column label="操作" width="170" align="center">
+        <template #default="scope">
+          <el-button size="small" text type="primary" v-if="!scope.row.folderName" @click="view(scope.row)">预览</el-button>
+          <el-button size="small" text type="primary" @click="edit(scope.row)">编辑组态图</el-button>
+          <el-button size="small" text type="warning" v-auth="'xxx'" @click="onDel(scope.row)">解绑</el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+    <pagination v-if="params.total" :total="params.total" v-model:page="params.pageNum" v-model:limit="params.pageSize" @pagination="getList()" />
+    <el-dialog title="添加组态" v-model="isShowDialog" width="400">
+      <el-form v-if="isShowDialog">
+        <el-form-item label="组态" style="margin-bottom: 0;">
+          <el-select v-model="form.resourcesKey" filterable placeholder="选择组态" :clearable="false" style="width: 100%">
+            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
+          </el-select>
+        </el-form-item>
+      </el-form>
+      <template #footer>
+        <span class="dialog-footer">
+          <el-button @click="onCancel">取 消</el-button>
+          <el-button type="primary" @click="onSubmit">确 定</el-button>
+        </span>
+      </template>
+    </el-dialog>
   </div>
 </template>
 
 <script lang="ts" setup>
+import { reactive, ref } from 'vue';
+import topoApi from '/@/api/configuration';
+import api from '/@/api/projects';
+import { useSearch } from '/@/hooks/useCommon';
+import { useRoute } from 'vue-router';
+import { ElMessage, ElMessageBox } from 'element-plus';
+import getOrigin from '/@/utils/origin'
+const route = useRoute();
+
+const props = defineProps({ resourcesTypes: Number })
+const isShowDialog = ref(false)
+const options = ref<any[]>([])
+const resourcesTypes = props.resourcesTypes
+const projectsCode = route.params.id
+
+const baseForm = {
+  resourcesKey: '',
+  projectsCode,
+  resourcesTypes
+}
+
+const form = reactive({
+  ...baseForm
+})
+
+const { params, tableData, getList, loading } = useSearch<any[]>(topoApi.getList, 'data', { ids: [], status: -1 });
+
+getOptions();
+getSourceList();
+
+function getSourceList() {
+  api.getProjectResourcesByCode({ projectsCode }).then((res: any) => {
+    params.ids = (res || []).filter((item: any) => item.resourcesTypes === resourcesTypes).map((item: any) => item.resourcesKey)
+
+    getList();
+    // if (!params.ids.length) {
+    //   params.pageNum = 1
+    //   tableData.value = []
+    // } else {
+    //   getList();
+    // }
+  })
+}
+
+function getOptions() {
+  topoApi.getList({ status: -1, pageNum: 1, pageSize: 500 }).then((res: any) => {
+    options.value = (res?.data || []).map((item: any) => ({ label: item.name, value: item.id }))
+  })
+}
+
+function onCancel() {
+  Object.assign(form, baseForm)
+  isShowDialog.value = false
+}
+
+function onSubmit() {
+  if (!form.resourcesKey) return ElMessage('请先选择组态')
+  api.bindResources(form).then((res: any) => {
+    onCancel()
+    getSourceList()
+    ElMessage.success('添加成功')
+  })
+}
+
+function addDevice() {
+  isShowDialog.value = true
+}
+
+function getTokenUrl(url: string) {
+  const tokenUrl = import.meta.env.VITE_TOPO_URL
+  return getOrigin(tokenUrl + url)
+}
+
+const view = (row: any) => {
+  const url = getTokenUrl('#/show/' + row.id);
+  window.open(url);
+};
+
+const edit = (row: any) => {
+  const url = getTokenUrl('#/editor/' + row.id);
+  window.open(url);
+};
+
+function onDel(row: any) {
+  ElMessageBox.confirm(`确定要解绑该组态?`, '提示', {
+    confirmButtonText: '确认',
+    cancelButtonText: '取消',
+    type: 'warning',
+  }).then(() => {
+    api.unbindResources({
+      projectsCode,
+      resourcesTypes,
+      resourcesKey: row.id
+    }).then(() => {
+      getSourceList()
+      ElMessage.success('解绑成功')
+    })
+  });
+}
 
 </script>

+ 107 - 2
src/views/iot/projects/detail/video.vue

@@ -1,9 +1,114 @@
 <template>
-  <div class="tab-content">
-    视频监控
+  <div class="tab-content h-full">
+    <div class="subtitle"><span></span> <el-button type="primary" size="small" @click="addDevice()">添加监控</el-button></div>
+    <el-table :data="tableData" style="width: 100%" v-loading="loading" max-height="calc(100vh - 280px)">
+      <el-table-column label="操作" width="120" align="center">
+        <template #default="scope">
+          <el-button size="small" text type="primary" v-auth="'xxx'" @click="$router.push('/iotmanager/scene/manage/' + scope.row.id)">监控详情</el-button>
+          <el-button size="small" text type="warning" v-auth="'xxx'" @click="onDel(scope.row)">解绑</el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+    <pagination v-if="params.total" :total="params.total" v-model:page="params.pageNum" v-model:limit="params.pageSize" @pagination="getList()" />
+    <el-dialog title="添加监控" v-model="isShowDialog" width="400">
+      <el-form v-if="isShowDialog">
+        <el-form-item label="监控" style="margin-bottom: 0;">
+          <el-select v-model="form.resourcesKey" filterable placeholder="选择监控" :clearable="false" style="width: 100%">
+            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
+          </el-select>
+        </el-form-item>
+      </el-form>
+      <template #footer>
+        <span class="dialog-footer">
+          <el-button @click="onCancel">取 消</el-button>
+          <el-button type="primary" @click="onSubmit">确 定</el-button>
+        </span>
+      </template>
+    </el-dialog>
   </div>
 </template>
 
 <script lang="ts" setup>
+import { reactive, ref } from 'vue';
+import topoApi from '/@/api/configuration';
+import api from '/@/api/projects';
+import { useSearch } from '/@/hooks/useCommon';
+import { useRoute } from 'vue-router';
+import { ElMessage, ElMessageBox } from 'element-plus';
+const route = useRoute();
+
+const props = defineProps({ resourcesTypes: Number })
+const isShowDialog = ref(false)
+const options = ref<any[]>([])
+const resourcesTypes = props.resourcesTypes
+const projectsCode = route.params.id
+
+const baseForm = {
+  resourcesKey: '',
+  projectsCode,
+  resourcesTypes
+}
+
+const form = reactive({
+  ...baseForm
+})
+
+const { params, tableData, getList, loading } = useSearch<any[]>(topoApi.getList, 'data', { ids: [], status: undefined });
+
+getOptions();
+getSourceList();
+
+function getSourceList() {
+  api.getProjectResourcesByCode({ projectsCode }).then((res: any) => {
+    params.ids = (res || []).filter((item: any) => item.resourcesTypes === resourcesTypes).map((item: any) => item.resourcesKey)
+    if (!params.ids.length) {
+      params.pageNum = 1
+      tableData.value = []
+    } else {
+      getList();
+    }
+  })
+}
+
+function getOptions() {
+  topoApi.getList({ status: -1, pageNum: 1, pageSize: 500 }).then((res: any) => {
+    options.value = (res?.data || []).map((item: any) => ({ label: item.name, value: item.id }))
+  })
+}
+
+function onCancel() {
+  Object.assign(form, baseForm)
+  isShowDialog.value = false
+}
+
+function onSubmit() {
+  if (!form.resourcesKey) return ElMessage('请先选择监控')
+  api.bindResources(form).then((res: any) => {
+    onCancel()
+    getSourceList()
+    ElMessage.success('添加成功')
+  })
+}
+
+function addDevice() {
+  isShowDialog.value = true
+}
+
+function onDel(row: any) {
+  ElMessageBox.confirm(`确定要解绑该监控?`, '提示', {
+    confirmButtonText: '确认',
+    cancelButtonText: '取消',
+    type: 'warning',
+  }).then(() => {
+    api.unbindResources({
+      projectsCode,
+      resourcesTypes,
+      resourcesKey: row.id
+    }).then(() => {
+      getSourceList()
+      ElMessage.success('解绑成功')
+    })
+  });
+}
 
 </script>

+ 1 - 3
src/views/iot/projects/list/index.vue

@@ -48,7 +48,7 @@
         <el-table-column type="selection" width="55" align="center" />
         <el-table-column prop="status" label="项目状态" width="100" :formatter="(row: any) => row.status ? '正常' : '禁用'" align="center"></el-table-column>
         <el-table-column prop="name" label="项目名称" min-width="120" show-overflow-tooltip></el-table-column>
-        <el-table-column prop="address" label="省/市/区/县" min-width="100" align="center"></el-table-column>
+        <el-table-column prop="address" label="省/市/区/县" min-width="200" align="center"></el-table-column>
         <el-table-column prop="addressDetail" label="详细地址" min-width="100" align="center"></el-table-column>
         <el-table-column prop="channelMerchants" label="渠道商" min-width="100" align="center"></el-table-column>
         <el-table-column prop="customName" label="关键客户" min-width="100" align="center"></el-table-column>
@@ -56,8 +56,6 @@
         <el-table-column prop="updatedAt" label="更新时间" width="165" align="center"></el-table-column>
         <el-table-column label="操作" width="160" align="center" fixed="right">
           <template #default="{ row }">
-            <!-- <el-button size="small" text type="info" @click="edit(row)">组态设计</el-button>
-            <el-button size="small" text type="info" @click="edit(row)">运行组态</el-button> -->
             <el-button size="small" text style="margin-left: 0;" type="primary" @click="$router.push('/iotmanager/projects/list/' + row.code)">详情</el-button>
             <el-button size="small" text type="warning" v-auth="'xxx'" @click="addOrEdit(row)">编辑</el-button>
             <el-button size="small" text type="primary" v-auth="'xxx'" @click="editStatus(row)">{{ row.status ? '禁用' : '启用' }}</el-button>