import {Base64} from 'js-base64';
import website from '~src/config';
import {getToken} from '~src/api/util/auth';

//状态管理
import pinia from "~src/store/init"
import {useAppStore} from "~src/store";
const store = useAppStore(pinia)

export function getTokenHeader(text= false) {
    let headers = {};
    headers['Authorization'] = `Basic ${Base64.encode(`${website.clientId}:${website.clientSecret}`)}`;
    headers['Tenantid'] = store.tenantId ? store.tenantId : website.tenantId;
    //让每个请求携带token
    const token = getToken()
    if (token) headers[website.tokenHeader] = 'bearer ' + token
    //headers中配置text请求
    if (text === true) {
        headers["Content-Type"] = "text/plain";
    }
    return headers;
}
