Create.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('system.text_130', [$t('dictionary.role')])}}</div>
  4. <div slot="body">
  5. <steps class="my-3" v-model="step" />
  6. <component :is="stepComponent" :domain="params.domain" ref="stepForm" />
  7. </div>
  8. <div slot="footer">
  9. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ confirmText }}</a-button>
  10. <a-button @click="cancel">{{ $t('dialog.cancel') }}</a-button>
  11. </div>
  12. </base-dialog>
  13. </template>
  14. <script>
  15. import DialogMixin from '@/mixins/dialog'
  16. import WindowsMixin from '@/mixins/windows'
  17. import StepMixin from '@/mixins/step'
  18. import SetPoliciesForm from '../components/SetPolicies'
  19. import CreateRoleForm from '../components/CreateRole'
  20. export default {
  21. name: 'RoleCreateDialog',
  22. components: {
  23. CreateRoleForm,
  24. SetPoliciesForm,
  25. },
  26. mixins: [DialogMixin, WindowsMixin, StepMixin],
  27. data () {
  28. return {
  29. loading: false,
  30. step: {
  31. steps: [
  32. { title: this.$t('system.role'), key: 'create-role-form' },
  33. { title: this.$t('role.create_step2'), key: 'set-policies-form' },
  34. ],
  35. currentStep: 0,
  36. },
  37. }
  38. },
  39. computed: {
  40. stepComponent () {
  41. return this.step.steps[this.step.currentStep].key
  42. },
  43. confirmText () {
  44. return this.stepComponent === 'create-role-form' ? this.$t('common.next_step') : this.$t('dialog.ok')
  45. },
  46. },
  47. methods: {
  48. async handleConfirm () {
  49. this.loading = true
  50. try {
  51. if (this.step.currentStep === 0) {
  52. const createRoleRes = await this.$refs.stepForm.create()
  53. this.rid = createRoleRes.data.id
  54. this.step.currentStep = this.step.currentStep + 1
  55. } else if (this.step.currentStep === 1) {
  56. await this.$refs.stepForm.set(this.rid)
  57. this.cancel()
  58. }
  59. } finally {
  60. this.loading = false
  61. }
  62. },
  63. cancel () {
  64. this.cancelDialog()
  65. if (this.step.currentStep === 1) {
  66. this.params.success()
  67. }
  68. },
  69. },
  70. }
  71. </script>