首页默认静默登陆
This commit is contained in:
123
App.vue
123
App.vue
@@ -151,16 +151,90 @@
|
||||
if (e === undefined)
|
||||
return {};
|
||||
|
||||
// 优先解析扫码参数,确保 store_id 在后续逻辑执行前被正确设置
|
||||
const sceneStr = e.query && e.query.scene ? decodeURIComponent(e.query.scene) : '';
|
||||
console.log('[扫码调试] 原始 scene 参数:', sceneStr);
|
||||
|
||||
if (sceneStr) {
|
||||
// 判断scene中是否包含sal_id
|
||||
const isSalespersonId = sceneStr.includes('sal_id');
|
||||
console.log('[扫码调试] 是否包含 sal_id:', isSalespersonId);
|
||||
|
||||
// 解析 STORE_QR_CODE_ 参数
|
||||
const sceneParts = sceneStr.split('STORE_QR_CODE_');
|
||||
console.log('[扫码调试] scene 分割结果:', sceneParts);
|
||||
|
||||
if (sceneParts.length > 1 && sceneParts[1]) {
|
||||
// 处理可能包含 & 的情况,提取 store_id
|
||||
const storeIdPart = sceneParts[1].split('&')[0];
|
||||
const decodedStoreId = decodeURIComponent(storeIdPart);
|
||||
|
||||
if (decodedStoreId && decodedStoreId !== 'undefined') {
|
||||
console.log('[扫码调试] 设置 store_id 和 stores_id:', decodedStoreId);
|
||||
uni.setStorageSync('stores_id', decodedStoreId);
|
||||
uni.setStorageSync('store_id', decodedStoreId);
|
||||
}
|
||||
}
|
||||
|
||||
// 解析其他参数
|
||||
const st_id = sceneStr.split('&');
|
||||
const doctors_id = sceneStr.split('=');
|
||||
|
||||
// 解析 doctors_id
|
||||
if (st_id[0] && st_id[0].includes('su_id=')) {
|
||||
const doctorsId = st_id[0].split('su_id=')[1];
|
||||
if (doctorsId) {
|
||||
uni.setStorageSync('doctors_id', doctorsId);
|
||||
console.log('[扫码调试] 设置 doctors_id:', doctorsId);
|
||||
}
|
||||
}
|
||||
|
||||
// 解析 sal_id
|
||||
if (isSalespersonId && st_id.length > 1 && st_id[1].includes('sal_id=')) {
|
||||
const salId = st_id[1].split('sal_id=')[1];
|
||||
if (salId) {
|
||||
uni.setStorageSync('sal_id', salId);
|
||||
console.log('[扫码调试] 设置 sal_id:', salId);
|
||||
}
|
||||
}
|
||||
|
||||
// 解析 st_id
|
||||
if (doctors_id.length > 2 && doctors_id[2]) {
|
||||
uni.setStorageSync('st_id', doctors_id[2]);
|
||||
console.log('[扫码调试] 设置 st_id:', doctors_id[2]);
|
||||
}
|
||||
|
||||
// 绑定推广员(如果已登录)
|
||||
const userId = uni.getStorageSync('user_id');
|
||||
if (isSalespersonId && userId && st_id.length > 1 && st_id[1].includes('sal_id=')) {
|
||||
const salId = st_id[1].split('sal_id=')[1];
|
||||
if (salId) {
|
||||
bindUserApi({
|
||||
user_id: userId,
|
||||
salesperson_id: salId,
|
||||
}).then((res) => {
|
||||
console.log('[扫码调试] 绑定推广员成功:', res);
|
||||
}).catch((err) => {
|
||||
console.error('[扫码调试] 绑定推广员失败:', err);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否已登录,如果未登录才检查配置并决定是否静默登录
|
||||
const token = uni.getStorageSync('token');
|
||||
const userInfo = uni.getStorageSync('userinfo');
|
||||
if (!token || !userInfo) {
|
||||
// 未登录,获取系统配置,判断是否需要静默登录
|
||||
// 此时 store_id 应该已经从扫码参数中正确设置
|
||||
try {
|
||||
const currentStoreId = uni.getStorageSync('store_id') || '11001';
|
||||
console.log('[扫码调试] 获取系统配置,使用 store_id:', currentStoreId);
|
||||
|
||||
const configRes = getSystemConfig({
|
||||
method: "get",
|
||||
data: {
|
||||
store_id: uni.getStorageSync('store_id') || '11001'
|
||||
store_id: currentStoreId
|
||||
}
|
||||
});
|
||||
|
||||
@@ -184,59 +258,20 @@
|
||||
// 执行静默登录(不显示提示,不跳转)
|
||||
silentLogin().then((loginResult) => {
|
||||
if (loginResult.success) {
|
||||
console.log('静默登录成功');
|
||||
console.log('[扫码调试] 静默登录成功');
|
||||
} else {
|
||||
console.error('静默登录失败:', loginResult.message);
|
||||
console.error('[扫码调试] 静默登录失败:', loginResult.message);
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.error('静默登录异常:', error);
|
||||
console.error('[扫码调试] 静默登录异常:', error);
|
||||
});
|
||||
}
|
||||
// 如果配置为需要登录页(need_login: true),不执行任何操作,等待用户手动登录
|
||||
} catch (error) {
|
||||
// 配置接口调用失败,不影响应用启动,仅记录日志
|
||||
console.error('获取系统配置失败:', error);
|
||||
console.error('[扫码调试] 获取系统配置失败:', error);
|
||||
}
|
||||
}
|
||||
const scene = decodeURIComponent(e.query.scene)
|
||||
// 这里接收扫码参数
|
||||
if (scene) {
|
||||
// 判断scene中是否包含sal_id
|
||||
let isSalespersonId = decodeURIComponent(e.query.scene).includes('sal_id');
|
||||
const scene = decodeURIComponent(e.query.scene).split('STORE_QR_CODE_')
|
||||
if (scene[1]) {
|
||||
uni.setStorageSync('stores_id', scene[1])
|
||||
uni.setStorageSync('store_id', scene[1])
|
||||
}
|
||||
// uni.setStorageSync('stores_id', scene[1])
|
||||
const st_id = decodeURIComponent(e.query.scene).split('&')
|
||||
let store_id = decodeURIComponent(e.query.scene).split('STORE_QR_CODE_')
|
||||
store_id = decodeURIComponent(store_id[1]).split('&')
|
||||
const doctors_id = decodeURIComponent(e.query.scene).split('=')
|
||||
if (store_id[0] !== 'undefined') {
|
||||
uni.setStorageSync('stores_id', store_id[0])
|
||||
uni.setStorageSync('store_id', store_id[0])
|
||||
}
|
||||
uni.setStorageSync('doctors_id', st_id[0].split('su_id=')[1])
|
||||
if (isSalespersonId) {
|
||||
uni.setStorageSync('sal_id', st_id[1].split('sal_id=')[1])
|
||||
}
|
||||
uni.setStorageSync('st_id', doctors_id[2])
|
||||
|
||||
let userId = uni.getStorageSync('user_id')
|
||||
if (isSalespersonId && userId) {
|
||||
bindUserApi({
|
||||
user_id: userId,
|
||||
salesperson_id: st_id[1].split('sal_id=')[1],
|
||||
}).then((res) => {
|
||||
console.log('userId', userId, st_id[0].split('su_id=')[1], res);
|
||||
})
|
||||
}
|
||||
// console.log(st_id, '4444111111111');
|
||||
// console.log(scene, '4444');
|
||||
}
|
||||
// const scene = decodeURIComponent(e.query.scene).split('STORE_QR_CODE_')
|
||||
// console.log(scene, '11111');
|
||||
},
|
||||
onHide: function() {
|
||||
// console.log('App Hide')
|
||||
|
||||
Reference in New Issue
Block a user