view.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <el-container direction="vertical">
  3. <!-- <div style="margin-bottom:10px">
  4. <el-button type="primary" plain @click="add" size="small">添加ip</el-button>
  5. </div>
  6. <el-table :data="ipList" border style="width: 100%">
  7. <el-table-column align="center" type="index" width="50" label="序号" />
  8. <el-table-column align="center" prop="ip" label="IP"></el-table-column>
  9. <el-table-column align="center" label="操作">
  10. <template slot-scope="scope">
  11. <el-button type="danger" plain @click="del(scope.$index)" size="small">删除</el-button>
  12. <el-tag type="danger" @click="del(scope.$index)">删除</el-tag>
  13. </template>
  14. </el-table-column>
  15. </el-table> -->
  16. <el-form label-width="120px">
  17. <el-form-item label="商户号:">
  18. {{merchantsCode}}
  19. </el-form-item>
  20. <el-form-item label="商户名称:">
  21. {{merchantsName}}
  22. </el-form-item>
  23. <el-form-item label="余额预警:">
  24. {{alarm_amount}}
  25. </el-form-item>
  26. <el-form-item label="密钥设置:">
  27. <el-input v-model="securityKey" autocomplete="off" style="width: 300px;margin-right:10px"></el-input>
  28. <el-button type="primary" size="small" @click="updateKey">确定</el-button>
  29. </el-form-item>
  30. <el-form-item label="ip白名单:" >
  31. <div v-for="(item, idx) in ipList" :key="item">
  32. <el-input style="width: 300px;margin-bottom: 10px;margin-right: 10px;" :value="item"></el-input>
  33. <i v-if="idx == 0" class="el-icon-circle-plus-outline" style="color:#409EFF;" @click="add"></i>
  34. <i v-else class="el-icon-remove-outline" style="color:#F56C6C;" @click="del(item)"></i>
  35. </div>
  36. </el-form-item>
  37. </el-form>
  38. <!-- 添加ip弹层 -->
  39. <el-dialog title="添加ip白名单" :visible="dialogFormVisible" @close="btnCancle">
  40. <el-form :model="ipFormData" :rules="rules" ref="ipFormData" label-width="80px">
  41. <el-form-item label="ip" prop="name">
  42. <el-input v-model="ipFormData.name" autocomplete="off" style="width: 300px"></el-input>
  43. </el-form-item>
  44. </el-form>
  45. <span slot="footer" class="dialog-footer">
  46. <el-button @click="btnCancle">取 消</el-button>
  47. <el-button type="primary" @click="onSubmit('ipFormData')">确 定</el-button>
  48. </span>
  49. </el-dialog>
  50. </el-container>
  51. </template>
  52. <script>
  53. // getIpList获取Ip列表 delIpList-删除 addIp-添加 getUserInfo-用户信息
  54. import {
  55. // getIpList,
  56. delIpList,
  57. addIp,
  58. getUserInfo,
  59. updateKey
  60. } from "@/api";
  61. export default {
  62. name: 'pageView',
  63. data() {
  64. return {
  65. pageSize: 10,
  66. pageNumber: 1,
  67. ipList: [],
  68. total: 0,
  69. // ip
  70. ip: null,
  71. // ip弹层
  72. dialogFormVisible: false,
  73. // 新增ip数据
  74. ipFormData: {
  75. name: ''
  76. },
  77. // 表单校验
  78. rules: {
  79. name: [
  80. { required: true, message: '请输入ip', trigger: 'blur' },
  81. { 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' }
  82. ]
  83. },
  84. repeatIp: false,
  85. // 商户号
  86. merchantsCode: '',
  87. // 商户名称
  88. merchantsName: '',
  89. // 余额预警
  90. alarm_amount: '',
  91. // 密钥
  92. securityKey: ''
  93. };
  94. },
  95. created() {
  96. // this.getIpList();
  97. this.getUserInfo()
  98. },
  99. computed: {
  100. },
  101. methods: {
  102. // 获取Ip列表
  103. // async getIpList() {
  104. // const res = await getIpList()
  105. // console.log('获取ip列表', res);
  106. // this.ipList = res.datas
  107. // },
  108. // 删除
  109. del(ip) {
  110. console.log('ip', ip);
  111. // 提示
  112. this.$confirm("确认删除该ip?", {
  113. confirmButtonText: "确定",
  114. cancelButtonText: "取消",
  115. type: "warning",
  116. })
  117. .then(async () => {
  118. // 调用删除接口
  119. const res = await delIpList({ip: ip})
  120. console.log('删除ip', res);
  121. if (res && res.code == 200) {
  122. // 提示
  123. this.$message({
  124. message: '删除成功',
  125. type: 'success'
  126. });
  127. // 获取列表
  128. this.getUserInfo()
  129. }
  130. })
  131. .catch(() => {
  132. return false;
  133. });
  134. },
  135. // 添加
  136. add() {
  137. this.ipFormData.name = ''
  138. this.dialogFormVisible = true
  139. },
  140. // 关闭弹层
  141. btnCancle() {
  142. this.dialogFormVisible = false
  143. this.$refs.ipFormData.resetFields()
  144. },
  145. // 确定添加
  146. onSubmit(formName) {
  147. this.$refs[formName].validate(async(valid) => {
  148. if (valid) {
  149. console.log(valid);
  150. if (this.ipList.length > 0) {
  151. this.ipList.forEach(item => {
  152. this.repeatIp = item.ip == this.ipFormData.name
  153. })
  154. this.repeatIp = this.ipList.find((item => item == this.ipFormData.name))
  155. }
  156. if (this.repeatIp) {
  157. this.$message.error('该ip已存在')
  158. return
  159. }
  160. // console.log('校验通过');
  161. const res = await addIp(this.ipFormData.name)
  162. console.log('添加ip', res);
  163. if (res && res.code == 200) {
  164. this.$message({
  165. message: '添加成功',
  166. type: 'success'
  167. });
  168. this.getUserInfo()
  169. this.dialogFormVisible = false
  170. this.ipFormData.name = ''
  171. }
  172. }
  173. });
  174. },
  175. // 获取商户号
  176. async getUserInfo() {
  177. const res = await getUserInfo()
  178. console.log('个人中心', res);
  179. this.merchantsCode = res.datas.mchid
  180. this.merchantsName = res.datas.name
  181. this.ipList = res.datas.ips
  182. this.alarm_amount = res.datas.alarm_amount
  183. },
  184. // 设置密钥
  185. async updateKey() {
  186. const res = await updateKey(this.securityKey)
  187. console.log('密钥', res);
  188. if (res && res.code == 200) {
  189. this.$message.success('设置密钥成功')
  190. }
  191. }
  192. // 新增
  193. // addIp() {}
  194. // 分页
  195. // onPageChange(page) {
  196. // if (page == this.pageNumber) {
  197. // return;
  198. // } else {
  199. // this.pageNumber = page;
  200. // setTimeout(() => {
  201. // // this.getIpList();
  202. // }, 0);
  203. // }
  204. // },
  205. // 搜索
  206. // onSearch() {
  207. // this.pageNumber = 1;
  208. // setTimeout(() => {
  209. // this.getIpList();
  210. // }, 0);
  211. // },
  212. // getBoxList() {
  213. // boxList({
  214. // cabinet_number: this.cabinetValue
  215. // }).then((res) => {
  216. // if (res && res.msg == "ok") {
  217. // this.boxOptions = res.data.rows;
  218. // }
  219. // });
  220. // },
  221. // getBoxActionList() {
  222. // let box = this.boxValue ? this.boxValue : 0;
  223. // boxActionList({
  224. // cabinet_number: this.cabinetValue,
  225. // box_number: box,
  226. // pageSize: this.pageSize,
  227. // pageNumber: this.pageNumber,
  228. // }).then((res) => {
  229. // console.log(res);
  230. // if (res && res.msg == "ok") {
  231. // this.total = res.data.total;
  232. // this.ipList = res.data.rows;
  233. // }
  234. // });
  235. // }
  236. },
  237. };
  238. </script>
  239. <style scoped>
  240. .dialog-footer {
  241. display: block;
  242. text-align: center;
  243. }
  244. .dialog-footer .el-button {
  245. margin: 0 30px;
  246. }
  247. .el-icon-circle-plus-outline,
  248. .el-icon-remove-outline {
  249. font-size: 25px;
  250. vertical-align: middle;
  251. }
  252. </style>