Browse Source

弹窗

feature/user-0111
XinYuan 7 months ago
parent
commit
d62ff8f705
  1. 2
      components.d.ts
  2. 28
      src/pages/Index/Settings/Users.vue
  3. 77
      src/pages/Index/components/Setting/EnterPinModal.vue
  4. 6
      src/types/Index/User.ts

2
components.d.ts

@ -8,7 +8,6 @@ export {}
declare module 'vue' { declare module 'vue' {
export interface GlobalComponents { export interface GlobalComponents {
ElButton: typeof import('element-plus/es')['ElButton'] ElButton: typeof import('element-plus/es')['ElButton']
ElCol: typeof import('element-plus/es')['ElCol']
ElDropdown: typeof import('element-plus/es')['ElDropdown'] ElDropdown: typeof import('element-plus/es')['ElDropdown']
ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem'] ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem']
ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu'] ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu']
@ -17,7 +16,6 @@ declare module 'vue' {
ElIcon: typeof import('element-plus/es')['ElIcon'] ElIcon: typeof import('element-plus/es')['ElIcon']
ElInput: typeof import('element-plus/es')['ElInput'] ElInput: typeof import('element-plus/es')['ElInput']
ElPopover: typeof import('element-plus/es')['ElPopover'] ElPopover: typeof import('element-plus/es')['ElPopover']
ElRow: typeof import('element-plus/es')['ElRow']
ElTable: typeof import('element-plus/es')['ElTable'] ElTable: typeof import('element-plus/es')['ElTable']
ElTableColumn: typeof import('element-plus/es')['ElTableColumn'] ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
ErrorModal: typeof import('./src/components/dialogs/ErrorModal.vue')['default'] ErrorModal: typeof import('./src/components/dialogs/ErrorModal.vue')['default']

28
src/pages/Index/Settings/Users.vue

@ -26,8 +26,8 @@
:message="updatePinMessage" description="您正在更改PIN码,请谨慎操作" confirm-text="确认更新" cancel-text="取消更新" :message="updatePinMessage" description="您正在更改PIN码,请谨慎操作" confirm-text="确认更新" cancel-text="取消更新"
@confirm="handleConfirmUpdatePin" @cancel="handleCancelUpdatePin" /> @confirm="handleConfirmUpdatePin" @cancel="handleCancelUpdatePin" />
<EnterPinModal v-if="enterPinModal" :visible="enterPinModal" :loading="updatePinLoading" @confirm="updatePinConfirm"
@cancel="closeEnterPinModal" />
<EnterPinModal v-if="enterPinModal" :visible="enterPinModal" :loading="updatePinLoading" mode="edit" :userId="selectedUsers[0]?.id"
@confirm="updatePinConfirm" @cancel="closeEnterPinModal" />
<DelMessage v-if="updatePinMsgModal" :visible="updatePinMsgModal" icon="/src/assets/OK.svg" message="PIN码更新成功" <DelMessage v-if="updatePinMsgModal" :visible="updatePinMsgModal" icon="/src/assets/OK.svg" message="PIN码更新成功"
:username="selectedUsers[0].account" @confirm="handleConfirmMsg" /> :username="selectedUsers[0].account" @confirm="handleConfirmMsg" />
@ -39,7 +39,7 @@
</template> </template>
<template v-else-if="currentStep === 'pin'"> <template v-else-if="currentStep === 'pin'">
<EnterPinModal :visible="isPinModalVisible" :loading="registerLoading" @confirm="handlePinConfirm"
<EnterPinModal :visible="isPinModalVisible" :loading="registerLoading" mode="add" @confirm="handlePinConfirm"
@cancel="closeModal" /> @cancel="closeModal" />
</template> </template>
@ -190,39 +190,47 @@ const handleConfirmMsgDelete = () => {
//PIN //PIN
// //
const handleUpdatePin = async () => { const handleUpdatePin = async () => {
if (selectedUsers.value.length!== 1) {
if (selectedUsers.value.length !== 1) {
ElMessage.warning('请选择一个用户来修改PIN码') ElMessage.warning('请选择一个用户来修改PIN码')
return return
} }
const user = tempUser.value
const user = selectedUsers.value[0]
const response = await changeUserPassword({ const response = await changeUserPassword({
id: user.id, id: user.id,
password: user.password,
oldpasswd: tempUser.value.password, //
password: tempUser.value.password //
}) })
if (response && response.success) { if (response && response.success) {
ElMessage.success('PIN码更新成功') ElMessage.success('PIN码更新成功')
fetchUserList() fetchUserList()
} else { } else {
ElMessage.error('修改用户权限失败')
ElMessage.error('修改密码失败')
} }
} }
//pin //pin
const handleConfirmUpdatePin = () => { const handleConfirmUpdatePin = () => {
if (selectedUsers.value.length !== 1) {
ElMessage.warning('请选择一个用户来修改PIN码')
return
}
updatePinModal.value = false updatePinModal.value = false
enterPinModal.value = true enterPinModal.value = true
} }
//pin //pin
const updatePinConfirm = (val: string) => {
const updatePinConfirm = (parameters: ChangePasswordParams) => {
enterPinModal.value = false enterPinModal.value = false
updatePinLoading.value = true updatePinLoading.value = true
tempUser.value.password = val
handleUpdatePin().then(() => {
changeUserPassword(parameters).then(() => {
updatePinLoading.value = false updatePinLoading.value = false
updatePinMsgModal.value = true updatePinMsgModal.value = true
}).catch(() => {
ElMessage.error('修改密码失败')
updatePinLoading.value = false
}) })
} }

77
src/pages/Index/components/Setting/EnterPinModal.vue

@ -4,16 +4,37 @@
<div class="modal-container"> <div class="modal-container">
<div class="modal-header"></div> <div class="modal-header"></div>
<div class="modal-title"> <div class="modal-title">
<span class="title-text">请输入 PIN </span>
<span class="title-text">{{ mode === 'edit'? 'Parameters' : '请输入 PIN 码' }}</span>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="input-container"> <div class="input-container">
<input type="password" v-model="pin" placeholder="输入 PIN 码" class="pin-input" />
<div v-if="mode === 'edit'">
<input
type="password"
v-model="form.oldpasswd"
placeholder="oldpasswd"
class="pin-input"
/>
<input
type="password"
v-model="form.password"
placeholder="password"
class="pin-input"
/>
</div>
<div v-else>
<input
type="password"
v-model="pin"
placeholder="输入 PIN 码"
class="pin-input"
/>
</div>
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<el-button type="danger" @click="cancel">取消</el-button> <el-button type="danger" @click="cancel">取消</el-button>
<el-button type="primary" @click="confirmPin" :loading="loading">确认</el-button>
<el-button type="primary" @click="confirm" :loading="loading">确认</el-button>
</div> </div>
</div> </div>
</div> </div>
@ -21,21 +42,49 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue'
import { ref, reactive } from 'vue'
import { ChangePasswordParams } from '../../../../types/Index/User'
// props
const props = defineProps<{
visible: boolean;
loading: boolean;
userId?: number;
mode: 'edit' | 'add';
}>()
defineProps<{ visible: boolean; loading: boolean }>()
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'confirm', pin: string): void
(e: 'confirm', params: ChangePasswordParams | string): void
(e: 'cancel'): void (e: 'cancel'): void
}>() }>()
//
const form = reactive({
oldpasswd: '',
password: ''
})
const pin = ref('') const pin = ref('')
const confirmPin = () => {
emit('confirm', pin.value)
//
const confirm = () => {
if (props.mode === 'edit') {
const parameters: ChangePasswordParams = {
id: props.userId,
oldpasswd: form.oldpasswd,
password: form.password
}
emit('confirm', parameters)
} else {
emit('confirm', pin.value)
}
} }
//
const cancel = () => { const cancel = () => {
if (props.mode === 'edit') {
form.oldpasswd = ''
form.password = ''
}
emit('cancel') emit('cancel')
} }
</script> </script>
@ -80,7 +129,7 @@ const cancel = () => {
justify-content: center; justify-content: center;
position: relative; position: relative;
.modal-header {
.modal-header {
background-color: #528dfe; background-color: #528dfe;
height: 8px; height: 8px;
position: absolute; position: absolute;
@ -89,7 +138,7 @@ const cancel = () => {
width: 100%; width: 100%;
} }
.modal-title {
.modal-title {
text-align: center; text-align: center;
margin-top: 15px; margin-top: 15px;
font-size: 32px; font-size: 32px;
@ -97,16 +146,16 @@ const cancel = () => {
font-weight: bold; font-weight: bold;
} }
.modal-body {
.modal-body {
display: flex; display: flex;
justify-content: center; justify-content: center;
padding: 20px; padding: 20px;
.input-container {
.input-container {
position: relative; position: relative;
width: 100%; width: 100%;
.pin-input {
.pin-input {
box-sizing: border-box; box-sizing: border-box;
width: 100%; width: 100%;
font-size: 32px; font-size: 32px;
@ -124,7 +173,7 @@ const cancel = () => {
} }
} }
.modal-footer {
.modal-footer {
display: flex; display: flex;
justify-content: space-around; justify-content: space-around;
padding: 20px; padding: 20px;

6
src/types/Index/User.ts

@ -19,3 +19,9 @@ export interface CurrentUserInfo {
timestamp: number timestamp: number
success: boolean success: boolean
} }
export interface ChangePasswordParams {
id: number; // integer($int32)
oldpasswd: string; // string (query)
password: string; // string (query)
}
Loading…
Cancel
Save