device.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <template>
  2. <div class="main">
  3. <el-card class="box-card-tree">
  4. <el-button size="mini" type="primary" @click="handleTreeAdd()"
  5. >新增</el-button
  6. >
  7. <el-button
  8. size="mini"
  9. type="primary"
  10. @click="handleTreeDel()"
  11. :disabled="!state.isDel"
  12. >删除</el-button
  13. >
  14. <el-tree
  15. style="margin-top: 10px"
  16. :data="state.treedata"
  17. :props="state.defaultProps"
  18. :default-expanded-keys="['23']"
  19. node-key="id"
  20. highlight-current
  21. :expand-on-click-node="false"
  22. @node-click="handleNodeClick"
  23. />
  24. </el-card>
  25. <el-card class="box-card" style="overflow-y: auto; max-height: 90vh">
  26. <el-tabs type="card">
  27. <!-- <el-tab-pane label="传感点">
  28. <point />
  29. </el-tab-pane> -->
  30. <el-tab-pane label="遥测点">
  31. <ycpoint />
  32. </el-tab-pane>
  33. <el-tab-pane label="遥信点">
  34. <yxpoint />
  35. </el-tab-pane>
  36. <el-tab-pane label="设备报警">
  37. <windturbine />
  38. </el-tab-pane>
  39. <el-tab-pane label="故障预警">
  40. <custom />
  41. </el-tab-pane>
  42. <el-tab-pane label="故障原因">
  43. <faultmode />
  44. </el-tab-pane>
  45. <el-tab-pane label="基本信息">
  46. <message />
  47. </el-tab-pane>
  48. </el-tabs>
  49. </el-card>
  50. <!-- tree add 弹出框 -->
  51. <el-dialog v-model="treeVisible" width="40%">
  52. <el-form :model="state.treeAddFormData" label-width="80px">
  53. <el-row :gutter="24">
  54. <el-col :span="12">
  55. <el-form-item label="结构编码">
  56. <el-input
  57. v-model="state.treeAddFormData.code"
  58. ></el-input> </el-form-item
  59. ></el-col>
  60. <el-col :span="12">
  61. <el-form-item label="上级节点" label-width="100px">
  62. <el-cascader
  63. v-model="state.treeAddFormData.parentcode"
  64. :options="state.cascaderdata"
  65. :props="{ checkStrictly: true, emitPath: false }"
  66. :show-all-levels="false"
  67. clearable
  68. /> </el-form-item
  69. ></el-col>
  70. </el-row>
  71. <el-row :gutter="24">
  72. <el-col :span="12">
  73. <el-form-item label="结构名称">
  74. <el-input
  75. v-model="state.treeAddFormData.name"
  76. ></el-input> </el-form-item
  77. ></el-col>
  78. <el-col :span="12">
  79. <el-form-item label="结构英文名称" label-width="100px">
  80. <el-input
  81. v-model="state.treeAddFormData.enname"
  82. ></el-input> </el-form-item
  83. ></el-col>
  84. </el-row>
  85. <el-row :gutter="24">
  86. <el-col :span="12"
  87. ><el-form-item label="序号">
  88. <el-input
  89. v-model="state.treeAddFormData.orderno"
  90. ></el-input> </el-form-item
  91. ></el-col>
  92. <el-col :span="4">
  93. <el-form-item label="是否有效">
  94. <el-switch
  95. v-model="state.treeAddFormData.enabled"
  96. active-color="#13ce66"
  97. inactive-color="#ff4949"
  98. /> </el-form-item
  99. ></el-col>
  100. <el-col :span="8">
  101. <el-form-item label="设备ID">
  102. <el-input
  103. v-model="state.treeAddFormData.deviceid"
  104. disabled
  105. ></el-input> </el-form-item
  106. ></el-col>
  107. </el-row>
  108. <el-form-item label="描述">
  109. <el-input
  110. v-model="state.treeAddFormData.description"
  111. :rows="4"
  112. clearable
  113. type="textarea"
  114. ></el-input>
  115. </el-form-item>
  116. </el-form>
  117. <template #footer>
  118. <span class="dialog-footer">
  119. <el-button @click="treeVisible = false">取 消</el-button>
  120. <el-button type="primary" @click="saveTreeAdd">确 定</el-button>
  121. </span>
  122. </template>
  123. </el-dialog>
  124. </div>
  125. </template>
  126. <script setup>
  127. import { ref, onMounted, reactive, provide, computed, nextTick } from "vue";
  128. import { ElMessageBox, ElMessage } from "element-plus";
  129. import faultmode from "./fan_components/faultmode.vue";
  130. import message from "./fan_components/message.vue";
  131. import ycpoint from "./fan_components/ycpoint.vue";
  132. import yxpoint from "./fan_components/yxpoint.vue";
  133. import custom from "./fan_components/custom.vue";
  134. import windturbine from "./fan_components/windturbine.vue";
  135. import { tree, treeDel, treeAdd } from "/@/api/api.js";
  136. let treeVisible = ref(false);
  137. let editFormData = ref({});
  138. onMounted(async () => {
  139. await getData();
  140. });
  141. let state = reactive({
  142. isDel: false, //是否能被删除
  143. treedata: [],
  144. cascaderdata: [],
  145. defaultProps: {
  146. children: "children",
  147. label: (a) => {
  148. return a.node.name;
  149. },
  150. },
  151. textarea: "",
  152. addFormData: {
  153. categorydata: "AI",
  154. categoryres1: null,
  155. categoryres2: null,
  156. categoryres3: null,
  157. categoryres4: null,
  158. categoryres5: null,
  159. categorysci: null,
  160. categorysys: null,
  161. description: null,
  162. deviceid: "windturbine",
  163. enname: null,
  164. id: null,
  165. metriccode: "",
  166. name: "",
  167. structurecode: "101010205",
  168. unitname: null,
  169. unitnamecn: null,
  170. deviceModelMetrics: [],
  171. },
  172. treeAddFormData: {
  173. code: "",
  174. parentcode: "",
  175. deviceid: "windturbine",
  176. name: "",
  177. enname: "",
  178. description: "",
  179. orderno: "",
  180. enabled: true,
  181. },
  182. options: [
  183. {
  184. value: "AI",
  185. label: "AI",
  186. },
  187. {
  188. value: "DI",
  189. label: "DI",
  190. },
  191. {
  192. value: "CI",
  193. label: "CI",
  194. },
  195. ],
  196. desc: {
  197. code: "",
  198. parentcode: "",
  199. deviceid: "",
  200. name: "",
  201. enname: "",
  202. description: "",
  203. orderno: "",
  204. enabled: true,
  205. },
  206. treeDelVal: "",
  207. deviceModel: [],
  208. deviceModelSel: "",
  209. treeId: "",
  210. });
  211. // 父子传参
  212. provide(
  213. "cascaderdata",
  214. computed(() => state.cascaderdata)
  215. );
  216. provide(
  217. "desc",
  218. computed(() => state.desc)
  219. );
  220. provide(
  221. "treeId",
  222. computed(() => state.treeId)
  223. );
  224. // tree click
  225. const handleNodeClick = (data) => {
  226. state.isDel = data.children ? false : true;
  227. state.treeId = data.id;
  228. state.desc = data.node;
  229. state.addFormData.structurecode = data.node.code;
  230. };
  231. // tree add
  232. const handleTreeAdd = () => {
  233. treeVisible.value = true;
  234. };
  235. // tree Del
  236. const handleTreeDel = () => {
  237. if (!state.isDel) {
  238. ElMessage.error(`不能删除该节点!!`);
  239. return;
  240. }
  241. ElMessageBox.confirm(`确定要删除 ${state.desc.name} 吗?`, "提示", {
  242. type: "warning",
  243. })
  244. .then(async () => {
  245. const res = await treeDel(state.desc.id);
  246. if (res == 1) {
  247. ElMessage.success(`删除成功!`);
  248. getData();
  249. } else {
  250. ElMessage.warning(`删除失败!`);
  251. }
  252. })
  253. .catch(() => {});
  254. };
  255. // delTreeBtn
  256. const delTreeBtn = async () => {
  257. const res = await treeDel(state.treeDelVal);
  258. if (res == 1) {
  259. ElMessage.success(`删除成功!`);
  260. getData();
  261. } else {
  262. ElMessage.warning(`删除失败!`);
  263. }
  264. state.treeDelVal = "";
  265. };
  266. //保存tree add
  267. const saveTreeAdd = async () => {
  268. const res = await treeAdd(state.treeAddFormData);
  269. if (res.status == 20000) {
  270. ElMessage.success(`操作成功!`);
  271. treeVisible.value = false;
  272. getData();
  273. } else {
  274. ElMessage.warning(res.msg);
  275. }
  276. };
  277. // getData
  278. const getData = async () => {
  279. const res = await tree();
  280. state.treedata = res.children.reverse();
  281. state.cascaderdata = cascaderforEach(res);
  282. };
  283. // 递归解析基础数据
  284. const cascaderforEach = (val) => {
  285. if (val.children != null) {
  286. val.children.forEach((v) => {
  287. v["value"] = v.node.code;
  288. v["label"] = v.node.name;
  289. v["id"] = v.node.id;
  290. cascaderforEach(v);
  291. });
  292. return val.children;
  293. }
  294. };
  295. </script>
  296. <style lang="scss" scoped>
  297. .main {
  298. display: flex;
  299. width: 100%;
  300. height: 100%;
  301. box-sizing: border-box;
  302. justify-content: space-between;
  303. .box-card-tree {
  304. width: 20%;
  305. margin-right: 1%;
  306. overflow: auto;
  307. }
  308. .box-card {
  309. flex: 1;
  310. .desc {
  311. display: flex;
  312. margin-bottom: 30px;
  313. span {
  314. width: 100px;
  315. }
  316. }
  317. }
  318. }
  319. </style>
  320. <style lang="scss" >
  321. .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
  322. background-color: #bbdbff !important;
  323. }
  324. .deviceModelClass {
  325. .el-table__header tr,
  326. .el-table__header th {
  327. padding: 0;
  328. height: 40px;
  329. }
  330. .el-table__body tr,
  331. .el-table__body td {
  332. padding: 0;
  333. height: 40px;
  334. }
  335. }
  336. </style>