feat: ResetPwdModal

pull/4/MERGE
xingyuv 2023-03-29 18:25:23 +08:00
parent 7801fc6629
commit 8e7581c6cf
4 changed files with 84 additions and 25 deletions

View File

@ -12,30 +12,6 @@ export interface ListItem {
color?: string
}
// tab的list
export const settingList = [
{
key: '1',
name: '基本设置',
component: 'BaseSetting'
},
{
key: '2',
name: '安全设置',
component: 'SecureSetting'
},
{
key: '3',
name: '账号绑定',
component: 'AccountBind'
},
{
key: '4',
name: '新消息通知',
component: 'MsgNotify'
}
]
// 基础设置 form
export const baseSetschemas: FormSchema[] = [
{

View File

@ -0,0 +1,42 @@
<template>
<BasicModal v-bind="$attrs" @register="registerModal" title="重置密码" @ok="handleSubmit">
<BasicForm @register="registerForm" />
</BasicModal>
</template>
<script lang="ts" setup name="ResetPwdModal">
import { ref } from 'vue'
import { BasicModal, useModalInner } from '@/components/Modal'
import { BasicForm, useForm } from '@/components/Form'
import { userPwdFormSchema } from './user.data'
import { resetUserPwd } from '@/api/system/user'
const emit = defineEmits(['success', 'register'])
const userId = ref(0)
const [registerForm, { resetFields, validate }] = useForm({
labelWidth: 120,
baseColProps: { span: 24 },
schemas: userPwdFormSchema,
showActionButtonGroup: false,
actionColOptions: { span: 23 }
})
const [registerModal, { setModalProps, closeModal }] = useModalInner((data) => {
resetFields()
userId.value = data.record.id
setModalProps({ confirmLoading: false })
})
async function handleSubmit() {
try {
const values = await validate()
await resetUserPwd(userId.value, values.newPassword)
setModalProps({ confirmLoading: true })
closeModal()
emit('success')
} finally {
setModalProps({ confirmLoading: false })
}
}
</script>

View File

@ -47,6 +47,7 @@
</BasicTable>
<UserModal @register="registerModal" @success="reload()" />
<UserRoleModal @register="registerRoleModal" @success="reload()" />
<ResetPwdModal @register="registerPwdModal" @success="reload()" />
</div>
</template>
<script lang="ts" setup name="User">
@ -56,6 +57,7 @@ import { useMessage } from '@/hooks/web/useMessage'
import { useModal } from '@/components/Modal'
import UserModal from './UserModal.vue'
import UserRoleModal from './UserRoleModal.vue'
import ResetPwdModal from './ResetPwdModal.vue'
import DeptTree from './DeptTree.vue'
import { IconEnum } from '@/enums/appEnum'
import { BasicTable, useTable, TableAction } from '@/components/Table'
@ -66,6 +68,7 @@ const { t } = useI18n()
const { createConfirm, createMessage } = useMessage()
const [registerModal, { openModal }] = useModal()
const [registerRoleModal, { openModal: openRoleModal }] = useModal()
const [registerPwdModal, { openModal: openPwdModal }] = useModal()
const searchInfo = reactive<Recordable>({})
const [registerTable, { getForm, reload }] = useTable({
@ -118,7 +121,7 @@ function handleRole(record: Recordable) {
/** 重置密码按钮操作 */
function handleResetPwd(record: Recordable) {
openModal(true, { record, isUpdate: true })
openPwdModal(true, { record })
}
/** 删除按钮操作 */

View File

@ -232,3 +232,41 @@ export const userRoleFormSchema: FormSchema[] = [
}
}
]
export const userPwdFormSchema: FormSchema[] = [
{
field: 'newPassword',
label: '新密码',
component: 'StrengthMeter',
componentProps: {
placeholder: '新密码'
},
rules: [
{
required: true,
message: '请输入新密码'
}
]
},
{
field: 'confirmPassword',
label: '确认密码',
component: 'InputPassword',
dynamicRules: ({ values }) => {
return [
{
required: true,
validator: (_, value) => {
if (!value) {
return Promise.reject('密码不能为空')
}
if (value !== values.newPassword) {
return Promise.reject('两次输入的密码不一致!')
}
return Promise.resolve()
}
}
]
}
}
]