123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <template>
- <div>
- <el-tabs v-model="activeRelation" @tab-click="changeTabs">
- <el-tab-pane v-for=" (item,index) in relationList" :key="index" :label="item.name" :name="item.code">
- <el-table :data="tableData" height="300" class="data-table border" :stripe="true" border size="small" v-loading="isLoading" style="width: 100%">
- <el-table-column width="180" label="设备名称">
- <template slot-scope="scope">
- <span>
- <el-tooltip :content="scope.row.infos.EquipName" placement="top">
- <span>{{scope.row.infos.EquipLocalName || scope.row.infos.EquipName | cutString(15)}}</span>
- </el-tooltip>
- </span>
- </template>
- </el-table-column>
- <el-table-column width="160" label="设备类">
- <template slot-scope="scope">
- <span>
- <span>{{getName(scope.row.category)}}</span>
- </span>
- </template>
- </el-table-column>
- <el-table-column label="操作">
- <template slot-scope="scope">
- <el-button plain @click="lockDetails(scope.row)">详情</el-button>
- <el-button v-if="scope.row.inSpace" plain type="danger" @click="deleteSpace(scope.row)">从空间移除</el-button>
- </template>
- </el-table-column>
- </el-table>
- <div class="right" v-show="tableData.length">
- <my-pagination :page="page" @change="pageChange"></my-pagination>
- </div>
- </el-tab-pane>
- </el-tabs>
- <el-dialog width="40%" title="设备详情" :visible.sync="innerVisible" append-to-body>
- <iframe height="400px" width="100%" :src="iframeSrc"></iframe>
- </el-dialog>
- </div>
- </template>
- <script>
- import myPagination from "@/components/common/myPagination.vue";
- import {
- getSpaceEquip,
- getEqCode,
- deleteRelation,
- getGraphyId,
- getSysToEq
- } from "@/api/scan/request";
- import {
- mapGetters,
- mapActions
- } from "vuex";
- export default {
- name: "equip-table",
- components: {
- myPagination
- },
- computed: {
- ...mapGetters("layout", [
- "projectId",
- "secret",
- "userId"
- ])
- },
- props: {
- param: {
- type: Object
- },
- activeTabType: {
- type: Object,
- default: function() {
- return {
- "code": "GeneralZone",
- "name": "默认分区",
- "rel_type": "99"
- }
- }
- }
- },
- data() {
- return {
- page: {
- size: 50,
- sizes: [10, 30, 50, 100, 150, 200],
- total: 0,
- currentPage: 1
- },
- tableData: [],
- data: {},
- EqCode: [],
- innerVisible: false,
- iframeSrc: "",
- title: "",
- graphyId: "",
- isLoading: false,
- relationList: [{
- name: "空间内的设备",
- code: "EquipinSpace"
- }, {
- name: "服务于空间的设备",
- code: "EquipforSpace"
- }, {
- name: "其他关系的设备",
- code: "EquipXSpace"
- }],
- activeRelation: "EquipinSpace",
- CalcUrl: {
- "code": "GeneralZone",
- "name": "默认分区",
- "rel_type": "99"
- },
- relType: 0
- };
- },
- created() {
- this.getEqCode();
- },
- methods: {
- changeTabs() {
- let param = {
- data: {
- limit: {
- // 可选
- skip: this.page.size * (this.page.currentPage - 1), // 跳过多少数据
- count: this.page.size // 查询跳过300条数据之后的50条 (默认按照创建时间从大-->小排序)
- },
- criteria: {
- space: this.data.id, // 必填, 指定业务空间id
- type: ["Eq"] // 必填, 查询类型, 允许四位编码的详细设备类
- }
- },
- ProjId: this.projectId, //项目id
- secret: this.secret
- };
- this.isLoading = true
- if (this.CalcUrl.rel_type == 99 && this.activeRelation == "EquipinSpace") {
- this.dataChange(param);
- } else {
- this.getRlations()
- }
- },
- getEqCode() {
- getEqCode()
- .then(res => {
- if (res.data.Result == "success") {
- this.EqCode = res.data.Content;
- } else {
- this.$message.error(res.data.ResultMsg);
- }
- })
- .catch(() => {
- this.$message.error("请求失败");
- });
- },
- getGraphyId(row) {
- let param = {
- type: this.activeRelation,
- ProjId: this.projectId, //项目id
- secret: this.secret
- };
- getGraphyId(param)
- .then(res => {
- if (res.data.Result == "success") {
- this.graphyId = res.data.graph_id;
- this.deleteOwn(row)
- } else {
- this.$message.error(res.data.ResultMsg);
- }
- })
- .catch(() => {
- this.$message.error("请求错误");
- });
- },
- getRlations() {
- this.isLoading = true
- this.relType = 0
- if (this.CalcUrl.rel_type == 99) {
- this.relType = "1"
- } else {
- if (this.CalcUrl.rel_type > 9) {
- this.relType = (this.CalcUrl.rel_type * 100).toString()
- } else {
- this.relType = '0' + (this.CalcUrl.rel_type * 100)
- }
- }
- let param = {
- data: {
- "limit": { // 可选
- skip: this.page.size * (this.page.currentPage - 1), // 跳过多少数据
- count: this.page.size // 查询跳过300条数据之后的50条 (默认按照创建时间从大-->小排序)
- },
- criteria: {
- graphType: this.activeRelation,
- relType: this.relType,
- toId: this.data.id,
- fromId: this.data.fromId,
- type: ["Eq"]
- }
- },
- ProjId: this.projectId, //项目id
- secret: this.secret
- }
- getSysToEq(param, res => {
- this.tableData = res.Content.map(item => {
- item.inSpace = true
- return item
- })
- this.page.total = res.TotalCount;
- this.isLoading = false
- })
- },
- deleteOwn(row) {
- let param = {
- data: {
- criterias: [{
- from_id: row.id, //选填
- to_id: this.data.id, //选填
- graph_id: this.graphyId, //选填
- rel_type: this.relType
- }]
- },
- ProjId: this.projectId, //项目id
- secret: this.secret
- };
- this.$confirm("正在删除设备关系, 是否继续?", "删除", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- })
- .then(() => {
- deleteRelation(param)
- .then(res => {
- if (res.data.Result == "success") {
- this.$message.success("删除成功");
- this.change();
- } else {
- this.$message.error(res.data.ResultMsg);
- }
- })
- .catch(() => {
- this.$message.error("请求出错");
- });
- })
- .catch(() => {
- this.$message("取消删除");
- });
- },
- getName(code) {
- let text = "",
- myClass = code.substring(0, 2),
- system = code.substring(2, 4),
- last = code.substring(2, 6);
- if (this.EqCode && this.EqCode.length) {
- this.EqCode.map(item => {
- if (item.code == myClass) {
- item.content.map(i => {
- if (i.code == system) {
- i.content.map(e => {
- if ((e.code == last)) {
- text = e.facility;
- }
- });
- }
- });
- }
- });
- }
- return text;
- },
- /**
- * 删除
- * @param row 点击的当条数据
- */
- deleteSpace(row) {
- this.getGraphyId(row)
- },
- /**
- * 获取数据
- * @param data 由上级页面传入,初始化table表格
- */
- getData(data, type) {
- this.activeRelation = "EquipinSpace"
- this.CalcUrl = type
- this.page = {
- size: 50,
- sizes: [10, 30, 50, 100, 150, 200],
- total: 0,
- currentPage: 1
- };
- this.data = data;
- this.change();
- },
- change() {
- let param = {
- data: {
- limit: {
- // 可选
- skip: this.page.size * (this.page.currentPage - 1), // 跳过多少数据
- count: this.page.size // 查询跳过300条数据之后的50条 (默认按照创建时间从大-->小排序)
- },
- criteria: {
- space: this.data.id, // 必填, 指定业务空间id
- type: ["Eq"] // 必填, 查询类型, 允许四位编码的详细设备类
- }
- },
- ProjId: this.projectId, //项目id
- secret: this.secret
- };
- this.isLoading = true
- if (this.CalcUrl.rel_type == 99) {
- this.dataChange(param);
- } else {
- this.getRlations()
- }
- },
- dataChange(param) {
- getSpaceEquip(param)
- .then(res => {
- if (res.data.Result == "success") {
- this.page.total = res.data.TotalCount;
- this.tableData = res.data.Content;
- this.isLoading = false
- } else {
- this.$message.error(res.data.ResultMsg);
- }
- })
- .catch(() => this.$message.error("请求失败"));
- },
- /**
- * 查看详情
- * @param row 点击的当条数据
- */
- lockDetails(row) {
- this.innerVisible = true;
- this.iframeSrc = this.iframeSrc =
- // "http://172.16.0.181:8889/#/details?perjectId=" +
- process.env.BASE_URL + ":8889/#/details?perjectId=" +
- this.projectId +
- "&secret=" +
- this.secret +
- "&FmId=" +
- row.id +
- "&type=0&code=" +
- row.category.substring(2, 6);
- },
- pageChange() {
- this.change();
- }
- },
- filters: {
- cutString: function(str, len) {
- //length属性读出来的汉字长度为1
- if (!!str && typeof str == "string" && str.length > len) {
- return str.substring(0, len) + "...";
- } else {
- return str || "--";
- }
- }
- }
- };
- </script>
- <style>
- /* .el-table tr th { */
- /* background: #fafafa !important; */
- /* } */
- </style>
|