国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

使用的uview 微信高版本 頭像昵稱填寫能力

這篇具有很好參考價值的文章主要介紹了使用的uview 微信高版本 頭像昵稱填寫能力。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

<template>
	<view>
		<button class="cu-btn block bg-blue margin-tb-sm lg" @tap="wxGetUserInfo">一鍵登錄</button>
		<view>
			<!-- 提示窗示例 -->
			<u-popup :show="show" background-color="#fff">
				<view class="infoBox">
					<view class="title">邀請您補(bǔ)全個人信息</view>
					<br>
					<br>
					<br>
					<form catchsubmit="getUserName">
						<view style="width: 100%;">
							<view class="popup-info">
								<view class="popup-info-left">頭像</view>
								<view class="popup-info-right">
									<button class="avatar-wrapper" open-type="chooseAvatar"
										@chooseavatar="onChooseAvatar" slot="right">
										<img class="avater" :src="avatarUrl" alt="用戶頭像"></button>
								</view>
							</view>
							<br>
							<br>
							<view class="popup-info">
								<view class="popup-info-left">昵稱</view>
								<view class="popup-info-right">
									<input type="nickname" class="nickName-input" @blur="userNameInput"
										placeholder="請輸入昵稱" />

								</view>
							</view>
						</view>
						<view class="buttonSum">
							<view class="button">
								<button @click="dialogClose">取消</button>
							</view>
							<view class="button" style="border-left: 1px solid #e2e1e1;color: #0081ff;">
								<button @click="submitSure" style="color: #0081ff;" form-type="submit">確定</button>
							</view>
						</view>
					</form>

				</view>

			</u-popup>
		</view>
		<view class="text-center margin-top-sm" @tap="back">暫不登錄</view>
	</view>
	</view>
</template>

<script>
	import avatarUrl from "@/static/logo.png"
	export default {
		data() {
			return {
				avatarUrl: avatarUrl,
				nickName: '',
				token: '',
				imgList: [],
				show: false,
			}
		},
		methods: {
			back() {
				uni.navigateBack({
					delta: 1,
				})
			},
			wxGetUserInfo(e) {
				// 1、授權(quán)必須要在用戶點擊事件之后進(jìn)行
				// 2、uni老的方法getUserInfo已經(jīng)拿不到用戶信息了
				// uni.getUserProfile高版本的也停用了,2.21以下的版本還可以用
				// #ifdef MP-WEIXIN
				uni.getUserProfile({
					desc: 'get_name', // 這個參數(shù)是必須的
					success: user => {
						console.log('用戶信息', user)
						uni.setStorageSync("user_info", user.userInfo)
						//由于低版本需要使用getUserProfile方法,高版本使用頭像昵稱填寫功能,所以先使用getUserProfile,如果得到的nickName是微信用戶,則說明獲取失敗,再使用頭像昵稱填寫功能獲取
						if (user.userInfo.nickName == '微信用戶') {
							this.show = true
						} else {
							uni.navigateBack({
								delta: 1
							})
						}
					}
				})
				// #endif
				// #ifdef MP-ALIPAY
				// uni.getUserInfo({
				// 	desc: 'get_name', // 這個參數(shù)是必須的
				// 	success: user => {
				// 		console.log(user)
				// 		uni.setStorageSync("user_info", user.userInfo)
				// 		// 虛假的openid
				// 		getApp().globalData.openId = user.ariverRpcTraceId;
				// 		uni.navigateBack({
				// 			delta: 1
				// 		})
				// 	}
				// })
				// #endif
			},
			// 點擊頭像
			async onChooseAvatar(e) {
				// 獲取到的圖片是臨時圖片,只能在本地訪問,不能在瀏覽器訪問,所以要把這個圖片轉(zhuǎn)成base64或者上傳七牛服務(wù)器換成網(wǎng)絡(luò)地址,再存儲起來
				this.avatarUrl = e.detail.avatarUrl;
				console.log(e.detail.avatarUrl, 'e.detail.avatarUrl'),
					// 臨時圖片轉(zhuǎn)為base64
					uni.getImageInfo({
						src: this.avatarUrl,
						success: function(res) {
							// 獲取到圖片的臨時地址
							var tempFilePath = res.path;
							// 將圖片轉(zhuǎn)為base64格式
							uni.getFileSystemManager().readFile({
								filePath: tempFilePath,
								encoding: 'base64',
								success: function(res) {
									var base64Img = 'data:image/png;base64,' + res.data;
									let userInfo = uni.getStorageSync("user_info")
									userInfo.avatarUrl = base64Img
									uni.setStorageSync("user_info", userInfo)
								}
							});
						}
					});
			},
			// 點擊昵稱
			userNameInput(e) {
				console.log(e.detail);
				this.nickName = e.detail.value
				let userInfo = uni.getStorageSync("user_info")
				userInfo.nickName = e.detail.value
				uni.setStorageSync("user_info", userInfo)
				console.log('點昵稱', this.nickName, e.detail.value, uni.getStorageSync("user_info"));
			},
			getUserName(e) {
				console.log('提交getUserName', e);
			},
			submitSure(e) {
				console.log('確定submitSure', e);
			},
			dialogClose(e) {
				console.log('dialogClose取消', e);
				this.show = false
			}
		},
		onLoad() {
			// this.show = true
		},
	}
