diff --git a/App.vue b/App.vue
index 822f9b4..2eaa067 100644
--- a/App.vue
+++ b/App.vue
@@ -12,6 +12,15 @@
export default {
// //初始化状态-如果登录过,保持登录状态
onLaunch: async function() {
+
+ silentLogin().then((loginResult) => {
+ if (loginResult.success) {
+ } else {
+ console.error('静默登录失败:', loginResult.message);
+ }
+ }).catch((error) => {
+ console.error('静默登录异常:', error);
+ });
const version = 4 // 如果当前版本和后台返回的版本一致,那就是审核中,审核通过后 后台设置加1,如果后台的比本地的大 那就是生产版本
const res = await getVersion()
const val = Number(res.data.data.value)
@@ -34,54 +43,54 @@
// 存储当前版本,也可以使用globalData
uni.setStorageSync('isShow_envVersion', isShow)
- // 检查是否已登录,如果未登录才检查配置并决定是否静默登录
- const token = uni.getStorageSync('token');
- const userInfo = uni.getStorageSync('userinfo');
+ // // 检查是否已登录,如果未登录才检查配置并决定是否静默登录
+ // const token = uni.getStorageSync('token');
+ // const userInfo = uni.getStorageSync('userinfo');
- if (!token || !userInfo) {
+ // if (!token || !userInfo) {
// 未登录,获取系统配置,判断是否需要静默登录
- try {
- const configRes = getSystemConfig({
- method: "get",
- data: {
- store_id: uni.getStorageSync('store_id') || '11001'
- }
- });
-
+ // try {
+ // const configRes = getSystemConfig({
+ // method: "get",
+ // data: {
+ // store_id: uni.getStorageSync('store_id') || '11001'
+ // }
+ // });
+ //
// 根据配置决定是否静默登录
// 注意:需要根据实际接口返回格式解析 need_login 字段
- const isGuest = isGuestMode();
- let needLogin = false; // 默认需要登录页
-
- if (isGuest && (configRes.data.code === 0 || configRes.data.code === '0')) {
- // 新格式:从 result 中获取
- const configData = configRes.data.result || {};
- needLogin = configData.need_login !== false; // false 表示静默登录
- } else if (!isGuest && (configRes.data?.errcode === 0 || configRes.data?.errcode === '0')) {
- // 旧格式:从 data 中获取
- const configData = configRes.data.data || {};
- needLogin = configData.need_login !== false; // false 表示静默登录
- }
-
- // 如果配置为静默登录(need_login: false),直接执行静默登录
- if (!needLogin) {
- // 执行静默登录(不显示提示,不跳转)
- silentLogin().then((loginResult) => {
- if (loginResult.success) {
- console.log('静默登录成功');
- } else {
- console.error('静默登录失败:', loginResult.message);
- }
- }).catch((error) => {
- console.error('静默登录异常:', error);
- });
- }
- // 如果配置为需要登录页(need_login: true),不执行任何操作,等待用户手动登录
- } catch (error) {
- // 配置接口调用失败,不影响应用启动,仅记录日志
- console.error('获取系统配置失败:', error);
- }
- }
+ // const isGuest = isGuestMode();
+ // let needLogin = false; // 默认需要登录页
+ //
+ // if (isGuest && (configRes.data.code === 0 || configRes.data.code === '0')) {
+ // // 新格式:从 result 中获取
+ // const configData = configRes.data.result || {};
+ // needLogin = configData.need_login !== false; // false 表示静默登录
+ // } else if (!isGuest && (configRes.data?.errcode === 0 || configRes.data?.errcode === '0')) {
+ // // 旧格式:从 data 中获取
+ // const configData = configRes.data.data || {};
+ // needLogin = configData.need_login !== false; // false 表示静默登录
+ // }
+ //
+ // // 如果配置为静默登录(need_login: false),直接执行静默登录
+ // if (!needLogin) {
+ // // 执行静默登录(不显示提示,不跳转)
+ // silentLogin().then((loginResult) => {
+ // if (loginResult.success) {
+ // console.log('静默登录成功');
+ // } else {
+ // console.error('静默登录失败:', loginResult.message);
+ // }
+ // }).catch((error) => {
+ // console.error('静默登录异常:', error);
+ // });
+ // }
+ // // 如果配置为需要登录页(need_login: true),不执行任何操作,等待用户手动登录
+ // } catch (error) {
+ // // 配置接口调用失败,不影响应用启动,仅记录日志
+ // console.error('获取系统配置失败:', error);
+ // }
+ // }
console.log('获取更新机制', uni.canIUse('getUpdateManager'))
// 获取小程序更新机制兼容
@@ -151,127 +160,92 @@
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: currentStoreId
- }
- });
-
- // 根据配置决定是否静默登录
- // 注意:需要根据实际接口返回格式解析 need_login 字段
- const isGuest = isGuestMode();
- let needLogin = false; // 默认需要登录页
-
- if (isGuest && (configRes.data.code === 0 || configRes.data.code === '0')) {
- // 新格式:从 result 中获取
- const configData = configRes.data.result || {};
- needLogin = configData.need_login !== false; // false 表示静默登录
- } else if (!isGuest && (configRes.data?.errcode === 0 || configRes.data?.errcode === '0')) {
- // 旧格式:从 data 中获取
- const configData = configRes.data.data || {};
- needLogin = configData.need_login !== false; // false 表示静默登录
- }
-
- // 如果配置为静默登录(need_login: false),直接执行静默登录
- if (!needLogin) {
- // 执行静默登录(不显示提示,不跳转)
- silentLogin().then((loginResult) => {
- if (loginResult.success) {
- console.log('[扫码调试] 静默登录成功');
- } else {
- console.error('[扫码调试] 静默登录失败:', loginResult.message);
- }
- }).catch((error) => {
- console.error('[扫码调试] 静默登录异常:', error);
- });
- }
- // 如果配置为需要登录页(need_login: true),不执行任何操作,等待用户手动登录
- } catch (error) {
- // 配置接口调用失败,不影响应用启动,仅记录日志
- console.error('[扫码调试] 获取系统配置失败:', error);
+ // const token = uni.getStorageSync('token');
+ // const userInfo = uni.getStorageSync('userinfo');
+ // if (!token || !userInfo) {
+ // // 未登录,获取系统配置,判断是否需要静默登录
+ // try {
+ // const configRes = getSystemConfig({
+ // method: "get",
+ // data: {
+ // store_id: uni.getStorageSync('store_id') || '11001'
+ // }
+ // });
+ //
+ // // 根据配置决定是否静默登录
+ // // 注意:需要根据实际接口返回格式解析 need_login 字段
+ // const isGuest = isGuestMode();
+ // let needLogin = false; // 默认需要登录页
+ //
+ // if (isGuest && (configRes.data.code === 0 || configRes.data.code === '0')) {
+ // // 新格式:从 result 中获取
+ // const configData = configRes.data.result || {};
+ // needLogin = configData.need_login !== false; // false 表示静默登录
+ // } else if (!isGuest && (configRes.data?.errcode === 0 || configRes.data?.errcode === '0')) {
+ // // 旧格式:从 data 中获取
+ // const configData = configRes.data.data || {};
+ // needLogin = configData.need_login !== false; // false 表示静默登录
+ // }
+ //
+ // // 如果配置为静默登录(need_login: false),直接执行静默登录
+ // if (!needLogin) {
+ // // 执行静默登录(不显示提示,不跳转)
+ // silentLogin().then((loginResult) => {
+ // if (loginResult.success) {
+ // console.log('静默登录成功');
+ // } else {
+ // console.error('静默登录失败:', loginResult.message);
+ // }
+ // }).catch((error) => {
+ // console.error('静默登录异常:', error);
+ // });
+ // }
+ // // 如果配置为需要登录页(need_login: true),不执行任何操作,等待用户手动登录
+ // } catch (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')
diff --git a/main.js b/main.js
index 1c5da02..aa57d96 100644
--- a/main.js
+++ b/main.js
@@ -6,12 +6,20 @@ import Vue from 'vue'
// main.js
import uView from "uview-ui";
import share from '@/common/share.js'
+import {setGuestMode} from "@/common/utils/auth";
Vue.mixin(share)
Vue.use(uView);
//防抖函数
import common from './common/common.js'
Vue.prototype.$noMultipleClicks = common.noMultipleClicks;
+
+const token = uni.getStorageSync('token');
+const userInfo = uni.getStorageSync('userinfo');
+if (!token || !userInfo) {
+ console.log('未登录')
+ setGuestMode();
+}
//时间戳的处理
Vue.filter("formatDate", function(value) {
var date = new Date(value * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
diff --git a/pages/home/home.vue b/pages/home/home.vue
index 299dc3d..e41e118 100644
--- a/pages/home/home.vue
+++ b/pages/home/home.vue
@@ -214,6 +214,7 @@ import { getStoreDrugListBySalespersonApi, getHomeTopProductsApi, getHomeZonesAp
import request from "@/request/api/request";
import MessageNotification from "@/components/MessageNotification/MessageNotification.vue";
import { setGuestMode, isGuestMode, isLoggedIn } from '@/common/utils/auth.js';
+import {silentLogin} from "@/utils/login";
export default {
components: {
@@ -259,11 +260,6 @@ export default {
}
},
onLoad() {
- // 判断是否已登录
- if (!isLoggedIn()) {
- // 未登录时设置guest模式标记和store_id
- setGuestMode();
- }
this.isShow_envVersion = uni.getStorageSync('isShow_envVersion')
if (this.isShow_envVersion === false) {
@@ -278,9 +274,27 @@ export default {
}
},
onReady() {
+
+ console.log('调试静默登陆', isLoggedIn());
+ // 判断是否已登录
+ if (!isLoggedIn()) {
+ console.log('调试静默登陆2', isLoggedIn());
+ // 未登录时设置guest模式标记和store_id
+ // setGuestMode();
+
+ // silentLogin().then((loginResult) => {
+ // if (loginResult.success) {
+ // } else {
+ // console.error('静默登录失败:', loginResult.message);
+ // }
+ // }).catch((error) => {
+ // console.error('静默登录异常:', error);
+ // });
+ }
// 未登录时也允许访问,使用默认store_id=11001
if (!uni.getStorageSync('store_id')) {
- uni.setStorageSync('store_id', '11001');
+ // uni.setStorageSync('store_id', '11001');
+
}
if (uni.getStorageSync('store_id')) {
this.getStore();
@@ -302,7 +316,52 @@ export default {
this.goProductDetail(item);
}
},
- goYard(type) {
+ async goYard(type) {
+ // 当 type === 3 (在线复诊) 时,需要先检查门店是否支持在线问诊功能
+ if (type === 3) {
+ try {
+ const storeId = uni.getStorageSync('store_id') || '11001';
+ const configRes = await checkOnlineConsultationConfigApi({
+ store_id: storeId,
+ guest: 1 // 使用 Guest 接口
+ });
+
+ // 直接使用新接口格式(code + result)
+ if (configRes.data?.code === 0 || configRes.data?.code === '0') {
+ // 获取结果数据,直接使用 result(返回格式:{ code: 0, result: { can_use: false, message: "..." } })
+ const result = configRes.data?.result;
+
+ // 检查是否可以使用在线问诊功能
+ if (!result?.can_use) {
+ // 显示后端返回的提示信息(使用 result 中的 message)
+ uni.showToast({
+ title: result?.message || '该门店暂不支持在线问诊功能',
+ icon: 'none',
+ duration: 2000
+ });
+ return; // 阻止跳转
+ }
+ } else {
+ // API调用失败,显示错误信息
+ uni.showToast({
+ title: configRes.data?.message || '检查在线问诊配置失败',
+ icon: 'none',
+ duration: 2000
+ });
+ return;
+ }
+ } catch (error) {
+ console.error('检查在线问诊配置失败:', error);
+ uni.showToast({
+ title: '检查在线问诊配置失败',
+ icon: 'none',
+ duration: 2000
+ });
+ return;
+ }
+ }
+
+ // 检查通过或非在线复诊类型,正常跳转
uni.navigateTo({
url: '/pages/Inquiries/Inquiries?type=' + type
})
@@ -398,20 +457,13 @@ export default {
this.getBannered();
} else {
this.storeinfo = res.data.data.list.filter((item) => item.is_online == 1)
- // 只在 store_id 不存在时才设置,避免覆盖扫码设置的 store_id
- if (!uni.getStorageSync('store_id') && this.storeinfo.length > 0) {
- uni.setStorageSync('store_id', this.storeinfo[0].store.id)
- }
- if (this.storeinfo.length > 0) {
- this.headerTitle = this.storeinfo[0].store['name']
- }
+ uni.setStorageSync('store_id', this.storeinfo[0].store.id)
+ this.headerTitle = this.storeinfo[0].store['name']
this.getBannered();
}
} else {
- // 接口失败时,只在 store_id 不存在时才设置默认值,避免覆盖扫码设置的 store_id
- if (!uni.getStorageSync('store_id')) {
- uni.setStorageSync('store_id', '11001');
- }
+ // 未登录时不跳转,使用默认store_id=11001
+ uni.setStorageSync('store_id', '11001');
this.getBannered();
}
})
diff --git a/request/api/api.js b/request/api/api.js
index d695f17..b7a69be 100644
--- a/request/api/api.js
+++ b/request/api/api.js
@@ -496,7 +496,7 @@ export async function getVersion(params) {
// 获取系统配置信息
export async function getSystemConfig(params) {
// let data = await http('/xkApi/platform/config', params)
- let data = await http('/xkApi/guest/guest-platform/config', params, 3)
+ let data = await http('/xkApi/platform/config', params, 3)
return data
}
diff --git a/request/api/product.js b/request/api/product.js
index bf2a934..3a807b7 100644
--- a/request/api/product.js
+++ b/request/api/product.js
@@ -51,11 +51,16 @@ export async function updateIntroductionImagesApi(params) {
/**
* 检查药店在线复诊配置(委托诊所和医生)
- * @param params { store_id: number }
+ * @param params { store_id: number, guest?: number } - guest: 0=普通接口, 1=Guest接口
* @returns {Promise<*>}
*/
export async function checkOnlineConsultationConfigApi(params) {
- return await get('/store/check-online-consultation-config', params, 3)
+ const { guest = 0, ...restParams } = params;
+ // guest=1 时调用 Guest 接口,guest=0 时调用普通接口
+ const url = guest === 1
+ ? '/guest/guest-platform/check-online-consultation-config'
+ : '/store/check-online-consultation-config';
+ return await get(url, restParams, 3)
}
/**
diff --git a/request/api/request.js b/request/api/request.js
index 92add88..4741047 100644
--- a/request/api/request.js
+++ b/request/api/request.js
@@ -112,6 +112,9 @@ function request(url, params, method = 0) {
} else if (url.indexOf('/oldApi/v1/store/detail') !== -1) {
url = url.replace('/oldApi/v1/store/detail', '/guest/guest-home/store-detail');
baseURL = envUrls.xkApi;
+ } else if (url.indexOf('/oldApi/v1/store/list') !== -1) {
+ url = url.replace('/oldApi/v1/store/list', '/guest/guest-home/store-list');
+ baseURL = envUrls.xkApi;
} else if (url.indexOf('/oldApi/v1/register/doc-register-info') !== -1) {
url = url.replace('/oldApi/v1/register/doc-register-info', '/guest/guest-doctor/doc-register-info');
baseURL = envUrls.xkApi;
@@ -132,6 +135,12 @@ function request(url, params, method = 0) {
} else if (url.indexOf('/v1/register/doc-register-info') !== -1 || url.indexOf('/member/v1/register/doc-register-info') !== -1) {
url = url.replace(/\/member\/v1\/register\/doc-register-info|\/v1\/register\/doc-register-info/, '/guest/guest-doctor/doc-register-info');
baseURL = envUrls.xkApi;
+ } else if (url.indexOf('/v1/store/info') !== -1 || url.indexOf('/member/v1/store/info') !== -1) {
+ url = url.replace(/\/member\/v1\/store\/info|\/v1\/store\/info/, '/guest/guest-home/store-info');
+ baseURL = envUrls.xkApi;
+ } else if (url.indexOf('/v1/store/list') !== -1 || url.indexOf('/member/v1/store/list') !== -1) {
+ url = url.replace(/\/member\/v1\/store\/list|\/v1\/store\/list/, '/guest/guest-home/store-list');
+ baseURL = envUrls.xkApi;
}
}
@@ -143,8 +152,8 @@ function request(url, params, method = 0) {
}
if (url.split('/').indexOf('xkApi') !== -1) {
baseURL = envUrls.xkApi;
- // 如果是guest模式且是xkApi请求,添加/guest/前缀
- if (isGuestRequest) {
+ // 如果是guest模式且是xkApi请求,添加/guest/前缀(但避免重复添加)
+ if (isGuestRequest && url.indexOf('/guest/') === -1) {
url = url.replace('/xkApi', '/guest/xkApi');
}
}
@@ -156,9 +165,20 @@ function request(url, params, method = 0) {
// 加密
if (params != null) {
params.data = getRes(params.data, false);
- // 如果是guest模式,强制设置store_id为11001
+ // 如果是guest模式,设置store_id(优先使用用户传入或本地存储的值)
if (isGuestRequest && params.data) {
- params.data.store_id = getGuestStoreId();
+ // 优先使用用户传入的 store_id
+ if (!params.data.store_id) {
+ // 如果用户没传,尝试从本地存储获取
+ const localStoreId = uni.getStorageSync('store_id');
+ if (localStoreId) {
+ params.data.store_id = localStoreId;
+ } else {
+ // 如果本地存储也没有,使用默认值(保持向后兼容)
+ params.data.store_id = getGuestStoreId();
+ }
+ }
+ // 如果用户已经传了 store_id,就使用用户传入的值,不做任何修改
}
}
let num = 0;
diff --git a/subPackages/chat/chat.vue b/subPackages/chat/chat.vue
index f73279e..9b21564 100644
--- a/subPackages/chat/chat.vue
+++ b/subPackages/chat/chat.vue
@@ -9,7 +9,8 @@
{{ doctorUserInfo.nick_name }}
- 在线 · 心血管内科
+
+ 在线