Refactor: UI & Feature updates (Calculator, UnitConverter, Privacy, Cleanup)

This commit is contained in:
2026-02-09 01:15:19 +08:00
parent fa1a8e083e
commit 2c5d5b7505
52 changed files with 1351 additions and 2702 deletions

View File

@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}

View File

@@ -0,0 +1,61 @@
Component({
data: {
innerShow: false,
privacyContractName: '《用户隐私保护指引》'
},
lifetimes: {
attached() {
// 注册隐私协议监听器
const _this = this;
if (wx.onNeedPrivacyAuthorization) {
wx.onNeedPrivacyAuthorization((resolve, eventInfo) => {
console.log('触发隐私协议弹窗', eventInfo);
const needsResolve = eventInfo.referrer === 'api'; // API调用触发需要手动resolve
_this.resolvePrivacyAuthorization = resolve; // 保存 resolve 函数
if (wx.getPrivacySetting) {
wx.getPrivacySetting({
success: (res) => {
console.log('getPrivacySetting success', res);
// 无论是否需要(needAuthorization), 只要触发了onNeedPrivacyAuthorization就证明被拦截了(或者需要再次确认)
// 通常 res.needAuthorization 为 true
_this.setData({
innerShow: true,
privacyContractName: res.privacyContractName || _this.data.privacyContractName
});
}
})
}
})
}
},
},
methods: {
handleDisagree() {
this.setData({ innerShow: false });
// 如果有保存的 resolve调用并报错拒绝虽然 API 主要是要 resolve({ buttonId: 'agree-btn', event: 'agree' }),拒绝通常不调 resolve 或调 fail
// 实际上用户拒绝后,该次 API 调用应该失败
if (this.resolvePrivacyAuthorization) {
// this.resolvePrivacyAuthorization({ event: 'disagree' }); // 某些场景下可能需要
this.resolvePrivacyAuthorization = null;
}
},
handleAgree(e: any) {
console.log('用户同意隐私协议');
// 按钮 open-type="agreePrivacyAuthorization" 会自动触发同意逻辑
// 这里的 bindagreeprivacyauthorization 回调用于 UI 反馈
this.setData({ innerShow: false });
// 如果是由 API 触发的(如 getClipboardData可以通过保存的 resolve 告知系统
// 但通常 open-type 按钮点击后系统会自动重试之前的 API 调用,或者在 button 上绑定 resolve
if (this.resolvePrivacyAuthorization) {
this.resolvePrivacyAuthorization({ buttonId: 'agree-btn', event: 'agree' });
this.resolvePrivacyAuthorization = null;
}
},
openPrivacyContract() {
wx.openPrivacyContract({})
}
}
})

View File

@@ -0,0 +1,14 @@
<view wx:if="{{innerShow}}" class="privacy-mask">
<view class="privacy-dialog">
<view class="privacy-title">用户隐私保护提示</view>
<view class="privacy-content">
感谢您使用本程序,在使用前您需仔细阅读
<text class="privacy-link" bindtap="openPrivacyContract">{{privacyContractName}}</text>
。当您点击同意并开始使用服务时,即表示您已理解并同意该条款内容。
</view>
<view class="privacy-btns">
<button class="btn-refuse" bindtap="handleDisagree">拒绝</button>
<button id="agree-btn" class="btn-agree" open-type="agreePrivacyAuthorization" bindagreeprivacyauthorization="handleAgree">同意</button>
</view>
</view>
</view>

View File

@@ -0,0 +1,68 @@
.privacy-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.6);
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
}
.privacy-dialog {
width: 600rpx;
background: #fff;
border-radius: 24rpx;
padding: 40rpx;
box-sizing: border-box;
}
.privacy-title {
font-weight: bold;
font-size: 34rpx;
margin-bottom: 30rpx;
text-align: center;
color: #333;
}
.privacy-content {
font-size: 28rpx;
color: #666;
line-height: 1.6;
margin-bottom: 50rpx;
text-align: justify;
}
.privacy-link {
color: #11616B; /* Color 01 */
font-weight: 500;
}
.privacy-btns {
display: flex;
gap: 30rpx;
}
.btn-refuse {
flex: 1;
background: #F2F2F2 !important;
color: #666 !important;
font-size: 30rpx !important;
border-radius: 12rpx !important;
height: 80rpx !important;
line-height: 80rpx !important;
border: none !important;
}
.btn-agree {
flex: 1;
background: #11616B !important; /* Color 01 */
color: #fff !important;
font-size: 30rpx !important;
border-radius: 12rpx !important;
height: 80rpx !important;
line-height: 80rpx !important;
border: none !important;
}