增量提交
This commit is contained in:
139
Claw/client/wechat_app/components/auth-prompt/auth-prompt.js
Normal file
139
Claw/client/wechat_app/components/auth-prompt/auth-prompt.js
Normal file
@@ -0,0 +1,139 @@
|
||||
// 授权提示组件
|
||||
Component({
|
||||
properties: {
|
||||
show: {
|
||||
type: Boolean,
|
||||
value: false
|
||||
},
|
||||
authType: {
|
||||
type: String,
|
||||
value: 'userInfo' // userInfo, location, camera, record
|
||||
}
|
||||
},
|
||||
|
||||
data: {
|
||||
authConfig: {
|
||||
userInfo: {
|
||||
title: '授权用户信息',
|
||||
desc: '为了提供更好的服务,需要获取您的用户信息',
|
||||
buttonText: '授权',
|
||||
icon: '/assets/images/user-avatar.png'
|
||||
},
|
||||
location: {
|
||||
title: '授权地理位置',
|
||||
desc: '为了提供基于位置的服务,需要获取您的地理位置',
|
||||
buttonText: '授权',
|
||||
icon: '/assets/images/location-icon.png'
|
||||
},
|
||||
camera: {
|
||||
title: '授权相机',
|
||||
desc: '为了拍摄照片或视频,需要获取相机权限',
|
||||
buttonText: '授权',
|
||||
icon: '/assets/images/camera-icon.png'
|
||||
},
|
||||
record: {
|
||||
title: '授权录音',
|
||||
desc: '为了录制语音,需要获取录音权限',
|
||||
buttonText: '授权',
|
||||
icon: '/assets/images/mic-icon.png'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
// 授权按钮点击
|
||||
handleAuth() {
|
||||
const { authType } = this.properties
|
||||
|
||||
switch (authType) {
|
||||
case 'userInfo':
|
||||
this.authUserInfo()
|
||||
break
|
||||
case 'location':
|
||||
this.authLocation()
|
||||
break
|
||||
case 'camera':
|
||||
this.authCamera()
|
||||
break
|
||||
case 'record':
|
||||
this.authRecord()
|
||||
break
|
||||
}
|
||||
},
|
||||
|
||||
// 授权用户信息
|
||||
authUserInfo() {
|
||||
const app = getApp()
|
||||
app.triggerUserAuth((userInfo) => {
|
||||
if (userInfo) {
|
||||
this.triggerEvent('authSuccess', { authType: 'userInfo', data: userInfo })
|
||||
this.setData({ show: false })
|
||||
} else {
|
||||
console.error('用户信息授权失败')
|
||||
this.triggerEvent('authFail', { authType: 'userInfo', error: '授权失败' })
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 授权地理位置
|
||||
authLocation() {
|
||||
wx.getLocation({
|
||||
type: 'wgs84',
|
||||
success: (res) => {
|
||||
this.triggerEvent('authSuccess', { authType: 'location', data: res })
|
||||
this.setData({ show: false })
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('地理位置授权失败:', err)
|
||||
this.triggerEvent('authFail', { authType: 'location', error: err })
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 授权相机
|
||||
authCamera() {
|
||||
wx.authorize({
|
||||
scope: 'scope.camera',
|
||||
success: () => {
|
||||
this.triggerEvent('authSuccess', { authType: 'camera' })
|
||||
this.setData({ show: false })
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('相机授权失败:', err)
|
||||
this.triggerEvent('authFail', { authType: 'camera', error: err })
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 授权录音
|
||||
authRecord() {
|
||||
wx.authorize({
|
||||
scope: 'scope.record',
|
||||
success: () => {
|
||||
this.triggerEvent('authSuccess', { authType: 'record' })
|
||||
this.setData({ show: false })
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('录音授权失败:', err)
|
||||
this.triggerEvent('authFail', { authType: 'record', error: err })
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 取消授权
|
||||
handleCancel() {
|
||||
this.triggerEvent('authCancel', { authType: this.properties.authType })
|
||||
this.setData({ show: false })
|
||||
},
|
||||
|
||||
// 打开设置
|
||||
openSettings() {
|
||||
wx.openSetting({
|
||||
success: (res) => {
|
||||
console.log('设置结果:', res.authSetting)
|
||||
this.triggerEvent('settingsOpen', { authType: this.properties.authType, settings: res.authSetting })
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {},
|
||||
"description": "授权提示组件"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<view class="auth-prompt" wx:if="{{show}}">
|
||||
<view class="auth-prompt-overlay" bindtap="handleCancel"></view>
|
||||
<view class="auth-prompt-content">
|
||||
<view class="auth-prompt-icon">
|
||||
<image src="{{authConfig[authType].icon}}" mode="aspectFit"></image>
|
||||
</view>
|
||||
<view class="auth-prompt-title">{{authConfig[authType].title}}</view>
|
||||
<view class="auth-prompt-desc">{{authConfig[authType].desc}}</view>
|
||||
<view class="auth-prompt-buttons">
|
||||
<button class="auth-prompt-cancel" bindtap="handleCancel">取消</button>
|
||||
<button class="auth-prompt-confirm" bindtap="handleAuth">{{authConfig[authType].buttonText}}</button>
|
||||
</view>
|
||||
<view class="auth-prompt-tip">
|
||||
<text>如果授权失败,请在</text>
|
||||
<text class="auth-prompt-settings" bindtap="openSettings">设置</text>
|
||||
<text>中开启权限</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
106
Claw/client/wechat_app/components/auth-prompt/auth-prompt.wxss
Normal file
106
Claw/client/wechat_app/components/auth-prompt/auth-prompt.wxss
Normal file
@@ -0,0 +1,106 @@
|
||||
.auth-prompt {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 9999;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.auth-prompt-overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.auth-prompt-content {
|
||||
position: relative;
|
||||
width: 80%;
|
||||
max-width: 400rpx;
|
||||
background-color: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 40rpx;
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.auth-prompt-icon {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
margin-bottom: 32rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.auth-prompt-icon image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.auth-prompt-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.auth-prompt-desc {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
text-align: center;
|
||||
line-height: 36rpx;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.auth-prompt-buttons {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.auth-prompt-cancel {
|
||||
flex: 1;
|
||||
height: 80rpx;
|
||||
line-height: 80rpx;
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
background-color: #f5f5f5;
|
||||
border-radius: 8rpx 0 0 8rpx;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.auth-prompt-confirm {
|
||||
flex: 1;
|
||||
height: 80rpx;
|
||||
line-height: 80rpx;
|
||||
font-size: 28rpx;
|
||||
color: #fff;
|
||||
background-color: #07c160;
|
||||
border-radius: 0 8rpx 8rpx 0;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.auth-prompt-tip {
|
||||
font-size: 20rpx;
|
||||
color: #999;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.auth-prompt-settings {
|
||||
color: #07c160;
|
||||
margin: 0 4rpx;
|
||||
}
|
||||
|
||||
.auth-prompt-settings:active {
|
||||
text-decoration: underline;
|
||||
}
|
||||
Reference in New Issue
Block a user