edit.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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="12">
  16. <a-form-item label="选择角色">
  17. <a-select
  18. ref="select"
  19. mode="multiple"
  20. v-model:value="form.roleids"
  21. placeholder="选择角色"
  22. style="width: 100%"
  23. >
  24. <a-select-option v-for="item in rolesOptions" :key="item.roleid" :value="item.roleid">{{item.rolename}}</a-select-option>
  25. </a-select>
  26. </a-form-item>
  27. </a-col>
  28. <a-col :span="12">
  29. <a-form-item label="账号" name="accountno">
  30. <a-input v-model:value="form.accountno" placeholder="账号" />
  31. </a-form-item>
  32. </a-col>
  33. <a-col :span="12">
  34. <a-form-item label="手机号码" name="phonenumber" :rules="[{ required: true, message: '请输入手机号码'},{ validator: validatePhoneNumber, message: '请输入有效的手机号码' }]">
  35. <a-input v-model:value="form.phonenumber" placeholder="输入手机号码" />
  36. </a-form-item>
  37. </a-col>
  38. <a-col :span="12">
  39. <a-form-item label="用户名称" name="name" :rules="[{ required: true, message: '请输入用户名称' }]">
  40. <a-input v-model:value="form.name" placeholder="输入用户名称" />
  41. </a-form-item>
  42. </a-col>
  43. </a-row>
  44. </a-form>
  45. <template #extra>
  46. <a-space>
  47. <a-button @click="onClose">关闭</a-button>
  48. <a-button type="primary" @click="submit">保存</a-button>
  49. </a-space>
  50. </template>
  51. </a-drawer>
  52. </div>
  53. </template>
  54. <script setup>
  55. import {ref,defineEmits,defineProps} from 'vue'
  56. import Api from '@/api/api'
  57. import utils from '@/utils/utils'
  58. const emit = defineEmits(['onSuccess'])
  59. const visible = ref(false)
  60. const props = defineProps(['data','disabled'])
  61. const form = ref({
  62. userid: 0,
  63. remarks:''
  64. })
  65. const validatePhoneNumber = async (rule, value)=> {
  66. const phoneNumberPattern = /^1\d{10}$/;
  67. if (phoneNumberPattern.test(value)) {
  68. return Promise.resolve();
  69. }
  70. return Promise.reject('请输入有效的手机号码');
  71. }
  72. const showDrawer = ()=>{
  73. form.value = Object.assign({},form.value,props.data)
  74. form.value.roleids = props.data.userrole.map(e=>e.roleid)
  75. visible.value = true
  76. roles()
  77. }
  78. const onClose = () => {
  79. visible.value = false;
  80. formRef.value.resetFields();
  81. };
  82. const formRef = ref()
  83. const submit = async ()=>{
  84. try {
  85. const values = await formRef.value.validateFields();
  86. const res = await Api.requested({
  87. id:20230608104302,
  88. "content": form.value
  89. })
  90. utils.message(res,'编辑成功',()=>{
  91. onClose()
  92. emit('onSuccess')
  93. })
  94. } catch (errorInfo) {
  95. console.log('Failed:', errorInfo);
  96. }
  97. }
  98. const rolesOptions = ref([])
  99. const roles = async ()=>{
  100. const res = await Api.optionstype('role')
  101. rolesOptions.value = res.data
  102. }
  103. </script>
  104. <style>
  105. </style>