index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div class="page">
  3. <el-card shadow="never">
  4. <el-form :model="params" inline ref="queryRef" @keyup.enter="getList">
  5. <el-form-item>
  6. <el-input v-model="params.keyword" placeholder="输入指标名称、编码或描述" style="width: 300px" clearable />
  7. </el-form-item>
  8. <el-form-item>
  9. <el-cascader :options="typeOptions" :props="{ checkStrictly: true, emitPath: false, value: 'code', label: 'name' }" placeholder="请选择指标类型" clearable class="w100" v-model="params.type">
  10. <template #default="{ node, data }">
  11. <span>{{ data.name }}</span>
  12. <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
  13. </template>
  14. </el-cascader>
  15. </el-form-item>
  16. <el-form-item>
  17. <el-select v-model="params.status" placeholder="全部状态" clearable style="width: 160px">
  18. <el-option value="-1" label="全部状态" />
  19. <el-option value="0" label="未发布" />
  20. <el-option value="1" label="已发布" />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" class="ml10" @click="getList">
  25. <el-icon><ele-Search /></el-icon>
  26. 查询
  27. </el-button>
  28. <el-button type="primary" class="ml10" @click="addOrEdit()">
  29. <el-icon><ele-FolderAdd /></el-icon>
  30. 新增指标
  31. </el-button>
  32. </el-form-item>
  33. </el-form>
  34. <el-table :data="tableData" style="width: 100%" row-key="code" v-loading="loading">
  35. <el-table-column label="指标编号" prop="code" align="left" width="120">
  36. <template #default="scope">
  37. <el-link type="primary" :underline="false">{{ scope.row.code }}</el-link>
  38. </template>
  39. </el-table-column>
  40. <el-table-column label="指标名称" prop="name" min-width="180" show-overflow-tooltip />
  41. <el-table-column label="指标类型" prop="type" width="120" align="center">
  42. <template #default="scope">
  43. <el-tag size="small">{{ scope.row.type || "-" }}</el-tag>
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="单位" prop="unit" width="100" align="center" />
  47. <el-table-column label="维度数" align="center" width="100">
  48. <template #default="scope">
  49. <el-tag size="small" type="info">{{ (scope.row.dimensions && scope.row.dimensions.length) || scope.row.dimensionCount || 0 }}</el-tag>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="状态" prop="status" width="100" align="center">
  53. <template #default="scope">
  54. <el-tag size="small" :type="scope.row.status == '1' ? 'success' : 'danger'">{{ scope.row.status == "1" ? "已发布" : "未发布" }}</el-tag>
  55. </template>
  56. </el-table-column>
  57. <el-table-column prop="createdAt" label="创建时间" align="center" width="180" />
  58. <el-table-column label="操作" align="center" width="220" fixed="right">
  59. <template #default="scope">
  60. <el-button size="small" text type="primary" v-if="scope.row.status == '0'" @click="publish(scope.row)">发布</el-button>
  61. <el-button size="small" text type="warning" v-else @click="unpublish(scope.row)">取消发布</el-button>
  62. <el-button size="small" text type="primary" @click="openDetail(scope.row)">详情</el-button>
  63. <el-button size="small" text type="success" @click="openData(scope.row)">数据</el-button>
  64. <el-button size="small" text type="primary" @click="addOrEdit(scope.row)">编辑</el-button>
  65. <el-button size="small" text type="danger" @click="onRowDel(scope.row)">删除</el-button>
  66. </template>
  67. </el-table-column>
  68. </el-table>
  69. <pagination v-if="params.total" :total="params.total" v-model:page="params.pageNum" v-model:limit="params.pageSize" @pagination="getList()" />
  70. </el-card>
  71. <EditIndicator ref="editFormRef" :typeOptions="typeOptions" @update="getList" />
  72. <DetailDialog ref="detailRef" />
  73. <DataDialog ref="dataRef" />
  74. </div>
  75. </template>
  76. <script lang="ts" setup>
  77. import { ref } from "vue";
  78. import { ElMessageBox, ElMessage } from "element-plus";
  79. import api from "/@/api/datahub";
  80. import { useSearch } from "/@/hooks/useCommon";
  81. import EditIndicator from "./component/edit.vue";
  82. import DetailDialog from "./component/detail.vue";
  83. import DataDialog from "./component/data.vue";
  84. import apiSystem from "/@/api/system";
  85. const editFormRef = ref();
  86. const detailRef = ref();
  87. const dataRef = ref();
  88. const queryRef = ref();
  89. const typeOptions = ref([]);
  90. apiSystem.getInfoByKey("sys.indicator.type.tagCode").then((res: any) => {
  91. const tagCode = res?.data?.configValue || "HARDWARE";
  92. api.tags.getTree({}).then((res: any) => {
  93. typeOptions.value = (res.data || []).find((item: any) => item.code === tagCode)?.children || [];
  94. });
  95. });
  96. const { params, tableData, getList, loading } = useSearch(api.indicator.getList, "data", {
  97. keyword: "",
  98. type: "",
  99. status: "-1",
  100. });
  101. getList();
  102. const publish = (row?: any) => {
  103. api.indicator.publish(row.code).then(() => {
  104. ElMessage.success("发布成功");
  105. getList();
  106. });
  107. };
  108. const unpublish = (row?: any) => {
  109. api.indicator.unpublish(row.code).then(() => {
  110. ElMessage.success("取消发布成功");
  111. getList();
  112. });
  113. };
  114. const addOrEdit = (row?: any) => {
  115. editFormRef.value.openDialog(row);
  116. };
  117. const openDetail = (row: any) => {
  118. detailRef.value.open(row);
  119. };
  120. const openData = (row: any) => {
  121. dataRef.value.open(row);
  122. };
  123. const onRowDel = (row: any) => {
  124. ElMessageBox.confirm(`此操作将永久删除指标:${row.name}(${row.code}),是否继续?`, "提示", {
  125. confirmButtonText: "删除",
  126. cancelButtonText: "取消",
  127. type: "warning",
  128. }).then(() => {
  129. api.indicator.del(row.code).then(() => {
  130. ElMessage.success("删除成功");
  131. getList();
  132. });
  133. });
  134. };
  135. const formatStatus = (s: string) => {
  136. if (s === "enabled") return "启用";
  137. if (s === "draft") return "草稿";
  138. if (s === "disabled") return "停用";
  139. return s || "-";
  140. };
  141. const statusTagType = (s: string) => {
  142. if (s === "enabled") return "success";
  143. if (s === "draft") return "info";
  144. if (s === "disabled") return "warning";
  145. return "info";
  146. };
  147. </script>
  148. <style lang="scss" scoped></style>