Create.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <div>
  3. <page-header :title="$t('system.text_167', [$t('dictionary.policy')])" />
  4. <page-body need-margin-bottom>
  5. <policy-form ref="policyForm" :edit-type="editType" @edit-type-change="val => editType = val" />
  6. </page-body>
  7. <page-footer>
  8. <div slot="right">
  9. <a-button class="mr-3" type="primary" @click="doCreate" :loading="submiting">{{ $t('common.create') }}</a-button>
  10. <a-button @click="handleCancel">{{ $t('common.cancel') }}</a-button>
  11. </div>
  12. </page-footer>
  13. </div>
  14. </template>
  15. <script>
  16. import PolicyForm from './components/Form'
  17. export default {
  18. name: 'PolicyCreate',
  19. components: {
  20. PolicyForm,
  21. },
  22. data () {
  23. return {
  24. submiting: false,
  25. editType: 'yaml',
  26. }
  27. },
  28. methods: {
  29. async doCreate () {
  30. this.submiting = true
  31. try {
  32. const data = await this.$refs.policyForm.getData()
  33. await this.$http.post('/v1/auth/policies', data)
  34. this.$router.push('/policy')
  35. } catch (error) {
  36. throw error
  37. } finally {
  38. this.submiting = false
  39. }
  40. },
  41. handleCancel () {
  42. this.$router.push('/policy')
  43. },
  44. },
  45. }
  46. </script>