</script>

<style lang="scss" scoped>
	.cu-btn {
		margin-top: 20px;
		margin-left: 20px;
		margin-right: 20px;
	}

	.infoBox {
		width: 80vw;
		height: 180px;
		position: relative;


		.title {
			font-size: 18px;
			text-align: center;
			margin-top: 15px;
			margin-bottom: 15px;
			font-weight: 500;
		}

		.popup-info {
			width: 100%;
			height: 40px;
			display: flex;
			justify-content: space-around;
			line-height: 40px;

			.popup-info-left {
				text-align: center;
				width: 50%;
			}

			.popup-info-right {
				width: 50%;
				display: flex;
				align-items: center;
				justify-content: center;

				button::after {
					border: none;
				}


				.nickName-input {
					display: inline-block;
					width: 100%;
					top: -5px;
				}

				.avatar-wrapper {
					border: none !important;
					width: 40px;
					height: 40px;
					padding: 0 !important;
					background: none;

					.avater {
						width: 40px;
						height: 40px;
					}
				}
			}
		}

		.buttonSum {
			width: 100%;
			display: flex;
			justify-content: space-around;
			position: absolute;
			bottom: 0;

			.button {
				width: 50%;
				border-top: 1px solid #e2e1e1;
			}

			button {
				width: 50%;
				background-color: #ffffff;
				font-size: 16px;
				outline: none;
			}

			button::after {
				border: none;
				border-radius: 0;
			}
		}
	}

	.u-popup__wrapper {
		border-radius: 10px;
	}
</style>


</style>

?效果

使用的uview 微信高版本 頭像昵稱填寫能力,前端,javascript,html

使用的uview 微信高版本 頭像昵稱填寫能力,前端,javascript,html

?使用的uview 微信高版本 頭像昵稱填寫能力,前端,javascript,html

?參考的這個

?微信小程序頭像昵稱填寫能力-CSDN博客

因為之前用的getUserProfile,有一天發(fā)現(xiàn)它獲取到的頭像是灰色,昵稱是微信用戶,一看官網(wǎng)說是不用了,低版本的還能用,高版本的要用頭像昵稱填寫來實現(xiàn)。

如下是我的小程序登錄頁面代碼:

邏輯:當(dāng)小程序判斷到?jīng)]有登陸時把用戶彈到登錄頁面,引導(dǎo)用戶登錄,用戶點擊一鍵登錄后彈出彈框引導(dǎo)用戶填寫昵稱和頭像,將信息存儲起來,方便在其他地方使用。

注意:

1、頭像獲取到的是臨時地址,需要處理,才能在瀏覽器展示,我采用的是將其轉(zhuǎn)化為base64的方式,具體請看:onChooseAvatar

2、昵稱獲取需要使用button的form-type="submit"屬性,觸發(fā)form提交來收集昵稱
?文章來源地址http://www.zghlxwxcb.cn/news/detail-805127.html

