chore: 纳入小程序完整源码

Co-authored-by: Cursor <cursoragent@cursor.com>
这个提交包含在:
可乐加冰
2026-09-23 20:25:01 +08:00
父节点 7f8c4966aa
当前提交 9d2488a631
共有 338 个文件被更改,包括 72261 次插入 和 0 次删除

55
pages/public/chat/index.vue 普通文件
查看文件

@@ -0,0 +1,55 @@
<!-- 客服兼容 -->
<template>
<view class="chat-template-box" v-if="showChat">
<Chat v-if="isShoproChat"></Chat>
<Wm v-if="!isShoproChat" :options="kefuOptions"></Wm>
</view>
</template>
<script>
import {
mapMutations,
mapActions,
mapState,
mapGetters
} from "vuex";
import Chat from "./shopro/index.vue";
import Wm from "./wm/index.vue";
export default {
components: {
Chat,
Wm
},
data() {
return {
isShoproChat: false,
kefuOptions: null,
showChat: false
};
},
computed: {
...mapGetters(["initAddons", "initChat"])
},
onLoad(options) {
this.kefuOptions = options;
//判断客服;
if (this.initChat && this.initChat.type === "shopro") {
this.isShoproChat = true;
} else {
if (this.initAddons.length && this.initAddons.includes("kefu")) {
this.isShoproChat = false;
}
}
this.showChat = true;
},
methods: {}
};
</script>
<style lang="scss">
.chat-template-box {
height: 100%;
width: 100%;
overflow: hidden;
}
</style>

查看文件

@@ -0,0 +1,161 @@
/**
* shopro
* 聊天配置,socket服务相关,心跳检测和重连
*/
/**
* socket
* @param {Object} config - 初始化配置对象
* @param {Number} wait = [10000] - 心跳频率
*/
import {
BASE_URL
} from '@/env.js'
const service = BASE_URL.split('://')[1].split(':')[0];
export default class Socket {
constructor(initData, callback) {
let {
ping,
is_ssl,
gateway_port,
ssl_type
} = initData;
let url = `${is_ssl?'wss':'ws'}://${service}:${gateway_port}/`
if (is_ssl && ssl_type === 'reverse_proxy') {
url = `wss://${service}/websocket/`
}
this.config = {
url: url,
session_id: uni.getStorageSync('chatSessionId'),
token: uni.getStorageSync('token'),
identify: 'user'
};
this.callback = callback; //onmsg回调
this.timeoutObj = null; //心跳检测定时器对象
this.lockReconnect = false; //检测次数锁
this.isClose = false; //链接断开
this.timer = null; // 检测定时器
this.limit = 0; //检测次数,默认最大12
this.timout = ping;
uni.setStorageSync('isSocketOpen', false)
this.init()
}
// 初始化
async init() {
await this.connect();
}
// 连接
async connect() {
if (!uni.getStorageSync('isSocketOpen')) {
let [error, res] = await uni.connectSocket({
url: `${this.config.url}?identify=${this.config.identify}&token=${this.config.token}&session_id=${this.config.session_id}`
});
if (res.errMsg === 'connectSocket:ok') {
this.initEventHandle();
}
}
}
// 发送消息
async send(msg = "") {
if (uni.getStorageSync('isSocketOpen')) {
let [error, res] = await uni.sendSocketMessage({
data: msg
});
return Promise.resolve(res);
}
}
// 监听消息
onMsg() {
uni.onSocketMessage(res => {
if (res.code === 1 && res.type === 'init') {
this.config.session_id = res.data.session_id;
}
this.callback(res)
});
}
// 关闭连接
close() {
uni.closeSocket();
uni.removeStorage({
key: 'isSocketOpen',
success: (res) => {
console.log('移除isSocketOpensuccess');
}
});
clearTimeout(this.timer);
clearTimeout(this.timeoutObj);
}
//心跳检测
start() {
clearTimeout(this.timeoutObj);
this.timeoutObj = setTimeout(() => {
let obj = {
type: 'ping'
};
let objStr = JSON.stringify(obj)
uni.sendSocketMessage({
data: objStr,
});
this.start()
}, this.timout)
}
// 监听事件集
initEventHandle() {
// 监听打开
uni.onSocketOpen(res => {
uni.setStorageSync('isSocketOpen', true)
console.log('连接成功!');
this.lockReconnect = true;
this.isClose = false;
this.start()
});
// 监听消息
this.onMsg()
// 监听错误
uni.onSocketError(err => {
console.log('连接错误', err);
uni.closeSocket();
});
// 监听关闭
uni.onSocketClose(res => {
console.log('关闭链接');
this.isClose = true;
if (uni.getStorageSync('isSocketOpen')) {
this.lockReconnect = false
this.reconnect()
}
});
}
// 重连
reconnect() {
if (this.lockReconnect) return;
clearTimeout(this.timer)
if (this.limit < 12) {
this.timer = setTimeout(() => {
console.log('重连中', this.limit);
this.init();
this.reconnect()
}, 5000);
this.limit += 1
}
}
}

