diff --git a/App.vue b/App.vue index 4007c3c..3cbbe5d 100644 --- a/App.vue +++ b/App.vue @@ -36,9 +36,29 @@ export default { /** 关闭启动画面,锁定竖屏 */ plus.navigator.closeSplashscreen(); plus.screen.lockOrientation("portrait-primary"); - - // #endif + + // uni-app客户端获取push客户端标记,代码可以实现在App.vue中 + uni.getPushClientId({ + success: (res) => { + let push_clientid = res.cid + uni.setStorageSync("push_clientid", push_clientid) + console.log('客户端推送标识cid:',push_clientid) + }, + fail(err) { + console.error("unipush: ", err) + } + }) + + + uni.onPushMessage((res)=>{ + console.log("收到推送消息:", res) + uni.showModal({ + title: res.data.title, + content: res.type, + showCancel: false + }); + }) /** 设置语言 (此处为了方便demo切换语言,将其存到本地,实际需根据业务情况设置)*/ setLanguage( diff --git a/androidPrivacy.json b/androidPrivacy.json new file mode 100644 index 0000000..12df862 --- /dev/null +++ b/androidPrivacy.json @@ -0,0 +1,3 @@ +{ + "prompt": "template" +} diff --git a/api/my_api.js b/api/my_api.js index e6abd35..1bea8e0 100644 --- a/api/my_api.js +++ b/api/my_api.js @@ -18,6 +18,10 @@ const my_api = { checkVersion(data) { return request('/expertAPI/checkVersion', data, 'post', true); + }, + + startpage() { + return request('/expertAPI/startpage', {}, 'post', true); } } diff --git a/manifest.json b/manifest.json index 684fb8e..1e19baf 100644 --- a/manifest.json +++ b/manifest.json @@ -21,7 +21,8 @@ "Payment" : {}, "Share" : {}, "Webview-x5" : {}, - "UIWebview" : {} + "UIWebview" : {}, + "Push" : {} }, /* 模块配置 */ "distribute" : { @@ -74,10 +75,29 @@ "UniversalLinks" : "https://doc.igandan.com/gdxzExpert/" } }, - "speech" : {} + "speech" : {}, + "push" : { + "unipush" : { + "version" : "2", + "offline" : false, + "hms" : {}, + "oppo" : {}, + "vivo" : {}, + "mi" : {}, + "meizu" : {}, + "honor" : {}, + "icons" : { + "small" : { + "xxhdpi" : "D:/haomi/Documents/WeChat Files/wxid_x5u4rycntnkq21/FileStorage/File/2025-09/专家版图标/专家版图标/72.png" + } + } + } + } }, "splashscreen" : { - "androidStyle" : "common" + "androidStyle" : "common", + "useOriginalMsgbox" : true, + "iosStyle" : "common" }, "icons" : { "android" : { @@ -132,5 +152,7 @@ "vueVersion" : "3", "uniStatistics" : { "version" : "2" - } + }, + "fallbackLocale" : "zh-Hans", + "locale" : "zh-Hans" } diff --git a/pages.json b/pages.json index db493d8..9391cdd 100644 --- a/pages.json +++ b/pages.json @@ -8,7 +8,18 @@ } }, - "pages": [{ + "pages": [ + { + "path" : "pages/ad/ad", + "style": { + "navigationBarTitleText": "", + "navigationStyle": "custom", + "app": { + "bounce": "none" + } + } + }, + { "path": "pages/index/index", "style": { "navigationBarTitleText": "", @@ -75,6 +86,7 @@ "enablePullDownRefresh": false } } + ], "subPackages": [ { @@ -1216,7 +1228,7 @@ "list": [ { "name": "", - "path": "pages/index/index", + "path": "pages/ad/ad", "query": "" } ] diff --git a/pages/ad/ad.vue b/pages/ad/ad.vue new file mode 100644 index 0000000..2e9f6b1 --- /dev/null +++ b/pages/ad/ad.vue @@ -0,0 +1,193 @@ + + + + + diff --git a/pages/my/my.vue b/pages/my/my.vue index fa6baa8..5f43b12 100644 --- a/pages/my/my.vue +++ b/pages/my/my.vue @@ -144,9 +144,9 @@ 更换手机号 - + - 通知已开 + 通知已{{notice_on?'开':'关'}} @@ -269,6 +269,7 @@ const totalPoints = ref(0) const sign_in = ref(0) const honor_list = ref([]) + const notice_on = ref(false) // 从storage获取用户信息 const getUserInfoFromStorage = () => { try { @@ -428,8 +429,9 @@ url="/pages_app/setting/setting" break; default: + const push_clientid = uni.getStorageSync("push_clientid") uni.showToast({ - title: '功能开发中', + title: 'push_clientid: '+push_clientid, icon: 'none' }); } @@ -438,6 +440,131 @@ }) }; +// 判断通知权限是否开启 +const isNoticeOn = () => { + // #ifdef APP-PLUS + if (plus.os.name == "Android") { + var main = plus.android.runtimeMainActivity(); + var NotificationManagerCompat = plus.android.importClass("android.support.v4.app.NotificationManagerCompat"); + if (NotificationManagerCompat == null) { + NotificationManagerCompat = plus.android.importClass("androidx.core.app.NotificationManagerCompat"); + } + var areNotificationsEnabled = NotificationManagerCompat.from(main).areNotificationsEnabled(); + notice_on.value = areNotificationsEnabled + return areNotificationsEnabled; + } else if (plus.os.name == "iOS") { + var isIosOn = undefined; + var types = 0; + var app = plus.ios.invoke("UIApplication", "sharedApplication"); + var settings = plus.ios.invoke(app, "currentUserNotificationSettings"); + if (settings) { + types = settings.plusGetAttribute("types"); + plus.ios.deleteObject(settings); + } else { + types = plus.ios.invoke(app, "enabledRemoteNotificationTypes"); + } + plus.ios.deleteObject(app); + isIosOn = 0 != types; + notice_on.value = isIosOn + return isIosOn; + } + // #endif +} + +// 前往系统设置页面开启或关闭通知权限 +const switchPushPermissions = () => { + const push_clientid = uni.getStorageSync("push_clientid") + // #ifdef APP-PLUS + let title = isNoticeOn() ? "通知权限关闭提醒" : "通知权限开启提醒"; + let content = isNoticeOn() + ? "通知权限已开启,是否前往设置关闭?"+push_clientid + : "您还没有开启通知权限,无法接受到消息通知,是否前往设置?"+push_clientid; + // 打开安卓系统设置页面 + let openAndroidSetting = () => { + var main = plus.android.runtimeMainActivity(); + var pkName = main.getPackageName(); + var uid = main.getApplicationInfo().plusGetAttribute("uid"); + var Intent = plus.android.importClass("android.content.Intent"); + var Build = plus.android.importClass("android.os.Build"); + //android 8.0引导 + if (Build.VERSION.SDK_INT >= 26) { + var intent = new Intent("android.settings.APP_NOTIFICATION_SETTINGS"); + intent.putExtra("android.provider.extra.APP_PACKAGE", pkName); + } else if (Build.VERSION.SDK_INT >= 21) { + //android 5.0-7.0 + var intent = new Intent("android.settings.APP_NOTIFICATION_SETTINGS"); + intent.putExtra("app_package", pkName); + intent.putExtra("app_uid", uid); + } else { + //(<21)其他--跳转到该应用管理的详情页 + intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); + var uri = Uri.fromParts("package", mainActivity.getPackageName(), null); + intent.setData(uri); + } + // 跳转到该应用的系统通知设置页 + main.startActivity(intent); + }; + // 打开苹果系统设置页面 + let openIOSSetting = () => { + var app = plus.ios.invoke("UIApplication", "sharedApplication"); + var setting = plus.ios.invoke("NSURL", "URLWithString:", "app-settings:"); + plus.ios.invoke(app, "openURL:", setting); + plus.ios.deleteObject(setting); + plus.ios.deleteObject(app); + // ios18跳转不过去的解决方案 + // 方案一:使用uni.openAppAuthorizeSetting(),文档地址:https://uniapp.dcloud.net.cn/api/system/openappauthorizesetting.html + // 方案二:待验证,AI生成;来源评论区:iOS 18以后,openURL:完全被弃用,需要用openURL:options:completionHandler:替代。 + // var app = plus.ios.invoke("UIApplication", "sharedApplication"); + // var url; + // // 获取安全 URL(iOS 8+) + // if (plus.ios.invoke("UIApplication", "respondsToSelector:", "openSettingsURLString")) { + // var urlString = plus.ios.invoke("UIApplication", "openSettingsURLString"); + // url = plus.ios.invoke("NSURL", "URLWithString:", urlString); + // } else { + // url = plus.ios.invoke("NSURL", "URLWithString:", "app-settings:"); + // } + // // 判断新 API 可用性(iOS 10+) + // var supportsNewAPI = plus.ios.invoke(app, "respondsToSelector:", "openURL:options:completionHandler:"); + // if (supportsNewAPI) { + // var options = plus.ios.newObject("NSDictionary"); + // var completion = plus.ios.newBlock(function(success) { + // console.log("跳转结果:" + success); + // if (!success) { + // plus.nativeUI.toast("无法打开设置,请手动前往"); + // } + // }, "v@:B"); + // plus.ios.invoke(app, "openURL:options:completionHandler:", url, options, completion); + // plus.ios.deleteObject(completion); + // } else { + // if (plus.ios.invoke(app, "canOpenURL:", url)) { + // plus.ios.invoke(app, "openURL:", url); + // } else { + // throw new Error("当前系统不支持跳转设置"); + // } + // } + // plus.ios.deleteObject(url); + // plus.ios.deleteObject(app); + }; + // 弹窗提醒开通或关闭权限,点击确认后,跳转到系统设置页面进行设置 + uni.showModal({ + title: title, + content: content, + showCancel: true, + confirmColor: "#ff903f", + success: (res) => { + if (res.confirm) { + if (plus.os.name == "Android") { + openAndroidSetting(); + } else if (plus.os.name == "iOS") { + openIOSSetting(); + } + } + }, + }); + // #endif +} + + const showYearSummary = () => { console.log('显示年度总结'); uni.showToast({ @@ -491,6 +618,7 @@ getUserInfoFromStorage() // 先从storage获取用户信息 fetchMyInfo() // 然后从API获取最新数据 getIsBoundWechat() + isNoticeOn() }); diff --git a/pages_app/setting/setting.vue b/pages_app/setting/setting.vue index 7784d5d..4a8e66e 100644 --- a/pages_app/setting/setting.vue +++ b/pages_app/setting/setting.vue @@ -22,7 +22,7 @@ 消息通知 - 已开启 + {{notice_on?'已':'未'}}开启 @@ -73,7 +73,7 @@ 清除缓存 - 1.39MB + {{fileSizeString}} @@ -144,7 +144,13 @@