index.vue 11 KB

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