AliyunAddCard.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div>
  3. <el-form ref="form" :model="form" label-width="100px">
  4. <el-form-item label="仓库认证" prop="repoAuthName">
  5. <el-row :gutter="10">
  6. <el-col :span="14">
  7. <el-select
  8. v-model="form.repoAuthName"
  9. placeholder="请选择仓库认证"
  10. style="width: 100%"
  11. :disabled="repoAuthNames.length === 0"
  12. >
  13. <el-option
  14. v-for="(item, index) in repoAuthNames"
  15. :key="index"
  16. :label="item.label"
  17. :value="item.value"
  18. />
  19. </el-select>
  20. </el-col>
  21. <el-col :span="6">
  22. <el-button
  23. type="text"
  24. icon="el-icon-plus"
  25. @click="handleAddRepoAuth"
  26. >
  27. {{ repoAuthNames.length === 0 ? '暂无数据,去添加' : '新增认证' }}
  28. </el-button>
  29. </el-col>
  30. </el-row>
  31. </el-form-item>
  32. <el-form-item label="OSS 地址">
  33. <el-input v-model="form.endpoint" style="width: 70%" placeholder="e.g. registry.cn-hangzhou.aliyuncs.com" />
  34. </el-form-item>
  35. <el-form-item label="OSS 名字">
  36. <el-input v-model="form.name" style="width: 70%" placeholder="e.g. reghao/" />
  37. </el-form-item>
  38. <el-form-item>
  39. <el-button type="primary" @click="onAddOss">确定</el-button>
  40. </el-form-item>
  41. </el-form>
  42. <el-dialog
  43. title="添加仓库认证"
  44. :visible.sync="showAddRepoAuthDialog"
  45. width="650px"
  46. :close-on-click-modal="false"
  47. append-to-body
  48. destroy-on-close
  49. >
  50. <repo-auth-add-card
  51. @close="showAddRepoAuthDialog = false"
  52. @success="handleAddRepoAuthSuccess"
  53. />
  54. </el-dialog>
  55. </div>
  56. </template>
  57. <script>
  58. import RepoAuthAddCard from "@/components/card/RepoAuthAddCard.vue";
  59. import {addAliyunKey, getRepoAuthNames} from "@/api/devops";
  60. export default {
  61. name: 'AliyunAddCard',
  62. components: {RepoAuthAddCard},
  63. data() {
  64. return {
  65. loading: false,
  66. active: 0,
  67. repoAuthNames: [],
  68. form: {
  69. repoAuthName: '',
  70. endpoint: '',
  71. name: ''
  72. },
  73. showAddRepoAuthDialog: false
  74. }
  75. },
  76. mounted() {
  77. this.initData()
  78. },
  79. methods: {
  80. // 1. 初始化数据:从后端获取下拉框选项
  81. async initData() {
  82. this.loading = true
  83. try {
  84. // 这里替换为你真实的 API 调用
  85. const [resp] = await Promise.all([getRepoAuthNames()])
  86. this.repoAuthNames = resp.data
  87. } catch (error) {
  88. this.$message.error('获取配置选项失败')
  89. } finally {
  90. this.loading = false
  91. }
  92. },
  93. async onAddOss() {
  94. this.$refs.form.validate((valid) => {
  95. if (valid) {
  96. addAliyunKey(this.form).then(resp => {
  97. if (resp.code === 0) {
  98. this.$emit('success', resp)
  99. } else {
  100. this.$message.warning(resp.msg)
  101. this.$emit('fail', resp)
  102. }
  103. }).catch(error => {
  104. this.$message.error(error.message)
  105. this.$emit('error', error)
  106. })
  107. } else {
  108. return false
  109. }
  110. })
  111. },
  112. async handleAddRepoAuth() {
  113. this.showAddRepoAuthDialog = true
  114. },
  115. handleAddRepoAuthSuccess() {
  116. this.showAddRepoAuthDialog = false
  117. getRepoAuthNames().then(resp => {
  118. if (resp.code === 0) {
  119. this.repoAuthNames = resp.data
  120. } else {
  121. this.$message.info(resp.msg)
  122. }
  123. }).catch(error => {
  124. this.$message.error(error.message)
  125. })
  126. }
  127. }
  128. }
  129. </script>
  130. <style scoped>
  131. .repo-auth-container {
  132. padding: 10px 20px;
  133. }
  134. .step-content {
  135. min-height: 240px;
  136. margin-top: 20px;
  137. }
  138. .dialog-footer {
  139. text-align: right;
  140. padding-top: 20px;
  141. margin-top: 20px;
  142. border-top: 1px solid #f2f6fc;
  143. }
  144. .none-tip {
  145. padding-top: 40px;
  146. }
  147. ::v-deep .el-textarea__inner {
  148. font-family: 'Fira Code', 'Courier New', monospace;
  149. background-color: #fcfcfc;
  150. font-size: 13px;
  151. }
  152. </style>