融合PK头像头像功能

This commit is contained in:
2026-02-08 15:33:10 +08:00
parent c6435c6db5
commit 76d83fc77e
55 changed files with 5403 additions and 14 deletions

View File

@@ -0,0 +1,136 @@
// 国家数据 - 简化版本,直接内嵌数据
const zhCountries = {
"CN": "中国",
"US": "美国",
"JP": "日本",
"KR": "韩国",
"GB": "英国",
"DE": "德国",
"FR": "法国",
"IT": "意大利",
"ES": "西班牙",
"RU": "俄罗斯",
"BR": "巴西",
"IN": "印度",
"AU": "澳大利亚",
"CA": "加拿大",
"MX": "墨西哥",
"ID": "印度尼西亚",
"TH": "泰国",
"VN": "越南",
"MY": "马来西亚",
"SG": "新加坡",
"PH": "菲律宾",
"TW": "中国台湾",
"HK": "中国香港",
"AE": "阿联酋",
"SA": "沙特阿拉伯",
"TR": "土耳其",
"EG": "埃及",
"ZA": "南非",
"NG": "尼日利亚",
"AR": "阿根廷",
"CL": "智利",
"CO": "哥伦比亚",
"PE": "秘鲁",
"PL": "波兰",
"NL": "荷兰",
"BE": "比利时",
"SE": "瑞典",
"NO": "挪威",
"DK": "丹麦",
"FI": "芬兰",
"AT": "奥地利",
"CH": "瑞士",
"PT": "葡萄牙",
"GR": "希腊",
"CZ": "捷克",
"RO": "罗马尼亚",
"HU": "匈牙利",
"UA": "乌克兰",
"IL": "以色列",
"PK": "巴基斯坦",
"BD": "孟加拉国",
"NZ": "新西兰"
}
const enCountries = {
"CN": "China",
"US": "United States",
"JP": "Japan",
"KR": "South Korea",
"GB": "United Kingdom",
"DE": "Germany",
"FR": "France",
"IT": "Italy",
"ES": "Spain",
"RU": "Russia",
"BR": "Brazil",
"IN": "India",
"AU": "Australia",
"CA": "Canada",
"MX": "Mexico",
"ID": "Indonesia",
"TH": "Thailand",
"VN": "Vietnam",
"MY": "Malaysia",
"SG": "Singapore",
"PH": "Philippines",
"TW": "Taiwan",
"HK": "Hong Kong",
"AE": "UAE",
"SA": "Saudi Arabia",
"TR": "Turkey",
"EG": "Egypt",
"ZA": "South Africa",
"NG": "Nigeria",
"AR": "Argentina",
"CL": "Chile",
"CO": "Colombia",
"PE": "Peru",
"PL": "Poland",
"NL": "Netherlands",
"BE": "Belgium",
"SE": "Sweden",
"NO": "Norway",
"DK": "Denmark",
"FI": "Finland",
"AT": "Austria",
"CH": "Switzerland",
"PT": "Portugal",
"GR": "Greece",
"CZ": "Czech Republic",
"RO": "Romania",
"HU": "Hungary",
"UA": "Ukraine",
"IL": "Israel",
"PK": "Pakistan",
"BD": "Bangladesh",
"NZ": "New Zealand"
}
// 创建中文名称到国家代码的映射
const zhNameToCode = {}
Object.entries(zhCountries).forEach(([code, zhName]) => {
zhNameToCode[zhName] = code
})
// 获取国家名称数组value 固定为中文名称label 根据当前语言变化
export function getCountryNamesArray() {
const currentLanguage = localStorage.getItem('language') || 'ZH'
return Object.entries(zhCountries).map(([code, zhName]) => ({
value: zhName,
label: currentLanguage === 'ZH' ? zhName : enCountries[code]
}))
}
// 根据中文名称获取当前语言环境的翻译
export function translateCountryName(zhName) {
const currentLanguage = localStorage.getItem('language') || 'ZH'
const code = zhNameToCode[zhName]
if (!code) return zhName
return currentLanguage === 'ZH' ? zhName : enCountries[code]
}

212
src/utils/pk-mini/goeasy.js Normal file
View File

