index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <span>
  3. <el-dialog
  4. :title="$t('plugins.api-base-url.title')"
  5. :visible.sync="active"
  6. width="400px"
  7. custom-class="ibps-api-base-url-controller"
  8. append-to-body
  9. :close-on-click-modal="false"
  10. :close-on-press-escape="false"
  11. >
  12. <el-scrollbar>
  13. <div class="wrapper">
  14. <div
  15. v-for="option of options"
  16. :key="option.value"
  17. class="item"
  18. >
  19. <el-button
  20. size="default"
  21. :type="isItemActive(option.value) ? 'primary' : 'default'"
  22. style="width: 100%;"
  23. @click="onSelect(option.value,option.single)"
  24. >
  25. <div flex="main:justify cross:center">
  26. <div flex="dir:top cross:top">
  27. <div class="item-name">
  28. {{ getTitle(option.name) }}
  29. ( {{ option.single? $t('plugins.api-base-url.constants.type.single') :$t('plugins.api-base-url.constants.type.non-single') }} )
  30. </div>
  31. <div class="item-value">
  32. {{ option.value }}
  33. </div>
  34. </div>
  35. <span v-if="isItemActive(option.value)">
  36. <ibps-icon class="item-icon" name="check-circle" />
  37. </span>
  38. <span
  39. v-else-if="option.type === 'custom'"
  40. @click.stop="onRemove(option.value)"
  41. >
  42. <ibps-icon class="item-icon" name="close" />
  43. </span>
  44. </div>
  45. </el-button>
  46. </div>
  47. </div>
  48. </el-scrollbar>
  49. <el-divider>{{ $t('plugins.api-base-url.or') }}</el-divider>
  50. <div flex="main:justify cross:center">
  51. <el-input
  52. v-model="customBaseUrl"
  53. class="ibps-mr-5"
  54. />
  55. <el-tooltip
  56. effect="dark"
  57. :content="$t('plugins.api-base-url.singleApp')"
  58. placement="bottom"
  59. >
  60. <el-switch v-model="customSingle" />
  61. </el-tooltip>
  62. <el-button
  63. :disabled="customBaseUrl.length === 0"
  64. @click="onSetCustom"
  65. >{{ $t('plugins.api-base-url.button.ok') }}</el-button>
  66. </div>
  67. <el-divider />
  68. <el-button
  69. type="primary"
  70. style="width:100%;"
  71. @click="onConfirm"
  72. >{{ $t('plugins.api-base-url.button.confirm') }}</el-button>
  73. </el-dialog>
  74. <span @click="onOpen">
  75. <slot />
  76. </span>
  77. </span>
  78. </template>
  79. <script>
  80. import { mapState, mapGetters, mapActions } from 'vuex'
  81. import { SINGLE_APP, BASE_API } from '@/api/baseUrl'
  82. export default {
  83. name: 'ibps-api-base-url-controller',
  84. data() {
  85. return {
  86. active: false,
  87. customBaseUrl: '',
  88. customSingle: '',
  89. baseUrl: this.base,
  90. baseSingle: this.single
  91. }
  92. },
  93. computed: {
  94. ...mapState('ibps/api', [
  95. 'base'
  96. ]),
  97. ...mapState('ibps/api', [
  98. 'single'
  99. ]),
  100. ...mapGetters('ibps/api', [
  101. 'options'
  102. ])
  103. },
  104. methods: {
  105. ...mapActions('ibps/api', {
  106. baseUrlCustom: 'custom',
  107. baseUrlSet: 'set',
  108. baseUrlOptionRemove: 'remove'
  109. }),
  110. onOpen() {
  111. this.customBaseUrl = BASE_API()
  112. this.customSingle = SINGLE_APP()
  113. this.baseUrl = this.base
  114. this.baseSingle = this.single
  115. this.active = true
  116. },
  117. onSelect(value, single) {
  118. this.baseUrl = value
  119. this.baseSingle = single
  120. },
  121. onSetCustom() {
  122. this.baseUrlCustom({
  123. baseUrl: this.customBaseUrl,
  124. single: this.customSingle
  125. })
  126. },
  127. onConfirm() {
  128. this.active = false
  129. if (this.base === this.baseUrl) {
  130. return
  131. }
  132. this.baseUrlSet({
  133. baseUrl: this.baseUrl,
  134. single: this.baseSingle,
  135. vm: this
  136. })
  137. this.$router.replace('/refresh')
  138. },
  139. onRemove(value) {
  140. this.baseUrlOptionRemove(value)
  141. },
  142. isItemActive(value) {
  143. return this.baseUrl === value
  144. },
  145. getTitle(name) {
  146. const nameLower = name.toLowerCase()
  147. if (this.$te('plugins.api-base-url.constants.env.' + nameLower)) {
  148. return this.$t('plugins.api-base-url.constants.env.' + nameLower)
  149. }
  150. return name
  151. }
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .ibps-api-base-url-controller {
  157. .el-dialog__body {
  158. .wrapper {
  159. max-height: 220px;
  160. .item {
  161. &:last-child {
  162. .el-button {
  163. margin-bottom: 0px;
  164. }
  165. }
  166. .el-button {
  167. margin-bottom: 10px;
  168. .item-name {
  169. font-size: 14px;
  170. font-weight: bold;
  171. margin-bottom: 4px;
  172. }
  173. .item-value {
  174. font-size: 12px;
  175. }
  176. .item-icon {
  177. font-size: 24px;
  178. }
  179. }
  180. }
  181. }
  182. }
  183. }
  184. </style>