使用接口获取APPKey
Showing
5 changed files
with
63 additions
and
17 deletions
| ... | @@ -26,6 +26,19 @@ server { | ... | @@ -26,6 +26,19 @@ server { |
| 26 | expires -1s; | 26 | expires -1s; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | # idaas api | ||
| 30 | location /idaas/ { | ||
| 31 | resolver 169.254.25.10 valid=30s; | ||
| 32 | proxy_set_header Host $host; | ||
| 33 | proxy_set_header X-Real-IP $remote_addr; | ||
| 34 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| 35 | proxy_set_header X-Forwarded-Proto $scheme; | ||
| 36 | proxy_set_header X-Forwarded-Port $server_port; | ||
| 37 | |||
| 38 | proxy_pass http://ms-idaas-server-service-release.tds:8080/; # 门户idaas http测试环境 | ||
| 39 | } | ||
| 40 | |||
| 41 | |||
| 29 | location /api/ { | 42 | location /api/ { |
| 30 | resolver 127.0.0.11 valid=10s; | 43 | resolver 127.0.0.11 valid=10s; |
| 31 | proxy_set_header Host $host; | 44 | proxy_set_header Host $host; |
| ... | @@ -37,12 +50,12 @@ server { | ... | @@ -37,12 +50,12 @@ server { |
| 37 | } | 50 | } |
| 38 | 51 | ||
| 39 | # 专门处理 config.json 的 location | 52 | # 专门处理 config.json 的 location |
| 40 | # location = /config.json { | 53 | location = /config.json { |
| 41 | # # 启用 sub_filter 并指定 MIME 类型为 application/json | 54 | # 启用 sub_filter 并指定 MIME 类型为 application/json |
| 42 | # sub_filter '{{{API_BASE_URL}}}' '${API_BASE_URL}'; | 55 | sub_filter '{{{APP_KEY}}}' '${APP_KEY}'; |
| 43 | # sub_filter_once off; | 56 | sub_filter_once off; |
| 44 | # sub_filter_types application/json; # 关键:允许替换 JSON 类型 | 57 | sub_filter_types application/json; # 关键:允许替换 JSON 类型 |
| 45 | # } | 58 | } |
| 46 | 59 | ||
| 47 | error_page 500 502 503 504 /50x.html; | 60 | error_page 500 502 503 504 /50x.html; |
| 48 | location = /50x.html { | 61 | location = /50x.html { | ... | ... |
| 1 | import request from "@/utils/request"; | 1 | import request from "@/utils/request"; |
| 2 | 2 | ||
| 3 | /** 获取appKey */ | ||
| 4 | export const getAppKey = () => { | ||
| 5 | return request({ | ||
| 6 | url: `${import.meta.env.VITE_APP_USER_API_BASEURL}/staff/getAppKey`, | ||
| 7 | method: "get", | ||
| 8 | }); | ||
| 9 | }; | ||
| 10 | |||
| 3 | /** 获取数往知来接入idaas的token。 */ | 11 | /** 获取数往知来接入idaas的token。 */ |
| 4 | export const getTokenByCode = (params) => { | 12 | export const getTokenByCode = (params) => { |
| 5 | return request({ | 13 | return request({ | ... | ... |
| ... | @@ -8,6 +8,7 @@ import router from './router' | ... | @@ -8,6 +8,7 @@ import router from './router' |
| 8 | import useSettingsStore from './store/modules/settings'; | 8 | import useSettingsStore from './store/modules/settings'; |
| 9 | import { ElMessage } from "element-plus" | 9 | import { ElMessage } from "element-plus" |
| 10 | import { getPublicIP, openMessageBox } from "@/utils/common" | 10 | import { getPublicIP, openMessageBox } from "@/utils/common" |
| 11 | import sysConfigStore from '@/store/modules/sysConfig' | ||
| 11 | 12 | ||
| 12 | // pinia设置 | 13 | // pinia设置 |
| 13 | import {createPinia} from 'pinia' | 14 | import {createPinia} from 'pinia' |
| ... | @@ -43,4 +44,6 @@ app.mount('#main-app') | ... | @@ -43,4 +44,6 @@ app.mount('#main-app') |
| 43 | 44 | ||
| 44 | getPublicIP().then((ip) => { | 45 | getPublicIP().then((ip) => { |
| 45 | localStorage.setItem('ipAddress', ip); | 46 | localStorage.setItem('ipAddress', ip); |
| 46 | }) | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 47 | }) | ||
| 48 | |||
| 49 | sysConfigStore().loadingAppKey(); | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | import { getAppKey } from '@/api/modules/queryService' | ||
| 2 | import { ElMessage } from 'element-plus'; | ||
| 3 | |||
| 4 | |||
| 1 | const sysConfigStore = defineStore( | 5 | const sysConfigStore = defineStore( |
| 2 | // 唯一ID | 6 | // 唯一ID |
| 3 | 'config', | 7 | 'sysConfig', |
| 4 | () => { | 8 | () => { |
| 5 | let configMap: any = {}; | 9 | let configMap: any = {}; |
| 6 | 10 | ||
| 11 | /** 动态appkey值,从接口获取 */ | ||
| 12 | let appKey = ''; | ||
| 13 | |||
| 14 | const loadingAppKey = () => { | ||
| 15 | getAppKey().then((res: any) => { | ||
| 16 | if (res?.code == '00000') { | ||
| 17 | appKey = res.data; | ||
| 18 | } else { | ||
| 19 | ElMessage.error('appKey获取失败'); | ||
| 20 | } | ||
| 21 | }) | ||
| 22 | } | ||
| 7 | // 封装请求配置文件的函数 | 23 | // 封装请求配置文件的函数 |
| 8 | const loadConfig = async () => { | 24 | const loadConfig = async () => { |
| 9 | try { | 25 | try { |
| ... | @@ -24,13 +40,19 @@ const sysConfigStore = defineStore( | ... | @@ -24,13 +40,19 @@ const sysConfigStore = defineStore( |
| 24 | } | 40 | } |
| 25 | 41 | ||
| 26 | const getConfig = (field) => { | 42 | const getConfig = (field) => { |
| 27 | // if (import.meta.env.MODE == 'nginx' || import.meta.env.MODE == 'development') { | 43 | if (import.meta.env.MODE == 'nginx' || import.meta.env.MODE == 'development') { |
| 28 | // return import.meta.env.VITE_appKey | 44 | return import.meta.env.VITE_appKey |
| 29 | // } | 45 | } |
| 30 | return (field ? configMap[field] : configMap) || '69afd501e4b08251f6cf6419'; | 46 | return (field ? configMap[field] : configMap) || '69afd501e4b08251f6cf6419'; |
| 31 | } | 47 | } |
| 32 | 48 | ||
| 49 | const getAppKeyValue = () => { | ||
| 50 | return appKey; | ||
| 51 | } | ||
| 52 | |||
| 33 | return { | 53 | return { |
| 54 | loadingAppKey, | ||
| 55 | getAppKeyValue, | ||
| 34 | configMap, | 56 | configMap, |
| 35 | loadConfig, | 57 | loadConfig, |
| 36 | setConfig, | 58 | setConfig, | ... | ... |
| ... | @@ -749,7 +749,7 @@ const imgCheckDialog = ref(false) | ... | @@ -749,7 +749,7 @@ const imgCheckDialog = ref(false) |
| 749 | let LOGINCODE = { | 749 | let LOGINCODE = { |
| 750 | grant_type: 'authorization_code', | 750 | grant_type: 'authorization_code', |
| 751 | response_type: 'code', | 751 | response_type: 'code', |
| 752 | client_id: sysConfigStore().getConfig('appKey'), | 752 | client_id: sysConfigStore().getAppKeyValue(), |
| 753 | scope: 'other', | 753 | scope: 'other', |
| 754 | state: 'authorization-life', | 754 | state: 'authorization-life', |
| 755 | loginRedirectUrl: window.location.origin // 登录重定向域名 | 755 | loginRedirectUrl: window.location.origin // 登录重定向域名 |
| ... | @@ -767,7 +767,7 @@ async function beforeLogin() { | ... | @@ -767,7 +767,7 @@ async function beforeLogin() { |
| 767 | let formData = await beforeLoginFormRef.value.getData(); | 767 | let formData = await beforeLoginFormRef.value.getData(); |
| 768 | let _logonUser = formData.logonUser; | 768 | let _logonUser = formData.logonUser; |
| 769 | let password = formData.password; | 769 | let password = formData.password; |
| 770 | loginStore.encodePwd = CryptoJS.AES.encrypt(password, sysConfigStore().getConfig('appKey')).toString(); | 770 | loginStore.encodePwd = CryptoJS.AES.encrypt(password, sysConfigStore().getAppKeyValue()).toString(); |
| 771 | loading.value = true; | 771 | loading.value = true; |
| 772 | let loginRes = await idaasStore.login(formData); | 772 | let loginRes = await idaasStore.login(formData); |
| 773 | loading.value = false; | 773 | loading.value = false; |
| ... | @@ -850,7 +850,7 @@ async function handleLogin(params) { | ... | @@ -850,7 +850,7 @@ async function handleLogin(params) { |
| 850 | //const result = isJsonString(res) ? JSON.parse(res) : res; | 850 | //const result = isJsonString(res) ? JSON.parse(res) : res; |
| 851 | // let scope = result.data.authorities?.map(a => a.authority).join(' '); | 851 | // let scope = result.data.authorities?.map(a => a.authority).join(' '); |
| 852 | if (!client_id) { | 852 | if (!client_id) { |
| 853 | client_id = sysConfigStore().getConfig('appKey'); | 853 | client_id = sysConfigStore().getAppKeyValue(); |
| 854 | } | 854 | } |
| 855 | let hrefOrigin = window.location.origin; | 855 | let hrefOrigin = window.location.origin; |
| 856 | if (!redirect_uri) { | 856 | if (!redirect_uri) { |
| ... | @@ -1041,12 +1041,12 @@ const passKeyLogin = () => { | ... | @@ -1041,12 +1041,12 @@ const passKeyLogin = () => { |
| 1041 | let client_id = route.query.client_id; | 1041 | let client_id = route.query.client_id; |
| 1042 | let redirect_uri = route.query.redirect_uri; | 1042 | let redirect_uri = route.query.redirect_uri; |
| 1043 | if (!client_id) { | 1043 | if (!client_id) { |
| 1044 | client_id = sysConfigStore().getConfig('appKey'); | 1044 | client_id = sysConfigStore().getAppKeyValue(); |
| 1045 | } | 1045 | } |
| 1046 | let hrefOrigin = window.location.origin; | 1046 | let hrefOrigin = window.location.origin; |
| 1047 | if (!redirect_uri) { | 1047 | if (!redirect_uri) { |
| 1048 | //redirect_uri = import.meta.env.VITE_redirectUrl | 1048 | //redirect_uri = import.meta.env.VITE_redirectUrl |
| 1049 | redirect_uri = hrefOrigin + '/login'; | 1049 | redirect_uri = hrefOrigin + '/'; |
| 1050 | } | 1050 | } |
| 1051 | let state = createStateHashCode(); | 1051 | let state = createStateHashCode(); |
| 1052 | let url = `${hrefOrigin}/idaas/oauth2/authorize?response_type=${LOGINCODE.response_type}&client_id=${client_id}&scope=other&state=${state}&redirect_uri=${encodeURIComponent(redirect_uri)}` | 1052 | 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 = () => { | ... | @@ -1067,7 +1067,7 @@ const passKeyLogin = () => { |
| 1067 | function toCheckSmsCode() { | 1067 | function toCheckSmsCode() { |
| 1068 | let isCheckSms = loginStore.isCheckSms; | 1068 | let isCheckSms = loginStore.isCheckSms; |
| 1069 | if (isCheckSms) { | 1069 | if (isCheckSms) { |
| 1070 | let password = CryptoJS.AES.decrypt(loginStore.encodePwd || '', sysConfigStore().getConfig('appKey')).toString(CryptoJS.enc.Utf8) | 1070 | let password = CryptoJS.AES.decrypt(loginStore.encodePwd || '', sysConfigStore().getAppKeyValue()).toString(CryptoJS.enc.Utf8) |
| 1071 | let principal = idaasStore.idaasUserInfo.principal | 1071 | let principal = idaasStore.idaasUserInfo.principal |
| 1072 | formType.value = 'login'; | 1072 | formType.value = 'login'; |
| 1073 | nextTick(()=>{ | 1073 | nextTick(()=>{ | ... | ... |
-
Please register or sign in to post a comment