修改密码
This commit is contained in:
parent
33e4cd45f3
commit
43b9a54b6a
|
|
@ -23,4 +23,6 @@ export function userBindMobile(data: any) {
|
|||
export function userMnpMobile(data: any) {
|
||||
return request.post({ url: '/user/mnpMobile', data: data })
|
||||
}
|
||||
|
||||
export function userChangePwd(data: any) {
|
||||
return request.post({ url: '/user/changePwd', data: data })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +1,67 @@
|
|||
<template>
|
||||
<view class="">
|
||||
<u-parse :html="agreementContent"></u-parse>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<template>
|
||||
<view
|
||||
class="register bg-white min-h-full flex flex-col items-center px-[40rpx] pt-[100rpx] box-border"
|
||||
>
|
||||
<view class="w-full">
|
||||
<view class="text-2xl font-medium mb-[60rpx]">修改登录密码</view>
|
||||
<u-form borderBottom :label-width="150">
|
||||
<u-form-item label="原密码" borderBottom>
|
||||
<u-input
|
||||
class="flex-1"
|
||||
v-model="formData.oldPassword"
|
||||
:border="false"
|
||||
placeholder="请输入原来的密码"
|
||||
/>
|
||||
</u-form-item>
|
||||
<u-form-item label="新密码" borderBottom>
|
||||
<u-input
|
||||
class="flex-1"
|
||||
type="password"
|
||||
v-model="formData.password"
|
||||
placeholder="6-20位数字+字母或符号组合"
|
||||
:border="false"
|
||||
/>
|
||||
</u-form-item>
|
||||
<u-form-item label="确认密码" borderBottom>
|
||||
<u-input
|
||||
class="flex-1"
|
||||
type="password"
|
||||
v-model="formData.password2"
|
||||
placeholder="再次输入新密码"
|
||||
:border="false"
|
||||
/>
|
||||
</u-form-item>
|
||||
</u-form>
|
||||
<view class="mt-[100rpx]">
|
||||
<u-button type="primary" shape="circle" @click="handleConfirm"> 确定 </u-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from 'vue'
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { AgreementEnum } from '@/enums/agreementEnums'
|
||||
import { getPolicy } from '@/api/app'
|
||||
|
||||
let agreementType = ref('') // 协议类型
|
||||
let agreementContent = ref('') // 协议内容
|
||||
// let agreementName = ref('') // 协议名称
|
||||
|
||||
const getData = async (type) => {
|
||||
let res = await getPolicy({ type })
|
||||
console.log(res, 'res')
|
||||
|
||||
agreementContent.value = res.content
|
||||
|
||||
uni.setNavigationBarTitle({
|
||||
title: res.name
|
||||
})
|
||||
}
|
||||
|
||||
onLoad((options: any) => {
|
||||
if(options.type) {
|
||||
agreementType.value = options.type
|
||||
getData(agreementType)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
import { userChangePwd } from '@/api/user'
|
||||
import { reactive } from 'vue'
|
||||
|
||||
const formData = reactive({
|
||||
oldPassword: '',
|
||||
password: '',
|
||||
password2: ''
|
||||
})
|
||||
|
||||
const handleConfirm = async () => {
|
||||
if (!formData.oldPassword) return uni.$u.toast('请输入原来的密码')
|
||||
if (!formData.password) return uni.$u.toast('请输入密码')
|
||||
if (!formData.password2) return uni.$u.toast('请输入确认密码')
|
||||
if (formData.password != formData.password2) return uni.$u.toast('两次输入的密码不一致')
|
||||
await userChangePwd(formData)
|
||||
uni.$u.toast('操作成功')
|
||||
uni.navigateBack()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
page {
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
class="register bg-white min-h-full flex flex-col items-center px-[40rpx] pt-[100rpx] box-border"
|
||||
>
|
||||
<view class="w-full">
|
||||
<view class="text-2xl font-medium mb-[100rpx]">忘记登录密码</view>
|
||||
<view class="text-2xl font-medium mb-[60rpx]">忘记登录密码</view>
|
||||
<u-form borderBottom :label-width="150">
|
||||
<u-form-item label="手机号" borderBottom>
|
||||
<u-input
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ const getData = async () => {
|
|||
state.pages = JSON.parse(data.pages)
|
||||
state.article = data.article
|
||||
}
|
||||
|
||||
getData()
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ import { SMSEnum } from '@/enums/appEnums'
|
|||
import { useLockFn } from '@/hooks/useLockFn'
|
||||
import { useAppStore } from '@/stores/app'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { currentPage } from '@/utils/util'
|
||||
import { reactive, ref, shallowRef } from 'vue'
|
||||
enum LoginTypeEnum {
|
||||
MOBILE = 'mobile',
|
||||
|
|
@ -197,7 +198,14 @@ const loginFun = async (scene: LoginTypeEnum, code?: string) => {
|
|||
await userStore.getUser()
|
||||
uni.$u.toast('登录成功')
|
||||
uni.hideLoading()
|
||||
uni.navigateBack()
|
||||
uni.navigateBack({
|
||||
success: () => {
|
||||
// @ts-ignore
|
||||
const { onLoad, options } = currentPage()
|
||||
// 刷新上一个页面
|
||||
onLoad && onLoad(options)
|
||||
}
|
||||
})
|
||||
} catch (error: any) {
|
||||
uni.hideLoading()
|
||||
throw new Error(error)
|
||||
|
|
|
|||
|
|
@ -1,353 +1,350 @@
|
|||
<template>
|
||||
<!-- Main Start -->
|
||||
<!-- 头部修改头像 -->
|
||||
<view class="header bg-white pt-[30rpx]">
|
||||
<view class="flex justify-center">
|
||||
<image @click="uploaderAvatar" :src="userInfo?.avatar"></image>
|
||||
</view>
|
||||
<view class="mt-[20rpx] text-center text-muted text-xs" @click="uploaderAvatar">点击修改头像</view>
|
||||
</view>
|
||||
<!-- Main Start -->
|
||||
<!-- 头部修改头像 -->
|
||||
<view class="header bg-white pt-[30rpx]">
|
||||
<view class="flex justify-center">
|
||||
<image @click="uploaderAvatar" :src="userInfo?.avatar"></image>
|
||||
</view>
|
||||
<view class="mt-[20rpx] text-center text-muted text-xs" @click="uploaderAvatar"
|
||||
>点击修改头像</view
|
||||
>
|
||||
</view>
|
||||
|
||||
<!-- 用户ID -->
|
||||
<view class="item text-nr flex justify-between" @click="(showUserName = true), (newUsername = userInfo?.username)">
|
||||
<view class="label">账号</view>
|
||||
<view class="content">{{ userInfo?.username }}</view>
|
||||
<u-icon name="arrow-right" size="22"></u-icon>
|
||||
</view>
|
||||
<!-- 用户ID -->
|
||||
<view
|
||||
class="item text-nr flex justify-between"
|
||||
@click=";(showUserName = true), (newUsername = userInfo?.username)"
|
||||
>
|
||||
<view class="label">账号</view>
|
||||
<view class="content">{{ userInfo?.username }}</view>
|
||||
<u-icon name="arrow-right" size="22"></u-icon>
|
||||
</view>
|
||||
|
||||
<!-- 昵称 -->
|
||||
<view class="item text-nr flex justify-between" @click="(showNickName = true), (newNickname = userInfo?.nickname)">
|
||||
<view class="label">昵称</view>
|
||||
<view class="content">{{ userInfo?.nickname }}</view>
|
||||
<u-icon name="arrow-right" size="22"></u-icon>
|
||||
</view>
|
||||
<!-- 昵称 -->
|
||||
<view
|
||||
class="item text-nr flex justify-between"
|
||||
@click=";(showNickName = true), (newNickname = userInfo?.nickname)"
|
||||
>
|
||||
<view class="label">昵称</view>
|
||||
<view class="content">{{ userInfo?.nickname }}</view>
|
||||
<u-icon name="arrow-right" size="22"></u-icon>
|
||||
</view>
|
||||
|
||||
<!-- 性别 -->
|
||||
<view class="item text-nr flex justify-between" @click="changeSex">
|
||||
<view class="label">性别</view>
|
||||
<view class="content">{{ userInfo?.sex }}</view>
|
||||
<u-icon name="arrow-right" size="22"></u-icon>
|
||||
</view>
|
||||
<!-- 性别 -->
|
||||
<view class="item text-nr flex justify-between" @click="changeSex">
|
||||
<view class="label">性别</view>
|
||||
<view class="content">{{ userInfo?.sex }}</view>
|
||||
<u-icon name="arrow-right" size="22"></u-icon>
|
||||
</view>
|
||||
|
||||
<!-- 手机号 -->
|
||||
<view class="item text-nr flex justify-between">
|
||||
<view class="label">手机号</view>
|
||||
<view class="content">{{ userInfo?.mobile == '' ? '未绑定手机号' : userInfo?.mobile }}</view>
|
||||
<!-- 手机号 -->
|
||||
<view class="item text-nr flex justify-between">
|
||||
<view class="label">手机号</view>
|
||||
<view class="content">{{
|
||||
userInfo?.mobile == '' ? '未绑定手机号' : userInfo?.mobile
|
||||
}}</view>
|
||||
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<u-button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" size="mini" type="primary" shape="circle" :plain="true">
|
||||
{{ userInfo?.mobile == '' ? '绑定手机号' : '更换手机号' }}
|
||||
</u-button>
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef MP-WEIXIN -->
|
||||
<u-button @click="" size="mini" type="primary" shape="circle" :plain="true">
|
||||
{{ userInfo?.mobile == '' ? '绑定手机号' : '更换手机号' }}
|
||||
</u-button>
|
||||
<!-- #endif -->
|
||||
</view>
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<u-button
|
||||
open-type="getPhoneNumber"
|
||||
@getphonenumber="getPhoneNumber"
|
||||
size="mini"
|
||||
type="primary"
|
||||
shape="circle"
|
||||
:plain="true"
|
||||
>
|
||||
{{ userInfo?.mobile == '' ? '绑定手机号' : '更换手机号' }}
|
||||
</u-button>
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef MP-WEIXIN -->
|
||||
<u-button @click="" size="mini" type="primary" shape="circle" :plain="true">
|
||||
{{ userInfo?.mobile == '' ? '绑定手机号' : '更换手机号' }}
|
||||
</u-button>
|
||||
<!-- #endif -->
|
||||
</view>
|
||||
|
||||
<!-- 注册时间 -->
|
||||
<view class="item text-nr flex justify-between">
|
||||
<view class="label">注册时间</view>
|
||||
<view class="content">{{ userInfo?.createTime }}</view>
|
||||
</view>
|
||||
<!-- 注册时间 -->
|
||||
<view class="item text-nr flex justify-between">
|
||||
<view class="label">注册时间</view>
|
||||
<view class="content">{{ userInfo?.createTime }}</view>
|
||||
</view>
|
||||
|
||||
<!-- 昵称修改组件 -->
|
||||
<u-popup v-model="showNickName" :closeable="true" mode="center" border-radius="20">
|
||||
<view class="px-[50rpx] py-[40rpx] bg-white" style="width: 85vw">
|
||||
<view class="mb-[70rpx] text-xl text-center">修改昵称</view>
|
||||
<u-field v-model="newNickname" label="新昵称" placeholder="请输入新的昵称"> </u-field>
|
||||
<view class="mt-[80rpx]">
|
||||
<u-button @click="changeNameConfirm" type="primary" shape="circle">
|
||||
确定
|
||||
</u-button>
|
||||
</view>
|
||||
</view>
|
||||
</u-popup>
|
||||
|
||||
<!-- 账号修改组件 -->
|
||||
<u-popup v-model="showUserName" :closeable="true" mode="center" border-radius="20">
|
||||
<view class="px-[50rpx] py-[40rpx] bg-white" style="width: 85vw">
|
||||
<view class="mb-[70rpx] text-xl text-center">修改账号</view>
|
||||
<u-field v-model="newUsername" label="新账号" placeholder="请输入新的账号"> </u-field>
|
||||
<view class="mt-[80rpx]">
|
||||
<u-button @click="changeUserNameConfirm" type="primary" shape="circle">
|
||||
确定
|
||||
</u-button>
|
||||
</view>
|
||||
</view>
|
||||
</u-popup>
|
||||
<!-- 昵称修改组件 -->
|
||||
<u-popup v-model="showNickName" :closeable="true" mode="center" border-radius="20">
|
||||
<view class="px-[50rpx] py-[40rpx] bg-white" style="width: 85vw">
|
||||
<view class="mb-[70rpx] text-xl text-center">修改昵称</view>
|
||||
<u-field v-model="newNickname" label="新昵称" placeholder="请输入新的昵称"> </u-field>
|
||||
<view class="mt-[80rpx]">
|
||||
<u-button @click="changeNameConfirm" type="primary" shape="circle"> 确定 </u-button>
|
||||
</view>
|
||||
</view>
|
||||
</u-popup>
|
||||
|
||||
<!-- 性别修改组件 -->
|
||||
<u-picker mode="selector" v-model="showPicker" confirm-color="#4173FF" :default-selector="[0]" :range="sexList"
|
||||
@confirm="changeSexConfirm" />
|
||||
|
||||
<!-- 账号修改组件 -->
|
||||
<u-popup v-model="showMobilePop" :closeable="true" mode="center" border-radius="20">
|
||||
<view class="px-[50rpx] py-[40rpx] bg-white" style="width: 85vw">
|
||||
<view class="mb-[70rpx] text-xl text-center">修改手机号码</view>
|
||||
<u-form-item borderBottom>
|
||||
<u-input
|
||||
class="flex-1"
|
||||
v-model="newMobile"
|
||||
placeholder="请输入新的手机号码"
|
||||
:border="false"
|
||||
/>
|
||||
</u-form-item>
|
||||
<u-form-item borderBottom>
|
||||
<u-input
|
||||
class="flex-1"
|
||||
v-model="mobileCode"
|
||||
placeholder="请输入验证码"
|
||||
:border="false"
|
||||
/>
|
||||
<view
|
||||
class="border-l border-solid border-0 border-light pl-3 text-muted leading-4 ml-3 w-[180rpx]"
|
||||
@click="sendSms"
|
||||
>
|
||||
<u-verification-code
|
||||
ref="uCodeRef"
|
||||
:seconds="60"
|
||||
@change="codeChange"
|
||||
change-text="x秒"
|
||||
/>
|
||||
{{ codeTips }}
|
||||
</view>
|
||||
</u-form-item>
|
||||
<view class="mt-[80rpx]">
|
||||
<u-button @click="changeCodeMobile" type="primary" shape="circle">
|
||||
确定
|
||||
</u-button>
|
||||
</view>
|
||||
</view>
|
||||
</u-popup>
|
||||
<!-- 账号修改组件 -->
|
||||
<u-popup v-model="showUserName" :closeable="true" mode="center" border-radius="20">
|
||||
<view class="px-[50rpx] py-[40rpx] bg-white" style="width: 85vw">
|
||||
<view class="mb-[70rpx] text-xl text-center">修改账号</view>
|
||||
<u-field v-model="newUsername" label="新账号" placeholder="请输入新的账号"> </u-field>
|
||||
<view class="mt-[80rpx]">
|
||||
<u-button @click="changeUserNameConfirm" type="primary" shape="circle">
|
||||
确定
|
||||
</u-button>
|
||||
</view>
|
||||
</view>
|
||||
</u-popup>
|
||||
|
||||
<!-- 性别修改组件 -->
|
||||
<u-picker
|
||||
mode="selector"
|
||||
v-model="showPicker"
|
||||
confirm-color="#4173FF"
|
||||
:default-selector="[0]"
|
||||
:range="sexList"
|
||||
@confirm="changeSexConfirm"
|
||||
/>
|
||||
|
||||
<!-- 账号修改组件 -->
|
||||
<u-popup v-model="showMobilePop" :closeable="true" mode="center" border-radius="20">
|
||||
<view class="px-[50rpx] py-[40rpx] bg-white" style="width: 85vw">
|
||||
<view class="mb-[70rpx] text-xl text-center">修改手机号码</view>
|
||||
<u-form-item borderBottom>
|
||||
<u-input
|
||||
class="flex-1"
|
||||
v-model="newMobile"
|
||||
placeholder="请输入新的手机号码"
|
||||
:border="false"
|
||||
/>
|
||||
</u-form-item>
|
||||
<u-form-item borderBottom>
|
||||
<u-input
|
||||
class="flex-1"
|
||||
v-model="mobileCode"
|
||||
placeholder="请输入验证码"
|
||||
:border="false"
|
||||
/>
|
||||
<view
|
||||
class="border-l border-solid border-0 border-light pl-3 text-muted leading-4 ml-3 w-[180rpx]"
|
||||
@click="sendSms"
|
||||
>
|
||||
<u-verification-code
|
||||
ref="uCodeRef"
|
||||
:seconds="60"
|
||||
@change="codeChange"
|
||||
change-text="x秒"
|
||||
/>
|
||||
{{ codeTips }}
|
||||
</view>
|
||||
</u-form-item>
|
||||
<view class="mt-[80rpx]">
|
||||
<u-button @click="changeCodeMobile" type="primary" shape="circle"> 确定 </u-button>
|
||||
</view>
|
||||
</view>
|
||||
</u-popup>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import {
|
||||
ref,
|
||||
shallowRef,
|
||||
} from 'vue'
|
||||
import {
|
||||
onShow,
|
||||
onUnload
|
||||
} from '@dcloudio/uni-app'
|
||||
import {
|
||||
getUserInfo,
|
||||
userEdit,
|
||||
userBindMobile,
|
||||
userMnpMobile,
|
||||
} from '@/api/user.ts'
|
||||
import { smsSend } from '@/api/app'
|
||||
import {
|
||||
FieldType,
|
||||
SMSEnum,
|
||||
} from '@/enums/appEnums'
|
||||
import {
|
||||
uploadFile
|
||||
} from '@/utils/util.ts'
|
||||
import { ref, shallowRef } from 'vue'
|
||||
import { onShow, onUnload } from '@dcloudio/uni-app'
|
||||
import { getUserInfo, userEdit, userBindMobile, userMnpMobile } from '@/api/user.ts'
|
||||
import { smsSend } from '@/api/app'
|
||||
import { FieldType, SMSEnum } from '@/enums/appEnums'
|
||||
import { uploadFile } from '@/utils/util.ts'
|
||||
|
||||
// 用户信息
|
||||
let userInfo = ref < any | null > (null)
|
||||
// 用户信息的枚举
|
||||
const fieldType = ref(FieldType.NONE)
|
||||
//选择性别数据
|
||||
const sexList = ref < Array < string > | null > (['男', '女'])
|
||||
|
||||
//显示昵称弹窗
|
||||
const showNickName = ref < boolean | null >(false)
|
||||
//显示账户弹窗
|
||||
const showUserName = ref < boolean | null >(false)
|
||||
//显示性别选择弹窗
|
||||
const showPicker = ref < boolean | null >(false)
|
||||
// 显示手机号验证码调整弹窗 非小程序才需要
|
||||
const showMobilePop = ref < boolean | null > (false)
|
||||
|
||||
//新昵称
|
||||
const newNickname = ref < string > ('')
|
||||
//新账号
|
||||
const newUsername = ref < string > ('')
|
||||
//新的手机号码
|
||||
const newMobile = ref < string > ('')
|
||||
|
||||
//修改手机验证码
|
||||
const mobileCode = ref <string > ('')
|
||||
const codeTips = ref('')
|
||||
const uCodeRef = shallowRef()
|
||||
|
||||
|
||||
// 获取用户信息
|
||||
const getUser = async (): Promise < void > => {
|
||||
userInfo.value = await getUserInfo()
|
||||
}
|
||||
|
||||
// 获取验证码显示字段
|
||||
const codeChange = (text: string) => {
|
||||
codeTips.value = text
|
||||
}
|
||||
|
||||
// 发送验证码
|
||||
const sendSms = async () => {
|
||||
if (!newMobile.value) return uni.$u.toast('请输入新的手机号码')
|
||||
if (uCodeRef.value?.canGetCode) {
|
||||
await smsSend({
|
||||
scene: userInfo.mobile ? SMSEnum.CHANGE_MOBILE : SMSEnum.BIND_MOBILE,
|
||||
mobile: newMobile.value
|
||||
})
|
||||
uni.$u.toast('发送成功')
|
||||
uCodeRef.value?.start()
|
||||
}
|
||||
}
|
||||
|
||||
// 验证码修改手机号-非微信小程序
|
||||
const changeCodeMobile = async () => {
|
||||
await userBindMobile({
|
||||
type: userInfo.mobile ? 'change' : 'bind',
|
||||
mobile: newMobile.value,
|
||||
code: mobileCode.value,
|
||||
})
|
||||
getUser()
|
||||
}
|
||||
|
||||
|
||||
// 修改用户信息
|
||||
const setUserInfoFun = async (value: string): Promise < void > => {
|
||||
await userEdit({
|
||||
field: fieldType.value,
|
||||
value: value,
|
||||
})
|
||||
getUser()
|
||||
}
|
||||
|
||||
// 上传头像
|
||||
const uploaderAvatar = () => {
|
||||
fieldType.value = FieldType.AVATAR
|
||||
uni.navigateTo({
|
||||
url: '/uni_modules/vk-uview-ui/components/u-avatar-cropper/u-avatar-cropper?destWidth=300&rectWidth=200&fileType=jpg',
|
||||
})
|
||||
}
|
||||
|
||||
// 显示修改用户性别弹窗
|
||||
const changeSex = () => {
|
||||
showPicker.value = true
|
||||
fieldType.value = FieldType.SEX
|
||||
}
|
||||
|
||||
// 修改用户性别
|
||||
const changeSexConfirm = (value) => {
|
||||
setUserInfoFun(value[0] + 1)
|
||||
showPicker.value = false
|
||||
}
|
||||
|
||||
// 修改用户账号
|
||||
const changeUserNameConfirm = () => {
|
||||
if (newUsername.value == '') return uni.$u.toast('账号不能为空')
|
||||
if (newUsername.value.length > 10) return uni.$u.toast('账号长度不得超过十位数')
|
||||
|
||||
fieldType.value = FieldType.USERNAME
|
||||
setUserInfoFun(newUsername.value)
|
||||
showUserName.value = false
|
||||
}
|
||||
|
||||
// 修改用户昵称
|
||||
const changeNameConfirm = () => {
|
||||
if (newNickname.value == '') return uni.$u.toast('昵称不能为空')
|
||||
if (newNickname.value.length > 10) return uni.$u.toast('昵称长度不得超过十位数')
|
||||
showNickName.value = false
|
||||
fieldType.value = FieldType.NICKNAME
|
||||
setUserInfoFun(newNickname.value)
|
||||
}
|
||||
|
||||
// 微信小程序 绑定||修改用户手机号
|
||||
const getPhoneNumber = async (e): Promise < void > => {
|
||||
fieldType.value = FieldType.MOBILE
|
||||
const {
|
||||
encryptedData,
|
||||
iv,
|
||||
code,
|
||||
} = e.detail
|
||||
let data = {
|
||||
code,
|
||||
encrypted_data: encryptedData,
|
||||
iv,
|
||||
}
|
||||
if (encryptedData) {
|
||||
await userMnpMobile({
|
||||
...data
|
||||
})
|
||||
getUser()
|
||||
}
|
||||
}
|
||||
// 用户信息
|
||||
const userInfo = ref<any | null>(null)
|
||||
// 用户信息的枚举
|
||||
const fieldType = ref(FieldType.NONE)
|
||||
//选择性别数据
|
||||
const sexList = ref<Array<string> | null>(['男', '女'])
|
||||
|
||||
const goPage = (url: string) => {
|
||||
uni.navigateTo({
|
||||
url: url,
|
||||
})
|
||||
}
|
||||
//显示昵称弹窗
|
||||
const showNickName = ref<boolean | null>(false)
|
||||
//显示账户弹窗
|
||||
const showUserName = ref<boolean | null>(false)
|
||||
//显示性别选择弹窗
|
||||
const showPicker = ref<boolean | null>(false)
|
||||
// 显示手机号验证码调整弹窗 非小程序才需要
|
||||
const showMobilePop = ref<boolean | null>(false)
|
||||
|
||||
// 监听从裁剪页发布的事件,获得裁剪结果
|
||||
uni.$on('uAvatarCropper', (path) => {
|
||||
uni.showLoading({
|
||||
title: '正在上传中...',
|
||||
mask: true,
|
||||
})
|
||||
uploadFile(path)
|
||||
.then((res) => {
|
||||
uni.hideLoading()
|
||||
setUserInfoFun(res.url)
|
||||
})
|
||||
.catch(() => {
|
||||
uni.hideLoading()
|
||||
uni.$u.toast('上传失败')
|
||||
})
|
||||
})
|
||||
//新昵称
|
||||
const newNickname = ref<string>('')
|
||||
//新账号
|
||||
const newUsername = ref<string>('')
|
||||
//新的手机号码
|
||||
const newMobile = ref<string>('')
|
||||
|
||||
onShow(async () => {
|
||||
getUser()
|
||||
})
|
||||
|
||||
onUnload(() => {
|
||||
uni.$off('uAvatarCropper')
|
||||
})
|
||||
//修改手机验证码
|
||||
const mobileCode = ref<string>('')
|
||||
const codeTips = ref('')
|
||||
const uCodeRef = shallowRef()
|
||||
|
||||
// 获取用户信息
|
||||
const getUser = async (): Promise<void> => {
|
||||
userInfo.value = await getUserInfo()
|
||||
}
|
||||
|
||||
// 获取验证码显示字段
|
||||
const codeChange = (text: string) => {
|
||||
codeTips.value = text
|
||||
}
|
||||
|
||||
// 发送验证码
|
||||
const sendSms = async () => {
|
||||
if (!newMobile.value) return uni.$u.toast('请输入新的手机号码')
|
||||
if (uCodeRef.value?.canGetCode) {
|
||||
await smsSend({
|
||||
scene: userInfo.value.mobile ? SMSEnum.CHANGE_MOBILE : SMSEnum.BIND_MOBILE,
|
||||
mobile: newMobile.value
|
||||
})
|
||||
uni.$u.toast('发送成功')
|
||||
uCodeRef.value?.start()
|
||||
}
|
||||
}
|
||||
|
||||
// 验证码修改手机号-非微信小程序
|
||||
const changeCodeMobile = async () => {
|
||||
await userBindMobile({
|
||||
type: userInfo.value.mobile ? 'change' : 'bind',
|
||||
mobile: newMobile.value,
|
||||
code: mobileCode.value
|
||||
})
|
||||
getUser()
|
||||
}
|
||||
|
||||
// 修改用户信息
|
||||
const setUserInfoFun = async (value: string): Promise<void> => {
|
||||
await userEdit({
|
||||
field: fieldType.value,
|
||||
value: value
|
||||
})
|
||||
getUser()
|
||||
}
|
||||
|
||||
// 上传头像
|
||||
const uploaderAvatar = () => {
|
||||
fieldType.value = FieldType.AVATAR
|
||||
uni.navigateTo({
|
||||
url: '/uni_modules/vk-uview-ui/components/u-avatar-cropper/u-avatar-cropper?destWidth=300&rectWidth=200&fileType=jpg'
|
||||
})
|
||||
}
|
||||
|
||||
// 显示修改用户性别弹窗
|
||||
const changeSex = () => {
|
||||
showPicker.value = true
|
||||
fieldType.value = FieldType.SEX
|
||||
}
|
||||
|
||||
// 修改用户性别
|
||||
const changeSexConfirm = (value) => {
|
||||
setUserInfoFun(value[0] + 1)
|
||||
showPicker.value = false
|
||||
}
|
||||
|
||||
// 修改用户账号
|
||||
const changeUserNameConfirm = () => {
|
||||
if (newUsername.value == '') return uni.$u.toast('账号不能为空')
|
||||
if (newUsername.value.length > 10) return uni.$u.toast('账号长度不得超过十位数')
|
||||
|
||||
fieldType.value = FieldType.USERNAME
|
||||
setUserInfoFun(newUsername.value)
|
||||
showUserName.value = false
|
||||
}
|
||||
|
||||
// 修改用户昵称
|
||||
const changeNameConfirm = () => {
|
||||
if (newNickname.value == '') return uni.$u.toast('昵称不能为空')
|
||||
if (newNickname.value.length > 10) return uni.$u.toast('昵称长度不得超过十位数')
|
||||
showNickName.value = false
|
||||
fieldType.value = FieldType.NICKNAME
|
||||
setUserInfoFun(newNickname.value)
|
||||
}
|
||||
|
||||
// 微信小程序 绑定||修改用户手机号
|
||||
const getPhoneNumber = async (e): Promise<void> => {
|
||||
fieldType.value = FieldType.MOBILE
|
||||
const { encryptedData, iv, code } = e.detail
|
||||
const data = {
|
||||
code,
|
||||
encrypted_data: encryptedData,
|
||||
iv
|
||||
}
|
||||
if (encryptedData) {
|
||||
await userMnpMobile({
|
||||
...data
|
||||
})
|
||||
getUser()
|
||||
}
|
||||
}
|
||||
|
||||
const goPage = (url: string) => {
|
||||
uni.navigateTo({
|
||||
url: url
|
||||
})
|
||||
}
|
||||
|
||||
// 监听从裁剪页发布的事件,获得裁剪结果
|
||||
uni.$on('uAvatarCropper', (path) => {
|
||||
uni.showLoading({
|
||||
title: '正在上传中...',
|
||||
mask: true
|
||||
})
|
||||
uploadFile(path)
|
||||
.then((res) => {
|
||||
uni.hideLoading()
|
||||
setUserInfoFun(res.url)
|
||||
})
|
||||
.catch(() => {
|
||||
uni.hideLoading()
|
||||
uni.$u.toast('上传失败')
|
||||
})
|
||||
})
|
||||
|
||||
onShow(async () => {
|
||||
getUser()
|
||||
})
|
||||
|
||||
onUnload(() => {
|
||||
uni.$off('uAvatarCropper')
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.header {
|
||||
width: 100%;
|
||||
height: 240rpx;
|
||||
// border-radius: 14rpx;
|
||||
.header {
|
||||
width: 100%;
|
||||
height: 240rpx;
|
||||
// border-radius: 14rpx;
|
||||
|
||||
image {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
}
|
||||
image {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
}
|
||||
|
||||
.item {
|
||||
margin-top: 2rpx;
|
||||
padding: 30rpx 20rpx;
|
||||
// border-radius: 14rpx;
|
||||
background-color: #ffffff;
|
||||
.item {
|
||||
margin-top: 2rpx;
|
||||
padding: 30rpx 20rpx;
|
||||
// border-radius: 14rpx;
|
||||
background-color: #ffffff;
|
||||
|
||||
.label {
|
||||
width: 150rpx;
|
||||
}
|
||||
.label {
|
||||
width: 150rpx;
|
||||
}
|
||||
|
||||
.content {
|
||||
flex: 1;
|
||||
width: 80%;
|
||||
}
|
||||
.content {
|
||||
flex: 1;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.bind {
|
||||
height: 56rpx;
|
||||
border-width: 1rpx;
|
||||
border-style: solid;
|
||||
}
|
||||
}
|
||||
.bind {
|
||||
height: 56rpx;
|
||||
border-width: 1rpx;
|
||||
border-style: solid;
|
||||
}
|
||||
}
|
||||
|
||||
.license {
|
||||
margin-top: 80rpx;
|
||||
color: #a7a7a7;
|
||||
}
|
||||
</style>
|
||||
.license {
|
||||
margin-top: 80rpx;
|
||||
color: #a7a7a7;
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -1,97 +1,108 @@
|
|||
<template>
|
||||
<view class="user-set">
|
||||
<navigator :url="`/pages/user_data/user_data`">
|
||||
<view class="item flex bg-white mt-[20rpx]">
|
||||
<u-avatar :src="userInfo.avatar" shape="square"></u-avatar>
|
||||
<view class="ml-[20rpx] flex flex-1 justify-between">
|
||||
<view>
|
||||
<view class="mb-[15rpx] text-xl font-medium">{{ userInfo.nickname }}</view>
|
||||
<view class="text-content text-xs">账号:{{ userInfo.username }}</view>
|
||||
</view>
|
||||
<u-icon name="arrow-right" color="#666"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
</navigator>
|
||||
<view class="item bg-white mt-[20rpx] btn-border flex flex-1 justify-between">
|
||||
<view class="text-xl">登录密码</view>
|
||||
<u-icon name="arrow-right" color="#666"></u-icon>
|
||||
</view>
|
||||
<view class="item bg-white btn-border flex flex-1 justify-between">
|
||||
<view class="text-xl">绑定微信</view>
|
||||
<view class=" flex justify-between">
|
||||
<view class="text-muted mr-[20rpx]">
|
||||
{{ userInfo.isBindMnp ? '已绑定' : '未绑定' }}
|
||||
</view>
|
||||
<u-icon name="arrow-right" color="#666"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
<view class="user-set">
|
||||
<navigator :url="`/pages/user_data/user_data`">
|
||||
<view class="item flex bg-white mt-[20rpx]">
|
||||
<u-avatar :src="userInfo.avatar" shape="square"></u-avatar>
|
||||
<view class="ml-[20rpx] flex flex-1 justify-between">
|
||||
<view>
|
||||
<view class="mb-[15rpx] text-xl font-medium">{{ userInfo.nickname }}</view>
|
||||
<view class="text-content text-xs">账号:{{ userInfo.username }}</view>
|
||||
</view>
|
||||
<u-icon name="arrow-right" color="#666"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
</navigator>
|
||||
<view
|
||||
class="item bg-white mt-[20rpx] btn-border flex flex-1 justify-between"
|
||||
@click="show = true"
|
||||
>
|
||||
<view class="text-xl">登录密码</view>
|
||||
<u-icon name="arrow-right" color="#666"></u-icon>
|
||||
</view>
|
||||
<view class="item bg-white btn-border flex flex-1 justify-between">
|
||||
<view class="text-xl">绑定微信</view>
|
||||
<view class="flex justify-between">
|
||||
<view class="text-muted mr-[20rpx]">
|
||||
{{ userInfo.isBindMnp ? '已绑定' : '未绑定' }}
|
||||
</view>
|
||||
<u-icon name="arrow-right" color="#666"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<navigator :url="`/pages/agreement/agreement?type=${ AgreementEnum.PRIVACY }`">
|
||||
<view class="item bg-white mt-[20rpx] btn-border flex flex-1 justify-between">
|
||||
<view class="text-xl">隐私政策</view>
|
||||
<u-icon name="arrow-right" color="#666"></u-icon>
|
||||
</view>
|
||||
</navigator>
|
||||
<navigator :url="`/pages/agreement/agreement?type=${ AgreementEnum.SERVICE }`">
|
||||
<view class="item bg-white btn-border flex flex-1 justify-between">
|
||||
<view class="text-xl">服务协议</view>
|
||||
<u-icon name="arrow-right" color="#666"></u-icon>
|
||||
</view>
|
||||
</navigator>
|
||||
<view class="item bg-white btn-border flex flex-1 justify-between">
|
||||
<view class="text-xl">关于我们</view>
|
||||
<view class="flex justify-between">
|
||||
<view class="text-muted mr-[20rpx]">
|
||||
{{ appStore.config.version }}
|
||||
</view>
|
||||
<u-icon name="arrow-right" color="#666"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<navigator :url="`/pages/agreement/agreement?type=${AgreementEnum.PRIVACY}`">
|
||||
<view class="item bg-white mt-[20rpx] btn-border flex flex-1 justify-between">
|
||||
<view class="text-xl">隐私政策</view>
|
||||
<u-icon name="arrow-right" color="#666"></u-icon>
|
||||
</view>
|
||||
</navigator>
|
||||
<navigator :url="`/pages/agreement/agreement?type=${AgreementEnum.SERVICE}`">
|
||||
<view class="item bg-white btn-border flex flex-1 justify-between">
|
||||
<view class="text-xl">服务协议</view>
|
||||
<u-icon name="arrow-right" color="#666"></u-icon>
|
||||
</view>
|
||||
</navigator>
|
||||
<view class="item bg-white btn-border flex flex-1 justify-between">
|
||||
<view class="text-xl">关于我们</view>
|
||||
<view class="flex justify-between">
|
||||
<view class="text-muted mr-[20rpx]">
|
||||
{{ appStore.config.version }}
|
||||
</view>
|
||||
<u-icon name="arrow-right" color="#666"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
<u-action-sheet :list="list" v-model="show" @click="handleClick"></u-action-sheet>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
getUserInfo
|
||||
} from '@/api/user'
|
||||
import {
|
||||
onShow
|
||||
} from '@dcloudio/uni-app'
|
||||
import {
|
||||
reactive,
|
||||
ref,
|
||||
} from 'vue'
|
||||
import {
|
||||
useAppStore
|
||||
} from '@/stores/app'
|
||||
import {
|
||||
AgreementEnum
|
||||
} from '@/enums/agreementEnums'
|
||||
import { getUserInfo } from '@/api/user'
|
||||
import { onShow } from '@dcloudio/uni-app'
|
||||
import { reactive, ref } from 'vue'
|
||||
import { useAppStore } from '@/stores/app'
|
||||
import { AgreementEnum } from '@/enums/agreementEnums'
|
||||
|
||||
const appStore = useAppStore()
|
||||
let userInfo = ref({})
|
||||
const appStore = useAppStore()
|
||||
const userInfo = ref({})
|
||||
const list = ref([
|
||||
{
|
||||
text: '修改密码'
|
||||
},
|
||||
{
|
||||
text: '忘记密码'
|
||||
}
|
||||
])
|
||||
const show = ref(false)
|
||||
const getUser = async () => {
|
||||
const res = await getUserInfo()
|
||||
console.log(res, 'res')
|
||||
|
||||
const getUser = async () => {
|
||||
let res = await getUserInfo()
|
||||
console.log(res, 'res')
|
||||
userInfo.value = res
|
||||
}
|
||||
|
||||
userInfo.value = res
|
||||
const handleClick = (index: number) => {
|
||||
switch (index) {
|
||||
case 0:
|
||||
uni.navigateTo({ url: '/pages/change_password/change_password' })
|
||||
break
|
||||
case 1:
|
||||
uni.navigateTo({ url: '/pages/forget_pwd/forget_pwd' })
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
onShow(() => {
|
||||
getUser()
|
||||
})
|
||||
onShow(() => {
|
||||
getUser()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.user-set {
|
||||
.item {
|
||||
padding: 30rpx;
|
||||
}
|
||||
.user-set {
|
||||
.item {
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.btn-border {
|
||||
border-bottom: 1rpx solid $u-form-item-border-color;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
.btn-border {
|
||||
border-bottom: 1rpx solid $u-form-item-border-color;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
Loading…
Reference in New Issue