view.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <el-container direction="vertical">
  3. <!-- <div style="margin:10px 0;">
  4. <el-input placeholder="ip" style="width:182px;margin-right:10px" v-model="ip"></el-input>
  5. <el-button type="primary" @click="onSearch">搜索</el-button>
  6. <el-button type="success" @click="addIp">新增</el-button>
  7. </div> -->
  8. <div style="margin-bottom:10px">
  9. <el-button type="primary" plain @click="add" size="small">添加ip</el-button>
  10. </div>
  11. <el-table :data="tableData" border style="width: 100%">
  12. <el-table-column align="center" type="index" width="50" label="序号" />
  13. <el-table-column align="center" prop="ip" label="IP"></el-table-column>
  14. <!-- <el-table-column align="center" prop="alias" label="状态">
  15. <el-tag type="info" disabled>禁用</el-tag>
  16. <el-tag type="success">已启用</el-tag>
  17. </el-table-column> -->
  18. <el-table-column align="center" label="操作">
  19. <template slot-scope="scope">
  20. <el-button type="danger" plain @click="del(scope.$index)" size="small">删除</el-button>
  21. <!-- <el-tag type="danger" @click="del(scope.$index)">删除</el-tag> -->
  22. </template>
  23. </el-table-column>
  24. </el-table>
  25. <!-- <el-row style="margin-top:10px;" type="flex" justify="end">
  26. <el-pagination background layout="prev, pager, next" :total="total" :page-size="pageSize" @current-change="onPageChange" :current-page="pageNumber"></el-pagination>
  27. </el-row> -->
  28. <!-- 添加ip弹层 -->
  29. <el-dialog title="添加ip白名单" :visible.sync="dialogFormVisible">
  30. <el-form :model="ipFormData" :rules="rules" ref="ipFormData" label-width="80px">
  31. <el-form-item label="ip" prop="name">
  32. <el-input v-model="ipFormData.name" autocomplete="off" style="width: 300px"></el-input>
  33. </el-form-item>
  34. <el-form-item >
  35. <el-button type="primary" @click="onSubmit('ipFormData')">确定</el-button>
  36. <el-button @click="dialogFormVisible = false">取消</el-button>
  37. </el-form-item>
  38. </el-form>
  39. </el-dialog>
  40. </el-container>
  41. </template>
  42. <script>
  43. // getIpList获取Ip列表 delIpList-删除 addIp-添加
  44. import {
  45. getIpList,
  46. delIpList,
  47. addIp
  48. } from "@/api";
  49. export default {
  50. name: 'pageView',
  51. data() {
  52. return {
  53. pageSize: 10,
  54. pageNumber: 1,
  55. // cabinetValue: "",
  56. // cabinetOptions: [],
  57. // boxOptions: [],
  58. // boxValue: "",
  59. tableData: [
  60. // {ip: 123},
  61. // {ip: 456},
  62. // {ip: 789},
  63. // {ip: 123},
  64. ],
  65. total: 0,
  66. // ip
  67. ip: null,
  68. // ip弹层
  69. dialogFormVisible: false,
  70. // 新增ip数据
  71. ipFormData: {
  72. name: ''
  73. },
  74. // 表单校验
  75. rules: {
  76. name: [
  77. { required: true, message: '请输入ip', trigger: 'blur' },
  78. { pattern: /((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)/, message:'请输入合法ip', trigger: 'blur' }
  79. ]
  80. },
  81. repeatIp: false
  82. };
  83. },
  84. created() {
  85. this.getIpList();
  86. },
  87. computed: {
  88. // disSearch() {
  89. // return this.boxValue != "" && this.cabinetValue == "";
  90. // },
  91. },
  92. methods: {
  93. // onChangeCabinet(value) {
  94. // if (value) {
  95. // // this.getBoxList();
  96. // }
  97. // console.log(value);
  98. // },
  99. // 获取Ip列表
  100. async getIpList() {
  101. const res = await getIpList()
  102. console.log('获取ip列表', res);
  103. this.tableData = res.datas
  104. },
  105. // 删除
  106. del(idx) {
  107. console.log('idx', idx);
  108. // 提示
  109. this.$confirm("确认删除该ip?", {
  110. confirmButtonText: "确定",
  111. cancelButtonText: "取消",
  112. type: "warning",
  113. })
  114. .then(async () => {
  115. // 调用删除接口
  116. const res = await delIpList({ip_key: idx})
  117. console.log('删除ip', res);
  118. if (res.code == 200) {
  119. // 提示
  120. this.$message({
  121. message: '删除成功',
  122. type: 'success'
  123. });
  124. // 获取列表
  125. this.getIpList()
  126. }
  127. })
  128. .catch(() => {
  129. return false;
  130. });
  131. },
  132. // 添加
  133. add() {
  134. this.ipFormData.name = ''
  135. this.$refs.ipFormData.resetFields()
  136. this.dialogFormVisible = true
  137. },
  138. // 确定添加
  139. onSubmit(formName) {
  140. this.$refs[formName].validate(async(valid) => {
  141. if (valid) {
  142. if (this.tableData.length > 0) {
  143. this.tableData.forEach(item => {
  144. this.repeatIp = item.ip == this.ipFormData.name
  145. })
  146. }
  147. if (this.repeatIp) {
  148. this.$message.error('该ip已存在')
  149. return
  150. }
  151. // console.log('校验通过');
  152. const res = await addIp(this.ipFormData.name)
  153. console.log('添加ip', res);
  154. if (res && res.code == 200) {
  155. this.$message({
  156. message: '添加成功',
  157. type: 'success'
  158. });
  159. this.getIpList()
  160. this.dialogFormVisible = false
  161. this.ipFormData.name = ''
  162. }
  163. }
  164. });
  165. }
  166. // 新增
  167. // addIp() {}
  168. // 分页
  169. // onPageChange(page) {
  170. // if (page == this.pageNumber) {
  171. // return;
  172. // } else {
  173. // this.pageNumber = page;
  174. // setTimeout(() => {
  175. // // this.getIpList();
  176. // }, 0);
  177. // }
  178. // },
  179. // 搜索
  180. // onSearch() {
  181. // this.pageNumber = 1;
  182. // setTimeout(() => {
  183. // this.getIpList();
  184. // }, 0);
  185. // },
  186. // getBoxList() {
  187. // boxList({
  188. // cabinet_number: this.cabinetValue
  189. // }).then((res) => {
  190. // if (res && res.msg == "ok") {
  191. // this.boxOptions = res.data.rows;
  192. // }
  193. // });
  194. // },
  195. // getBoxActionList() {
  196. // let box = this.boxValue ? this.boxValue : 0;
  197. // boxActionList({
  198. // cabinet_number: this.cabinetValue,
  199. // box_number: box,
  200. // pageSize: this.pageSize,
  201. // pageNumber: this.pageNumber,
  202. // }).then((res) => {
  203. // console.log(res);
  204. // if (res && res.msg == "ok") {
  205. // this.total = res.data.total;
  206. // this.tableData = res.data.rows;
  207. // }
  208. // });
  209. // }
  210. },
  211. };
  212. </script>
  213. <style scoped>
  214. </style>