index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <div class="airportInfo scroll-y">
  3. <div class="wrap">
  4. <Minheader :is-auth="true" :is-statuser="true" powerData="equipment_addition_button" @addForm="addForm">
  5. <template #header>
  6. <div class="status flex-wrap">
  7. <div class="manageTitle">设备维护</div>
  8. </div>
  9. </template>
  10. </Minheader>
  11. <div class="app-containers">
  12. <DataTable :tableHeader="tableCols" :tableData="tableData" :tableBtnGroup="tableBtnGroup" :tableProperty="{ rowKey: 'ID' }" @btnClick="btnClick" />
  13. </div>
  14. <Dialog :flag="flag" :type="type" :msgTitle="msgTitle" :delName="tableForm.deviceName" @resetForm="resetForm" @delRest="delRest" @submitForm="submitForm" @delRemove="delRemove">
  15. <div class="diacont">
  16. <el-form :model="tableForm" :rules="formRules" ref="equipmentMaintenanceForm">
  17. <el-row :gutter="24">
  18. <el-col>
  19. <el-form-item label="设备ID" size="default" prop="deviceID" :rules="formRules.isNotNull">
  20. <el-input v-model="tableForm.deviceID" placeholder="请输入设备ID" />
  21. </el-form-item>
  22. </el-col>
  23. <el-col>
  24. <el-form-item label="设备名称" size="default" prop="deviceName" :rules="formRules.isNotNull">
  25. <el-input v-model="tableForm.deviceName" placeholder="请输入设备名称" />
  26. </el-form-item>
  27. </el-col>
  28. <el-col>
  29. <el-form-item label="设备类型" size="default" :rules="formRules.isNotNull" prop="deviceType">
  30. <el-input v-model="tableForm.deviceType" placeholder="请输入设备类型" />
  31. </el-form-item>
  32. </el-col>
  33. <el-col>
  34. <el-form-item label="设备位置" size="default" :rules="formRules.isNotNull" prop="location">
  35. <el-input v-model="tableForm.location" placeholder="请输入设备位置" />
  36. </el-form-item>
  37. </el-col>
  38. <el-col>
  39. <el-form-item label="设备编码" size="default" prop="deviceCode" :rules="formRules.isNotNull">
  40. <el-input v-model="tableForm.deviceCode" placeholder="请输入设备编码" />
  41. </el-form-item>
  42. </el-col>
  43. <el-col>
  44. <el-form-item label="IP" size="default" prop="deviceIP" :rules="formRules.isNotNull">
  45. <el-input type="textarea" v-model="tableForm.deviceIP" placeholder="请输入IP" />
  46. </el-form-item>
  47. </el-col>
  48. <el-col>
  49. <el-form-item label="备注" :rules="formRules.isNotNull" size="default">
  50. <el-input type="textarea" v-model="tableForm.remarks" placeholder="请输入备注" />
  51. </el-form-item>
  52. </el-col>
  53. </el-row>
  54. </el-form>
  55. </div>
  56. </Dialog>
  57. </div>
  58. </div>
  59. </template>
  60. <script setup lang="ts">
  61. import DataTable from "@/components/tableTemp/index.vue";
  62. import Minheader from "@/components/minheader/index.vue";
  63. import Dialog from "@/components/dialog/index.vue";
  64. import { Query, GeneralDataReception } from "@/api/webApi";
  65. import { ElMessage } from "element-plus";
  66. const formRules = useElement().formRules;
  67. const page = ref<number>(0); //分页参数
  68. const dataContent = ref<object>({});
  69. const noMore = ref<boolean>(false);
  70. const rowTitle = ref<string>("");
  71. const tableCols = ref<any>([]); //表头数据
  72. const serviceId = ref<any>("");
  73. const tableObj = ref({}); //增删改数据缓存
  74. const flag = ref<boolean>(false); //弹窗开关
  75. const type = ref<string>(""); //判断是否删除
  76. const msgTitle = ref<string>("新增设备维护"); //弹窗标题
  77. const tableColsCopys = reactive<Object>({}); //弹窗
  78. const tableForm = reactive<any>({
  79. deviceID: "",
  80. deviceName: "",
  81. deviceType: "",
  82. deviceIP: "",
  83. location: "",
  84. deviceCode: "",
  85. remarks: "",
  86. event: "",
  87. }); //弹窗内容
  88. //列表
  89. const tableData = ref<any>([]);
  90. //表头
  91. const state = reactive({
  92. list: [
  93. { label: "设备名称", key: "name" },
  94. { label: "所在位置", key: "china" },
  95. { label: "设备类型", key: "englin" },
  96. { label: "设备IP", key: "two" },
  97. { label: "在离线状态", key: "three" },
  98. { label: "忙碌空闲", key: "text" },
  99. ],
  100. listLoading: true,
  101. });
  102. const tableBtnGroup = ref([
  103. {
  104. name: "编辑",
  105. className: "editBtn",
  106. param: 2,
  107. is: "device_editing_button",
  108. },
  109. {
  110. name: "删除",
  111. className: "delBtn",
  112. param: 3,
  113. is: "device_deletion_button",
  114. },
  115. ]);
  116. //新增
  117. const addForm = () => {
  118. msgTitle.value = "新增设备维护";
  119. flag.value = true;
  120. type.value = "";
  121. for (const key in tableForm) {
  122. tableForm[key] = "";
  123. }
  124. tableForm.event = 1;
  125. };
  126. //取消
  127. const resetForm = () => {
  128. equipmentMaintenanceForm.value?.resetFields();
  129. flag.value = false;
  130. // tableForm.deviceID = "";
  131. // tableForm.deviceName = "";
  132. // tableForm.deviceType = "";
  133. // tableForm.deviceIP = "";
  134. // tableForm.deviceCode = "";
  135. // tableForm.remarks = "";
  136. };
  137. //编辑
  138. const editDialog = (data) => {
  139. msgTitle.value = "编辑设备维护";
  140. flag.value = true;
  141. type.value = "";
  142. tableForm.name = data.name;
  143. tableForm.englin = data.englin;
  144. tableForm.two = data.two;
  145. };
  146. //删除
  147. const eleDialog = () => {
  148. msgTitle.value = "删除设备维护";
  149. flag.value = true;
  150. type.value = "del";
  151. };
  152. const delRemove = () => {
  153. const obj = {
  154. deviceID: tableForm.deviceID,
  155. event: 3,
  156. };
  157. generalDataReception(obj);
  158. };
  159. //删除
  160. const delRest = () => {
  161. flag.value = false;
  162. };
  163. //编辑-删除
  164. const btnClick = (row, index, param) => {
  165. if (param === 2) {
  166. msgTitle.value = "编辑设备维护";
  167. flag.value = true;
  168. type.value = "";
  169. tableForm.event = 2;
  170. tableForm.deviceID = index.deviceID;
  171. tableForm.deviceName = index.deviceName;
  172. tableForm.deviceType = index.deviceType;
  173. tableForm.location = index.location;
  174. tableForm.deviceIP = index.deviceIP;
  175. tableForm.deviceCode = index.deviceCode;
  176. tableForm.remarks = index.remarks;
  177. } else if (param === 3) {
  178. msgTitle.value = "删除设备维护";
  179. flag.value = true;
  180. type.value = "del";
  181. tableForm.event = 3;
  182. tableForm.deviceID = index.deviceID;
  183. tableForm.deviceName = index.deviceName;
  184. tableForm.deviceType = index.deviceType;
  185. tableForm.location = index.location;
  186. tableForm.deviceIP = index.deviceIP;
  187. tableForm.deviceCode = index.deviceCode;
  188. tableForm.deviceCode = index.deviceCode;
  189. } else if (param === 4) {
  190. }
  191. };
  192. //获取表格数据
  193. const getQuery = async () => {
  194. try {
  195. const { code, returnData } = await Query({
  196. id: DATACONTENT_ID.equipmentNodeId,
  197. needPage: ++page.value,
  198. dataContent: Object.values(dataContent.value),
  199. });
  200. if (code === "0") {
  201. if (returnData.listValues.length === 0) {
  202. page.value--;
  203. noMore.value = true;
  204. }
  205. const titleColumn = returnData.columnSet.find(
  206. (item) => item.needShow === 1
  207. );
  208. if (titleColumn) {
  209. rowTitle.value = titleColumn.columnName;
  210. }
  211. tableData.value.push(...returnData.listValues);
  212. tableCols.value = returnData.columnSet;
  213. tableCols.value.forEach((element) => {
  214. element.label = element.columnLabel;
  215. element.key = element.columnName;
  216. // if (element.columnName === "queryTemplate") {
  217. // element.width = "300px";
  218. // }
  219. });
  220. serviceId.value = returnData.submitID;
  221. } else {
  222. page.value--;
  223. }
  224. } catch (error) {
  225. page.value--;
  226. }
  227. };
  228. //确认提交
  229. const equipmentMaintenanceForm: any = ref(null);
  230. const submitForm = () => {
  231. equipmentMaintenanceForm.value.validate((valid: any) => {
  232. if (valid) {
  233. generalDataReception(tableForm);
  234. } else {
  235. return false;
  236. }
  237. });
  238. };
  239. const resetTable = () => {
  240. page.value = 0;
  241. noMore.value = false;
  242. tableData.value = [];
  243. };
  244. const btnAuthMap = [
  245. ,
  246. "equipment_addition_button",
  247. "device_editing_button",
  248. "device_deletion_button",
  249. ];
  250. //新增-编辑-删除
  251. const generalDataReception = async (data) => {
  252. try {
  253. const { code } = await GeneralDataReception({
  254. serviceId: serviceId.value,
  255. dataContent: JSON.stringify(data),
  256. btnAuth: btnAuthMap[data.event],
  257. });
  258. if (code == 0) {
  259. ElMessage.success(`操作成功`);
  260. // this.$message.success("操作成功");
  261. resetTable();
  262. getQuery();
  263. resetForm();
  264. flag.value = false;
  265. // rmFlag.value = false;
  266. tableObj.value = {};
  267. // this.$router.go(0);
  268. } else {
  269. ElMessage.error(`操作失败`);
  270. // this.$message.error("操作失败");
  271. // this.flag = false;
  272. // this.rmFlag = false;
  273. tableObj.value = {};
  274. resetForm();
  275. }
  276. } catch (error) {
  277. flag.value = false;
  278. // rmFlag.value = false;
  279. tableObj.value = {};
  280. resetForm();
  281. }
  282. };
  283. getQuery();
  284. </script>
  285. <style lang="scss" scoped>
  286. ::v-deep .el-form-item__label {
  287. width: 80px;
  288. }
  289. </style>