|
@@ -19,7 +19,7 @@ import { PayReq } from '@tencent/wechat_open_sdk';
|
|
|
import { cryptoFramework } from '@kit.CryptoArchitectureKit';
|
|
import { cryptoFramework } from '@kit.CryptoArchitectureKit';
|
|
|
import json from '@ohos.util.json';
|
|
import json from '@ohos.util.json';
|
|
|
import UserUtil, { VipFeature, VipPlanApi, VipPlanListApiResponse, WeChatPrepayId } from '../common/util/UserUtil';
|
|
import UserUtil, { VipFeature, VipPlanApi, VipPlanListApiResponse, WeChatPrepayId } from '../common/util/UserUtil';
|
|
|
-
|
|
|
|
|
|
|
+import { Utility } from '../common/util/Utility';
|
|
|
|
|
|
|
|
|
|
|
|
|
// 微信支付相关工具方法
|
|
// 微信支付相关工具方法
|
|
@@ -125,7 +125,6 @@ export struct UserCenter {
|
|
|
@State hasActiveSubscription: boolean = false;
|
|
@State hasActiveSubscription: boolean = false;
|
|
|
@State subscriptionName: string = '';
|
|
@State subscriptionName: string = '';
|
|
|
@State subscriptionEndDate: string = '';
|
|
@State subscriptionEndDate: string = '';
|
|
|
- @State userToken: string = '';
|
|
|
|
|
private wxApi = WXApi
|
|
private wxApi = WXApi
|
|
|
private wxEventHandler = WXEventHandler
|
|
private wxEventHandler = WXEventHandler
|
|
|
@StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD;
|
|
@StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD;
|
|
@@ -171,7 +170,7 @@ export struct UserCenter {
|
|
|
ToastUtil.showToast('支付成功!');
|
|
ToastUtil.showToast('支付成功!');
|
|
|
// 可在此处刷新会员状态或其他支付成功后的业务逻辑
|
|
// 可在此处刷新会员状态或其他支付成功后的业务逻辑
|
|
|
// this.fetchVipPlans(); // 刷新会员套餐信息
|
|
// this.fetchVipPlans(); // 刷新会员套餐信息
|
|
|
- this.fetchUserInfo(this.userToken);
|
|
|
|
|
|
|
+ this.fetchUserInfo();
|
|
|
} else {
|
|
} else {
|
|
|
// 其他类型的成功回调
|
|
// 其他类型的成功回调
|
|
|
ToastUtil.showToast('操作成功!');
|
|
ToastUtil.showToast('操作成功!');
|
|
@@ -190,39 +189,66 @@ export struct UserCenter {
|
|
|
|
|
|
|
|
// 通过code换取用户信息
|
|
// 通过code换取用户信息
|
|
|
async getUserInfoByCode(code: string) {
|
|
async getUserInfoByCode(code: string) {
|
|
|
- await UserUtil.getUserInfoByCode(code).then(()=>{
|
|
|
|
|
- this.showUserInfo()
|
|
|
|
|
|
|
+ await UserUtil.getUserInfoByCode(code).then(async ()=>{
|
|
|
|
|
+ // 登录后同步本地会员到线上(仅本地有会员且线上无会员时)
|
|
|
|
|
+ Utility.getLocalNobleExpireDate().then((expireDate)=>{
|
|
|
|
|
+ if (Utility.isNoble() && !this.hasActiveSubscription && expireDate) {
|
|
|
|
|
+ UserUtil.syncLocalNobleToServer(expireDate).then((success)=>{
|
|
|
|
|
+ if (success) {
|
|
|
|
|
+ ToastUtil.showToast('本地会员已同步到账号');
|
|
|
|
|
+ PreferencesUtil.putSync('isNoble', false);
|
|
|
|
|
+ this.fetchUserInfo();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.fetchUserInfo();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.fetchUserInfo();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 通过华为账号信息换取用户信息和会员状态
|
|
// 通过华为账号信息换取用户信息和会员状态
|
|
|
async getUserInfoByHuawei(openID: string, unionID: string, nickname: string, avatarUri: string) {
|
|
async getUserInfoByHuawei(openID: string, unionID: string, nickname: string, avatarUri: string) {
|
|
|
- await UserUtil.getUserInfoByHuawei(openID, unionID, nickname, avatarUri).then((data)=>{
|
|
|
|
|
- this.userToken = PreferencesUtil.getStringSync('userToken', '');
|
|
|
|
|
- this.showUserInfo();
|
|
|
|
|
|
|
+ await UserUtil.getUserInfoByHuawei(openID, unionID, nickname, avatarUri).then(async (data)=>{
|
|
|
|
|
+ // 登录后同步本地会员到线上(仅本地有会员且线上无会员时)
|
|
|
|
|
+ Utility.getLocalNobleExpireDate().then((expireDate)=>{
|
|
|
|
|
+ if (Utility.isNoble() && !this.hasActiveSubscription && expireDate) {
|
|
|
|
|
+ UserUtil.syncLocalNobleToServer(expireDate).then((success)=>{
|
|
|
|
|
+ if (success) {
|
|
|
|
|
+ ToastUtil.showToast('本地会员已同步到账号');
|
|
|
|
|
+ // 关键:同步成功后再刷新用户信息
|
|
|
|
|
+ this.fetchUserInfo();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 同步失败也刷新一次
|
|
|
|
|
+ this.fetchUserInfo();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 不需要同步会员,直接刷新
|
|
|
|
|
+ this.fetchUserInfo();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Builder
|
|
|
|
|
+ syncNobleDialogContentBuilder(): void {
|
|
|
|
|
+ Text('检测到您是本地会员,为保障权益请登录账号,会员权益将自动同步到您的账号。')
|
|
|
|
|
+ .fontSize(16)
|
|
|
|
|
+ .fontColor('#222')
|
|
|
|
|
+ .width('100%')
|
|
|
|
|
+ .textAlign(TextAlign.Center)
|
|
|
|
|
+ .padding(16)
|
|
|
|
|
+ }
|
|
|
aboutToAppear(): void {
|
|
aboutToAppear(): void {
|
|
|
this.topRectHeight = px2vp(AppUtil.getStatusBarHeight());
|
|
this.topRectHeight = px2vp(AppUtil.getStatusBarHeight());
|
|
|
let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
|
|
let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
|
|
|
this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
|
|
this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
|
|
|
AppStorage.setOrCreate('themeColor', themeColor);
|
|
AppStorage.setOrCreate('themeColor', themeColor);
|
|
|
this.themeColor = themeColor;
|
|
this.themeColor = themeColor;
|
|
|
- this.showUserInfo()
|
|
|
|
|
- this.wxEventHandler.registerOnWXRespCallback(this.onWXResp)
|
|
|
|
|
- this.fetchVipPlans();
|
|
|
|
|
- if (this.isLogin && this.userToken) {
|
|
|
|
|
- void this.fetchUserInfo(this.userToken);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- aboutToDisappear() {
|
|
|
|
|
- this.wxEventHandler.unregisterOnWXRespCallback(this.onWXResp)
|
|
|
|
|
- }
|
|
|
|
|
- showUserInfo(){
|
|
|
|
|
- // 自动恢复本地登录状态
|
|
|
|
|
this.isLogin = PreferencesUtil.getBooleanSync('isLogin', false);
|
|
this.isLogin = PreferencesUtil.getBooleanSync('isLogin', false);
|
|
|
this.userId = PreferencesUtil.getNumberSync('userId', 0);
|
|
this.userId = PreferencesUtil.getNumberSync('userId', 0);
|
|
|
this.userName = PreferencesUtil.getStringSync('userName', '未登录用户');
|
|
this.userName = PreferencesUtil.getStringSync('userName', '未登录用户');
|
|
@@ -230,7 +256,35 @@ export struct UserCenter {
|
|
|
this.subscriptionName = PreferencesUtil.getStringSync('subscriptionName', '');
|
|
this.subscriptionName = PreferencesUtil.getStringSync('subscriptionName', '');
|
|
|
this.subscriptionEndDate = PreferencesUtil.getStringSync('subscriptionEndDate', '');
|
|
this.subscriptionEndDate = PreferencesUtil.getStringSync('subscriptionEndDate', '');
|
|
|
this.hasActiveSubscription = PreferencesUtil.getBooleanSync('hasActiveSubscription', false);
|
|
this.hasActiveSubscription = PreferencesUtil.getBooleanSync('hasActiveSubscription', false);
|
|
|
- this.userToken = PreferencesUtil.getStringSync('userToken', '');
|
|
|
|
|
|
|
+
|
|
|
|
|
+ this.wxEventHandler.registerOnWXRespCallback(this.onWXResp)
|
|
|
|
|
+ this.fetchVipPlans();
|
|
|
|
|
+ if (this.isLogin) {
|
|
|
|
|
+ void this.fetchUserInfo();
|
|
|
|
|
+ }
|
|
|
|
|
+ // 新增:未登录但本地是会员,弹窗提示登录同步会员
|
|
|
|
|
+ if (!this.isLogin && Utility.isNoble()) {
|
|
|
|
|
+ DialogHelper.showCustomContentDialog({
|
|
|
|
|
+ dialogId: 'syncNobleDialog',
|
|
|
|
|
+ title: '会员同步提示',
|
|
|
|
|
+ contentBuilder: () => {
|
|
|
|
|
+ this.syncNobleDialogContentBuilder();
|
|
|
|
|
+ },
|
|
|
|
|
+ buttons: [
|
|
|
|
|
+ { value: '暂不登录' },
|
|
|
|
|
+ {
|
|
|
|
|
+ value: '去登录',
|
|
|
|
|
+ action: () => {
|
|
|
|
|
+ this.showLoginDialog();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ aboutToDisappear() {
|
|
|
|
|
+ this.wxEventHandler.unregisterOnWXRespCallback(this.onWXResp)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
build() {
|
|
build() {
|
|
@@ -975,7 +1029,7 @@ export struct UserCenter {
|
|
|
new Pay().pay(orderInfo, true).then(async (result) => {
|
|
new Pay().pay(orderInfo, true).then(async (result) => {
|
|
|
if (result.get('resultStatus') === '9000') {
|
|
if (result.get('resultStatus') === '9000') {
|
|
|
ToastUtil.showToast('支付成功!');
|
|
ToastUtil.showToast('支付成功!');
|
|
|
- void this.fetchUserInfo(this.userToken);
|
|
|
|
|
|
|
+ void this.fetchUserInfo();
|
|
|
// 可在此处刷新会员状态
|
|
// 可在此处刷新会员状态
|
|
|
} else {
|
|
} else {
|
|
|
ToastUtil.showToast('取消支付!');
|
|
ToastUtil.showToast('取消支付!');
|
|
@@ -987,7 +1041,21 @@ export struct UserCenter {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 每次进入页面时刷新用户数据
|
|
// 每次进入页面时刷新用户数据
|
|
|
- async fetchUserInfo(token: string) {
|
|
|
|
|
- await UserUtil.fetchUserInfo(token);
|
|
|
|
|
|
|
+ async fetchUserInfo() {
|
|
|
|
|
+ // console.log('Heanup 刷新用户信息:'+token)
|
|
|
|
|
+ await UserUtil.fetchUserInfo().then((user_info)=>{
|
|
|
|
|
+ console.log("Heanup UserInfo:"+json.stringify(user_info))
|
|
|
|
|
+ this.isLogin = PreferencesUtil.getBooleanSync('isLogin', false);
|
|
|
|
|
+ this.userId = PreferencesUtil.getNumberSync('userId', 0);
|
|
|
|
|
+ this.userName = PreferencesUtil.getStringSync('userName', '未登录用户');
|
|
|
|
|
+ this.userAvatarUrl = PreferencesUtil.getStringSync('userAvatarUrl', '');
|
|
|
|
|
+ this.subscriptionName = PreferencesUtil.getStringSync('subscriptionName', '');
|
|
|
|
|
+ this.subscriptionEndDate = PreferencesUtil.getStringSync('subscriptionEndDate', '');
|
|
|
|
|
+ this.hasActiveSubscription = PreferencesUtil.getBooleanSync('hasActiveSubscription', false);
|
|
|
|
|
+ console.log('Heanup hasActiveSubscription:'+this.hasActiveSubscription)
|
|
|
|
|
+ // 新增:同步线上会员状态到本地,便于 Utility.isNoble 全局判断
|
|
|
|
|
+ PreferencesUtil.putSync('hasActiveSubscription', this.hasActiveSubscription);
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|