Files
xdd-uniapp-new/pages/authorization/index.vue
T

555 lines
14 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="pages-auth v12-justify-between v12-flex-column">
<!-- <view class="tip-1">为了提供更优质的服务需要获取</view>
<view class="tip-2">您的头像昵称</view>
<view class="wechat flex jc-between ai-center">
<view class="flex ai-end">
<image class="avatar" :src="avatarUrl"></image>
<view>
<view class="name">微信用户</view>
<view class="info">微信个人信息</view>
</view>
</view>
<image class="select" :src="webUrl+'/20220613104953149068.png'" mode="scaleToFill"/>
</view> -->
<view class="dialog-mask" v-if="show">
<view class="dialog-body">
<image class="btn-close" :src="webUrl+'/20221230200935413332.png'" @click="changeShow"/>
<view class="content">
<view class="title tc bold">用户协议及隐私政策</view>
<rich-text :nodes="agreeInfo.privacyPolicy"/>
<view class="title tc">
<button size="mini" @click="changeShow">关闭</button>
</view>
</view>
</view>
</view>
<view class="dialog-mask" v-if="showFillOut">
<view class="dialog-fill flex flex-col ai-center">
<!-- <view class="title bold">请完善您的信息</view> -->
<view class="v12-align-center v12-justify-start v12-py-4" style="width:550rpx">
<view class="v12-mr-3">
<image class="app-logo__image--inner" :src="webUrl+'/orderIcon/applogo.png'" mode="aspectFit|aspectFill|widthFix" lazy-load="true"></image>
</view>
<view class="v12-dark-text v12-font-bold">
<text class="v12-font-40">
地标文化特产
</text>
<text class="v12-mx-1">
|
</text>
<text class="v12-font-24">
申请使用
</text>
</view>
</view>
<view class="v12-dark-text v12-font-40 v12-mt-3 v12-font-bold" style="width:550rpx">
获取你的昵称头像
</view>
<view class="v12-align-center v12-justify-between v12-mb-3 v12-mt-6" style="width:550rpx">
<view class="v12-align-center">
<view class="v12-dark-text v12-mr-3">
头像
</view>
<button
class="avatar-wrapper v12-ma-0"
open-type="chooseAvatar"
@chooseavatar="onChooseAvatar"
>
<image
:src="avatarUrl"
class="avatar"
/>
</button>
</view>
<view>
<u-icon name="arrow-right"></u-icon>
</view>
</view>
<view class="v12-align-center v12-justify-between v12-my-4" style="width:550rpx">
<view class="v12-align-center">
<view class="v12-dark-text v12-mr-3">
昵称
</view>
<input
type="nickname"
maxlength="12"
class="input-wrapper "
placeholder="请填写您的昵称"
v-model="nickname"
@input="inputName"
@confirm="inputName"
@blur="inputName"
/>
</view>
<view>
<u-icon name="close" @click="clearName"></u-icon>
</view>
</view>
<!-- <view class="input-wrapper">
<picker
:value="form.birthday"
mode="date"
class="picker"
@change="birthdayChange"
>
{{ form.birthday || '请选择出生日期' }}
</picker>
</view> -->
<!-- <view class="gender-row">
性别
<u-radio-group
v-model="form.gender"
placement="row"
>
<u-radio
:name="1"
:customStyle="{marginRight: '16px'}"
active-color="#C41617"
label="男"
/>
<u-radio
:name="2"
active-color="#C41617"
label="女"
/>
</u-radio-group>
</view> -->
<view class="v12-justify-between v12-py-6 " style="width: 550rpx">
<view class="v12-primary-border v12-primary v12-white-text v12-btn v12-px-8 v12-py-1" @click="onSubmit">允许</view>
<view class="v12-dark-border v12-dark-text v12-btn v12-px-8 v12-py-1" @click="back">拒绝</view>
</view>
</view>
</view>
<view class="app-logo v12-align-center v12-flex-column">
<image class="app-logo__image" :src="webUrl+'/orderIcon/applogo.png'" mode="aspectFit|aspectFill|widthFix" lazy-load="true"></image>
<view class="v12-mt-3 v12-font-32 v12-dark-text v12-font-weight-600">发现家乡好物</view>
</view>
<view class="btn-box">
<button class="btn-yes v12-primary" type="mini" v-if="canIUseGetUserProfile" @tap="getUserInfoProfile">快捷登录</button>
<!-- <button class="btn-no" type="default" @tap="back">拒绝</button> -->
</view>
<view class="agree-box v12-align-center">
<u-checkbox-group
@change="changeAgree"
v-model="isAgree"
>
<u-checkbox
activeColor="#C52733"
size="16"
name="yes"
>
</u-checkbox>
</u-checkbox-group>
<text @click="changeShow">我已阅读并同意
<text class="btn-show">用户服务协议及隐私政策</text>
</text>
<!-- <checkbox-group @change="changeAgree">
<label>
<checkbox value="yes" style="transform:scale(0.6)" iconColor="#C52733" />
</label>
</checkbox-group> -->
</view>
</view>
</template>
<script>
import {mapActions, mapMutations, mapState} from 'vuex'
import cookie from '@/utils/store/cookie'
import {login, uploadImage} from '@/utils'
import {getAgree} from "@/api/public"
import {postUserEdit} from "@/api/user"
export default {
data() {
return {
webUrl: this.$VUE_APP_RESOURCES_URL,
authorize: false,
canIUseGetUserProfile: false,
agreeInfo: {},
isAgree: [],
show: false,
showFillOut: false,
nickname: '',
avatarUrl: this.$VUE_APP_RESOURCES_URL + '/20230506100714762257.png',
form: {
gender: '',
birthday: ''
}
}
},
computed: {
...mapState(['isAuthorization', '$deviceType', 'token']),
},
onLoad() {
if (wx.getUserProfile) {
this.canIUseGetUserProfile = true
}
// 先校验用户是否授权,如果没有授权,显示授权按钮
getAgree().then(({data}) => this.agreeInfo = data);
},
onHide() {
this.updateAuthorizationPage(false)
this.changeAuthorization(false)
},
onUnload() {
this.updateAuthorizationPage(false)
this.changeAuthorization(false)
},
methods: {
...mapActions(['changeAuthorization', 'setUserInfo']),
...mapMutations(['updateAuthorizationPage']),
changeShow(){
this.show=!this.show;
},
changeAgree(event) {
this.isAgree = event
},
clearName() {
this.nickname = ''
},
toLogin() {
this.$yrouter.push({
path: '/pages/user/Login/index',
query: {},
})
},
back() {
this.$yrouter.switchTab({
path: '/pages/home/index',
query: {},
})
},
doneRedirect() {
let redirectUrl = cookie.get('redirect') || "";
redirectUrl = redirectUrl.replace(/\ /g, '');
//如果已经是授权页,跳转主页
if (redirectUrl == '/pages/authorization/index' || redirectUrl.length === 0) {
redirectUrl = '/pages/home/index';
}
this.$yrouter.reLaunch({
path: redirectUrl,
})
},
getUserInfoProfile() {
if (!this.isAgree[0]) {
uni.showToast({
title: "请先阅读并同意《用户服务协议及隐私政策》",
icon: "none",
duration: 5000
})
return
}
wx.getUserProfile({
lang: 'zh_CN',
desc: '需要获取您的信息用来展示',
success: res => {
uni.showLoading({
title: '登录中',
})
login(res).then(e => {
let db_nickname = e.data.nickname;
if (db_nickname === null || db_nickname === undefined || db_nickname === "" || db_nickname === "微信用户") {
this.showFillOut = true;
} else {
this.doneRedirect();
}
}).catch(error => {
uni.showToast({
title: error,
icon: 'none',
duration: 2000,
})
})
},
})
},
onChooseAvatar(e) {
const {avatarUrl} = e.detail;
this.avatarUrl = avatarUrl;
},
inputName(e) {
this.nickname = e.detail.value;
},
birthdayChange(e) {
const value = e.detail.value
this.form.birthday = value
},
onSubmit() {
let that = this;
this.nickname = this.nickname.trim();
if (this.nickname.length === 0) {
uni.showToast({
title: "请输入您的昵称",
icon: "none",
duration: 5000
})
return
}
// 临时地址图片上传
if (that.avatarUrl.indexOf("/tmp/") > -1 || that.avatarUrl.indexOf("wxfile") > -1) {
uploadImage(this.avatarUrl, img => {
that.avatarUrl = img;
})
let timer = setInterval(() => {
if (that.avatarUrl.indexOf("/tmp/") === -1 && that.avatarUrl.indexOf("wxfile") === -1) {
clearInterval(timer);
that.saveUserInfo();
}
}, 100)
} else {
that.saveUserInfo();
}
},
saveUserInfo() {
const param = {
nickname: this.nickname,
avatar: this.avatarUrl,
gender: this.form.gender || 0,
birthday: this.form.birthday || ''
}
postUserEdit(param).then(res => {
if (res.status === 200) {
this.doneRedirect();
} else {
uni.showToast({
title: res.msg,
icon: "none",
duration: 5000
})
}
}).catch(error => {
uni.showToast({
title: error,
icon: "none",
duration: 5000
})
})
}
}
}
</script>
<style lang="less">
.app-logo{
margin-top: 70rpx;
}
.app-logo__image--inner{
width: 100rpx;
height: 100rpx;
border-radius: 50%;
}
.pages-auth {
padding: 148rpx 48rpx;
padding: 148rpx 48rpx;
height: 100vh;
box-sizing: border-box;
.tip-1 {
font-size: 28rpx;
line-height: 40rpx;
color: #333333;
}
.tip-2 {
margin-top: 20rpx;
font-size: 40rpx;
line-height: 58rpx;
color: #333333;
}
.wechat {
margin-top: 80rpx;
.avatar {
width: 112rpx;
height: 112rpx;
margin-right: 24rpx;
border-radius: 8rpx;
}
.name {
font-size: 32rpx;
line-height: 48rpx;
color: #333333;
}
.info {
margin-top: 28rpx;
font-size: 24rpx;
line-height: 34rpx;
color: #CECECE;
}
.select {
width: 40rpx;
height: 40rpx;
}
}
.agree-box {
// margin: 200rpx 0 60rpx;
font-size: 28rpx;
color: #333;
padding: 0 20rpx;
.btn-show {
color: #4099FF;
}
}
.dialog-mask {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: rgba(0, 0, 0, .4);
z-index: 99;
.dialog-body {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 686rpx;
height: 70vh;
box-sizing: border-box;
padding: 60rpx;
border-radius: 10rpx;
background: #fff;
overflow: hidden;
.btn-close {
position: absolute;
top: 20rpx;
right: 20rpx;
width: 28rpx;
height: 28rpx;
}
.content {
height: 100%;
overflow-y: auto;
}
.title {
margin: 30rpx auto;
}
}
.dialog-fill {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
box-sizing: border-box;
overflow: hidden;
width: 686rpx;
border-radius: 24rpx;
background: #fff;
.title {
margin-top: 60rpx;
color: #333;
font-size: 36rpx;
line-height: 1;
}
.avatar-wrapper {
width: 80rpx;
height: 80rpx;
padding: 0;
background: none;
.avatar {
width: 80rpx;
height: 80rpx;
border-radius: 50%;
}
}
.avatar-wrapper::after {
display: none;
}
.input-wrapper {
height: 72rpx;
background: rgba(248, 249, 251, 1);
color: #999;
font-size: 32rpx;
text-align: left;
border-radius: 40rpx;
padding: 0 20rpx;
}
.gender-row {
display: flex;
align-items: center;
margin-top: 32rpx;
}
.picker {
text-align: center;
line-height: 72rpx;
}
.btn-submit {
width: 100%;
height: 100rpx;
margin: 32rpx 0 0 0;
box-sizing: border-box;
border-top: 2rpx solid #E0E0E0;
color: #3A87FC;
font-size: 32rpx;
line-height: 100rpx;
text-align: center;
}
}
}
.btn-box {
// width: 338rpx;
// margin: 0 auto;
padding: 0 20rpx;
padding-bottom: 340rpx;
button::after {
border: none;
}
button {
height: 72rpx;
font-size: 30rpx;
}
.btn-yes {
color: #fff;
width: 100%;
border-radius: 40rpx;
letter-spacing: 1px;
}
.btn-no {
margin-top: 32rpx;
background: #eee;
color: #FF564A;
}
}
}
.app-logo__image{
width: 200rpx;
height: 200rpx;
border-radius: 50%;
}
</style>