view.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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" :model="formKey" :rules="ruleKey">
  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="密钥设置:" :prop="isKey == '1' ? 'ReSecurityKey' : 'securityKey'">
  27. <el-input v-if="isKey == '1'" v-model="formKey.ReSecurityKey" autocomplete="off" style="width: 300px;margin-right:10px"></el-input>
  28. <el-input v-else v-model="formKey.securityKey" autocomplete="off" style="width: 300px;margin-right:10px"></el-input>
  29. <el-button type="primary" size="small" @click="updateKey">{{isKey == '1' ? '重设' : '设置'}}</el-button>
  30. <el-alert
  31. title="请输入数字,字母或者两者结合的字符作为密钥。用于接口对接时生成签名"
  32. type="info"
  33. show-icon
  34. style="width:880px;margin-top:5px"
  35. :closable="false">
  36. </el-alert>
  37. </el-form-item>
  38. <el-form-item label="ip白名单:" >
  39. <div v-if="cIpList">
  40. <el-input style="width: 300px;margin-bottom: 10px;margin-right: 10px;" :value="ipFormData.name"></el-input>
  41. <i class="el-icon-circle-plus-outline" style="color:#409EFF;" @click="add"></i>
  42. </div>
  43. <template v-else>
  44. <div v-for="(item, idx) in ipList" :key="item">
  45. <el-input style="width: 300px;margin-bottom: 10px;margin-right: 10px;" :value="item"></el-input>
  46. <template v-if="idx == 0">
  47. <i class="el-icon-circle-plus-outline" style="color:#409EFF;" @click="add"></i>
  48. <i class="el-icon-remove-outline" style="color:#F56C6C;margin-left:10px" @click="del(item)"></i>
  49. </template>
  50. <!-- <i v-if="idx == 0" class="el-icon-circle-plus-outline" style="color:#409EFF;" @click="add"></i> -->
  51. <i v-else class="el-icon-remove-outline" style="color:#F56C6C;" @click="del(item)"></i>
  52. </div>
  53. </template>
  54. </el-form-item>
  55. </el-form>
  56. <!-- 添加ip弹层 -->
  57. <el-dialog title="添加ip白名单" :visible="dialogFormVisible" @close="btnCancle">
  58. <el-form :model="ipFormData" :rules="rules" ref="ipFormData" label-width="80px">
  59. <el-form-item label="ip" prop="name">
  60. <el-input v-model="ipFormData.name" autocomplete="off" style="width: 300px"></el-input>
  61. </el-form-item>
  62. </el-form>
  63. <span slot="footer" class="dialog-footer">
  64. <el-button @click="btnCancle">取 消</el-button>
  65. <el-button type="primary" @click="onSubmit('ipFormData')">确 定</el-button>
  66. </span>
  67. </el-dialog>
  68. </el-container>
  69. </template>
  70. <script>
  71. // getIpList获取Ip列表 delIpList-删除 addIp-添加 getUserInfo-用户信息
  72. import {
  73. // getIpList,
  74. delIpList,
  75. addIp,
  76. getUserInfo,
  77. updateKey
  78. } from "@/api";
  79. export default {
  80. name: 'pageView',
  81. data() {
  82. return {
  83. pageSize: 10,
  84. pageNumber: 1,
  85. ipList: [],
  86. total: 0,
  87. // ip
  88. ip: null,
  89. // ip弹层
  90. dialogFormVisible: false,
  91. // 新增ip数据
  92. ipFormData: {
  93. name: ''
  94. },
  95. // 表单校验
  96. rules: {
  97. name: [
  98. { required: true, message: '请输入ip', trigger: 'blur' },
  99. { 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' }
  100. ]
  101. },
  102. repeatIp: false,
  103. // 商户号
  104. merchantsCode: '',
  105. // 商户名称
  106. merchantsName: '',
  107. // 余额预警
  108. alarm_amount: '',
  109. // 密钥
  110. // securityKey: '',
  111. // 密钥校验,只能是数字和字母
  112. formKey: {
  113. securityKey: '',
  114. ReSecurityKey: ''
  115. },
  116. ruleKey: {
  117. securityKey: [
  118. { required: true, message: '请输入密钥', trigger: 'blur' },
  119. { pattern: /^[A-Za-z0-9]{1,30}$/, message:'请输入合法密钥,字母或者数字或者两者结合,字数在30个以内', trigger: 'blur' }
  120. ],
  121. // 之前设置过密钥
  122. ReSecurityKey: [
  123. { pattern: /^[A-Za-z0-9]{1,30}$/, message:'请输入合法密钥,字母或者数字或者两个结合,字数在30个以内', trigger: 'blur' }
  124. ]
  125. },
  126. // 是否设置过密钥 1-设置过
  127. isKey: ''
  128. };
  129. },
  130. created() {
  131. // this.getIpList();
  132. this.getUserInfo()
  133. },
  134. computed: {
  135. cIpList() {
  136. return this.ipList < 1
  137. }
  138. },
  139. methods: {
  140. // 获取Ip列表
  141. // async getIpList() {
  142. // const res = await getIpList()
  143. // console.log('获取ip列表', res);
  144. // this.ipList = res.datas
  145. // },
  146. // 删除
  147. del(ip) {
  148. console.log('ip', ip);
  149. // 提示
  150. this.$confirm("确认删除该ip?", {
  151. confirmButtonText: "确定",
  152. cancelButtonText: "取消",
  153. type: "warning",
  154. })
  155. .then(async () => {
  156. // 调用删除接口
  157. const res = await delIpList({ip: ip})
  158. console.log('删除ip', res);
  159. if (res && res.code == 200) {
  160. // 提示
  161. this.$message({
  162. message: '删除成功',
  163. type: 'success'
  164. });
  165. // 获取列表
  166. this.getUserInfo()
  167. }
  168. })
  169. .catch(() => {
  170. return false;
  171. });
  172. },
  173. // 添加
  174. add() {
  175. this.ipFormData.name = ''
  176. this.dialogFormVisible = true
  177. },
  178. // 关闭弹层
  179. btnCancle() {
  180. this.dialogFormVisible = false
  181. this.$refs.ipFormData.resetFields()
  182. },
  183. // 确定添加
  184. onSubmit(formName) {
  185. this.$refs[formName].validate(async(valid) => {
  186. if (valid) {
  187. console.log(valid);
  188. if (this.ipList.length > 0) {
  189. this.ipList.forEach(item => {
  190. this.repeatIp = item.ip == this.ipFormData.name
  191. })
  192. this.repeatIp = this.ipList.find((item => item == this.ipFormData.name))
  193. }
  194. if (this.repeatIp) {
  195. this.$message.error('该ip已存在')
  196. return
  197. }
  198. // console.log('校验通过');
  199. const res = await addIp(this.ipFormData.name)
  200. console.log('添加ip', res);
  201. if (res && res.code == 200) {
  202. this.$message({
  203. message: '添加成功',
  204. type: 'success'
  205. });
  206. this.getUserInfo()
  207. this.dialogFormVisible = false
  208. this.ipFormData.name = ''
  209. }
  210. }
  211. });
  212. },
  213. // 获取商户号
  214. async getUserInfo() {
  215. const res = await getUserInfo()
  216. console.log('个人中心', res);
  217. if (res && res.code == 200) {
  218. this.merchantsCode = res.datas.mchid
  219. this.merchantsName = res.datas.name
  220. this.ipList = res.datas.ips
  221. this.alarm_amount = res.datas.alarm_amount
  222. this.isKey = res.datas.is_key
  223. }
  224. },
  225. // 设置密钥
  226. async updateKey() {
  227. const res = await updateKey(this.formKey.securityKey)
  228. console.log('密钥', res);
  229. if (res && res.code == 200) {
  230. this.$message.success('设置密钥成功')
  231. }
  232. }
  233. // 新增
  234. // addIp() {}
  235. // 分页
  236. // onPageChange(page) {
  237. // if (page == this.pageNumber) {
  238. // return;
  239. // } else {
  240. // this.pageNumber = page;
  241. // setTimeout(() => {
  242. // // this.getIpList();
  243. // }, 0);
  244. // }
  245. // },
  246. // 搜索
  247. // onSearch() {
  248. // this.pageNumber = 1;
  249. // setTimeout(() => {
  250. // this.getIpList();
  251. // }, 0);
  252. // },
  253. // getBoxList() {
  254. // boxList({
  255. // cabinet_number: this.cabinetValue
  256. // }).then((res) => {
  257. // if (res && res.msg == "ok") {
  258. // this.boxOptions = res.data.rows;
  259. // }
  260. // });
  261. // },
  262. // getBoxActionList() {
  263. // let box = this.boxValue ? this.boxValue : 0;
  264. // boxActionList({
  265. // cabinet_number: this.cabinetValue,
  266. // box_number: box,
  267. // pageSize: this.pageSize,
  268. // pageNumber: this.pageNumber,
  269. // }).then((res) => {
  270. // console.log(res);
  271. // if (res && res.msg == "ok") {
  272. // this.total = res.data.total;
  273. // this.ipList = res.data.rows;
  274. // }
  275. // });
  276. // }
  277. },
  278. };
  279. </script>
  280. <style scoped>
  281. .dialog-footer {
  282. display: block;
  283. text-align: center;
  284. }
  285. .dialog-footer .el-button {
  286. margin: 0 30px;
  287. }
  288. .el-icon-circle-plus-outline,
  289. .el-icon-remove-outline {
  290. font-size: 25px;
  291. vertical-align: middle;
  292. }
  293. .el-alert {
  294. padding: 0px 10px;
  295. }
  296. </style>