cyl/master-0819
wangxia 3 months ago
parent 1e5a475195
commit 0a0fd61c86

@ -4,44 +4,34 @@ import V2NIM, { V2NIMConst } from "nim-web-sdk-ng/dist/v2/NIM_UNIAPP_SDK";
import { getMsgContentTipByType } from "./pages/NEUIKit/utils/msg"; import { getMsgContentTipByType } from "./pages/NEUIKit/utils/msg";
import { STORAGE_KEY } from "./pages/NEUIKit/utils/constants"; import { STORAGE_KEY } from "./pages/NEUIKit/utils/constants";
import { isWxApp } from "./pages/NEUIKit/utils"; import { isWxApp } from "./pages/NEUIKit/utils";
import { V2NIMMessage, V2NIMMessagePushConfig } from "nim-web-sdk-ng/dist/v2/NIM_UNIAPP_SDK/V2NIMMessageService"; import { V2NIMMessage, V2NIMMessagePushConfig, V2NIMConversation } from "nim-web-sdk-ng/dist/v2/NIM_UNIAPP_SDK/V2NIMMessageService";
import { unix } from "dayjs"; import { unix } from "dayjs";
export default { export default {
globalData: { globalData: {
timer: null, // timer: null, //
reconnectTimer: null, //
themeColor: "#00b666", themeColor: "#00b666",
themeBackgroundColor: "#00b66621", themeBackgroundColor: "#00b66621",
}, },
onLaunch() { onLaunch() {
let that = this; let that = this;
uni.removeStorageSync("selectedCity"); uni.removeStorageSync("selectedCity");
//
// uni.onBeforeAppRoute((res) => {
// console.log("setNavStyle", res);
// try {
// that.G.Post("/common/user/browsing/history/addRecord", { browsingUrl: res.path }, (res) => {});
// } catch (error) {
// console.log("error", error);
// }
// });
// //
uni.addInterceptor("navigateTo", { uni.addInterceptor("navigateTo", {
//
invoke(args) { invoke(args) {
console.log("navigateTo 跳转前", args); console.log("navigateTo 跳转前", args);
that.G.watchUserPage(args.url); that.G.watchUserPage(args.url);
}, },
}); });
uni.addInterceptor("reLaunch", { uni.addInterceptor("reLaunch", {
//
invoke(args) { invoke(args) {
console.log("reLaunch 跳转前", args); console.log("reLaunch 跳转前", args);
that.G.watchUserPage(args.url); that.G.watchUserPage(args.url);
}, },
}); });
uni.addInterceptor("redirectTo", { uni.addInterceptor("redirectTo", {
//
invoke(args) { invoke(args) {
console.log("redirectTo 跳转前", args); console.log("redirectTo 跳转前", args);
that.G.watchUserPage(args.url); that.G.watchUserPage(args.url);
@ -51,6 +41,7 @@ export default {
onShow: function (options) { onShow: function (options) {
let that = this; let that = this;
console.log("show 项目init", options, decodeURIComponent(options.query.scene)); console.log("show 项目init", options, decodeURIComponent(options.query.scene));
// id // id
uni.removeStorageSync("scene"); uni.removeStorageSync("scene");
uni.removeStorageSync("user_scene"); uni.removeStorageSync("user_scene");
@ -74,15 +65,21 @@ export default {
} else { } else {
uni.setStorageSync("apply-invite-code", ""); uni.setStorageSync("apply-invite-code", "");
} }
if (uni.getStorageSync("apply-token")) { if (uni.getStorageSync("apply-token")) {
this.G.checkToken(); this.G.checkToken();
} }
// -
if (!that.globalData.timer) { if (!that.globalData.timer) {
that.checkNum(); that.checkNum();
that.checkAndReconnectIM(); //
// 15
that.globalData.timer = setInterval(() => { that.globalData.timer = setInterval(() => {
console.log("inner+++++++++++++++++++++++++++++++++++++++++++++++");
that.checkNum(); that.checkNum();
}, 30 * 1000); that.checkAndReconnectIM();
}, 15 * 1000);
} }
uni.$on("isGlogin", function (data) { uni.$on("isGlogin", function (data) {
@ -91,19 +88,127 @@ export default {
that.initWyyx(); that.initWyyx();
} }
}); });
//
if (uni.getStorageSync("apply-token")) { if (uni.getStorageSync("apply-token")) {
console.log("app.vue 是否调用"); console.log("app.vue 检查IM连接状态");
that.initWyyx(); that.checkAndReconnectIM();
} }
}, },
onHide: function () { onHide: function () {
//
console.log("应用进入后台保持IM连接检测");
//
if (uni.$UIKitNIM && uni.$UIKitNIM.V2NIMLoginService) {
uni.$UIKitNIM.V2NIMLoginService.ping().then(() => {
console.log("后台心跳发送成功");
}).catch(err => {
console.error("后台心跳发送失败,准备重连", err);
this.reconnectIM();
});
}
},
onUnload() {
//
if (this.globalData.timer) { if (this.globalData.timer) {
clearInterval(this.globalData.timer); clearInterval(this.globalData.timer);
this.globalData.timer = null; this.globalData.timer = null;
console.log("定时任务已清除"); console.log("定时器已清除");
}
if (this.globalData.reconnectTimer) {
clearInterval(this.globalData.reconnectTimer);
this.globalData.reconnectTimer = null;
} }
}, },
methods: { methods: {
// IM
checkAndReconnectIM() {
let that = this;
// SDK
setTimeout(() => {
if (uni.$UIKitNIM && uni.$UIKitStore) {
const connectStatus = uni.$UIKitStore.connectStore.connectStatus;
console.log('当前IM连接状态:', connectStatus);
//
// 0:
// 1:
// 2:
// 3:
if (connectStatus !== 2 && connectStatus !== 3) {
console.log("IM连接已断开尝试重连...");
that.reconnectIM();
}
} else if (uni.getStorageSync("apply-token") && uni.getStorageSync("apply-uid")) {
console.log("IM SDK未初始化重新初始化...");
that.initWyyx();
}
}, 1000);
},
// IM
reconnectIM() {
let that = this;
//
if (this.globalData.reconnectTimer) {
console.log("正在重连中,无需重复操作");
return;
}
//
const attemptReconnect = () => {
if (!uni.getStorageSync("apply-token") || !uni.getStorageSync("apply-uid")) {
console.log("用户未登录,停止重连");
clearInterval(that.globalData.reconnectTimer);
that.globalData.reconnectTimer = null;
return;
}
if (uni.$UIKitNIM && uni.$UIKitNIM.V2NIMLoginService) {
const account = uni.getStorageSync("im-accid");
const token = uni.getStorageSync("im-token");
if (account && token) {
console.log(`尝试重连IM (account: ${account})`);
uni.$UIKitNIM.V2NIMLoginService.login(account, token)
.then(() => {
console.log("IM重连成功");
clearInterval(that.globalData.reconnectTimer);
that.globalData.reconnectTimer = null;
})
.catch((error) => {
console.error("IM重连失败将再次尝试", error);
});
} else {
console.log("重连信息不全重新初始化IM");
that.initWyyx();
}
} else {
console.log("SDK未初始化重新初始化IM");
that.initWyyx();
}
};
//
// attemptReconnect();
// 510
let reconnectAttempts = 0;
this.globalData.reconnectTimer = setInterval(() => {
reconnectAttempts++;
if (reconnectAttempts >= 10) {
console.log("重连尝试次数已达上限,停止重连");
clearInterval(that.globalData.reconnectTimer);
that.globalData.reconnectTimer = null;
return;
}
attemptReconnect();
}, 5000);
},
initWyyx() { initWyyx() {
let that = this; let that = this;
@ -114,36 +219,46 @@ export default {
}, },
(res) => { (res) => {
console.log("wyyx_getConfig", res); console.log("wyyx_getConfig", res);
//
if (!res || !res.appKey || !res.accid || !res.token) {
console.error("获取IM配置失败参数不完整");
return;
}
let resData = { let resData = {
appkey: res.appKey, appkey: res.appKey,
accid: res.accid, accid: res.accid,
token: res.token, token: res.token,
}; };
// IM
uni.setStorageSync('im-appkey', resData.appkey);
uni.setStorageSync('im-accid', resData.accid);
uni.setStorageSync('im-token', resData.token);
const imOptions = { const imOptions = {
appkey: resData.appkey, // appkey appkey: resData.appkey,
account: resData.accid, // account account: resData.accid,
token: resData.token, // token token: resData.token,
// appkey: "7e19d679085266aa872a8de12f0c1ae5", // appkey
// account: "9", // account
// token: "2d4ca36cca6293cf3a81d6ca1b8026f7", // token
}; };
if (imOptions) {
this.initNim(imOptions); this.initNim(imOptions);
} else {
// ,
}
} }
); );
}, },
async initNim(opts) { async initNim(opts) {
let that = this; let that = this;
// nim sdk // nim sdk
const nim = (uni.$UIKitNIM = V2NIM.getInstance( const nim = (uni.$UIKitNIM = V2NIM.getInstance(
{ {
appkey: opts.appkey, appkey: opts.appkey,
needReconnect: true, needReconnect: true,
// "reconnectionAttempts": 5, reconnectionAttempts: 10, //
debugLevel: "error", reconnectionDelay: 3000, // 3
heartbeatInterval: 20000, // 20
debugLevel: "warn", // 便
apiVersion: "v2", apiVersion: "v2",
enableV2CloudConversation: true, enableV2CloudConversation: true,
}, },
@ -151,10 +266,8 @@ export default {
V2NIMLoginServiceConfig: { V2NIMLoginServiceConfig: {
lbsUrls: isWxApp ? ["https://lbs.netease.im/lbs/wxwebconf.jsp"] : ["https://lbs.netease.im/lbs/webconf.jsp"], lbsUrls: isWxApp ? ["https://lbs.netease.im/lbs/wxwebconf.jsp"] : ["https://lbs.netease.im/lbs/webconf.jsp"],
linkUrl: isWxApp ? "wlnimsc0.netease.im" : "weblink.netease.im", linkUrl: isWxApp ? "wlnimsc0.netease.im" : "weblink.netease.im",
/** isFixedDeviceId: true, // 使ID
* 使用固定设备 ID autoLogin: true, //
*/
isFixedDeviceId: true,
}, },
} }
)); ));
@ -166,9 +279,7 @@ export default {
nim, nim,
{ {
addFriendNeedVerify: false, addFriendNeedVerify: false,
// p2p p2p false
p2pMsgReceiptVisible: true, p2pMsgReceiptVisible: true,
// false
teamMsgReceiptVisible: true, teamMsgReceiptVisible: true,
teamAgreeMode: V2NIMConst.V2NIMTeamAgreeMode.V2NIM_TEAM_AGREE_MODE_NO_AUTH, teamAgreeMode: V2NIMConst.V2NIMTeamAgreeMode.V2NIM_TEAM_AGREE_MODE_NO_AUTH,
sendMsgBefore: async (options: { msg: V2NIMMessage; conversationId: string; serverExtension?: Record<string, unknown> }) => { sendMsgBefore: async (options: { msg: V2NIMMessage; conversationId: string; serverExtension?: Record<string, unknown> }) => {
@ -178,8 +289,6 @@ export default {
}); });
const yxAitMsg = options.serverExtension ? options.serverExtension.yxAitMsg : { forcePushIDsList: "[]", needForcePush: false }; const yxAitMsg = options.serverExtension ? options.serverExtension.yxAitMsg : { forcePushIDsList: "[]", needForcePush: false };
// at 线
const { forcePushIDsList, needForcePush } = yxAitMsg const { forcePushIDsList, needForcePush } = yxAitMsg
? // @ts-ignore ? // @ts-ignore
store.msgStore._formatExtAitToPushInfo(yxAitMsg, options.msg.text) store.msgStore._formatExtAitToPushInfo(yxAitMsg, options.msg.text)
@ -192,26 +301,21 @@ export default {
const targetId = nim.V2NIMConversationIdUtil.parseConversationTargetId(conversationId); const targetId = nim.V2NIMConversationIdUtil.parseConversationTargetId(conversationId);
const pushPayload = JSON.stringify({ const pushPayload = JSON.stringify({
// oppo
oppoField: { oppoField: {
click_action_type: 4, // oppo click_action_type: 4,
click_action_activity: "", // TODO click_action_activity: "",
action_parameters: { action_parameters: {
sessionId: targetId, sessionId: targetId,
sessionType: conversationType, sessionType: conversationType,
}, //
}, },
},
// vivo
vivoField: { vivoField: {
pushMode: 0, //0 1 0 pushMode: 0,
}, },
// huawei
hwField: { hwField: {
click_action: { click_action: {
type: 1, type: 1,
action: "", // TODO action: "",
}, },
androidConfig: { androidConfig: {
category: "IM", category: "IM",
@ -221,8 +325,6 @@ export default {
}), }),
}, },
}, },
//
sessionId: targetId, sessionId: targetId,
sessionType: conversationType, sessionType: conversationType,
}); });
@ -243,6 +345,16 @@ export default {
"UniApp" "UniApp"
)); ));
//
nim.V2NIMLoginService.on("onConnectStatusChanged", (status) => {
console.log("IM连接状态变化:", status);
// 1
if (status === 1) {
console.log("检测到连接断开,触发重连");
that.reconnectIM();
}
});
// #ifdef APP-PLUS // #ifdef APP-PLUS
const nimPushPlugin = uni.requireNativePlugin("NIMUniPlugin-PluginModule"); const nimPushPlugin = uni.requireNativePlugin("NIMUniPlugin-PluginModule");
nim.V2NIMSettingService.setOfflinePushConfig(nimPushPlugin, { nim.V2NIMSettingService.setOfflinePushConfig(nimPushPlugin, {
@ -264,41 +376,56 @@ export default {
certificateName: "rongyaoCertificateName", certificateName: "rongyaoCertificateName",
}, },
apns: { apns: {
// certificateName: 'AuthKey_98P8URRXUD_test', //: certificateName: "AuthKey_98P8URRXUD",
certificateName: "AuthKey_98P8URRXUD", //
}, },
}); });
console.log("是否执行 推送"); console.log("推送配置已设置");
// #endif // #endif
nim.V2NIMLoginService.login(opts.account, opts.token).then(() => {}); // IM
nim.V2NIMLoginService.login(opts.account, opts.token)
.then(() => {
console.log("IM登录成功");
//
if (that.globalData.reconnectTimer) {
clearInterval(that.globalData.reconnectTimer);
that.globalData.reconnectTimer = null;
}
})
.catch((error) => {
console.error("IM登录失败", error);
//
that.reconnectIM();
});
//
nim.V2NIMConversationService.on("onConversationChanged", function (conversationList: V2NIMConversation[]) { nim.V2NIMConversationService.on("onConversationChanged", function (conversationList: V2NIMConversation[]) {
console.log("初始化监听会话:", conversationList); console.log("初始化监听会话:", conversationList);
let _bool = conversationList.filter((item) => { let unreadConversations = conversationList.filter((item) => {
return Number(item.unreadCount) > 0; return Number(item.unreadCount) > 0;
}); });
console.log("初始化监听会话bool:", _bool); console.log("未读会话数量:", unreadConversations.length);
if (_bool && _bool.length > 0) { if (unreadConversations.length > 0) {
that.playAudio(); // that.playAudio();
} }
}); });
}, },
playAudio() { playAudio() {
let that = this; let that = this;
const innerAudioContext = uni.createInnerAudioContext(); const innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.autoplay = true; innerAudioContext.autoplay = true;
innerAudioContext.src = "https://matripe-cms.oss-cn-beijing.aliyuncs.com/ibocai/tip.mp3"; innerAudioContext.src = "https://matripe-cms.oss-cn-beijing.aliyuncs.com/ibocai/tip.mp3";
innerAudioContext.onPlay(() => { innerAudioContext.onPlay(() => {
console.log("开始播放"); console.log("开始播放提示音");
}); });
uni.vibrateShort(); uni.vibrateShort();
innerAudioContext.onError((res) => { innerAudioContext.onError((res) => {
console.log(res.errMsg); console.log("提示音播放错误:", res.errMsg, res.errCode);
console.log(res.errCode);
}); });
}, },
checkNum() { checkNum() {
let that = this; let that = this;
if (uni.getStorageSync("apply-token")) { if (uni.getStorageSync("apply-token")) {
@ -310,14 +437,14 @@ export default {
index: 2, index: 2,
text: String(res.approvePassHasNotRed + applyNum), text: String(res.approvePassHasNotRed + applyNum),
fail(err) { fail(err) {
console.log("err", err); console.log("设置tabBar徽章失败:", err);
}, },
}); });
} else { } else {
uni.removeTabBarBadge({ uni.removeTabBarBadge({
index: 2, index: 2,
fail(err) { fail(err) {
console.log("err", err); console.log("移除tabBar徽章失败:", err);
}, },
}); });
} }
@ -333,15 +460,14 @@ export default {
@import "./static/css/iconfont.css"; @import "./static/css/iconfont.css";
@import "./uni_modules/vk-uview-ui/index.scss"; @import "./uni_modules/vk-uview-ui/index.scss";
@import "./static/css/base.scss"; @import "./static/css/base.scss";
// @import "./static/font/iconfont-weapp-icon.css";
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
page { page {
width: 100vw; width: 100vw;
height: 100vh; height: 100vh;
} }
// #endif // #endif
// #ifdef H5 || APP-PLUS || MP-TOUTIAO || MP-KUAISHOU // #ifdef H5 || APP-PLUS || MP-TOUTIAO || MP-KUAISHOU
page { page {
width: 100vw; width: 100vw;
@ -352,7 +478,6 @@ page {
--color-027: #ff4400; --color-027: #ff4400;
--color-href: #576b95; --color-href: #576b95;
} }
// #endif // #endif
// uview // uview

@ -184,34 +184,33 @@ export function createApp () {
uni.showLoading({ uni.showLoading({
title: '上传中...', title: '上传中...',
}) })
let imgPath = JSON.parse(imgRes)[0]
console.log('imgPath', imgPath);
G.Get(apiInfo.getOssInfo, {}, ({ data }) => { G.Get(apiInfo.getOssInfo, {}, ({ data }) => {
console.log('uploadImgToOssresresresres', data); console.log('uploadImgToOssresresresres', data);
const { policy, signature, accessid, dir, host } = data; const { policy, signature, accessid, dir, host } = data;
const formData = {
const dataObj = { "key": dir + that.getUUID() + "_${filename}",
policy, "policy": policy,
"OSSAccessKeyId": accessid,
signature, signature,
ossaccessKeyId: accessid, "success_action_status": "200",
key: dir + that.getUUID() + "_${filename}",
dir,
host,
}; };
const formData = new FormData();
formData.append("key", dataObj.key);
formData.append("OSSAccessKeyId", dataObj.ossaccessKeyId);
formData.append("policy", dataObj.policy);
formData.append("Signature", dataObj.signature);
formData.append("success_action_status", "200");
uni.uploadFile({ uni.uploadFile({
url: dataObj.host, url: host,
method: "post", filePath: imgPath,
filePath: JSON.parse(imgRes)[0], name: "file",
name: "uploadFile",
header: Object.assign({
Authorization: 'Bearer ' + uni.getStorageSync("apply-token")
}, Ajax.setPublicParams()),
formData: formData, formData: formData,
success: function (res) { success: function (res) {
if (res.errMsg = "uploadFile:ok") {
const imgUrl = host + "/" + dir + imgPath.split('/').pop();
callback({
status: '上传成功',
image: imgUrl
});
}
console.log('resresresresresresres', res); console.log('resresresresresresres', res);
}, },
fail: function (res) { }, fail: function (res) { },

@ -96,7 +96,9 @@ const typeGroup = ref([
const current = ref(0); const current = ref(0);
const count = ref(0); // const count = ref(0); //
const userInfo = ref({}); const userInfo = ref({});
onLoad(() => { onLoad(() => {});
onShow(() => {
current.value = 1;
isLogin.value = uni.getStorageSync("apply-token") ? true : false; isLogin.value = uni.getStorageSync("apply-token") ? true : false;
console.log("count.value", count.value); console.log("count.value", count.value);
corpUserFlag.value = uni.getStorageSync("apply-userinfo").corpUserFlag; corpUserFlag.value = uni.getStorageSync("apply-userinfo").corpUserFlag;
@ -144,7 +146,6 @@ onLoad(() => {
current.value = 0; current.value = 0;
} }
}); });
onShow(() => {});
const goLogin = () => { const goLogin = () => {
uni.reLaunch({ uni.reLaunch({
url: "/root/person/loginIndex", url: "/root/person/loginIndex",

@ -1,5 +1,5 @@
<template> <template>
<div v-if="!isConnected && text && false" class="network-alert"> <div v-if="!isConnected && text " class="network-alert">
{{ text }} {{ text }}
</div> </div>
</template> </template>

@ -19,8 +19,7 @@
</view> </view>
<view class="g_flex_row_center g_mt_30"> <view class="g_flex_row_center g_mt_30">
<view v-if="!isEdit" class="g_flex_row_center"> <view v-if="!isEdit" class="g_flex_row_center">
<button aria-role="button" class="g_w_110 g_h_32 g_flex_c g_radius_17 g_c_f" <button aria-role="button" class="g_w_110 g_h_32 g_flex_c g_radius_17 g_c_f" style="border: 1px solid #fff; background-color: transparent; font-size: 14px" @click="handleOpenAvatar"></button>
style="border: 1px solid #fff; background-color: transparent; font-size: 14px" @click="handleOpenAvatar">更换头像</button>
</view> </view>
<view v-if="isEdit" class="g_flex_row_center"> <view v-if="isEdit" class="g_flex_row_center">
<view class="g_w_110 g_h_32 g_flex_c g_radius_17 g_c_f g_mr_16" style="border: 1px solid #fff" @click="handleCancel"></view> <view class="g_w_110 g_h_32 g_flex_c g_radius_17 g_c_f g_mr_16" style="border: 1px solid #fff" @click="handleCancel"></view>
@ -73,9 +72,8 @@ export default {
}, },
setAvatar($type) { setAvatar($type) {
let that = this; let that = this;
that.G.uploadImgToOss()
return
that.G.uploadImg( that.G.uploadImg(
// that.G.uploadImgToOss(
(res) => { (res) => {
console.log("获取数据", res); console.log("获取数据", res);
that.avatar = res.image; that.avatar = res.image;
@ -121,8 +119,8 @@ export default {
that.G.checkToken(); that.G.checkToken();
setTimeout(() => { setTimeout(() => {
uni.redirectTo({ uni.redirectTo({
url:'/root/person/info' url: "/root/person/info",
}) });
}, 1500); }, 1500);
}); });
}, },

Loading…
Cancel
Save