<template>
 
		<button class="cu-btn block bg-blue margin-tb-sm lg" @tap="wxGetUserInfo">一鍵登錄</button>
		<view>
			<!-- 提示窗示例 -->
			<uni-popup ref="alertDialog" background-color="#fff">
				<view class="infoBox">
					<view class="title">邀請您補(bǔ)全個人信息</view>
					<br>
					<br>
					<br>
					<form catchsubmit="getUserName">
						<view style="width: 100%;">
							<view class="popup-info">
								<view class="popup-info-left">頭像</view>
								<view class="popup-info-right">
									<button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar" slot="right">
										<img class="avater" :src="avatarUrl" alt="用戶頭像"></button>
								</view>
							</view>
							<br>
							<br>
							<view class="popup-info">
								<view class="popup-info-left">昵稱</view>
 
								<view class="popup-info-right">
									<input type="nickname" class="nickName-input" @blur="userNameInput" placeholder="請輸入昵稱" />
 
								</view>
							</view>
						</view>
						<view class="buttonSum">
							<view class="button">
								<button @click="dialogClose">取消</button>
							</view>
							<view class="button" style="border-left: 1px solid #e2e1e1;color: #0081ff;">
								<button @click="submitSure" style="color: #0081ff;" form-type="submit">確定</button>
							</view>
						</view>
					</form>
 
				</view>
 
			</uni-popup>
		</view>
		<view class="text-center margin-top-sm" @tap="back">暫不登錄</view>
	</view>
</template>
 
<script src="path/to/canvas/library.js"></script>
<script>
	import qiniuUploader from '../../util/qiniuUploader.js'
	import {
		RequestConstant
	} from '../../util/constant.js'
	export default {
		data() {
			return {
				avatarUrl: '../../static/icon-avatar.png',
				nickName: '',
				token: '',
				imgList: []
			}
		},
		methods: {
			back() {
				uni.navigateBack({
					delta: 1,
				})
			},
			wxGetUserInfo(e) {
				// 1、授權(quán)必須要在用戶點擊事件之后進(jìn)行
				// 2、uni老的方法getUserInfo已經(jīng)拿不到用戶信息了
				// uni.getUserProfile高版本的也停用了,2.21以下的版本還可以用
				// #ifdef MP-WEIXIN
				uni.getUserProfile({
					desc: 'get_name', // 這個參數(shù)是必須的
					success: user => {
						console.log('用戶信息', user)
						uni.setStorageSync("user_info", user.userInfo)
						//由于低版本需要使用getUserProfile方法,高版本使用頭像昵稱填寫功能,所以先使用getUserProfile,如果得到的nickName是微信用戶,則說明獲取失敗,再使用頭像昵稱填寫功能獲取
						if (user.userInfo.nickName == '微信用戶') {
							this.$refs.alertDialog.open()
						} else {
							uni.navigateBack({
								delta: 1
							})
						}
					}
				})
				// #endif
				// #ifdef MP-ALIPAY
				uni.getUserInfo({
					desc: 'get_name', // 這個參數(shù)是必須的
					success: user => {
						console.log(user)
						uni.setStorageSync("user_info", user.userInfo)
						// 虛假的openid
						getApp().globalData.openId = user.ariverRpcTraceId;
						uni.navigateBack({
							delta: 1
						})
					}
				})
				// #endif
			},
			// 打開彈框
			dialogToggle() {
				this.$refs.alertDialog.open()
			},
			// 點擊頭像
			async onChooseAvatar(e) {
				// 獲取到的圖片是臨時圖片,只能在本地訪問,不能在瀏覽器訪問,所以要把這個圖片轉(zhuǎn)成base64或者上傳七牛服務(wù)器換成網(wǎng)絡(luò)地址,再存儲起來
				this.avatarUrl = e.detail.avatarUrl;
				console.log(e.detail.avatarUrl,'e.detail.avatarUrl'),
				// 臨時圖片轉(zhuǎn)為base64
				uni.getImageInfo({
					src: this.avatarUrl,
					success: function(res) {
						// 獲取到圖片的臨時地址
						var tempFilePath = res.path;
						// 將圖片轉(zhuǎn)為base64格式
						uni.getFileSystemManager().readFile({
							filePath: tempFilePath,
							encoding: 'base64',
							success: function(res) {
								var base64Img = 'data:image/png;base64,' + res.data;
								let userInfo = uni.getStorageSync("user_info")
								userInfo.avatarUrl = base64Img
								uni.setStorageSync("user_info", userInfo)
							}
						});
					}
				});
			},
			// 點擊昵稱
			userNameInput(e) {
				console.log(e.detail);
				this.nickName = e.detail.value
				let userInfo = uni.getStorageSync("user_info")
				userInfo.nickName = e.detail.value
				uni.setStorageSync("user_info", userInfo)
				console.log('點昵稱', this.nickName, e.detail.value, uni.getStorageSync("user_info"));
			},
			getUserName(e) {
				console.log('提交getUserName', e);
			},
			submitSure(e) {
				console.log('確定submitSure', e);
				uni.navigateBack({
					delta: 1
				})
			},
			dialogClose(e) {
				console.log('dialogClose取消', e);
				this.$refs.alertDialog.close()
			}
		},
		onLoad() {},
	}
