zhengyiming
2025-02-17 9402749e7e8bd7d7be88084a55323c748ea02cc6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<template>
  <ProDialog
    :title="form.title"
    v-model="visible"
    @close="onDialogClose"
    destroy-on-close
    draggable
    :width="800"
  >
    <ProForm :model="form" ref="dialogForm" label-width="120px">
      <ProFormItemV2 label="账号:" prop="userName" :check-rules="[{ message: '请输入账号' }]">
        <ProFormText placeholder="请输入账号" v-model.trim="form.userName"></ProFormText>
      </ProFormItemV2>
      <ProFormItemV2 label="姓名:" prop="name" :check-rules="[{ message: '请输入姓名' }]">
        <ProFormText placeholder="请输入姓名" v-model.trim="form.name"></ProFormText>
      </ProFormItemV2>
      <ProFormItemV2
        label="手机号:"
        prop="phoneNumber"
        :check-rules="[{ message: '请输入手机号', type: 'phone' }]"
      >
        <ProFormText placeholder="请输入手机号" v-model.trim="form.phoneNumber"></ProFormText>
      </ProFormItemV2>
      <ProFormItemV2 label="渠道:" prop="channel" :check-rules="[{ message: '请输入渠道' }]">
        <ProFormText placeholder="请输入渠道" v-model.trim="form.channel"></ProFormText>
      </ProFormItemV2>
      <ProFormItemV2
        label="密码:"
        prop="password"
        :check-rules="[{ message: '请输入密码', required: !form.id }]"
      >
        <ProFormText placeholder="请输入密码" v-model.trim="form.password"></ProFormText>
      </ProFormItemV2>
      <ProFormItemV2 label="角色:" prop="roleName" :check-rules="[{ message: '请选择角色' }]">
        <ProFormRadio
          v-model.trim="form.roleName"
          :value-enum="allRoleList"
          :button-style="false"
          enum-label-key="name"
          enum-value-key="name"
        />
      </ProFormItemV2>
 
      <ProFormItemV2 label="备注:" prop="remark">
        <ProFormTextArea
          v-model="form.remark"
          placeholder="请输入备注"
          :maxlength="2000"
        ></ProFormTextArea>
      </ProFormItemV2>
    </ProForm>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="emit('onCancel')">取 消</el-button>
        <el-button type="primary" @click="handleConfirm">确 定</el-button>
      </span>
    </template>
  </ProDialog>
</template>
 
<script setup lang="ts">
import { FormInstance } from 'element-plus';
import {
  ProDialog,
  ProForm,
  ProFormItemV2,
  ProFormText,
  ProFormRadio,
  ProFormTextArea,
} from '@bole-core/components';
import { useAllRoleList } from '@/hooks';
 
defineOptions({
  name: 'AddOrEditAccountDialog',
});
 
// type Props = {};
 
// const props = withDefaults(defineProps<Props>(), {});
 
const visible = defineModel({ type: Boolean });
 
type Form = {
  title?: string;
  id: string;
  userName: string;
  name: string;
  phoneNumber: string;
  channel: string;
  password: string;
  roleName: string;
  remark: string;
};
 
const form = defineModel<Form>('form');
 
const emit = defineEmits<{
  (e: 'onConfirm'): void;
  (e: 'onCancel'): void;
}>();
 
const dialogForm = ref<FormInstance>();
 
const { allRoleList } = useAllRoleList();
 
function onDialogClose() {
  if (!dialogForm.value) return;
  dialogForm.value.resetFields();
}
 
function handleConfirm() {
  if (!dialogForm.value) return;
  dialogForm.value.validate((valid) => {
    if (valid) {
      emit('onConfirm');
    } else {
      return;
    }
  });
}
</script>