第一次提交:小程序前端最新版本

This commit is contained in:
XingQue
2026-06-14 02:38:05 +08:00
commit 5e90f7c87c
677 changed files with 153758 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
// utils/imAuth/dashoujianquan.js
const imRequest = require('./imRequest.js');
/**
* 打手 IM 权限检测
* POST /yonghu/dshqltqx
* 后端返回 { code: 0, allow: 1 } 或 { code: 0, allow: 0 }
*/
async function dashoujianquan(app) {
const uid = wx.getStorageSync('uid');
if (!uid) return { allowed: false, reason: '未登录' };
try {
const res = await imRequest({
url: '/yonghu/dshqltqx',
method: 'POST',
data: { uid }
});
if (res && res.data && res.data.code === 0) {
const allow = res.data.allow;
if (allow === 1) {
return { allowed: true };
} else {
await app.disconnectGoEasy();
wx.showToast({
title: '当前身份已不支持消息聊天功能,请充值会员或联系管理员后尝试',
icon: 'none',
duration: 2000,
mask: true
});
await new Promise(r => setTimeout(r, 2100));
return { allowed: false, reason: '打手消息权限被限制' };
}
}
throw new Error(res.data?.msg || '鉴权接口异常');
} catch (err) {
console.error('打手鉴权失败:', err);
await app.disconnectGoEasy();
wx.showToast({
title: '消息服务暂不可用,请稍后重试',
icon: 'none',
duration: 2000,
mask: true
});
await new Promise(r => setTimeout(r, 2100));
return { allowed: false, reason: '鉴权请求失败' };
}
}
module.exports = { dashoujianquan };

67
utils/imAuth/imRequest.js Normal file
View File

@@ -0,0 +1,67 @@
// utils/imAuth/imRequest.js
// 专用于 IM 鉴权模块的请求封装
// 与 utils/request.js 功能完全一致,但不依赖 getApp()API 域名硬编码
const API_BASE_URL = 'https://6ccy.top/hqhd';
function imRequest(options) {
const token = wx.getStorageSync('token');
const header = {
'Content-Type': 'application/json',
...options.header,
};
if (token) {
header['Authorization'] = 'Bearer ' + token;
}
return new Promise((resolve, reject) => {
wx.request({
url: API_BASE_URL + options.url,
method: options.method,
data: options.data || {},
header,
success: async (res) => {
if (res.statusCode === 401 || res.statusCode === 403) {
// 如果全局有登录 Promise 在等待,则等待完成后重试
const app = getApp();
if (app && app.globalData && app.globalData.loginPromise) {
try {
await app.globalData.loginPromise;
const retryRes = await imRequest(options);
resolve(retryRes);
} catch (err) {
wx.showModal({
content: '操作失败,请先登录',
success: (modalRes) => {
if (modalRes.confirm) {
wx.removeStorageSync('token');
wx.switchTab({ url: '/pages/wode/wode' });
}
},
});
resolve(res);
}
return;
}
// 常规未登录提示
wx.showModal({
content: '操作失败,请先登录',
success: (modalRes) => {
if (modalRes.confirm) {
wx.removeStorageSync('token');
wx.switchTab({ url: '/pages/wode/wode' });
}
},
});
resolve(res);
return;
}
// 正常响应
resolve(res);
},
fail: reject,
});
});
}
module.exports = imRequest;

View File

@@ -0,0 +1,58 @@
// utils/imAuth/jianquanxian.js
// 原require('./laobanjianquan')
// 改:
const { laobanjianquan } = require('./laobanjianquan.js');
const { dashoujianquan } = require('./dashoujianquan.js');
/**
* IM 长连接权限统一入口
* 按顺序进行:
* 1. 检查本地 token/uid 是否存在
* 2. 若不存在,强制断开已有连接,弹窗提示未登录(强制阅读 2 秒)
* 3. 若存在,根据当前角色调用具体的鉴权模块
*
* @param {Object} app 全局 App 实例
* @returns {Promise<{ allowed: boolean, reason?: string }>}
*/
async function jianquanxian(app) {
// 1. 检测登录态(用 uid 或 token
const token = wx.getStorageSync('token') || wx.getStorageSync('uid');
if (!token) {
// 没登录:先强制断开(如果已连接)
await app.disconnectGoEasy();
// 弹窗提示,强制阅读 2 秒
wx.showToast({
title: '您当前处于未登录状态,消息功能暂不可用',
icon: 'none',
duration: 2000,
mask: true
});
// 等待提示结束,确保用户看到
await new Promise(resolve => setTimeout(resolve, 2100));
return { allowed: false, reason: '未登录' };
}
// 2. 获取当前选中的角色
const role = app.globalData.currentRole || 'normal';
// 3. 根据角色分发到具体鉴权模块
switch (role) {
case 'normal': // 点单老板
return laobanjianquan(app);
case 'dashou': // 打手
return dashoujianquan(app);
// 其他角色暂未细分,统一放行(后续可新增对应文件)
case 'shangjia':
case 'guanshi':
case 'zuzhang':
case 'kaoheguan':
return { allowed: true };
default:
return { allowed: false, reason: '未知角色' };
}
}
module.exports = { jianquanxian };

View File

@@ -0,0 +1,51 @@
// utils/imAuth/laobanjianquan.js
const imRequest = require('./imRequest.js');
/**
* 老板点单用户IM 权限检测
* POST /yonghu/lbhqltqx
* 后端返回 { code: 0, allow: 1 } 或 { code: 0, allow: 0 }
*/
async function laobanjianquan(app) {
const uid = wx.getStorageSync('uid');
if (!uid) return { allowed: false, reason: '未登录' };
try {
const res = await imRequest({
url: '/yonghu/lbhqltqx',
method: 'POST',
data: { uid }
});
if (res && res.data && res.data.code === 0) {
const allow = res.data.allow;
if (allow === 1) {
return { allowed: true };
} else {
await app.disconnectGoEasy();
wx.showToast({
title: '当前身份已不支持使用消息功能',
icon: 'none',
duration: 1000,
mask: true
});
await new Promise(r => setTimeout(r, 1100));
return { allowed: false, reason: '当前身份无消息权限' };
}
}
throw new Error(res.data?.msg || '鉴权接口异常');
} catch (err) {
console.error('老板鉴权失败:', err);
await app.disconnectGoEasy();
wx.showToast({
title: '消息服务暂不可用,请稍后重试',
icon: 'none',
duration: 2000,
mask: true
});
await new Promise(r => setTimeout(r, 2100));
return { allowed: false, reason: '鉴权请求失败' };
}
}
module.exports = { laobanjianquan };