index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <template>
  2. <div class="body">
  3. <!-- 头部区域 -->
  4. <div class="head">
  5. <div class="head-img">
  6. <img src="../../../public/images/img-1.png" />
  7. </div>
  8. <div class="head-info">设备管理</div>
  9. </div>
  10. <!-- 添加按钮区域 -->
  11. <div class="switch">
  12. <div class="switch-button">
  13. <el-row>
  14. <el-button
  15. type="primary"
  16. size="small"
  17. @click="handleCreate"
  18. ><img src="../../../public/images/img-3.png" />添加
  19. </el-button>
  20. </el-row>
  21. </div>
  22. </div>
  23. <!-- 表格区域 -->
  24. <div class="form">
  25. <el-table :data="list">
  26. <el-table-column
  27. label="序列号"
  28. align="center"
  29. prop="serialNumber"
  30. >
  31. </el-table-column>
  32. <el-table-column
  33. label="名称"
  34. width="300px"
  35. align="center"
  36. prop="name"
  37. >
  38. </el-table-column>
  39. <el-table-column
  40. label="厂家"
  41. align="center"
  42. prop="manufacturer"
  43. >
  44. </el-table-column>
  45. <el-table-column
  46. label="型号"
  47. align="center"
  48. prop="model"
  49. >
  50. </el-table-column>
  51. <el-table-column
  52. label="IP地址"
  53. align="center"
  54. prop="ipAddress"
  55. >
  56. </el-table-column>
  57. <el-table-column
  58. label="开关"
  59. align="center"
  60. >
  61. <template slot-scope="{ row }">
  62. <el-switch
  63. v-model="row.status"
  64. active-color="#3BAAFD"
  65. inactive-color="#CCCCCC"
  66. :active-value="1"
  67. :inactive-value="0"
  68. disabled
  69. @click.native="changeSwitch(row)"
  70. >
  71. </el-switch>
  72. </template>
  73. </el-table-column>
  74. <el-table-column
  75. label="操作"
  76. width="180px"
  77. align="center"
  78. >
  79. <template slot-scope="{ row, $index }">
  80. <el-button
  81. type="text"
  82. size="small"
  83. @click="handleUpdate(row)"
  84. >编辑</el-button>
  85. <el-button
  86. type="text"
  87. size="small"
  88. class="button"
  89. @click="handleDelete(row)"
  90. ><img src="../../../public/images/img-2.png" />删除</el-button>
  91. </template>
  92. </el-table-column>
  93. </el-table>
  94. <!-- 底部分页区 -->
  95. <div class="block">
  96. <template>
  97. <pagination
  98. :total="total"
  99. :page.sync="listQuery.page"
  100. :limit.sync="listQuery.limit"
  101. @pagination="getList"
  102. />
  103. </template>
  104. </div>
  105. </div>
  106. <!-- 添加编辑弹窗区域 -->
  107. <el-dialog
  108. :title="textMap[dialogStatus]"
  109. :visible.sync="dialogVisible"
  110. width="30%"
  111. center
  112. >
  113. <el-form
  114. ref="dataForm"
  115. :model="temp"
  116. :rules="rules"
  117. >
  118. <el-form-item
  119. style="white-space: pre"
  120. label="序列号:"
  121. class="switch-button-item"
  122. prop="serialNumber"
  123. >
  124. <el-col :span="12">
  125. <el-input
  126. v-model="temp.serialNumber"
  127. autocomplete="off"
  128. placeholder="请输入序列号"
  129. ></el-input>
  130. </el-col>
  131. </el-form-item>
  132. <el-form-item
  133. style="white-space: pre"
  134. label="名 称:"
  135. class="switch-button-item"
  136. prop="name"
  137. >
  138. <el-col :span="12">
  139. <el-input
  140. v-model="temp.name"
  141. autocomplete="off"
  142. placeholder="请输入名称"
  143. ></el-input>
  144. </el-col>
  145. </el-form-item>
  146. <el-form-item
  147. style="white-space: pre"
  148. label="厂 家:"
  149. class="switch-button-item"
  150. prop="manufacturer"
  151. >
  152. <el-col :span="12">
  153. <el-input
  154. v-model="temp.manufacturer"
  155. autocomplete="off"
  156. placeholder="请输入厂家"
  157. ></el-input>
  158. </el-col>
  159. </el-form-item>
  160. <el-form-item
  161. style="white-space: pre"
  162. label="型 号:"
  163. class="switch-button-item"
  164. prop="model"
  165. >
  166. <el-col :span="12">
  167. <el-input
  168. v-model="temp.model"
  169. autocomplete="off"
  170. placeholder="请输入型号"
  171. ></el-input>
  172. </el-col>
  173. </el-form-item>
  174. <el-form-item
  175. style="white-space: pre"
  176. label="IP 地 址:"
  177. class="switch-button-item"
  178. prop="ipAddress"
  179. >
  180. <el-col :span="12">
  181. <el-input
  182. v-model="temp.ipAddress"
  183. autocomplete="off"
  184. placeholder="请输入IP地址"
  185. ></el-input>
  186. </el-col>
  187. </el-form-item>
  188. </el-form>
  189. <span slot="footer">
  190. <el-button
  191. type="primary"
  192. @click="dialogStatus === 'create' ? createData() : updateData()"
  193. >确 定</el-button>
  194. <el-button @click="dialogVisible = false">取 消</el-button>
  195. </span>
  196. </el-dialog>
  197. </div>
  198. </template>
  199. <script>
  200. import Pagination from "@/components/Pagination";
  201. import {
  202. fetchList,
  203. createDevice,
  204. updateDevice,
  205. deletDevice,
  206. } from "@/api/devicemanagement";
  207. export default {
  208. components: {
  209. Pagination,
  210. },
  211. data() {
  212. return {
  213. list: [],
  214. total: 0, //数据的总数//
  215. listQuery: {
  216. page: 1, //当前在第几页//
  217. limit: 8, //一页几条//
  218. },
  219. dialogVisible: false,
  220. dialogStatus: "",
  221. textMap: {
  222. update: "编辑门禁设备",
  223. create: "添加门禁设备",
  224. },
  225. temp: {
  226. id: "",
  227. serialNumber: "",
  228. name: "",
  229. manufacturer: "",
  230. model: "",
  231. ipAddress: "",
  232. status: "1",
  233. },
  234. rules: {
  235. serialNumber: [
  236. {
  237. required: true,
  238. message: "请输入序列号",
  239. trigger: "change",
  240. },
  241. ],
  242. name: [
  243. {
  244. required: true,
  245. message: "请输入名称",
  246. trigger: "change",
  247. },
  248. ],
  249. },
  250. };
  251. },
  252. created() {
  253. this.getList();
  254. },
  255. methods: {
  256. // 获取列表数据
  257. getList() {
  258. fetchList(this.listQuery).then((response) => {
  259. console.log(response);
  260. this.list = response.data;
  261. this.total = response.total;
  262. });
  263. },
  264. // 重置表单为空
  265. resetTemp() {
  266. this.temp = {
  267. id: undefined,
  268. serialNumber: "",
  269. name: "",
  270. manufacturer: "",
  271. model: "",
  272. ipAddress: "",
  273. status: "1",
  274. };
  275. },
  276. // 添加按钮回调
  277. handleCreate() {
  278. this.resetTemp();
  279. this.dialogStatus = "create";
  280. this.dialogVisible = true;
  281. this.$nextTick(() => {
  282. this.$refs["dataForm"].clearValidate();
  283. });
  284. },
  285. // 编辑按钮回调
  286. handleUpdate(row) {
  287. this.temp = Object.assign({}, row); // copy obj
  288. this.dialogStatus = "update";
  289. this.dialogVisible = true;
  290. this.$nextTick(() => {
  291. this.$refs["dataForm"].clearValidate();
  292. });
  293. },
  294. // 删除按钮回调
  295. handleDelete(row) {
  296. this.$confirm(`此操作将永久删除 ${row.name}, 是否继续?`, "提示", {
  297. confirmButtonText: "确定",
  298. cancelButtonText: "取消",
  299. type: "warning",
  300. })
  301. .then(() => {
  302. deletDevice({ id: row.id }).then(() => {
  303. this.getList();
  304. this.$notify({
  305. title: "删除成功",
  306. type: "success",
  307. duration: 2000,
  308. });
  309. });
  310. })
  311. .catch(() => {
  312. this.$message.info("已取消删除");
  313. });
  314. },
  315. // 添加设备请求
  316. createData() {
  317. this.$refs["dataForm"].validate((valid) => {
  318. if (valid) {
  319. createDevice(this.temp).then(() => {
  320. this.dialogVisible = false;
  321. this.$notify({
  322. title: "添加成功",
  323. type: "success",
  324. duration: 1500,
  325. });
  326. this.getList();
  327. });
  328. }
  329. });
  330. },
  331. // 编辑设备请求
  332. updateData() {
  333. this.$refs["dataForm"].validate((valid) => {
  334. if (valid) {
  335. const tempData = Object.assign({}, this.temp);
  336. updateDevice(tempData).then(() => {
  337. this.dialogVisible = false;
  338. this.getList();
  339. this.$notify({
  340. title: "编辑成功",
  341. type: "success",
  342. duration: 1500,
  343. });
  344. });
  345. }
  346. });
  347. },
  348. // 更换开关状态
  349. changeSwitch(row) {
  350. // console.log(row);
  351. this.temp = Object.assign({}, row);
  352. if (this.temp.status == 0) {
  353. if (confirm("确定开启设备吗?")) {
  354. updateDevice({ id: this.temp.id, status: 1 }).then(() => {
  355. this.getList();
  356. });
  357. this.$notify({
  358. title: "开启成功",
  359. type: "success",
  360. duration: 1500,
  361. });
  362. }
  363. } else {
  364. if (confirm("确定关闭设备吗?")) {
  365. updateDevice({ id: this.temp.id, status: 0 }).then(() => {
  366. this.getList();
  367. });
  368. this.$notify({
  369. title: "关闭成功",
  370. type: "success",
  371. duration: 1500,
  372. });
  373. }
  374. }
  375. },
  376. },
  377. };
  378. </script>
  379. <style lang="scss" scoped>
  380. .body {
  381. width: 1551px;
  382. margin: 29px 29px 0 31px;
  383. .head {
  384. display: flex;
  385. width: 1380px;
  386. height: 55px;
  387. margin-left: 40px;
  388. border-bottom: 1px solid #cccccc;
  389. .head-img {
  390. width: 30px;
  391. height: 30px;
  392. img {
  393. width: 30px;
  394. }
  395. }
  396. .head-info {
  397. width: 95px;
  398. height: 22px;
  399. margin-top: 5px;
  400. margin-left: 16px;
  401. font-weight: bold;
  402. }
  403. }
  404. .switch {
  405. display: flex;
  406. width: 1380px;
  407. line-height: 58px;
  408. margin-left: 40px;
  409. font-size: 9px;
  410. .switch-button {
  411. width: 50px;
  412. img {
  413. width: 10.5px;
  414. margin-right: 8px;
  415. }
  416. }
  417. }
  418. .form {
  419. margin-left: 40px;
  420. width: 1380px;
  421. .el-switch.is-disabled {
  422. opacity: 1;
  423. ::v-deep .el-switch__core {
  424. cursor: pointer;
  425. }
  426. }
  427. .button {
  428. color: red;
  429. }
  430. img {
  431. width: 8.5px;
  432. margin-right: 8px;
  433. }
  434. .block {
  435. float: right;
  436. }
  437. }
  438. .switch-button-item {
  439. margin-left: 120px;
  440. margin-top: 32px;
  441. }
  442. }
  443. </style>