@@ -0,0 +1,212 @@
import GoEasy from 'goeasy'
import { pkIMloginStore } from '@/stores/pk-mini/notice.js'
// PK Mini 模块专用 GoEasy 实例
let pkGoEasyInstance = null
// 获取或创建 PK GoEasy 实例
export function getPkGoEasy() {
if (!pkGoEasyInstance) {
pkGoEasyInstance = GoEasy.getInstance({
host: 'hangzhou.goeasy.io',
appkey: 'PC-a88037e060ed4753bb316ac7239e62d9',
modules: ['im']
})
}
return pkGoEasyInstance
}
// 初始化 PK GoEasy (在 PkMiniWorkbench 挂载时调用)
export function initPkGoEasy() {
return getPkGoEasy()
}
// 链接 IM (登录 IM)
export function goEasyLink(data) {
const goeasy = getPkGoEasy()
const counter = pkIMloginStore()
return new Promise((resolve, reject) => {
goeasy.connect({
id: data.id,
data: { avatar: data.avatar, nickname: data.nickname },
otp: data.key,
onSuccess: function () {
console.log('PK IM 连接成功')
counter.setIMstate(true)
resolve(true)
},
onFailed: function (error) {
console.log('PK IM 连接失败,错误码:' + error.code + ',错误信息:' + error.content)
reject(error)
},
onProgress: function (attempts) {
console.log('PK IM 正在重连中...')
}
})
})
}
// 断开 IM
export function goEasyDisConnect() {
const goeasy = getPkGoEasy()
return new Promise((resolve, reject) => {
goeasy.disconnect({
onSuccess: function () {
resolve(true)
},
onFailed: function (error) {
console.log('断开失败, code:' + error.code + ',error:' + error.content)
reject(error)
}
})
})
}
// 获取会话列表
export function goEasyGetConversations() {
const goeasy = getPkGoEasy()
const im = goeasy.im
return new Promise((resolve, reject) => {
im.latestConversations({
onSuccess: function (result) {
resolve(result)
},
onFailed: function (error) {
console.log('获取会话列表失败,错误码:' + error.code + ' content:' + error.content)
reject(error)
}
})
})
}
// 获取指定会话的消息列表
export function goEasyGetMessages(data) {
const goeasy = getPkGoEasy()
const im = goeasy.im
return new Promise((resolve, reject) => {
im.history({
id: data.id,
type: GoEasy.IM_SCENE.PRIVATE,
lastTimestamp: data.timestamp,
limit: 30,
onSuccess: function (result) {
resolve(result.content)
},
onFailed: function (error) {
console.log('获取消息列表失败,错误码:' + error.code + ' content:' + error.content)
reject(error)
}
})
})
}
// 发送文本消息
export function goEasySendMessage(data) {
const goeasy = getPkGoEasy()
const im = goeasy.im
let textMessage = im.createTextMessage({
text: data.text,
to: {
type: GoEasy.IM_SCENE.PRIVATE,
id: data.id,
data: { avatar: data.avatar, nickname: data.nickname }
}
})
return new Promise((resolve, reject) => {
im.sendMessage({
message: textMessage,
onSuccess: function () {
resolve(textMessage)
},
onFailed: function (error) {
console.log('Failed to send private messagecode:' + error.code + ' ,error ' + error.content)
reject(error)
}
})
})
}
// 发送图片消息
export function goEasySendImageMessage(data) {
const goeasy = getPkGoEasy()
const im = goeasy.im
const message = im.createImageMessage({
file: data.imagefile,
to: {
type: GoEasy.IM_SCENE.PRIVATE,
id: data.id,
data: { avatar: data.avatar, nickname: data.nickname }
}
})
return new Promise((resolve, reject) => {
im.sendMessage({
message: message,
onSuccess: function () {
resolve(message)
},
onFailed: function (error) {
console.log('Failed to send messagecode:' + error.code + ',error' + error.content)
reject(error)
}
})
})
}
// 发送 PK 消息
export function goEasySendPKMessage(data) {
const goeasy = getPkGoEasy()
const im = goeasy.im
const customData = {
id: data.msgid,
pkIdA: data.pkIdA,
pkIdB: data.pkIdB
}
const order = {
customData: customData,
link: 'https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/pk.png',
text: 'PK'
}
const customMessage = im.createCustomMessage({
type: 'pk',
payload: order,
to: {
type: GoEasy.IM_SCENE.PRIVATE,
id: data.id,
data: { avatar: data.avatar, nickname: data.nickname }
}
})
return new Promise((resolve, reject) => {
im.sendMessage({
message: customMessage,
onSuccess: function () {
resolve(customMessage)
},
onFailed: function (error) {
console.log('Failed to send messagecode:' + error.code + ',error' + error.content)
reject(error)
}
})
})
}
// 消息已读
export function goEasyMessageRead(data) {
const goeasy = getPkGoEasy()
const im = goeasy.im
return new Promise((resolve, reject) => {
im.markMessageAsRead({
id: data.id,
type: GoEasy.IM_SCENE.PRIVATE,
onSuccess: function () {
resolve(true)
},
onFailed: function (error) {
console.log('标记私聊已读失败', error)
reject(error)
}
})
})
}

