index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <div class="global-variable" v-loading="loading">
  3. <div class="left">
  4. <el-input
  5. class="filterInput"
  6. placeholder="输入关键字进行过滤"
  7. v-model="filterText"
  8. >
  9. </el-input>
  10. <el-tree
  11. class="filter-tree"
  12. :data="data"
  13. highlight-current
  14. :props="defaultProps"
  15. default-expand-all
  16. :current-node-key="initBatchCode"
  17. :filter-node-method="filterNode"
  18. @node-click="handleNodeClick"
  19. :node-key="'codeNumber'"
  20. ref="tree"
  21. />
  22. </div>
  23. <div class="right">
  24. <el-menu
  25. :default-active="activeIndex"
  26. class="el-menu-demo"
  27. mode="horizontal"
  28. @select="handleSelect"
  29. >
  30. <template v-for="menuItem in assetssTypeData">
  31. <el-submenu
  32. :index="menuItem.typeCode + menuItem.typeName"
  33. v-if="menuItem.children && menuItem.children.length"
  34. >
  35. <template slot="title">{{ menuItem.typeName }}</template>
  36. <el-menu-item
  37. v-for="submenuItem in menuItem.children"
  38. :index="
  39. submenuItem.typeName === '机组指标'
  40. ? 'production_indicator_unit'
  41. : submenuItem.typeName === '全场指标'
  42. ? 'production_indicator_all'
  43. : submenuItem.typeName === '机组故障统计'
  44. ? 'fault_unit'
  45. : submenuItem.typeName === '全场故障统计'
  46. ? 'fault_all'
  47. : submenuItem.typeName === '齿轮箱-高速轴温度分析'
  48. ? 'temperature_large_components_hig'
  49. : submenuItem.typeName === '齿轮箱-中速轴温度分析'
  50. ? 'temperature_large_components_mid'
  51. : submenuItem.typeName === '齿轮箱-低速轴温度分析'
  52. ? 'temperature_large_components_low'
  53. : submenuItem.typeName === '主轴承温度分析'
  54. ? 'temperature_large_components_min'
  55. : submenuItem.typeName === '发电机-驱动端轴承温度分析'
  56. ? 'temperature_large_components_adriven'
  57. : submenuItem.typeName === '发电机-非驱动端轴承温度分析'
  58. ? 'temperature_large_components_undriven'
  59. : submenuItem.typeName === '发电机-轴承温度偏差分析'
  60. ? 'temperature_large_components_tem_deviation'
  61. : submenuItem.typeName === '发电机-绕组温度分析'
  62. ? 'temperature_large_components_Winding_tem'
  63. : submenuItem.typeCode
  64. "
  65. >{{ submenuItem.typeName }}</el-menu-item
  66. >
  67. </el-submenu>
  68. <el-menu-item :index="menuItem.typeCode" v-else>{{
  69. menuItem.typeName
  70. }}</el-menu-item>
  71. </template>
  72. </el-menu>
  73. <!-- 动态渲染组件 -->
  74. <component
  75. :is="currentComponent"
  76. :initBatchCode="initBatchCode"
  77. :analysisTypeCode="analysisTypeCode"
  78. :batchCodeList="batchCodeList"
  79. @setInitBathCode="setInitBathCode"
  80. ></component>
  81. </div>
  82. <!-- <el-empty description="暂无数据"></el-empty> -->
  83. </div>
  84. </template>
  85. <script>
  86. import { assetssType } from "./js/assetssType";
  87. import { queryAllAnalysisType } from "@/api/performance";
  88. import { getAnalysisCodeInfo } from "@/api/overview";
  89. export default {
  90. data() {
  91. return {
  92. loading: false,
  93. filterText: "",
  94. data: [],
  95. batchCodeList: [], //批次数组用于切换上一条、下一条
  96. initBatchCode: "", // 初始化分析编号
  97. analysisTypeCode: "", // 当前选中的分析类型
  98. windEngineGroupList: "", //风机编码
  99. defaultProps: {
  100. children: "children",
  101. label: "fieldOrCompanyName",
  102. },
  103. currentComponent: () =>
  104. import("./components/analysis_information/index.vue"), // 默认加载AnalysisInformation组件
  105. assetssTypeData: [
  106. {
  107. id: "1",
  108. label: "分析信息",
  109. typeCode: "analysis_information",
  110. },
  111. ],
  112. activeIndex: "analysis_information", // 默认选中的菜单项
  113. };
  114. },
  115. watch: {
  116. filterText(val) {
  117. this.$refs.tree.filter(val);
  118. },
  119. // 监听 initBatchCode 的变化,确保树节点正确选中
  120. initBatchCode(newVal) {
  121. this.$nextTick(() => {
  122. const tree = this.$refs.tree;
  123. if (tree) {
  124. tree.setCurrentKey(newVal); // 设置当前选中的节点
  125. }
  126. });
  127. },
  128. analysisTypeCode(newVal) {
  129. console.log(newVal, "分析类型 ");
  130. },
  131. },
  132. created() {
  133. this.getTreeData();
  134. if (this.$route.query.batchCode) {
  135. this.initBatchCode = this.$route.query.batchCode;
  136. }
  137. },
  138. methods: {
  139. // 获取树形结构数据
  140. getTreeData() {
  141. this.loading = true;
  142. getAnalysisCodeInfo()
  143. .then((res) => {
  144. if (res.code === 200) {
  145. this.loading = false;
  146. this.batchCodeList = [];
  147. const formattedData = this.formatData(res.data);
  148. this.data = formattedData;
  149. // 确保数据加载完成后才查询其他分析类型
  150. this.queryAllAnalysisType();
  151. }
  152. })
  153. .catch((err) => {});
  154. },
  155. //数据格式化树形结构
  156. formatData(data) {
  157. return (
  158. data &&
  159. data.map((item) => {
  160. item.levelstate = "1";
  161. if (item.children && item.children.length > 0) {
  162. item.children = item.children.map((child) => ({
  163. //二级
  164. fieldOrCompanyName: child.fieldOrCompanyName,
  165. codeNumber: child.codeNumber,
  166. levelstate: "2",
  167. children: child.batchCodes
  168. ? child.batchCodes.map((bc) => {
  169. if (this.initBatchCode === "") {
  170. this.initBatchCode = bc.batchCode; // 初始化选中的节点
  171. }
  172. this.batchCodeList.push(bc.batchCode);
  173. return {
  174. //三级
  175. fieldOrCompanyName: bc.analysisName,
  176. codeNumber: bc.batchCode,
  177. levelstate: "3",
  178. };
  179. })
  180. : [],
  181. }));
  182. }
  183. return item;
  184. })
  185. );
  186. },
  187. // 点击树形节点时
  188. handleNodeClick(data) {
  189. console.log(data, "data");
  190. if (data.levelstate === "1" || data.levelstate === "2") {
  191. this.$message.warning("当前选中风场未进行任何分析,请重新选择");
  192. } else {
  193. this.initBatchCode = data.codeNumber; // 更新选中的节点
  194. }
  195. },
  196. //获取
  197. queryAllAnalysisType() {
  198. queryAllAnalysisType().then((res) => {
  199. if (res.code === 200) {
  200. this.assetssTypeData = [
  201. {
  202. id: "1",
  203. typeName: "分析信息",
  204. typeCode: "analysis_information",
  205. },
  206. ...res.data,
  207. ];
  208. }
  209. });
  210. },
  211. // 过滤树形节点的方法
  212. filterNode(value, data) {
  213. if (!value) return true;
  214. return data.fieldOrCompanyName.indexOf(value) !== -1;
  215. },
  216. setInitBathCode(val) {
  217. this.initBatchCode = val;
  218. },
  219. // 菜单选中项的事件
  220. handleSelect(key, keyPath) {
  221. console.log(key, keyPath, "切换");
  222. this.analysisTypeCode = key;
  223. this.currentComponent = () => import(`./components/${key}/index.vue`);
  224. },
  225. },
  226. };
  227. </script>
  228. <style scoped lang="scss">
  229. .global-variable {
  230. display: flex;
  231. height: 90vh;
  232. overflow: hidden;
  233. .left {
  234. width: 200px;
  235. border-right: 1px solid #ebeef5;
  236. padding-right: 20px;
  237. margin-bottom: 20px;
  238. overflow-y: scroll;
  239. /* 滚动条整体样式 */
  240. &::-webkit-scrollbar {
  241. width: 0px; /* 滚动条宽度 */
  242. }
  243. /* 滚动条轨道 */
  244. &::-webkit-scrollbar-track {
  245. background: #f5f7fa;
  246. border-radius: 3px;
  247. }
  248. /* 滚动条滑块 */
  249. &::-webkit-scrollbar-thumb {
  250. background: #c0c4cc;
  251. border-radius: 3px;
  252. }
  253. /* 滚动条滑块悬停时 */
  254. &::-webkit-scrollbar-thumb:hover {
  255. background: #909399;
  256. }
  257. .filterInput {
  258. margin: 20px 0;
  259. }
  260. }
  261. .right {
  262. flex: 1;
  263. padding-left: 20px;
  264. overflow: hidden;
  265. /* 横向滚动设置 */
  266. .el-menu-demo {
  267. max-width: 100%; /* 容器宽度为100% */
  268. white-space: nowrap; /* 阻止换行 */
  269. overflow-x: auto; /* 允许横向滚动 */
  270. display: flex; /* 让子菜单元素保持在同一行 */
  271. /* 滚动条整体样式 */
  272. &::-webkit-scrollbar {
  273. height: 6px; /* 滚动条宽度 */
  274. }
  275. /* 滚动条轨道 */
  276. &::-webkit-scrollbar-track {
  277. background: #f5f7fa;
  278. border-radius: 3px;
  279. }
  280. /* 滚动条滑块 */
  281. &::-webkit-scrollbar-thumb {
  282. background: #c0c4cc;
  283. border-radius: 3px;
  284. }
  285. /* 滚动条滑块悬停时 */
  286. &::-webkit-scrollbar-thumb:hover {
  287. background: #909399;
  288. }
  289. }
  290. }
  291. .el-menu-demo {
  292. border-bottom: 1px solid #ebeef5;
  293. }
  294. ::v-deep .el-submenu__title {
  295. padding: 0 10px !important;
  296. }
  297. }
  298. </style>