no message
This commit is contained in:
parent
f80dbbadfe
commit
c7c0570dd9
@ -60,13 +60,18 @@ export default defineStore("accountStore", () => {
|
|||||||
corpId,
|
corpId,
|
||||||
});
|
});
|
||||||
if (res.success && res.data) {
|
if (res.success && res.data) {
|
||||||
|
const { sessionToken, sessionExpiresAt, sessionKey, ...safeAccount } = res.data;
|
||||||
|
if (sessionToken) {
|
||||||
|
uni.setStorageSync("miniappSessionToken", sessionToken);
|
||||||
|
uni.setStorageSync("miniappSessionExpiresAt", sessionExpiresAt || 0);
|
||||||
|
}
|
||||||
// if (!res.data.mobile) {
|
// if (!res.data.mobile) {
|
||||||
// const target = '/pages/login/login';
|
// const target = '/pages/login/login';
|
||||||
// uni.redirectTo({ url: target });
|
// uni.redirectTo({ url: target });
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
account.value = { ...res.data, corpId };
|
account.value = { ...safeAccount, corpId };
|
||||||
openid.value = res.data.openid;
|
openid.value = safeAccount.openid;
|
||||||
// 持久化账户信息
|
// 持久化账户信息
|
||||||
// cache.set(CACHE_KEYS.ACCOUNT, res.data);
|
// cache.set(CACHE_KEYS.ACCOUNT, res.data);
|
||||||
// cache.set(CACHE_KEYS.OPENID, res.data.openid);
|
// cache.set(CACHE_KEYS.OPENID, res.data.openid);
|
||||||
@ -155,6 +160,8 @@ export default defineStore("accountStore", () => {
|
|||||||
|
|
||||||
// 清空账户信息
|
// 清空账户信息
|
||||||
account.value = null;
|
account.value = null;
|
||||||
|
uni.removeStorageSync("miniappSessionToken");
|
||||||
|
uni.removeStorageSync("miniappSessionExpiresAt");
|
||||||
openid.value = "";
|
openid.value = "";
|
||||||
isIMInitialized.value = false;
|
isIMInitialized.value = false;
|
||||||
doctorInfo.value = null;
|
doctorInfo.value = null;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { loading, hideLoading } from "./widget";
|
import { loading, hideLoading } from "./widget";
|
||||||
const env = __VITE_ENV__;
|
const env = __VITE_ENV__;
|
||||||
const baseUrl = env.MP_API_BASE_URL;
|
const baseUrl = env.MP_API_BASE_URL;
|
||||||
|
const SH6_CORP_ID = "wpLgjyawAAxKtBH5GVT5DVhLefg246Ag";
|
||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
header: {
|
header: {
|
||||||
@ -100,6 +101,7 @@ const request = async (options = {}, showLoading = true) => {
|
|||||||
if (!options.data.corpId) {
|
if (!options.data.corpId) {
|
||||||
options.data.corpId = env.MP_CORP_ID;
|
options.data.corpId = env.MP_CORP_ID;
|
||||||
}
|
}
|
||||||
|
const requiresMiniappSession = options.data.corpId === SH6_CORP_ID;
|
||||||
|
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
@ -108,12 +110,10 @@ const request = async (options = {}, showLoading = true) => {
|
|||||||
url: baseUrl + options.url,
|
url: baseUrl + options.url,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 添加 token 到请求头
|
const sessionToken = uni.getStorageSync("miniappSessionToken");
|
||||||
// const accessToken = uni.getStorageSync("accessToken");
|
if (requiresMiniappSession && sessionToken) {
|
||||||
// if (accessToken) {
|
config.header = { ...(config.header || {}), "X-Miniapp-Session": sessionToken };
|
||||||
// if (!config.header) config.header = {};
|
}
|
||||||
// config.header.Authorization = `Bearer ${accessToken}`;
|
|
||||||
// }
|
|
||||||
|
|
||||||
const key = `${JSON.stringify(config)}_${Date.now()}`;
|
const key = `${JSON.stringify(config)}_${Date.now()}`;
|
||||||
if (showLoading) {
|
if (showLoading) {
|
||||||
@ -127,6 +127,10 @@ const request = async (options = {}, showLoading = true) => {
|
|||||||
removeTask(key)
|
removeTask(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (requiresMiniappSession && res.statusCode === 401) {
|
||||||
|
uni.removeStorageSync("miniappSessionToken");
|
||||||
|
uni.removeStorageSync("miniappSessionExpiresAt");
|
||||||
|
}
|
||||||
// 如果返回 401,尝试刷新 token
|
// 如果返回 401,尝试刷新 token
|
||||||
// if (res.statusCode === 401) {
|
// if (res.statusCode === 401) {
|
||||||
// if (showLoading) {
|
// if (showLoading) {
|
||||||
@ -210,9 +214,13 @@ export function getFullPath(path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function upload(path) {
|
export function upload(path) {
|
||||||
|
const sessionToken = uni.getStorageSync("miniappSessionToken");
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
uni.uploadFile({
|
uni.uploadFile({
|
||||||
url: uploadUrl, // 替换为你的上传接口地址
|
url: uploadUrl, // 替换为你的上传接口地址
|
||||||
|
header: env.MP_CORP_ID === SH6_CORP_ID && sessionToken
|
||||||
|
? { "X-Miniapp-Session": sessionToken }
|
||||||
|
: {},
|
||||||
filePath: path,
|
filePath: path,
|
||||||
name: 'file',
|
name: 'file',
|
||||||
fileType: 'image',
|
fileType: 'image',
|
||||||
@ -230,4 +238,3 @@ export function upload(path) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user