</script>
 
<style lang="less" scoped>
	.cu-btn {
		margin-top: 20px;
		margin-left: 20px;
		margin-right: 20px;
	}
 
	.infoBox {
		width: 80vw;
		height: 180px;
		position: relative;
 
 
		.title {
			font-size: 18px;
			text-align: center;
			margin-top: 15px;
			margin-bottom: 15px;
			font-weight: 500;
		}
 
		.popup-info {
			width: 100%;
			height: 40px;
			display: flex;
			justify-content: space-around;
			line-height: 40px;
 
			.popup-info-left {
				text-align: center;
				width: 50%;
			}
 
			.popup-info-right {
				width: 50%;
				display: flex;
				align-items: center;
				justify-content: center;
 
				button::after {
					border: none;
				}
 
 
				.nickName-input {
					display: inline-block;
					width: 100%;
					top: -5px;
				}
 
				.avatar-wrapper {
					border: none !important;
					width: 40px;
					height: 40px;
					padding: 0 !important;
					background: none;
 
					.avater {
						width: 40px;
						height: 40px;
					}
				}
			}
		}
 
		.buttonSum {
			width: 100%;
			display: flex;
			justify-content: space-around;
			position: absolute;
			bottom: 0;
 
			.button {
				width: 50%;
				border-top: 1px solid #e2e1e1;
			}
 
			button {
				width: 50%;
				background-color: #ffffff;
				font-size: 16px;
				outline: none;
			}
 
			button::after {
				border: none;
				border-radius: 0;
			}
		}
	}
 
	.uni-popup__wrapper {
		border-radius: 10px;
	}
</style>
 
 
</style>

