edit.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div>
  3. <a-button :disabled="disabled" type="primary" @click="showDrawer">编辑</a-button>
  4. <a-drawer
  5. v-model:visible="visible"
  6. class="custom-class"
  7. title="编辑用户"
  8. placement="right"
  9. width="600"
  10. :closable="false"
  11. @close="onClose"
  12. >
  13. <a-form ref="formRef" :model="form" size="small" layout="vertical">
  14. <a-row :gutter="16">
  15. <a-col :span="24">
  16. <a-form-item label="角色名称" name="rolename" :rules="[{ required: true, message: '请输入角色名称'}]">
  17. <a-input v-model:value="form.rolename" placeholder="角色名称" />
  18. </a-form-item>
  19. </a-col>
  20. <a-col :span="24">
  21. <a-form-item label="角色描述" name="remarks" :rules="[{ required: true, message: '请输入角色描述'}]">
  22. <a-input v-model:value="form.remarks" placeholder="输入角色描述" />
  23. </a-form-item>
  24. </a-col>
  25. <a-col :span="12">
  26. <a-form-item label="角色类型" name="usertype" :rules="[{ required: true, message: '请输入角色描述'}]">
  27. <a-select
  28. ref="select"
  29. v-model:value="form.usertype"
  30. placeholder="选择角色类型"
  31. style="width: 100%"
  32. >
  33. <a-select-option v-for="item in userTypeOptions" :key="item.value" :value="Number(item.value)">{{item.remarks}}</a-select-option>
  34. </a-select>
  35. </a-form-item>
  36. </a-col>
  37. <a-col :span="12">
  38. <a-form-item label="是否隐藏敏感信息">
  39. <a-select
  40. ref="select"
  41. v-model:value="form.isshieldinfo"
  42. placeholder="选择角色"
  43. style="width: 100%"
  44. >
  45. <a-select-option :value="1">是</a-select-option>
  46. <a-select-option :value="0">否</a-select-option>
  47. </a-select>
  48. </a-form-item>
  49. </a-col>
  50. </a-row>
  51. </a-form>
  52. <template #extra>
  53. <a-space>
  54. <a-button @click="onClose">关闭</a-button>
  55. <a-button type="primary" @click="submit">保存</a-button>
  56. </a-space>
  57. </template>
  58. </a-drawer>
  59. </div>
  60. </template>
  61. <script setup>
  62. import {ref,defineEmits,defineProps} from 'vue'
  63. import Api from '@/api/api'
  64. import utils from '@/utils/utils'
  65. const emit = defineEmits(['onSuccess'])
  66. const visible = ref(false)
  67. const props = defineProps(['data','disabled'])
  68. const form = ref({
  69. })
  70. const showDrawer = ()=>{
  71. roles()
  72. visible.value = true
  73. form.value = Object.assign({},form.value,props.data)
  74. }
  75. const onClose = () => {
  76. visible.value = false;
  77. formRef.value.resetFields();
  78. };
  79. const formRef = ref()
  80. const submit = async ()=>{
  81. try {
  82. const values = await formRef.value.validateFields();
  83. const res = await Api.requested({
  84. id:20230608102302,
  85. "content": form.value
  86. })
  87. utils.message(res,'编辑成功',()=>{
  88. onClose()
  89. emit('onSuccess')
  90. })
  91. } catch (errorInfo) {
  92. console.log('Failed:', errorInfo);
  93. }
  94. }
  95. const userTypeOptions = ref([])
  96. const roles = async ()=>{
  97. const res = await Api.optionstype('usertype')
  98. userTypeOptions.value = res.data
  99. }
  100. </script>
  101. <style>
  102. </style>