global-config.vue 8.5 KB

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