This commit is contained in:
haomingming 2025-10-15 11:44:47 +08:00
parent dd9b2984b2
commit 2a1f4a2405
12 changed files with 352 additions and 104 deletions

125
App.vue
View File

@ -19,7 +19,8 @@ import { isWxApp } from "@/utils/im/index";
/** 国际化*/
import { setLanguage } from "@/utils/im/i18n";
import BASE_URL from "@/utils/config.js"
import my_api from '@/api/my_api.js'
import GlobalDialog from "@/components/GlobalDialog.vue"
// #ifdef APP-PLUS
/** 推送插件 */
const nimPushPlugin = uni.requireNativePlugin("NIMUniPlugin-PluginModule");
@ -42,9 +43,35 @@ export default {
uni.getPushClientId({
success: (res) => {
let push_clientid = res.cid
uni.setStorageSync("push_clientid", push_clientid)
console.log('客户端推送标识cid:',push_clientid)
},
uni.setStorageSync("push_clientid", push_clientid)
console.log('客户端推送标识cid:',push_clientid)
const systemInfo = uni.getSystemInfoSync();
console.log("systemInfo:", systemInfo)
let userInfo= uni.getStorageSync('userInfo')
console.log("userinfo:", userInfo)
if(!userInfo){
return
}
if(userInfo.uuid){
let client_type = ""
if (systemInfo.platform === 'android') {
client_type = "A"
} else if (systemInfo.platform === 'ios') {
client_type = "I"
}
console.log("client_type:", client_type)
if(client_type){
my_api.addUniappCid({
user_uuid: userInfo.uuid,
client_type:client_type,
cid: push_clientid
})
}
}
},
fail(err) {
console.error("unipush: ", err)
}
@ -53,28 +80,39 @@ export default {
uni.onPushMessage((res)=>{
console.log("收到推送消息:", res)
uni.showModal({
let app_isback = uni.getStorageSync("app_isback")
console.log("app_isback", app_isback)
uni.showModal({
title: res.data.title,
content: res.type,
showCancel: false
});
if(res.type === 'click' ){
if(res.type === 'click' ){
}else{
uni.createPushMessage({
title: res.data.title,
content: res.data.content,
payload: res.data.payload,
delay: 1,
success: (res) => {
console.log("创建推送消息成功", res)
}
})
}
}else{
if(app_isback){
uni.createPushMessage({
title: res.data.title,
content: res.data.content,
payload: res.data.payload,
delay: 1,
success: (res) => {
console.log("创建推送消息成功", res)
}
})
}else{
console.log('[App] emit global-dialog:show', res)
uni.$emit('global-dialog:show', {
title: res.data.title || '消息通知',
content: res.data.content || '',
confirmText: '我知道了',
position: 'top',
offsetTop: '160rpx'
})
}
}
})
/** 设置语言 此处为了方便demo切换语言将其存到本地实际需根据业务情况设置*/
@ -141,23 +179,25 @@ export default {
// #ifdef APP-PLUS
console.log("onShow");
uni?.$UIKitNIM?.V2NIMSettingService?.setAppBackground(false);
uni.setStorageSync("app_isback", false)
//
nimPushPlugin.addOpenNotificationListener((res) => {
console.log("推送监听");
console.log("res",res);
if (typeof res == "object" && res?.sessionId && res?.sessionType) {
// id
const imOptions = uni.getStorageSync(STORAGE_KEY);
//
const type = res?.sessionType;
// ID
startByNotificationId = `${imOptions.account}|${type}|${res?.sessionId}`;
}
});
// nimPushPlugin.addOpenNotificationListener((res) => {
// console.log("");
// console.log("res",res);
// if (typeof res == "object" && res?.sessionId && res?.sessionType) {
// // id
// const imOptions = uni.getStorageSync(STORAGE_KEY);
// //
// const type = res?.sessionType;
// // ID
// startByNotificationId = `${imOptions.account}|${type}|${res?.sessionId}`;
// }
// });
// #endif
},
onHide() {
console.log("onHide");
uni.setStorageSync("app_isback", true)
// #ifdef APP-PLUS
uni?.$UIKitNIM?.V2NIMSettingService?.setAppBackground(true);
// #endif
@ -165,6 +205,9 @@ export default {
// startByNotificationId
startByNotificationId = "";
},
components:{
GlobalDialog
},
methods: {
initNim(opts) {
console.log("initNim1111111111");
@ -349,12 +392,12 @@ export default {
// appId: "",
// certificateName: "",
// },
// oppoPush: {
// appId: "",
// appKey: "",
// certificateName: "",
// secret: "",
// },
oppoPush: {
appId: "3364888",
appKey: "75D5Vqsg63wok0S0w4SKog0w8",
certificateName: "Expert_Op_Push",
secret: "9e93Ce2AbA97E15F3852279b639b014e",
},
vivoPush: {
appId: "100034326",
appKey: "e789634c1f76c8f184b1def1101ce824",
@ -464,6 +507,10 @@ export default {
};
</script>
<template>
<GlobalDialog />
</template>
<style lang="scss">
/*每个页面公共css */

View File

@ -22,6 +22,9 @@ const my_api = {
startpage() {
return request('/expertAPI/startpage', {}, 'post', true);
},
addUniappCid(data) {
return request('/expertAPI/addUniappCid', data, 'post', true);
}
}

169
components/GlobalDialog.vue Normal file
View File

@ -0,0 +1,169 @@
<template>
<view v-show="visible" class="gd-mask" :class="alignClass" :style="maskStyle">
<view
class="gd-dialog"
@touchstart="onTouchStart"
@touchmove="onTouchMove"
@touchend="onTouchEnd"
>
<view class="gd-title">{{ title }}</view>
<scroll-view class="gd-content" scroll-y>
<text class="gd-text">{{ content }}</text>
</scroll-view>
<!-- <view class="gd-footer">
<view class="gd-btn gd-confirm" @click="handleConfirm">{{ confirmText }}</view>
</view> -->
</view>
</view>
</template>
<script setup>
import { ref, onMounted, onBeforeUnmount, computed } from 'vue'
const visible = ref(false)
const title = ref('消息通知')
const content = ref('')
const confirmText = ref('我知道了')
const position = ref('center') // 'center' | 'top'
const offsetTop = ref('20rpx')
const autoHideTimer = ref(null)
const startY = ref(0)
const hasSwipedUp = ref(false)
const emit = defineEmits(['confirm'])
function handleConfirm(){
visible.value = false
emit('confirm')
}
function show(payload = {}){
title.value = payload.title || '消息通知'
content.value = payload.content || ''
confirmText.value = payload.confirmText || '我知道了'
position.value = payload.position === 'top' ? 'top' : 'center'
offsetTop.value = payload.offsetTop || '20rpx'
visible.value = true
// 5
if (autoHideTimer.value) clearTimeout(autoHideTimer.value)
autoHideTimer.value = setTimeout(() => {
hide()
}, 5000)
}
function hide(){
visible.value = false
if (autoHideTimer.value) {
clearTimeout(autoHideTimer.value)
autoHideTimer.value = null
}
}
function onTouchStart(e){
const touch = e.changedTouches ? e.changedTouches[0] : (e.touches ? e.touches[0] : null)
if (!touch) return
startY.value = touch.clientY || touch.pageY || 0
hasSwipedUp.value = false
}
function onTouchMove(e){
const touch = e.changedTouches ? e.changedTouches[0] : (e.touches ? e.touches[0] : null)
if (!touch) return
const currentY = touch.clientY || touch.pageY || 0
const deltaY = currentY - startY.value
if (deltaY < -60) {
hasSwipedUp.value = true
}
}
function onTouchEnd(){
if (hasSwipedUp.value) {
hide()
}
}
onMounted(() => {
console.log('[GlobalDialog] mounted')
uni.$on('global-dialog:show', show)
uni.$on('global-dialog:hide', hide)
// 便
// @ts-ignore
uni.$showGlobalDialog = (payload = {}) => {
console.log('[GlobalDialog] uni.$showGlobalDialog called', payload)
uni.$emit('global-dialog:show', payload)
}
})
onBeforeUnmount(() => {
uni.$off('global-dialog:show', show)
uni.$off('global-dialog:hide', hide)
})
const alignClass = computed(() => position.value === 'top' ? 'is-top' : 'is-center')
const maskStyle = computed(() => position.value === 'top' ? { paddingTop: offsetTop.value } : {})
</script>
<style scoped lang="scss">
.gd-mask{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
//
pointer-events: none;
}
.gd-mask.is-top{
align-items: flex-start;
justify-content: center;
}
.gd-dialog{
width: 600rpx;
max-width: 90%;
background: #fff;
border-radius: 16rpx;
overflow: hidden;
//
pointer-events: auto;
//
transition: transform 0.2s ease, opacity 0.2s ease;
}
.gd-title{
padding: 28rpx 32rpx 12rpx;
font-size: 32rpx;
font-weight: 600;
color: #111;
text-align: left;
}
.gd-content{
max-height: 420rpx;
padding: 0 32rpx 24rpx;
}
.gd-text{
font-size: 28rpx;
line-height: 1.7;
color: #333;
}
.gd-footer{
padding: 16rpx 24rpx 24rpx;
display: flex;
justify-content: center;
}
.gd-btn{
min-width: 200rpx;
padding: 20rpx 24rpx;
text-align: center;
border-radius: 12rpx;
font-size: 28rpx;
}
.gd-confirm{
background: #2979ff;
color: #fff;
}
</style>

View File

@ -33,11 +33,13 @@
<!-- <view class="active-indicator" v-if="currentTab === index"></view> -->
</view>
</view>
<GlobalDialog />
</template>
<script setup>
import { ref, reactive, onMounted, nextTick } from 'vue';
import { onShow, onLoad } from "@dcloudio/uni-app";
import GlobalDialog from "@/components/GlobalDialog.vue"
import home from '@/static/home_nor.png'
import homeOn from '@/static/home_sel.png'
import classroom from "@/static/classroom.png"

View File

@ -21,8 +21,7 @@
"Payment" : {},
"Share" : {},
"Webview-x5" : {},
"UIWebview" : {},
"Push" : {}
"UIWebview" : {}
},
/* */
"distribute" : {
@ -77,23 +76,7 @@
}
},
"speech" : {},
"push" : {
"unipush" : {
"version" : "2",
"offline" : false,
"hms" : {},
"oppo" : {},
"vivo" : {},
"mi" : {},
"meizu" : {},
"honor" : {},
"icons" : {
"small" : {
"xxhdpi" : "D:/uniapp/专家版图标/72.png"
}
}
}
}
"push" : {}
},
"splashscreen" : {
"androidStyle" : "common",

View File

@ -69,18 +69,6 @@
"title": "用户服务协议" //
}
]
},
"buttons": { // 3.1.14+
"iconWidth": "45px", // 45px
"list": [{
"provider": "apple",
"iconPath": "/static/apple.png" //
},
{
"provider": "weixin",
"iconPath": "/static/wechat.png" //
}
]
}
},
success(res) { //
@ -89,6 +77,9 @@
fail(res) { //
console.log(res.errCode)
console.log(res.errMsg)
uni.redirectTo({
url: '/pages_app/login/login?univerify=0'
});
}
})
// #endif

View File

@ -16,9 +16,9 @@
<!-- 手机号显示 -->
<!-- #ifdef APP -->
<view class="phone-display">
<!-- <view class="phone-display">
<text class="phone-number">176****8628</text>
</view>
</view> -->
<!-- 登录按钮 -->
<view class="login-button" @click="onOneClickLogin">
@ -129,15 +129,16 @@
};
//
const onOneClickLogin = () => {
if (!isAgreed.value) {
uni.showToast({
title: '请先同意相关协议',
icon: 'none'
const res = checkUniverifyLogin()
if(res){
uni.redirectTo({
url: '/pages/univerify/univerify'
});
}else{
uni.redirectTo({
url: '/pages_app/smsLogin/smsLogin'
});
return;
}
console.log('一键登录');
};
//
@ -320,11 +321,31 @@
url:'/pages/index/index'
})
}
const univerify = ref(1)
//
onLoad(() => {
console.log('登录页面加载完成');
// #ifdef APP
onLoad((options) => {
if(options.univerify){
univerify.value = options.univerify // App-Plus
}
})
const res = checkUniverifyLogin()
if(res){
uni.redirectTo({
url: '/pages/univerify/univerify'
});
}else{
uni.redirectTo({
url: '/pages_app/smsLogin/smsLogin'
});
}
});
const checkUniverifyLogin=()=>{
let res = false
// #ifdef APP
uni.getProvider({
service: 'oauth',
success: function (res) {
@ -334,33 +355,27 @@
provider: 'univerify',
success(){ //
//
uni.redirectTo({
url: '/pages/univerify/univerify'
});
if(univerify.value == 1){
return true
}
},
fail(res){ //
//
//
console.log(res.errCode)
console.log(res.errMsg)
uni.redirectTo({
url: '/pages_app/smsLogin/smsLogin'
});
return false
}
})
}else{
uni.redirectTo({
url: '/pages_app/smsLogin/smsLogin'
});
return false
}
}
});
// #endif
});
return res
}
//
onShow(() => {
// #ifdef APP

View File

@ -0,0 +1,17 @@
// 简单的使用示例
'use strict';
const uniPush = uniCloud.getPushManager({
appId: "__UNI__89F511F"
})
exports.main = async (event) => {
let obj = JSON.parse(event.body)
const res = await uniPush.sendMessage({
"title": obj.title,
"content": obj.content,
"settings": obj.settings,
"payload": obj.payload,
"force_notification": false,
"request_id": obj.request_id,
})
return res;
};

View File

@ -0,0 +1,7 @@
{
"name": "allPush",
"dependencies": {},
"extensions": {
"uni-cloud-push": {}
}
}

View File

@ -6,15 +6,13 @@ appId: "__UNI__89F511F"
exports.main = async (event) => {
let obj = JSON.parse(event.body)
const res = await uniPush.sendMessage({
"push_clientid": obj.cids, // 设备id支持多个以数组的形式指定多个设备如["cid-1","cid-2"]数组长度不大于1000
"title": obj.title, // 标题
"content": obj.content, // 内容
"settings": obj.settings, // 消息有效期
"payload": obj.payload, // 数据
"category": obj.category, // HarmonyOS NEXT系统纯血鸿蒙、非安卓鸿蒙的消息分类要给鸿蒙设备推送时才必传
"force_notification": true, //填写true客户端就会对在线消息自动创建“通知栏消息”不填写则需要客户端自己处理。
"request_id": obj.request_id ,//请求唯一标识号10-32位之间如果request_id重复会导致消息丢失
"options":obj.options //消息分类,没申请可以不传这个参数
"push_clientid": obj.cids,
"title": obj.title,
"content": obj.content,
"settings": obj.settings,
"payload": obj.payload,
"force_notification": false,
"request_id": obj.request_id,
})
return res;
};

View File

@ -0,0 +1,9 @@
// 简单的使用示例
'use strict';
const uniPush = uniCloud.getPushManager({
appId: "__UNI__89F511F"
})
exports.main = async (event) => {
const res = await uniPush.getClientDetailByCid('27ab08ad61e30572654bd2b3bf05ad9c')
return res;
};

View File

@ -0,0 +1,7 @@
{
"name": "getClientDetailByCid",
"dependencies": {},
"extensions": {
"uni-cloud-push": {}
}
}