查看文件

@@ -0,0 +1,185 @@
.bg-gradual-purple {
background-image: linear-gradient(45deg, #9000ff, #5e00ff);
color: #ffffff;
}
.bg-white {
background-color: #ffffff;
color: #666666;
}
.round {
border-radius: 5000upx;
}
/* ==================
聊天
==================== */
.cu-avatar {
font-variant: small-caps;
margin: 0;
padding: 0;
display: inline-flex;
text-align: center;
justify-content: center;
align-items: center;
background-color: #ccc;
color: #ffffff;
white-space: nowrap;
position: relative;
width: 64upx;
height: 64upx;
background-size: cover;
background-position: center;
vertical-align: middle;
font-size: 1.5em;
}
.cu-bar {
display: flex;
position: relative;
align-items: center;
min-height: 100upx;
justify-content: space-between;
background-color: #fff;
}
.cu-bar .action {
display: flex;
align-items: center;
height: 100%;
justify-content: center;
max-width: 100%;
}
.cu-bar.foot {
position: fixed;
width: 100%;
bottom: 0;
z-index: 1024;
box-shadow: 0 -1upx 6upx rgba(0, 0, 0, 0.1);
}
.cu-chat {
display: flex;
flex-direction: column;
}
.cu-chat .cu-item {
display: flex;
padding: 30upx 30upx 70upx;
position: relative;
}
.cu-chat .cu-item > .cu-avatar {
width: 80upx;
height: 80upx;
}
.cu-chat .cu-item > .main {
max-width: calc(100% - 260upx);
margin: 0 40upx;
display: flex;
align-items: center;
}
.cu-chat .cu-item > image {
height: 320upx;
}
.cu-chat .cu-item > .main .content {
padding: 20upx;
border-radius: 6upx;
display: inline-flex;
max-width: 100%;
align-items: center;
font-size: 30upx;
position: relative;
min-height: 80upx;
line-height: 40upx;
text-align: left;
}
.cu-chat .cu-item > .main .content:not([class*='bg-']) {
background-color: #ffffff;
color: #333333;
}
.cu-chat .cu-item .date {
position: absolute;
font-size: 24upx;
color: #8799a3;
width: calc(100% - 320upx);
bottom: 20upx;
left: 160upx;
}
.cu-chat .cu-item .action {
padding: 0 30upx;
display: flex;
align-items: center;
}
.cu-chat .cu-item > .main .content::after {
content: '';
top: 27upx;
transform: rotate(45deg);
position: absolute;
z-index: 100;
display: inline-block;
overflow: hidden;
width: 24upx;
height: 24upx;
left: -12upx;
right: initial;
background-color: inherit;
}
.cu-chat .cu-item.self > .main .content::after {
left: auto;
right: -12upx;
}
.cu-chat .cu-item > .main .content::before {
content: '';
top: 30upx;
transform: rotate(45deg);
position: absolute;
z-index: -1;
display: inline-block;
overflow: hidden;
width: 24upx;
height: 24upx;
left: -12upx;
right: initial;
background-color: inherit;
filter: blur(5upx);
opacity: 0.3;
}
.cu-chat .cu-item > .main .content:not([class*='bg-'])::before {
background-color: #333333;
opacity: 0.1;
}
.cu-chat .cu-item.self > .main .content::before {
left: auto;
right: -12upx;
}
.cu-chat .cu-item.self {
justify-content: flex-end;
text-align: right;
}
.cu-chat .cu-info {
display: inline-block;
margin: 20upx auto;
font-size: 24upx;
padding: 8upx 12upx;
background-color: rgba(0, 0, 0, 0.2);
border-radius: 6upx;
color: #ffffff;
max-width: 400upx;
line-height: 1.4;
}

文件差异内容过多而无法显示 加载差异

查看文件

@@ -0,0 +1,131 @@
import {
BASE_URL
} from '@/env.js'
const expression = [{
'title': '[zy]',
'src': '/emoji/1.png'
}, {
'title': '[zm]',
'src': '/emoji/2.png'
}, {
'title': '[jy]',
'src': '/emoji/3.png'
},
{
'title': '[jyb]',
'src': '/emoji/4.png'
}, {
'title': '[bx]',
'src': '/emoji/5.png'
}, {
'title': '[kzn]',
'src': '/emoji/6.png'
},
{
'title': '[gg]',
'src': '/emoji/7.png'
}, {
'title': '[ll]',
'src': '/emoji/8.png'
}, {
'title': '[jyll]',
'src': '/emoji/9.png'
},
{
'title': '[o]',
'src': '/emoji/10.png'
}, {
'title': '[yz]',
'src': '/emoji/11.png'
}, {
'title': '[wx]',
'src': '/emoji/12.png'
},
{
'title': '[zyb]',
'src': '/emoji/13.png'
}, {
'title': '[tp]',
'src': '/emoji/14.png'
}, {
'title': '[wxb]',
'src': '/emoji/15.png'
},
{
'title': '[zyc]',
'src': '/emoji/16.png'
}, {
'title': '[llb]',
'src': '/emoji/17.png'
}, {
'title': '[xm]',
'src': '/emoji/18.png'
},
{
'title': '[qz]',
'src': '/emoji/19.png'
}, {
'title': '[zmb]',
'src': '/emoji/20.png'
}, {
'title': '[kx]',
'src': '/emoji/21.png'
},
{
'title': '[mm]',
'src': '/emoji/22.png'
}, {
'title': '[bz]',
'src': '/emoji/23.png'
}, {
'title': '[bkx]',
'src': '/emoji/24.png'
},
{
'title': '[mg]',
'src': '/emoji/25.png'
}, {
'title': '[pz]',
'src': '/emoji/26.png'
}, {
'title': '[pzb]',
'src': '/emoji/27.png'
},
{
'title': '[wxc]',
'src': '/emoji/28.png'
}, {
'title': '[jyc]',
'src': '/emoji/29.png'
}, {
'title': '[jyd]',
'src': '/emoji/30.png'
},
{
'title': '[dm]',
'src': '/emoji/31.png'
}, {
'title': '[tpb]',
'src': '/emoji/32.png'
}, {
'title': '[tpc]',
'src': '/emoji/33.png'
},
{
'title': '[tpd]',
'src': '/emoji/34.png'
}, {
'title': '[ly]',
'src': '/emoji/35.png'
}, {
'title': '[zyd]',
'src': '/emoji/36.png'
},
];
let service = BASE_URL.split('://')[1].split(':')[0];
export default {
baseURL: service, // dev.7wpp.com 启动workerman服务的域名,无需填写协议和端口
https_switch: false, // 是否启用https协议(默认关,正式版必开,且需要参考文档创建wss服务)
expression
}

1622
pages/public/chat/wm/index.vue 普通文件

文件差异内容过多而无法显示 加载差异