123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- <template>
- <BasicModal
- v-bind="$attrs"
- @cancel="resetFields"
- @register="register"
- :title="title"
- :min-height="230"
- @ok="handleOk"
- >
- <BasicForm @register="registerForm" />
- </BasicModal>
- </template>
- <script lang="ts">
- import { defineComponent, ref, computed } from 'vue';
- import { UserListApi, saveApi, updateApi, getRoleListByParam } from '/@/api/staff/list'; //roleLIstApi
- import { BasicModal, useModalInner } from '/@/components/Modal';
- import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
- import { useI18n } from '/@/hooks/web/useI18n';
- import { useMessage } from '/@/hooks/web/useMessage';
- import { useUserStore } from '/@/store/modules/user';
- import { debounce } from 'lodash-es';
- const { t } = useI18n();
- export default defineComponent({
- components: { BasicModal, BasicForm },
- props: {
- userData: { type: Object },
- },
- emits: ['ok'],
- setup(_, context) {
- const modelRef = ref({});
- const optionData = ref([])
- const userStore = useUserStore();
- const userinfo = computed(() => userStore.getUserInfo);
- const preventAutoFill = ref(true);
- const { companyId } = userinfo.value;
- const schemas: FormSchema[] = [
- {
- field: 'userName',
- component: 'Select',
- label: '账号',
- required: true,
- colProps: {
- span: 20,
- },
- componentProps:{
- showSearch:true,
- listHeight:200,
- labelField: 'userName',
- valueField: 'userName',
- options:optionData.value,
- onSearch:debounce(async value => {
- optionData.value = []
- const data = await UserListApi({userName:value})
- optionData.value = data.map(ele =>{
- return {
- label: ele.userName,
- value: ele.userName,
- key: ele.userName,
- }
- }) || []
- updateSchema({
- field: 'userName',
- componentProps:{
- options: optionData.value,
- },
- })
- }),
- placeholder:"请输入字母或数字组合",
- autoComplete:'off',
- maxLength: 15,
- readonly:preventAutoFill.value,
- },
- rules: [
- {
- required: true,
- // @ts-ignore
- validator: async (rule, value) => {
- console.log('value',value)
- const regPos = /^[\da-z]+$/i; // 非中文
- if (!value) {
- return Promise.reject('请输入字母或数字组合');
- }
- if (!regPos.test(value)) {
- /* eslint-disable-next-line */
- return Promise.reject('请输入字母或数字组合');
- }
- return Promise.resolve();
- },
- trigger: 'change',
- },
- ],
- },{
- field: 'roleId',
- component: 'ApiSelect',
- label: '角色',
- required: true,
- itemProps: {
- validateTrigger: 'blur',
- },
- colProps: {
- span: 20,
- },
- defaultValue: '',
- componentProps: {
- listHeight:120,
- api: getRoleListByParam,
- labelField: 'roleName',
- valueField: 'id',
- params: {
- type: 1,
- },
- },
- },{
- field: 'dingAccount',
- component: 'Input',
- label: '钉钉账号',
- colProps: {
- span: 20,
- },
- },
- // {
- // field: 'password',
- // component: 'StrengthMeter',
- // label: '密码',
- // required: true,
- // colProps: {
- // span: 20,
- // },
- // rules: [
- // {
- // required: true,
- // // @ts-ignore
- // validator: async (rule, value) => {
- // console.log('value',value)
- // const regPos = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/; // 非中文
- // if (!value) {
- // return Promise.reject('请输入8-16位数字、字母大小写组合');
- // }
- // if (!regPos.test(value)) {
- // /* eslint-disable-next-line */
- // return Promise.reject('请输入8-16位数字、字母大小写组合');
- // }
- // return Promise.resolve();
- // },
- // trigger: 'change',
- // },
- // ],
- // componentProps:{
- // placeholder:"请输入8-16位数字、字母大小写组合",
- // maxLength: 16,
- // readonly:preventAutoFill.value,
- // minLength: 8,
- // autoComplete:'off',
- // }
- // },
- {
- field: 'id',
- component: 'Input',
- label: 'id',
- show: false,
- },
- ];
- const title = ref('新增账号');
- const { createMessage } = useMessage();
- const [registerForm, { setFieldsValue, validate, updateSchema, resetFields }] = useForm({
- labelWidth: 120,
- schemas,
- showActionButtonGroup: false,
- actionColOptions: {
- span: 24,
- },
- });
- const [register, { closeModal }] = useModalInner((data) => {
- data && onDataReceive(data);
- });
- function onDataReceive(data) {
- console.log('onDataReceive',data)
- // 方式1;
- // setTimeout(()=>{
- // preventAutoFill.value = false
- // updateSchema([{
- // field: 'userName',
- // componentProps:{
- // readonly:false,
- // }
- // },{
- // field: 'password',
- // componentProps:{
- // readonly:false,
- // }
- // }])
- // // updateSchema(schemas);
- // },500)
- }
- function companyIdChange(companyId) {
- // resetFields(['permList'])
- updateSchema([
- {
- field: 'permList',
- componentProps: {
- params: {
- companyId: companyId,
- },
- },
- },
- ]);
- setFieldsValue({
- permList: [],
- });
- }
- async function handleOk() {
- let data = await validate();
- const requestApi = data.id ? updateApi : saveApi;
- let res = await requestApi({
- ...data,
- // userName: data.phone,
- phone: data.phone,
- nickName: data.nickName,
- roleId: data.roleId,
- id: data.id,
- });
- context && context.emit('ok', res);
- createMessage.success(t('common.optSuccess'));
- closeModal();
- resetFields();
- }
- return {
- register,
- title,
- preventAutoFill,
- schemas,
- registerForm,
- modelRef,
- handleOk,
- resetFields,
- };
- },
- });
- </script>
|