2021-06-07 17:22:07 +08:00
|
|
|
<template>
|
2025-04-26 17:37:09 +08:00
|
|
|
<div>
|
2025-04-15 21:42:31 +08:00
|
|
|
<el-dialog :title="title" v-model="visible" :before-close="cancel" :show-close="false" width="600px" :destroy-on-close="true">
|
2023-07-03 21:42:04 +08:00
|
|
|
<el-form :model="form" ref="accountForm" :rules="rules" label-width="auto">
|
2024-11-20 22:43:53 +08:00
|
|
|
<el-form-item prop="name" :label="$t('system.account.name')">
|
|
|
|
|
<el-input v-model.trim="form.name" auto-complete="off" clearable></el-input>
|
2022-10-29 20:08:15 +08:00
|
|
|
</el-form-item>
|
2024-11-20 22:43:53 +08:00
|
|
|
|
|
|
|
|
<el-form-item prop="username" :label="$t('common.username')">
|
2023-07-31 17:34:32 +08:00
|
|
|
<el-input
|
|
|
|
|
:disabled="edit"
|
|
|
|
|
v-model.trim="form.username"
|
2024-11-20 22:43:53 +08:00
|
|
|
:placeholder="$t('system.account.usernamePlacholder')"
|
2023-07-31 17:34:32 +08:00
|
|
|
auto-complete="off"
|
|
|
|
|
clearable
|
|
|
|
|
></el-input>
|
2021-06-07 17:22:07 +08:00
|
|
|
</el-form-item>
|
2024-11-20 22:43:53 +08:00
|
|
|
|
2025-04-15 21:42:31 +08:00
|
|
|
<el-form-item prop="mobile" :label="$t('common.mobile')">
|
|
|
|
|
<el-input v-model.trim="form.mobile" clearable></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
<el-form-item prop="email" :label="$t('common.email')">
|
|
|
|
|
<el-input v-model.trim="form.email" auto-complete="off" clearable></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
2024-11-20 22:43:53 +08:00
|
|
|
<el-form-item :required="!edit" prop="password" :label="$t('common.password')">
|
|
|
|
|
<el-input type="password" v-model.trim="form.password" autocomplete="new-password" show-password>
|
|
|
|
|
<template #append>
|
|
|
|
|
<el-button
|
|
|
|
|
@click="
|
|
|
|
|
{
|
|
|
|
|
form.password = randomPassword(10);
|
|
|
|
|
}
|
|
|
|
|
"
|
|
|
|
|
>
|
|
|
|
|
{{ $t('system.account.random') }}
|
|
|
|
|
</el-button>
|
|
|
|
|
</template>
|
|
|
|
|
</el-input>
|
2021-06-07 17:22:07 +08:00
|
|
|
</el-form-item>
|
2025-04-15 21:42:31 +08:00
|
|
|
|
|
|
|
|
<el-form-item :label="$t('system.account.qywxUserId')">
|
|
|
|
|
<el-input v-model.trim="form.extra.qywxUserId" clearable></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="$t('system.account.feishuUserId')">
|
|
|
|
|
<el-input v-model.trim="form.extra.feishuUserId" clearable></el-input>
|
|
|
|
|
</el-form-item>
|
2021-06-07 17:22:07 +08:00
|
|
|
</el-form>
|
|
|
|
|
|
|
|
|
|
<template #footer>
|
2025-04-15 21:42:31 +08:00
|
|
|
<el-button @click="cancel()">{{ $t('common.cancel') }}</el-button>
|
|
|
|
|
<el-button type="primary" :loading="saveBtnLoading" @click="btnOk">{{ $t('common.confirm') }}</el-button>
|
2021-06-07 17:22:07 +08:00
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
<script lang="ts" setup>
|
2025-04-15 21:42:31 +08:00
|
|
|
import { toRefs, reactive, watch, ref } from 'vue';
|
2021-06-07 17:22:07 +08:00
|
|
|
import { accountApi } from '../api';
|
2024-11-20 22:43:53 +08:00
|
|
|
import { randomPassword } from '@/common/utils/string';
|
2025-03-05 12:47:52 +08:00
|
|
|
import { useI18nFormValidate, useI18nSaveSuccessMsg } from '@/hooks/useI18n';
|
|
|
|
|
import { Rules } from '@/common/rule';
|
2021-06-07 17:22:07 +08:00
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
const props = defineProps({
|
|
|
|
|
account: {
|
|
|
|
|
type: [Boolean, Object],
|
2021-06-07 17:22:07 +08:00
|
|
|
},
|
2022-10-29 20:08:15 +08:00
|
|
|
title: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2023-07-06 20:59:22 +08:00
|
|
|
});
|
2021-06-07 17:22:07 +08:00
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
//定义事件
|
2025-04-26 17:37:09 +08:00
|
|
|
const emit = defineEmits(['cancel', 'val-change']);
|
2021-06-07 17:22:07 +08:00
|
|
|
|
2025-04-15 21:42:31 +08:00
|
|
|
const visible = defineModel<boolean>('visible', { default: false });
|
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
const accountForm: any = ref(null);
|
2021-06-07 17:22:07 +08:00
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
const rules = {
|
2025-03-05 12:47:52 +08:00
|
|
|
name: [Rules.requiredInput('system.account.name')],
|
|
|
|
|
username: [Rules.requiredInput('common.username'), Rules.accountUsername],
|
|
|
|
|
password: [Rules.requiredInput('common.password')],
|
2023-07-06 20:59:22 +08:00
|
|
|
};
|
2021-06-07 17:22:07 +08:00
|
|
|
|
2025-04-15 21:42:31 +08:00
|
|
|
const defaultForm = () => {
|
|
|
|
|
return {
|
2022-10-29 20:08:15 +08:00
|
|
|
id: null,
|
|
|
|
|
name: null,
|
|
|
|
|
username: null,
|
2025-04-15 21:42:31 +08:00
|
|
|
mobile: null,
|
|
|
|
|
email: null,
|
2024-11-20 22:43:53 +08:00
|
|
|
password: '',
|
2022-10-29 20:08:15 +08:00
|
|
|
repassword: null,
|
2025-04-15 21:42:31 +08:00
|
|
|
extra: {
|
|
|
|
|
qywxUserId: '',
|
|
|
|
|
feishuUserId: '',
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const state = reactive({
|
|
|
|
|
edit: false,
|
|
|
|
|
form: defaultForm(),
|
2021-06-07 17:22:07 +08:00
|
|
|
});
|
2022-10-29 20:08:15 +08:00
|
|
|
|
2025-04-15 21:42:31 +08:00
|
|
|
const { edit, form } = toRefs(state);
|
2023-12-11 01:00:09 +08:00
|
|
|
|
|
|
|
|
const { isFetching: saveBtnLoading, execute: saveAccountExec } = accountApi.save.useApi(form);
|
2022-10-29 20:08:15 +08:00
|
|
|
|
|
|
|
|
watch(props, (newValue: any) => {
|
|
|
|
|
if (newValue.account) {
|
|
|
|
|
state.form = { ...newValue.account };
|
2025-04-15 21:42:31 +08:00
|
|
|
if (!state.form.extra) {
|
|
|
|
|
state.form.extra = {} as any;
|
|
|
|
|
}
|
2022-10-29 20:08:15 +08:00
|
|
|
state.edit = true;
|
|
|
|
|
} else {
|
|
|
|
|
state.edit = false;
|
2025-04-15 21:42:31 +08:00
|
|
|
state.form = defaultForm();
|
2024-04-17 21:28:28 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
const btnOk = async () => {
|
2024-11-20 22:43:53 +08:00
|
|
|
await useI18nFormValidate(accountForm);
|
2024-05-10 19:59:49 +08:00
|
|
|
await saveAccountExec();
|
2024-11-20 22:43:53 +08:00
|
|
|
useI18nSaveSuccessMsg();
|
2024-05-10 19:59:49 +08:00
|
|
|
emit('val-change', state.form);
|
|
|
|
|
//重置表单域
|
|
|
|
|
accountForm.value.resetFields();
|
2022-10-29 20:08:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const cancel = () => {
|
2025-04-15 21:42:31 +08:00
|
|
|
visible.value = false;
|
2022-10-29 20:08:15 +08:00
|
|
|
emit('cancel');
|
|
|
|
|
};
|
2021-06-07 17:22:07 +08:00
|
|
|
</script>
|
2023-07-06 20:59:22 +08:00
|
|
|
<style lang="scss"></style>
|