修改账号信息
This commit is contained in:
@@ -59,3 +59,19 @@ export const googleAuth = (data: GoogleAuthParamsType): Promise<LoginResponse> =
|
|||||||
params: data
|
params: data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** 更改用户信息
|
||||||
|
* @param data 包含用户信息的对象
|
||||||
|
* @param data.username 用户名
|
||||||
|
* @param data.email 邮箱
|
||||||
|
* @param data.password 密码
|
||||||
|
* @returns 包含更新后的用户信息的对象
|
||||||
|
*/
|
||||||
|
export const updateUserInfo = (data: any) => {
|
||||||
|
return request({
|
||||||
|
url: '/api/auth/updateUserInfo',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, onMounted, inject } from 'vue'
|
import { ref, reactive, onMounted, inject } from 'vue'
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
import { showConfirmDialog } from 'vant'
|
import { showConfirmDialog, showToast } from 'vant'
|
||||||
import { useUserInfoStore, useOverallStore } from '@/stores'
|
import { useUserInfoStore, useOverallStore } from '@/stores'
|
||||||
import { LogOut } from '@/api/login'
|
import { LogOut } from '@/api/login'
|
||||||
import { getCustomerList, type CustomerListParams, customerCheckin } from '@/api/workshop'
|
import { getCustomerList, type CustomerListParams, customerCheckin } from '@/api/workshop'
|
||||||
import MyEvent from '@/utils/myEvent'
|
import MyEvent from '@/utils/myEvent'
|
||||||
|
import { encryptPassword } from '@/utils/tools'
|
||||||
|
import { updateUserInfo } from '@/api/login'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
isCustomer?: boolean
|
isCustomer?: boolean
|
||||||
@@ -17,11 +19,14 @@ const emit = defineEmits(['view-type', 'selected-customer'])
|
|||||||
const show = ref(false)
|
const show = ref(false)
|
||||||
const isEdit = ref(false)
|
const isEdit = ref(false)
|
||||||
const form = reactive({
|
const form = reactive({
|
||||||
name: { msg: '', value: userInfoStore.state.userInfo.username },
|
name: { msg: '', value: '' },
|
||||||
email: { msg: '', value: userInfoStore.state.userInfo.email },
|
email: { msg: '', value: '' },
|
||||||
// password: { show: false, msg: '', value: userInfoStore.state.userInfo.password }
|
password: { show: true, msg: '', value: '' }
|
||||||
})
|
})
|
||||||
const open = () => {
|
const open = () => {
|
||||||
|
form.name.value = userInfoStore.state.userInfo.username
|
||||||
|
form.email.value = userInfoStore.state.userInfo.email
|
||||||
|
form.password.value = ''
|
||||||
isEdit.value = false
|
isEdit.value = false
|
||||||
show.value = true
|
show.value = true
|
||||||
}
|
}
|
||||||
@@ -41,19 +46,37 @@ const switchCustomer = () => {
|
|||||||
handleShowPopup(true)
|
handleShowPopup(true)
|
||||||
}
|
}
|
||||||
const edit = () => {
|
const edit = () => {
|
||||||
|
form.password.value = ''
|
||||||
isEdit.value = true
|
isEdit.value = true
|
||||||
}
|
}
|
||||||
const confirm = () => {
|
const confirm = () => {
|
||||||
overallStore.setLoading(true)
|
const password = form.password.value
|
||||||
const params = {
|
const params = {
|
||||||
username: form.name.value,
|
username: form.name.value,
|
||||||
email: form.email.value,
|
email: form.email.value,
|
||||||
|
password
|
||||||
}
|
}
|
||||||
console.log(params)
|
if (password) {
|
||||||
setTimeout(() => {
|
if (password.length < 6) {
|
||||||
|
return showToast('Password must be at least 6 characters')
|
||||||
|
} else {
|
||||||
|
params.password = encryptPassword(password)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
params.password = userInfoStore.state.userInfo.password
|
||||||
|
}
|
||||||
|
|
||||||
|
overallStore.setLoading(true)
|
||||||
|
updateUserInfo(params).then((res) => {
|
||||||
overallStore.setLoading(false)
|
overallStore.setLoading(false)
|
||||||
|
showToast('Update success')
|
||||||
|
userInfoStore.setUserInfo({
|
||||||
|
...userInfoStore.state.userInfo,
|
||||||
|
...params
|
||||||
|
})
|
||||||
|
form.password.value = ''
|
||||||
isEdit.value = false
|
isEdit.value = false
|
||||||
}, 1000)
|
})
|
||||||
}
|
}
|
||||||
const logout = () => {
|
const logout = () => {
|
||||||
showConfirmDialog({
|
showConfirmDialog({
|
||||||
@@ -232,7 +255,7 @@ defineExpose({ open, close, openSwitchCustomerPopup })
|
|||||||
</label>
|
</label>
|
||||||
<p class="error" v-show="form.email.msg">{{ form.email.msg }}</p>
|
<p class="error" v-show="form.email.msg">{{ form.email.msg }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-item" v-if="form.password">
|
<div class="form-item" v-if="isEdit">
|
||||||
<div class="label">Password</div>
|
<div class="label">Password</div>
|
||||||
<label class="input">
|
<label class="input">
|
||||||
<div class="icon" @click="form.password.show = !form.password.show">
|
<div class="icon" @click="form.password.show = !form.password.show">
|
||||||
@@ -260,7 +283,7 @@ defineExpose({ open, close, openSwitchCustomerPopup })
|
|||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<button class="switch" @click="switchCustomer">Switch Customer</button>
|
<button class="switch" @click="switchCustomer">Switch Customer</button>
|
||||||
<!-- <button class="edit" @click="edit">Edit Profile</button> -->
|
<button class="edit" @click="edit">Edit Profile</button>
|
||||||
<button class="logout" @click="logout">Log out</button>
|
<button class="logout" @click="logout">Log out</button>
|
||||||
</template>
|
</template>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user