2021-06-07 17:22:07 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="account-dialog">
|
2022-06-16 15:55:18 +08:00
|
|
|
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :show-close="false" width="35%" :destroy-on-close="true">
|
2022-01-12 16:00:31 +08:00
|
|
|
<el-form :model="form" ref="accountForm" :rules="rules" label-width="85px">
|
2021-06-07 17:22:07 +08:00
|
|
|
<el-form-item prop="username" label="用户名:" required>
|
2022-07-10 12:14:06 +08:00
|
|
|
<el-input :disabled="edit" v-model.trim="form.username" placeholder="请输入账号用户名,密码默认与账号名一致" auto-complete="off"></el-input>
|
2021-06-07 17:22:07 +08:00
|
|
|
</el-form-item>
|
2022-08-26 20:15:36 +08:00
|
|
|
<el-form-item v-if="edit" prop="password" label="密码:" required>
|
2021-06-07 17:22:07 +08:00
|
|
|
<el-input type="password" v-model.trim="form.password" placeholder="请输入密码" autocomplete="new-password"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
<div class="dialog-footer">
|
2022-01-12 16:00:31 +08:00
|
|
|
<el-button @click="cancel()">取 消</el-button>
|
|
|
|
|
<el-button type="primary" :loading="btnLoading" @click="btnOk">确 定</el-button>
|
2021-06-07 17:22:07 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
|
|
|
|
|
import { accountApi } from '../api';
|
|
|
|
|
import { ElMessage } from 'element-plus';
|
|
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
name: 'AccountEdit',
|
|
|
|
|
props: {
|
|
|
|
|
visible: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
},
|
|
|
|
|
account: {
|
|
|
|
|
type: [Boolean, Object],
|
|
|
|
|
},
|
|
|
|
|
title: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
setup(props: any, { emit }) {
|
|
|
|
|
const accountForm: any = ref(null);
|
|
|
|
|
const state = reactive({
|
2021-09-08 17:55:57 +08:00
|
|
|
dialogVisible: false,
|
2021-06-07 17:22:07 +08:00
|
|
|
edit: false,
|
|
|
|
|
form: {
|
|
|
|
|
id: null,
|
|
|
|
|
username: null,
|
|
|
|
|
password: null,
|
|
|
|
|
repassword: null,
|
|
|
|
|
},
|
|
|
|
|
btnLoading: false,
|
|
|
|
|
rules: {
|
|
|
|
|
username: [
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
|
message: '请输入用户名',
|
|
|
|
|
trigger: ['change', 'blur'],
|
|
|
|
|
},
|
|
|
|
|
],
|
2021-07-28 18:03:19 +08:00
|
|
|
// password: [
|
|
|
|
|
// {
|
|
|
|
|
// required: true,
|
|
|
|
|
// message: '请输入密码',
|
|
|
|
|
// trigger: ['change', 'blur'],
|
|
|
|
|
// },
|
|
|
|
|
// ],
|
2021-06-07 17:22:07 +08:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2021-09-08 17:55:57 +08:00
|
|
|
watch(props, (newValue) => {
|
2021-06-07 17:22:07 +08:00
|
|
|
if (newValue.account) {
|
|
|
|
|
state.form = { ...newValue.account };
|
2022-08-26 20:15:36 +08:00
|
|
|
state.edit = true;
|
2021-06-07 17:22:07 +08:00
|
|
|
} else {
|
|
|
|
|
state.form = {} as any;
|
|
|
|
|
}
|
2021-09-08 17:55:57 +08:00
|
|
|
state.dialogVisible = newValue.visible;
|
2021-06-07 17:22:07 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const btnOk = async () => {
|
|
|
|
|
accountForm.value.validate((valid: boolean) => {
|
|
|
|
|
if (valid) {
|
2022-08-26 20:15:36 +08:00
|
|
|
accountApi.save.request(state.form).then(() => {
|
2021-06-07 17:22:07 +08:00
|
|
|
ElMessage.success('操作成功');
|
|
|
|
|
emit('val-change', state.form);
|
|
|
|
|
state.btnLoading = true;
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
state.btnLoading = false;
|
|
|
|
|
}, 1000);
|
|
|
|
|
//重置表单域
|
2022-04-22 17:49:21 +08:00
|
|
|
accountForm.value.resetFields();
|
2021-06-07 17:22:07 +08:00
|
|
|
state.form = {} as any;
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
ElMessage.error('表单填写有误');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const cancel = () => {
|
|
|
|
|
emit('update:visible', false);
|
|
|
|
|
emit('cancel');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...toRefs(state),
|
|
|
|
|
accountForm,
|
|
|
|
|
btnOk,
|
|
|
|
|
cancel,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
</style>
|