zhitong.yu
8 天以前 378d781e6f35f89652aa36e079a8b7fc44cea77e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<template>
  <div class="table-box">
    <!-- 根据布局模式渲染不同的组件 -->
 
    <ProTable ref="proTable" :columns="columns" :request-api="getTableList" :init-param="initParam">
      <!-- Expand -->
      <template #expand="scope">
        {{ scope.row }}
      </template>
      <template #Sign="scope">
        <span style="margin-left: 10px">
          <b>{{ t("systemlog.tagId") }} </b>
          <el-divider direction="vertical" border-style="dashed" />{{ scope.row.tagId }}
        </span>
      </template>
      <template #power="scope">
        <VueUiGizmo :config="config" :dataset="scope.row.power" />
      </template>
      <template #Context="scope">
        <el-tabs>
          <el-tab-pane :label="t('systemlog.tagInfo')">
            <p>
              {{ t("systemlog.type") }}:<el-tag effect="plain">{{ scope.row.type }}</el-tag>
            </p>
            <p>
              {{ t("systemlog.power") }}:<el-tag effect="plain">{{ scope.row.power }}</el-tag>
            </p>
            <p>
              {{ t("systemlog.version") }}:<el-tag effect="plain">{{ scope.row.version }}</el-tag>
            </p>
            <!-- 基本信息字段 -->
          </el-tab-pane>
        </el-tabs>
      </template>
      <template #Footer="scope">
        <span>
          <b>{{ t("systemlog.status") }}:</b>
          <el-tag :type="getStatusType(scope.row.anchormode)">{{ getStatusText(scope.row.anchormode) }}</el-tag>
        </span>
      </template>
      <!-- 表格操作 -->
    </ProTable>
 
    <UserDrawer ref="drawerRef" />
    <ImportExcel ref="dialogRef" />
  </div>
</template>
 
<script setup lang="tsx" name="useProTable">
import { ref, reactive } from "vue";
import { useI18n } from "vue-i18n";
import { User } from "@/api/interface";
import {} from "@/hooks/useHandleData";
// import { ElMessage } from "element-plus";
import ProTable from "@/components/ProTable/card.vue";
import ImportExcel from "@/components/ImportExcel/index.vue";
import UserDrawer from "@/views/proTable/components/UserDrawer.vue";
import { ProTableInstance, ColumnProps } from "@/components/ProTable/interface";
import {} from "@element-plus/icons-vue";
import { getSystemLogist } from "@/api/modules/hxzk/system/systemlog";
import { VueUiGizmo } from "vue-data-ui";
import "vue-data-ui/style.css";
 
const { t } = useI18n();
 
// ProTable 实例
const proTable = ref<ProTableInstance>();
 
// 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
const initParam = reactive({ type: 1 });
const getTableList = (params: any) => {
  let newParams = JSON.parse(JSON.stringify(params));
 
  // 提取 tableList 对象
  const { pageSize, pageNum, name, sign, ...restParams } = newParams;
  const tableList = { pageSize, pageNum };
 
  // 提取 person 对象
  const { ...restParams2 } = restParams;
  const systemlog = { name, sign };
 
  // 处理 createTime 字段
  if (restParams2.createTime) {
    restParams2.startTime = restParams2.createTime[0];
    restParams2.endTime = restParams2.createTime[1];
    delete restParams2.createTime;
  }
 
  // 合并所有参数
  const finalParams = {
    ...restParams2,
    tableList,
    systemlog
  };
 
  return getSystemLogist(finalParams);
};
 
// 表格配置项
const columns = reactive<ColumnProps<User.ResUserList>[]>([
  { type: "selection", fixed: "left", width: 70 },
  {
    prop: "name",
    label: t("systemlog.operator"),
    search: { el: "input", span: 4 }
  },
  {
    prop: "type",
    label: t("systemlog.type"),
    render: scope => {
      const tagType =
        scope.row.type === t("systemlog.delete")
          ? "danger"
          : scope.row.type === t("systemlog.add")
            ? "success"
            : scope.row.type === t("systemlog.edit")
              ? "warning"
              : "";
      return (
        <el-tag size="large" effect="" type={tagType}>
          {scope.row.type}
        </el-tag>
      );
    }
  },
  {
    prop: "content",
    label: t("systemlog.content")
  },
  {
    prop: "sign",
    label: t("systemlog.dataIdentifier"),
    search: { el: "input", span: 4 },
    render: scope => {
      return (
        <el-tag size="large" effect="">
          {scope.row.sign}
        </el-tag>
      );
    }
  },
  {
    prop: "status",
    label: t("systemlog.status"),
    render: scope => {
      const tagType = scope.row.status === t("systemlog.failed") ? "error" : "success";
      return <el-result icon={tagType} title="" sub-title="" class="el-result-override"></el-result>;
    }
  },
 
  {
    prop: "time",
    label: t("Config.time")
  }
]);
 
// 电量配置项
const config = ref({
  type: "battery",
  size: 60,
  stroke: "#8a8a8aff",
  color: "#33ff57ff",
  useGradient: false,
  gradientColor: "rgba(255, 0, 0, 1)",
  showPercentage: true,
  textColor: "rgba(26, 26, 26, 1)",
  fontFamily: "inherit",
  formatter: null
});
 
// 根据 anchormode 的值返回状态文字
const getStatusText = anchormode => {
  return anchormode === "1" ? t("systemlog.online") : t("systemlog.offline");
};
 
// 根据 anchormode 的值返回标签类型
const getStatusType = anchormode => {
  return anchormode === "1" ? "success" : "danger";
};
 
// 打开 drawer(新增、查看、编辑)
const drawerRef = ref<InstanceType<typeof UserDrawer> | null>(null);
</script>
<style scoped>
:deep(.el-result) {
  --el-result-icon-font-size: 20px !important;
  --el-result-subtitle-margin-top: 0px;
  --el-result-padding: 0px 0px !important;
}
</style>