xcAccountParam.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div class="form-wrap">
  3. <div class="searchBox">
  4. <div class="btn-wrap">
  5. <el-button
  6. type="primary"
  7. @click="showDialog('add')">新增账号</el-button>
  8. </div>
  9. </div>
  10. <div class="tableBox">
  11. <el-table
  12. v-loading="loading"
  13. row-class-name="is-center"
  14. :data="tableData">
  15. <el-table-column
  16. prop="createTime"
  17. label="创建时间"
  18. width="180">
  19. </el-table-column>
  20. <el-table-column
  21. prop="updateTime"
  22. label="更新时间"
  23. width="180">
  24. </el-table-column>
  25. <el-table-column
  26. prop="accountId"
  27. label="接口帐号"
  28. min-width="160">
  29. </el-table-column>
  30. <el-table-column
  31. prop="secretKey"
  32. label="接口密钥"
  33. min-width="200"
  34. show-overflow-tooltip>
  35. </el-table-column>
  36. <el-table-column
  37. prop="aesKey"
  38. label="AES 加密密钥"
  39. min-width="200"
  40. show-overflow-tooltip>
  41. </el-table-column>
  42. <el-table-column
  43. prop="aesVector"
  44. label="AES 加密初始向量"
  45. min-width="200"
  46. show-overflow-tooltip>
  47. </el-table-column>
  48. <el-table-column
  49. fixed="right"
  50. label="操作"
  51. width="160">
  52. <template slot-scope="scope">
  53. <el-button
  54. type="text"
  55. @click="showDialog('edit', scope.row)">编辑</el-button>
  56. <el-button
  57. type="text"
  58. @click="handleDelete(scope.row)">删除</el-button>
  59. </template>
  60. </el-table-column>
  61. </el-table>
  62. </div>
  63. <!-- 新增/编辑弹框 -->
  64. <el-dialog
  65. :title="dialogType === 'add' ? '新增账号' : '编辑账号'"
  66. :visible.sync="dialogVisible"
  67. width="600px">
  68. <el-form
  69. ref="accountForm"
  70. :model="accountForm"
  71. label-width="130px">
  72. <el-form-item
  73. label="接口帐号"
  74. prop="accountId"
  75. :rules="[{ required: true, message: '请输入接口帐号', trigger: 'blur' }]">
  76. <el-input
  77. v-model="accountForm.accountId"
  78. placeholder="请输入接口帐号"></el-input>
  79. </el-form-item>
  80. <el-form-item
  81. label="接口密钥"
  82. prop="secretKey"
  83. :rules="[{ required: true, message: '请输入接口密钥', trigger: 'blur' }]">
  84. <el-input
  85. v-model="accountForm.secretKey"
  86. placeholder="请输入接口密钥"></el-input>
  87. </el-form-item>
  88. <el-form-item
  89. label="AES 加密密钥"
  90. prop="aesKey"
  91. :rules="[{ required: true, message: '请输入AES 加密密钥', trigger: 'blur' }]">
  92. <el-input
  93. v-model="accountForm.aesKey"
  94. placeholder="请输入AES 加密密钥"></el-input>
  95. </el-form-item>
  96. <el-form-item
  97. label="AES 加密初始向量"
  98. prop="aesVector"
  99. :rules="[{ required: true, message: '请输入AES 加密初始向量', trigger: 'blur' }]">
  100. <el-input
  101. v-model="accountForm.aesVector"
  102. placeholder="请输入AES 加密初始向量"></el-input>
  103. </el-form-item>
  104. </el-form>
  105. <div slot="footer">
  106. <el-button @click="dialogVisible = false">取 消</el-button>
  107. <el-button
  108. type="primary"
  109. :loading="submitLoading"
  110. @click="handleSubmit">确 定</el-button>
  111. </div>
  112. </el-dialog>
  113. </div>
  114. </template>
  115. <script>
  116. import { getXcAccountList, addXcAccount, updateXcAccount, deleteXcAccount } from '@/api/platform'
  117. export default {
  118. name: 'XcAccountParam',
  119. data () {
  120. return {
  121. loading: false,
  122. submitLoading: false,
  123. tableData: [],
  124. dialogVisible: false,
  125. dialogType: 'add',
  126. accountForm: {
  127. id: '',
  128. accountId: '',
  129. secretKey: '',
  130. aesKey: '',
  131. aesVector: ''
  132. }
  133. }
  134. },
  135. created () {
  136. this.getList()
  137. },
  138. methods: {
  139. getList () {
  140. this.loading = true
  141. getXcAccountList().then(res => {
  142. this.loading = false
  143. this.tableData = res.data || []
  144. }).catch(() => {
  145. this.loading = false
  146. })
  147. },
  148. showDialog (type, row) {
  149. this.dialogType = type
  150. if (type === 'edit' && row) {
  151. this.accountForm = {
  152. id: row.id,
  153. accountId: row.accountId,
  154. secretKey: row.secretKey,
  155. aesKey: row.aesKey,
  156. aesVector: row.aesVector
  157. }
  158. } else {
  159. this.accountForm = {
  160. id: '',
  161. accountId: '',
  162. secretKey: '',
  163. aesKey: '',
  164. aesVector: ''
  165. }
  166. }
  167. this.dialogVisible = true
  168. this.$nextTick(() => {
  169. this.$refs.accountForm && this.$refs.accountForm.clearValidate()
  170. })
  171. },
  172. handleSubmit () {
  173. this.$refs.accountForm.validate(valid => {
  174. if (!valid) return
  175. this.submitLoading = true
  176. const api = this.dialogType === 'add' ? addXcAccount : updateXcAccount
  177. const params = { ...this.accountForm }
  178. if (this.dialogType === 'add') {
  179. delete params.id
  180. }
  181. api(params).then(() => {
  182. this.submitLoading = false
  183. this.dialogVisible = false
  184. this.$message.success(this.dialogType === 'add' ? '新增成功' : '编辑成功')
  185. this.getList()
  186. }).catch(() => {
  187. this.submitLoading = false
  188. })
  189. })
  190. },
  191. handleDelete (row) {
  192. this.$confirm('确定删除该账号?', '提示', {
  193. confirmButtonText: '确定',
  194. cancelButtonText: '取消',
  195. type: 'warning'
  196. }).then(() => {
  197. deleteXcAccount({ idList: [row.id] }).then(() => {
  198. this.$message.success('删除成功')
  199. this.getList()
  200. })
  201. })
  202. }
  203. }
  204. }
  205. </script>
  206. <style scoped>
  207. </style>