addUserApiKey.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div id="addUserApiKey" v-loading="isLoading">
  3. <el-dialog
  4. title="添加ApiKey"
  5. width="40%"
  6. top="2rem"
  7. :close-on-click-modal="false"
  8. :visible.sync="showDialog"
  9. :destroy-on-close="true"
  10. @close="close()"
  11. >
  12. <div id="shared" style="margin-right: 20px;">
  13. <el-form ref="formRef" :model="form" :rules="rules" status-icon label-width="80px">
  14. <el-form-item label="应用名" prop="app">
  15. <el-input
  16. v-model="form.app"
  17. property="app"
  18. autocomplete="off"/>
  19. </el-form-item>
  20. <el-form-item label="启用状态" prop="enable" style="text-align: left">
  21. <el-switch
  22. v-model="form.enable"
  23. property="enable"
  24. active-text="启用"
  25. inactive-text="停用"/>
  26. </el-form-item>
  27. <el-form-item label="过期时间" prop="expiresAt" style="text-align: left">
  28. <el-date-picker v-model="form.expiresAt"
  29. style="width: 100%"
  30. property="expiresAt"
  31. type="datetime"
  32. value-format="yyyy-MM-dd HH:mm:ss"
  33. format="yyyy-MM-dd HH:mm:ss"
  34. placeholder="选择过期时间"/>
  35. </el-form-item>
  36. <el-form-item label="备注信息" prop="remark">
  37. <el-input v-model="form.remark"
  38. type="textarea"
  39. property="remark"
  40. autocomplete="off"
  41. :autosize="{ minRows: 5}"
  42. maxlength="255"
  43. show-word-limit/>
  44. </el-form-item>
  45. <el-form-item>
  46. <div style="float: right;">
  47. <el-button type="primary" @click="onSubmit">保存</el-button>
  48. <el-button @click="close">取消</el-button>
  49. </div>
  50. </el-form-item>
  51. </el-form>
  52. </div>
  53. </el-dialog>
  54. </div>
  55. </template>
  56. <script>
  57. export default {
  58. name: 'addUserApiKey',
  59. props: {},
  60. computed: {},
  61. created() {
  62. },
  63. data() {
  64. return {
  65. userId: null,
  66. form: {
  67. app: null,
  68. enable: true,
  69. expiresAt: null,
  70. remark: null
  71. },
  72. rules: {
  73. app: [{required: true, trigger: 'blur', message: '应用名不能为空'}]
  74. },
  75. listChangeCallback: null,
  76. showDialog: false,
  77. isLoading: false
  78. };
  79. },
  80. methods: {
  81. resetForm() {
  82. this.form = {
  83. app: null,
  84. enable: true,
  85. expiresAt: null,
  86. remark: null
  87. }
  88. },
  89. openDialog(userId, callback) {
  90. this.resetForm()
  91. this.userId = userId
  92. this.listChangeCallback = callback
  93. this.showDialog = true
  94. },
  95. onSubmit() {
  96. this.$refs.formRef.validate((valid) => {
  97. if (valid) {
  98. this.$axios({
  99. method: 'post',
  100. url: '/api/userApiKey/add',
  101. params: {
  102. userId: this.userId,
  103. app: this.form.app,
  104. enable: this.form.enable,
  105. expiresAt: this.form.expiresAt,
  106. remark: this.form.remark,
  107. }
  108. }).then((res) => {
  109. if (res.data.code === 0) {
  110. this.$message({
  111. showClose: true,
  112. message: '添加成功',
  113. type: 'success'
  114. });
  115. this.showDialog = false
  116. if (this.listChangeCallback) {
  117. this.listChangeCallback()
  118. }
  119. } else {
  120. this.$message({
  121. showClose: true,
  122. message: res.data.msg,
  123. type: 'error'
  124. });
  125. }
  126. }).catch((error) => {
  127. console.error(error)
  128. });
  129. }
  130. });
  131. },
  132. close() {
  133. this.showDialog = false
  134. }
  135. },
  136. };
  137. </script>