View File

@@ -0,0 +1,79 @@
// PK Mini 模块专用 Storage 工具
// 使用 pk_mini_ 前缀避免与主项目冲突
const PREFIX = 'pk_mini_'
export function setStorage(key, value) {
localStorage.setItem(PREFIX + key, JSON.stringify(value))
}
export function getStorage(key) {
const value = localStorage.getItem(PREFIX + key)
if (value) {
try {
return JSON.parse(value)
} catch (e) {
return value
}
}
return null
}
export function getPromiseStorage(key) {
return new Promise((resolve, reject) => {
const value = getStorage(key)
if (value) {
resolve(value)
} else {
reject(new Error('Key not found: ' + key))
}
})
}
export function clearStorage(key) {
localStorage.removeItem(PREFIX + key)
}
export function getPromiseSessionStorage(key) {
return new Promise((resolve, reject) => {
const value = sessionStorage.getItem(PREFIX + key)
if (value) {
try {
resolve(JSON.parse(value))
} catch (e) {
resolve(value)
}
} else {
reject(new Error('Key not found: ' + key))
}
})
}
export function setSessionStorage(key, value) {
sessionStorage.setItem(PREFIX + key, JSON.stringify(value))
}
// 获取主项目的用户数据(用于获取 token 和用户信息)
// 主项目使用 'user' 键存储用户信息
export function getMainUserData() {
// 优先从 'user' 获取(主项目当前使用的键)
let userData = localStorage.getItem('user')
if (userData) {
try {
return JSON.parse(userData)
} catch (e) {
// 解析失败,继续尝试其他键
}
}
// 兼容:尝试从 'user_data' 获取(旧键名)
userData = localStorage.getItem('user_data')
if (userData) {
try {
return JSON.parse(userData)
} catch (e) {
return null
}
}
return null
}

View File

@@ -0,0 +1,13 @@
// 时间戳转换为本地时间,格式为 YYYY/MM/DD hh:mm
export function TimestamptolocalTime(date) {
if (!date || isNaN(date)) return ''
const d = new Date(date)
const year = d.getFullYear()
const month = String(d.getMonth() + 1).padStart(2, '0')
const day = String(d.getDate()).padStart(2, '0')
const hours = String(d.getHours()).padStart(2, '0')
const minutes = String(d.getMinutes()).padStart(2, '0')
return `${year}/${month}/${day} ${hours}:${minutes}`
}

View File

@@ -0,0 +1,27 @@
// 记录上次调用时间
let lastTimestamp = null
/**
* 比较时间戳是否超过 5 分钟
* @param {number} timestamp - 要比较的时间戳(毫秒)
* @returns {boolean} - 是否超过 5 分钟或第一次调用
*/
export function timeDisplay(timestamp) {
// 第一次调用直接返回 true
if (lastTimestamp === null) {
lastTimestamp = timestamp
return true
}
// 计算时间差(毫秒)
const timeDiff = Math.abs(timestamp - lastTimestamp)
lastTimestamp = timestamp
// 5 分钟 = 300,000 毫秒
return timeDiff > 300000
}
// 重置时间戳(在组件卸载时调用)
export function resetTimeDisplay() {
lastTimestamp = null
}