c154a02a by lihua

使用接口获取APPKey

1 parent 0b0869a4
......@@ -26,6 +26,19 @@ server {
expires -1s;
}
# idaas api
location /idaas/ {
resolver 169.254.25.10 valid=30s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_pass http://ms-idaas-server-service-release.tds:8080/; # 门户idaas http测试环境
}
location /api/ {
resolver 127.0.0.11 valid=10s;
proxy_set_header Host $host;
......@@ -37,12 +50,12 @@ server {
}
# 专门处理 config.json 的 location
# location = /config.json {
# # 启用 sub_filter 并指定 MIME 类型为 application/json
# sub_filter '{{{API_BASE_URL}}}' '${API_BASE_URL}';
# sub_filter_once off;
# sub_filter_types application/json; # 关键:允许替换 JSON 类型
# }
location = /config.json {
# 启用 sub_filter 并指定 MIME 类型为 application/json
sub_filter '{{{APP_KEY}}}' '${APP_KEY}';
sub_filter_once off;
sub_filter_types application/json; # 关键:允许替换 JSON 类型
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
......
import request from "@/utils/request";
/** 获取appKey */
export const getAppKey = () => {
return request({
url: `${import.meta.env.VITE_APP_USER_API_BASEURL}/staff/getAppKey`,
method: "get",
});
};
/** 获取数往知来接入idaas的token。 */
export const getTokenByCode = (params) => {
return request({
......
......@@ -8,6 +8,7 @@ import router from './router'
import useSettingsStore from './store/modules/settings';
import { ElMessage } from "element-plus"
import { getPublicIP, openMessageBox } from "@/utils/common"
import sysConfigStore from '@/store/modules/sysConfig'
// pinia设置
import {createPinia} from 'pinia'
......@@ -44,3 +45,5 @@ app.mount('#main-app')
getPublicIP().then((ip) => {
localStorage.setItem('ipAddress', ip);
})
sysConfigStore().loadingAppKey();
\ No newline at end of file
......
import { getAppKey } from '@/api/modules/queryService'
import { ElMessage } from 'element-plus';
const sysConfigStore = defineStore(
// 唯一ID
'config',
'sysConfig',
() => {
let configMap: any = {};
/** 动态appkey值,从接口获取 */
let appKey = '';
const loadingAppKey = () => {
getAppKey().then((res: any) => {
if (res?.code == '00000') {
appKey = res.data;
} else {
ElMessage.error('appKey获取失败');
}
})
}
// 封装请求配置文件的函数
const loadConfig = async () => {
try {
......@@ -24,13 +40,19 @@ const sysConfigStore = defineStore(
}
const getConfig = (field) => {
// if (import.meta.env.MODE == 'nginx' || import.meta.env.MODE == 'development') {
// return import.meta.env.VITE_appKey
// }
if (import.meta.env.MODE == 'nginx' || import.meta.env.MODE == 'development') {
return import.meta.env.VITE_appKey
}
return (field ? configMap[field] : configMap) || '69afd501e4b08251f6cf6419';
}
const getAppKeyValue = () => {
return appKey;
}
return {
loadingAppKey,
getAppKeyValue,
configMap,
loadConfig,
setConfig,
......
......@@ -749,7 +749,7 @@ const imgCheckDialog = ref(false)
let LOGINCODE = {
grant_type: 'authorization_code',
response_type: 'code',
client_id: sysConfigStore().getConfig('appKey'),
client_id: sysConfigStore().getAppKeyValue(),
scope: 'other',
state: 'authorization-life',
loginRedirectUrl: window.location.origin // 登录重定向域名
......@@ -767,7 +767,7 @@ async function beforeLogin() {
let formData = await beforeLoginFormRef.value.getData();
let _logonUser = formData.logonUser;
let password = formData.password;
loginStore.encodePwd = CryptoJS.AES.encrypt(password, sysConfigStore().getConfig('appKey')).toString();
loginStore.encodePwd = CryptoJS.AES.encrypt(password, sysConfigStore().getAppKeyValue()).toString();
loading.value = true;
let loginRes = await idaasStore.login(formData);
loading.value = false;
......@@ -850,7 +850,7 @@ async function handleLogin(params) {
//const result = isJsonString(res) ? JSON.parse(res) : res;
// let scope = result.data.authorities?.map(a => a.authority).join(' ');
if (!client_id) {
client_id = sysConfigStore().getConfig('appKey');
client_id = sysConfigStore().getAppKeyValue();
}
let hrefOrigin = window.location.origin;
if (!redirect_uri) {
......@@ -1041,12 +1041,12 @@ const passKeyLogin = () => {
let client_id = route.query.client_id;
let redirect_uri = route.query.redirect_uri;
if (!client_id) {
client_id = sysConfigStore().getConfig('appKey');
client_id = sysConfigStore().getAppKeyValue();
}
let hrefOrigin = window.location.origin;
if (!redirect_uri) {
//redirect_uri = import.meta.env.VITE_redirectUrl
redirect_uri = hrefOrigin + '/login';
redirect_uri = hrefOrigin + '/';
}
let state = createStateHashCode();
let url = `${hrefOrigin}/idaas/oauth2/authorize?response_type=${LOGINCODE.response_type}&client_id=${client_id}&scope=other&state=${state}&redirect_uri=${encodeURIComponent(redirect_uri)}`
......@@ -1067,7 +1067,7 @@ const passKeyLogin = () => {
function toCheckSmsCode() {
let isCheckSms = loginStore.isCheckSms;
if (isCheckSms) {
let password = CryptoJS.AES.decrypt(loginStore.encodePwd || '', sysConfigStore().getConfig('appKey')).toString(CryptoJS.enc.Utf8)
let password = CryptoJS.AES.decrypt(loginStore.encodePwd || '', sysConfigStore().getAppKeyValue()).toString(CryptoJS.enc.Utf8)
let principal = idaasStore.idaasUserInfo.principal
formType.value = 'login';
nextTick(()=>{
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!