到了這里,關(guān)于使用的uview 微信高版本 頭像昵稱填寫能力的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • uniapp onChooseAvatar,uniapp微信頭像昵稱填寫,uniapp chooseAvatar,does not have a method “onChooseAvatar“

    開放能力?/用戶信息?/獲取頭像昵稱 從基礎(chǔ)庫?2.21.2?開始支持 當(dāng)小程序需要讓用戶完善個人資料時,可以通過微信提供的頭像昵稱填寫能力快速完善。 頭像選擇 需要將?button?組件? open-type ?的值設(shè)置為? chooseAvatar ,當(dāng)用戶選擇需要使用的頭像之后,可以通過? bindchoosea

    2024年02月14日
    瀏覽(18)
  • 修復(fù)微信小程序不能獲取頭像和昵稱的bug,微信小程序新版頭像昵稱API使用

    修復(fù)微信小程序不能獲取頭像和昵稱的bug,微信小程序新版頭像昵稱API使用

    大廠程序員都是有KPI績效考核的,所以他們不能閑著,每天要想著怎么優(yōu)化程序代碼、怎么滿足奇葩用戶的需求,所以苦逼了我們這些小公司程序員,微信一個小小的API接口改動,可能就讓一個小公司因此損失慘重,甚至直接面臨倒閉。鵝廠可不管你這些小公司的死活,畢竟

    2024年02月11日
    瀏覽(296)
  • uniapp小程序使用getUserProfile登錄(獲取昵稱統(tǒng)一為‘微信用戶’+頭像為灰色頭像)

    一、微信授權(quán)登錄按鈕 二、微信授權(quán)登錄彈窗 三、數(shù)據(jù)定義 四、登錄方法

    2024年02月13日
    瀏覽(18)
  • Uniapp寫微信小程序時,如何獲取用戶頭像和昵稱使用微信用戶信息登錄?

    Uniapp寫微信小程序時,如何獲取用戶頭像和昵稱使用微信用戶信息登錄?

    實現(xiàn)效果如下: 首先使用uni.login獲取用戶登錄憑證code: 官方代碼: success返回參數(shù)如下: 頭像選擇: 需要將?button?組件? open-type ?的值設(shè)置為? chooseAvatar ,當(dāng)用戶選擇需要使用的頭像之后,可以通過? bindchooseavatar ?事件回調(diào)獲取到頭像信息的臨時路徑。 從基礎(chǔ)庫2.24.4版本

    2024年02月04日
    瀏覽(24)
  • 最新微信小程序獲取頭像昵稱,直接用,uniapp獲取微信小程序頭像昵稱

    最新微信小程序獲取頭像昵稱,直接用,uniapp獲取微信小程序頭像昵稱

    微信小程序獲取用戶頭像和昵稱一個開放接口是wx.getUserInfo,2021年4月5日被廢棄,原因是很多開發(fā)者在打開小程序時就通過組件方式喚起getUserInfo彈窗,如果用戶點擊拒絕,無法使用小程序,這種做法打斷了用戶正常使用小程序的流程,同時也不利于小程序獲取新用戶,后面新

    2024年02月11日
    瀏覽(95)
  • 關(guān)于微信小程序用戶頭像昵稱獲取規(guī)則調(diào)整后的頭像昵稱獲取方式

    小程序用戶頭像昵稱獲取規(guī)則調(diào)整公告:小程序用戶頭像昵稱獲取規(guī)則調(diào)整公告 | 微信開放社區(qū) ? 點擊登錄按鈕,先去檢查用戶授權(quán)信息,會彈出用戶授權(quán)彈窗(首次),用戶點擊同意授權(quán)之后,調(diào)用 wx.login 方法獲取登錄憑證(code),把code傳給后端寫的登錄接口進(jìn)行解析登

    2024年02月05日
    瀏覽(93)
  • 微信小程序獲取昵稱,頭像

    微信小程序獲取昵稱,頭像

    1,昵稱:使用到的是微信小程序文檔里的api input框的type值設(shè)置為nickname,再使用雙向綁定的方法拿到值 這個方法點擊input框的時候它會彈出你當(dāng)前的微信名稱,基礎(chǔ)庫版本較低的話電腦上無法顯示,只能在真機(jī)調(diào)試上顯示 2,頭像 點擊按鈕底部彈出自己的頭像,也可以上傳新

    2024年02月12日
    瀏覽(90)
  • 微信小程序更改頭像昵稱

    目錄 背景 解決思路 前面寫了一篇關(guān)于小程序頭像昵稱獲取更改的方案,有很多小伙伴私信我發(fā)一個整體的邏輯思路! 前面的這篇文章中我們給出了頁面中獲取頭像昵稱的代碼: 上方代碼中我們可以很清晰的看到用戶的頭像和昵稱,使用button和input輸入框來填充或者更改的。

    2024年02月09日
    瀏覽(21)
  • 微信小程序獲取頭像昵稱 保存頭像到服務(wù)器

    微信官方推薦的替代做法: 頭像昵稱填寫 | 微信開放文檔 (qq.com) ?wxml js wxss

    2024年02月16日
    瀏覽(94)
  • uniapp微信小程序獲取用戶名和頭像最新方式(頭像填寫)

    uniapp微信小程序獲取用戶名和頭像最新方式(頭像填寫)

    getUserProfile 接口、getUserInfo 接口在最新的小程序基礎(chǔ)庫 已經(jīng)不能獲取到用戶信息 官方推薦用頭像填寫能力 實現(xiàn)了一版 代碼如下 做個記錄 方便下次找到

    2024年02月11日
    瀏覽(24)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包