global-config.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <script lang="ts" setup>
  2. import { computed, ref } from "vue";
  3. import type { TabsPaneContext } from "element-plus";
  4. import {
  5. instrumentConfigPage,
  6. globalDataPage,
  7. configUpdate,
  8. configAdd,
  9. configDel,
  10. globalDataAdd,
  11. globalDataDel,
  12. globalDataUpdate,
  13. } from "@/api/config";
  14. import configAddVue from "./components/ConfigAdd.vue";
  15. import globalAddVue from "./components/globalDataAdd.vue";
  16. import SecondHeader from "@/views/modules/conmon/SecondHeader.vue";
  17. const route = useRoute();
  18. const activeName = ref("仪器配置");
  19. const handleClick = (tab: TabsPaneContext, event: Event) => {
  20. // console.log(tab, event);
  21. };
  22. //配置列表请求参数
  23. const configParams = ref({
  24. orders: [
  25. {
  26. column: "",
  27. isAsc: true,
  28. },
  29. ],
  30. pageNo: 1,
  31. pageSize: 10,
  32. });
  33. //分页
  34. const configHandleChange = (currentPage: number, pageSize: number) => {
  35. console.log(currentPage);
  36. configParams.value.pageNo = currentPage;
  37. getInstrumentConfig();
  38. // console.log(pageSize);
  39. };
  40. //测试仪器配置数组
  41. const instrumentConfigList = ref([]);
  42. //数据total
  43. const instrumentConfigTotal = ref(1);
  44. //请求数据
  45. const getInstrumentConfig = () => {
  46. instrumentConfigPage(configParams.value).then((res) => {
  47. console.log(res);
  48. instrumentConfigList.value = res.data.records;
  49. instrumentConfigTotal.value = res.data.totalCount;
  50. });
  51. };
  52. //全局列表请求参数
  53. const globalParams = ref({
  54. orders: [
  55. {
  56. column: "",
  57. isAsc: true,
  58. },
  59. ],
  60. pageNo: 1,
  61. pageSize: 10,
  62. });
  63. //分页
  64. const globalHandleChange = (currentPage: number, pageSize: number) => {
  65. console.log(currentPage);
  66. globalParams.value.pageNo = currentPage;
  67. getglobalData();
  68. };
  69. //全局数据数组
  70. const globalDataList = ref([]);
  71. //全局数据数据total
  72. const globalDataTotal = ref(1);
  73. //请求数据 全局数据
  74. const getglobalData = () => {
  75. globalDataPage(globalParams.value).then((res) => {
  76. console.log(res);
  77. globalDataList.value = res.data.records;
  78. globalDataTotal.value = res.data.totalCount;
  79. });
  80. };
  81. onMounted?.(() => {
  82. getInstrumentConfig();
  83. getglobalData();
  84. console.log("当前页面的engineerid", route.params.engineerId);
  85. });
  86. const configChildRef = ref();
  87. const configHandleEdit = (index: number, row: any) => {
  88. configChildRef.value && configChildRef.value.showDialog("change", row);
  89. };
  90. const addConfigFun = () => {
  91. configChildRef.value && configChildRef.value.showDialog("add", {});
  92. };
  93. /**
  94. //新增或修改仪器配置
  95. *
  96. * @param {any} data - 要保存的仪器配置数据
  97. * @param {string} flag - 操作标识,"add" 表示新增,其他值表示修改
  98. *
  99. * 根据 flag 的值调用相应的 API 进行新增或修改操作,
  100. * 操作完成后关闭弹框并重新请求仪器配置数据。
  101. */
  102. const configSaveFun = (data: any, flag: string) => {
  103. if (flag === "add") {
  104. configAdd(data).then((res) => {
  105. configChildRef.value && configChildRef.value.hiddenDialog(); //关闭弹框
  106. getInstrumentConfig(); //重新请求数据
  107. });
  108. } else {
  109. configUpdate(data).then((res) => {
  110. configChildRef.value && configChildRef.value.hiddenDialog(); //关闭弹框
  111. getInstrumentConfig(); //重新请求数据
  112. });
  113. }
  114. };
  115. /**
  116. * 处理删除配置项的函数
  117. * @param {number} index - 配置项在列表中的索引
  118. * @param {any} row - 当前配置项的数据对象
  119. *
  120. * 此函数调用 configDel 方法删除指定的配置项,并在成功后重新请求配置数据。
  121. */
  122. const configHandleDelete = (index: number, row: any) => {
  123. configDel({ id: row.id }).then((res) => {
  124. getInstrumentConfig(); //重新请求数据
  125. });
  126. };
  127. // =======================
  128. const globalChildRef = ref();
  129. const globalHandleEdit = (index: number, row: any) => {
  130. globalChildRef.value && globalChildRef.value.showDialog("change", row);
  131. };
  132. const addglobalFun = () => {
  133. globalChildRef.value && globalChildRef.value.showDialog("add", {});
  134. };
  135. const globalSaveFun = (data: any, flag: string) => {
  136. if (flag === "add") {
  137. globalDataAdd(data).then((res) => {
  138. globalChildRef.value && globalChildRef.value.hiddenDialog(); //关闭弹框
  139. getglobalData(); //重新请求数据
  140. });
  141. } else {
  142. globalDataUpdate(data).then((res) => {
  143. globalChildRef.value && globalChildRef.value.hiddenDialog(); //关闭弹框
  144. getglobalData(); //重新请求数据
  145. });
  146. }
  147. };
  148. const globalHandledel = (index: number, row: any) => {
  149. globalDataDel({ id: row.id }).then((res) => {
  150. getglobalData(); //重新请求数据
  151. });
  152. };
  153. </script>
  154. <template>
  155. <div class="global-config">
  156. <SecondHeader>全局配置</SecondHeader>
  157. <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
  158. <el-tab-pane label="仪器配置" name="仪器配置">
  159. <div class="global-config-pane">
  160. <div class="btns">
  161. <el-button type="primary" @click="addConfigFun">
  162. <span class="add">+</span>
  163. 新增
  164. </el-button>
  165. </div>
  166. <div>
  167. <el-table :data="instrumentConfigList" style="width: 100%">
  168. <el-table-column label="序号" type="index" width="80" />
  169. <el-table-column label="所需仪器类型" prop="instrumentType" />
  170. <el-table-column label="名称" prop="configName" />
  171. <el-table-column label="仪器地址" prop="configIp" />
  172. <el-table-column label="操作" prop="操作" fixed="right">
  173. <template #default="scope">
  174. <el-button
  175. text
  176. size="small"
  177. type="primary"
  178. @click="configHandleDelete(scope.$index, scope.row)"
  179. >
  180. 删除
  181. </el-button>
  182. <el-button
  183. text
  184. size="small"
  185. type="primary"
  186. @click="configHandleEdit(scope.$index, scope.row)"
  187. >
  188. 修改
  189. </el-button>
  190. </template>
  191. </el-table-column>
  192. </el-table>
  193. <el-pagination
  194. class="content-pag"
  195. background
  196. layout="prev, pager, next"
  197. :page-size="10"
  198. :total="instrumentConfigTotal"
  199. @change="configHandleChange"
  200. />
  201. </div>
  202. </div>
  203. </el-tab-pane>
  204. <el-tab-pane label="全局数据" name="全局数据">
  205. <div class="global-config-pane">
  206. <div class="btns">
  207. <el-button type="primary" @click="addglobalFun">
  208. <span class="add">+</span>
  209. 新增
  210. </el-button>
  211. </div>
  212. <div>
  213. <el-table :data="globalDataList" style="width: 100%">
  214. <el-table-column label="序号" type="index" width="80" />
  215. <el-table-column label="数据项名称" prop="dataItemName" />
  216. <el-table-column label="设定值" prop="setValue" />
  217. <el-table-column label="操作" prop="操作" fixed="right">
  218. <template #default="scope">
  219. <el-button
  220. text
  221. size="small"
  222. type="primary"
  223. @click="globalHandledel(scope.$index, scope.row)"
  224. >
  225. 删除
  226. </el-button>
  227. <el-button
  228. text
  229. size="small"
  230. type="primary"
  231. @click="globalHandleEdit(scope.$index, scope.row)"
  232. >
  233. 修改
  234. </el-button>
  235. </template>
  236. </el-table-column>
  237. </el-table>
  238. <el-pagination
  239. class="content-pag"
  240. background
  241. layout="prev, pager, next"
  242. :page-size="10"
  243. :total="globalDataTotal"
  244. @change="globalHandleChange"
  245. />
  246. </div>
  247. </div>
  248. </el-tab-pane>
  249. <el-tab-pane label="执行终端" name="执行终端"
  250. >跟仪器配置一样只是 instrumentProperty 仪器属性(1工程仪器 2执行仪器)
  251. 仪器类型接口 在仪器配置接口API里面</el-tab-pane
  252. >
  253. </el-tabs>
  254. <configAddVue ref="configChildRef" @save="configSaveFun"></configAddVue>
  255. <globalAddVue ref="globalChildRef" @save="globalSaveFun"></globalAddVue>
  256. </div>
  257. </template>
  258. <style scoped lang="scss">
  259. .global-config {
  260. width: 100%;
  261. height: 100vh;
  262. .demo-tabs {
  263. // background-color: red;
  264. :deep(.el-tabs__nav-scroll) {
  265. padding: 0 20px;
  266. }
  267. }
  268. .global-config-pane {
  269. padding: 0 20px;
  270. .btns {
  271. text-align: right;
  272. margin-bottom: 12px;
  273. }
  274. }
  275. .add {
  276. width: 12px;
  277. height: 12px;
  278. line-height: 12px;
  279. border-radius: 12px;
  280. text-align: center;
  281. background-color: #fff;
  282. color: #3b7cff;
  283. margin-right: 10px;
  284. vertical-align: middle;
  285. }
  286. .content-pag {
  287. float: right;
  288. margin-right: 20px;
  289. margin-top: 20px;
  290. padding-bottom: 30px;
  291. }
  292. }
  293. </style>