index.vue 10 KB

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