JM-MiniApp/pages/login/login.vue

199 lines
5.2 KiB
Vue
Raw Normal View History

2024-02-28 00:47:54 +08:00
<script setup>
2023-10-18 21:00:42 +08:00
// 引入依赖
2024-03-20 14:44:01 +08:00
import { onLoad, onBackPress } from "@dcloudio/uni-app"
2023-10-18 21:00:42 +08:00
// import mySwiper from "@/components/mySwiper.vue"
import {ref,onMounted,nextTick,watch} from "vue"
import {useStore} from '@/store/index.js'
const store = useStore()
import api from "@/api/index"
import custom from "@/utils/index.js"
2023-10-25 23:45:00 +08:00
onLoad((e) => {
token_info.value = JSON.parse(decodeURIComponent(e.token_info))
2023-10-18 21:00:42 +08:00
})
2024-03-20 14:44:01 +08:00
onBackPress(() => {
return false
})
2023-10-18 21:00:42 +08:00
// 变量
2023-10-25 23:45:00 +08:00
const token_info = ref(null)
2023-10-18 21:00:42 +08:00
const avatarUrl = ref(null)
const nickname = ref('')
2024-03-20 14:44:01 +08:00
var isOperation = ref([ // 是否已手术
{
index:0,
name:"否"
},
{
index: 1,
name: "是"
}
])
2023-10-18 21:00:42 +08:00
// 函数
function onChooseAvatar(e) {
avatarUrl.value = e.detail.avatarUrl
}
2024-03-20 14:44:01 +08:00
2023-10-18 21:00:42 +08:00
async function updateFunc(){ // 更新用户信息,通过此接口获取用户是否填写手术信息
let user_info = JSON.parse(uni.getStorageSync('userInfo'))
user_info.avatar = avatarUrl.value
user_info.id =user_info.userId
return await api.userinfoUpdae(user_info)
}
function nameInput(e) {
nickname.value = e.detail.value
}
2023-10-25 23:45:00 +08:00
async function updateInfoFunc() {
if(!avatarUrl.value) {
uni.showToast({
title:"请选择头像!",
icon:"error",
duration:1500
})
return
}
if(!nickname.value) {
uni.showToast({
title:"请填写昵称!",
icon:"error",
duration:1500
})
return
}
await custom.uploadImage(avatarUrl.value,async (file)=>{
avatarUrl.value = file.data.file.url
uni.setStorageSync('avatarUrl', file.data.file.url);//头像链接
token_info.value.nickname = nickname.value
token_info.value.avatar = avatarUrl.value
uni.setStorageSync('userInfo',JSON.stringify(token_info.value))
2024-03-20 14:44:01 +08:00
uni.setStorageSync('access_token','Bearer '+token_info.value.access_token);// 为了保险,token单独缓存一次
2023-10-25 23:45:00 +08:00
const up_res = await updateFunc() // 更新用户信息
2024-03-20 14:44:01 +08:00
store.checkLogin() // 检查一遍登录情况
2023-10-25 23:45:00 +08:00
uni.switchTab({
url:"/pages/user/index"
})
})
}
2024-03-20 14:44:01 +08:00
function bindOperationPickerChange(e) {
token_info.value.IsSurgery = e.detail.value
}
2024-02-28 00:47:54 +08:00
</script>
2023-10-18 21:00:42 +08:00
<template>
<view class="loginBox page-box img-part card-part" style="text-align:center">
<view class="base-info">
<button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar" style="border-radius: 50%;">
<image class="avatar" v-if="avatarUrl" mode="aspectFill" :src="avatarUrl"></image>
<uni-icons type="person-filled" color="white" v-else size="60"></uni-icons>
</button>
<input type="nickname" @blur="nameInput" class="weui-input" placeholder="请输入昵称" v-model="nickname" />
</view>
2024-03-20 14:44:01 +08:00
<!-- <view class="row-box">
<view class="rb-card" @tap="toDetail(5)">
<view class="rbc-content">
<view class="rbc-content-row rbc-content-left rbc-content-left-box">
<uni-icons type="paperplane" color="gray" size="26"></uni-icons>
已经手术</view>
<view class="rbc-content-row rbc-content-right">
<picker @change="bindOperationPickerChange" :value="token_info?.IsSurgery" :range="isOperation" range-key="name" >
<view class="rbc-content-row rbc-content-right rbc-content-right-box">
<view class="uni-input">{{ isOperation[token_info?.IsSurgery]?.name }}</view>
<uni-icons type="forward" color="gray" size="20"></uni-icons>
</view>
</picker>
</view>
</view>
</view>
2024-02-28 00:47:54 +08:00
</view> -->
2023-10-18 21:00:42 +08:00
<view class="btn-part">
2023-10-25 23:45:00 +08:00
<button class="buy-btn" @tap="updateInfoFunc">立即登录</button>
2023-10-18 21:00:42 +08:00
</view>
2024-02-28 00:47:54 +08:00
</view>
</template>
2023-10-18 21:00:42 +08:00
<style scoped lang="scss">
2024-03-20 14:44:01 +08:00
.rbc-content-right-box,.rbc-content-left-box{
display: flex;
align-items: center;
justify-content: center;
}
.row-box{
padding: 20rpx 0;
.rb-card{
padding: 20rpx;
background: white;
margin-bottom: 2rpx;
.rbc-title{
}
.rbc-content-box{
margin-top: 10rpx;
.rbc-content-row{
width: 50%;
text-align: center;
// padding: 40rpx 20rpx;
// box-shadow: 10rpx 10rpx 10rpx #cdcdcd;
border-radius: 10rpx;
}
}
.rbc-content{
display: flex;
align-items: center;
justify-content: space-between;
}
}
}
2023-10-18 21:00:42 +08:00
.base-info{
padding: 50rpx 0;
}
.loginBox{
}
/* pages/login/login.wxss */
page{
height: 100%;
}
.container{
align-items: center;
}
.title{
font-weight: bolder;
font-size: 40rpx;
}
.more-info{
color: gray;
font-size: 24rpx;
margin-top: 1rem;
}
.buy-btn{
display: inline-block;
margin-top:1rem;
background-color: #26758d;
color: white;
border-radius: 50rpx;
font-weight: 200;
font-size: 24rpx;
2024-03-20 14:44:01 +08:00
width: 80%;
2023-10-18 21:00:42 +08:00
padding: 10rpx 0;
}
.title-part{
text-align: center;
}
.avatar-wrapper{
width: 160rpx !important;
height: 160rpx;
padding: 0px;
margin: 0 auto;
overflow: hidden;
margin-bottom: 40rpx;
// border: 1px solid #26758d;
background: #ececec;
display: flex;
align-items: center;
justify-content: center;
}
.avatar{
width: 160rpx;
height: 160rpx;
}
.weui-input{
2024-02-28 00:47:54 +08:00
}
2023-10-18 21:00:42 +08:00
</style>