Update.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('system.text_479')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.user')" :count="params.data.length" :action="params.title" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. :form="form.fc"
  9. v-bind="formItemLayout">
  10. <a-form-item :label="$t('scope.text_245')" v-if="params.data.length<=1">
  11. <a-input :placeholder="$t('system.displayname_tip')" v-decorator="decorators.displayname" />
  12. </a-form-item>
  13. <a-form-item :label="$t('system.text_475')">
  14. <a-switch :checkedChildren="$t('system.text_134')" :unCheckedChildren="$t('system.text_135')" v-decorator="decorators['allow_web_console']" />
  15. </a-form-item>
  16. <a-form-item :label="$t('system.text_483')" :extra="mfaExtra">
  17. <a-switch :disabled="!!mfaExtra" :checkedChildren="$t('system.text_134')" :unCheckedChildren="$t('system.text_135')" v-decorator="decorators['enable_mfa']" />
  18. </a-form-item>
  19. </a-form>
  20. </div>
  21. <div slot="footer">
  22. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  23. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  24. </div>
  25. </base-dialog>
  26. </template>
  27. <script>
  28. import { mapGetters } from 'vuex'
  29. import DialogMixin from '@/mixins/dialog'
  30. import WindowsMixin from '@/mixins/windows'
  31. export default {
  32. name: 'UserUpdateDialog',
  33. mixins: [DialogMixin, WindowsMixin],
  34. data () {
  35. return {
  36. loading: false,
  37. form: {
  38. fc: this.$form.createForm(this),
  39. },
  40. decorators: {
  41. allow_web_console: [
  42. 'allow_web_console',
  43. {
  44. initialValue: this.params.data[0].allow_web_console,
  45. valuePropName: 'checked',
  46. },
  47. ],
  48. enable_mfa: [
  49. 'enable_mfa',
  50. {
  51. initialValue: this.params.data[0].enable_mfa,
  52. valuePropName: 'checked',
  53. },
  54. ],
  55. displayname: [
  56. 'displayname',
  57. {
  58. initialValue: this.params.data[0].displayname || '',
  59. rules: [{ required: false }],
  60. },
  61. ],
  62. },
  63. formItemLayout: {
  64. wrapperCol: {
  65. span: 19,
  66. },
  67. labelCol: {
  68. span: 5,
  69. },
  70. },
  71. mfaExtra: '',
  72. }
  73. },
  74. computed: {
  75. ...mapGetters(['userInfo']),
  76. },
  77. destroyed () {
  78. this.manager = null
  79. },
  80. created () {
  81. this.manager = new this.$Manager('services', 'v1')
  82. this.fetchApiServiceConfig()
  83. },
  84. methods: {
  85. async fetchApiServiceConfig () {
  86. try {
  87. const serviceRes = await this.manager.list({
  88. params: {
  89. type: ['yunionapi'],
  90. },
  91. })
  92. if (serviceRes.data.data && serviceRes.data.data[0]) {
  93. const id = serviceRes.data.data[0].id
  94. const configRes = await this.manager.getSpecific({
  95. id,
  96. spec: 'config',
  97. })
  98. const config = (configRes.data.config && configRes.data.config.default) || {}
  99. if (!config.enable_totp) {
  100. this.mfaExtra = this.$t('system.text_509')
  101. }
  102. return config
  103. }
  104. } catch (error) {
  105. if (error.response && error.response.status) {
  106. this.mfaExtra = this.$t('system.text_510')
  107. }
  108. throw error
  109. }
  110. },
  111. async handleConfirm () {
  112. this.loading = true
  113. const { data = [], onManager } = this.params
  114. try {
  115. const values = await this.form.fc.validateFields()
  116. let isSelf = false
  117. await onManager('batchUpdate', {
  118. id: data.map(({ id }) => {
  119. if (id === this.userInfo.id) isSelf = true
  120. return id
  121. }),
  122. managerArgs: {
  123. data: values,
  124. },
  125. })
  126. this.cancelDialog()
  127. // 当是本人时,更新用户信息
  128. if (data.length === 1 && isSelf) {
  129. await this.$store.dispatch('auth/getInfo')
  130. }
  131. } catch (error) {
  132. this.loading = false
  133. throw error
  134. }
  135. },
  136. },
  137. }
  138. </script>