From fe56872f72c5b141138c980b0dd2bc62cc3ddc5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=98=B1=E8=BE=BE?= Date: Mon, 10 Mar 2025 19:05:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(env):=20=E6=B7=BB=E5=8A=A0=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E9=85=8D=E7=BD=AE=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=90=86=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 .env 文件,配置不同环境下的基础 URL - 更新 vite.config.ts,添加环境变量加载和代理配置- 添加 request.js 工具类,用于处理 HTTP 请求 - 更新相关组件,集成新的请求方法 --- .env | 10 ++ .env.development | 12 +- .env.production | 2 - .env.sit | 2 - .env.uat | 2 - auto-imports.d.ts | 4 +- package-lock.json | 125 ++++++++++++++++-- package.json | 5 +- src/api/home/index.js | 9 ++ src/components/YLPicker.vue | 8 +- src/config.js | 12 ++ src/utils/request.js | 94 +++++++++++++ .../Home/components/CreateSurvey/Index.vue | 5 + vite.config.ts | 102 ++++++++------ 14 files changed, 321 insertions(+), 71 deletions(-) create mode 100644 .env delete mode 100644 .env.production delete mode 100644 .env.sit delete mode 100644 .env.uat create mode 100644 src/api/home/index.js create mode 100644 src/config.js create mode 100644 src/utils/request.js diff --git a/.env b/.env new file mode 100644 index 0000000..996e123 --- /dev/null +++ b/.env @@ -0,0 +1,10 @@ +# .env +VITE_APP_BASE_URL=http://192.168.3.7:15001/ +VITE_APP_ENV=development +VITE_APP_CURRENTMODE=dev +VITE_APP_BASEOSS=https://diaoyan-files.automark.cc +VITE_APP_DELIVERY_BASEURL=https://javaxq.test.automark.cc/ +VITE_APP_MESSAGE_CENTER=http://gtech-gateway.dcin-test.digitalyili.com/apigtech/message-send-center/ +VITE_APP_SOCKETURL=wss://yls-api-uat.dctest.digitalyili.com/survey_sync +VITE_APP_JSONPURL=https://iam-uat.dctest.digitalyili.com/idp/restful/getIDPToken +VITE_APP_YQRURL=https://ocp-uat-ain.digitalyili.com diff --git a/.env.development b/.env.development index e8d30fa..7bceb85 100644 --- a/.env.development +++ b/.env.development @@ -1,2 +1,10 @@ -VITE_APP_BASE_URL = '/' -VITE_APP_ENV = 'development' +# .env.development +VITE_APP_BASEURL=http://192.168.3.7:15001/api/ +VITE_APP_ENV=development +VITE_APP_CURRENTMODE=dev +VITE_APP_BASEOSS=https://diaoyan-files.automark.cc +VITE_APP_DELIVERY_BASEURL=https://javaxq.test.automark.cc/ +VITE_APP_MESSAGE_CENTER=http://gtech-gateway.dcin-test.digitalyili.com/apigtech/message-send-center/ +VITE_APP_SOCKETURL=wss://yls-api-uat.dctest.digitalyili.com/survey_sync +VITE_APP_JSONPURL=https://iam-uat.dctest.digitalyili.com/idp/restful/getIDPToken +VITE_APP_YQRURL=https://ocp-uat-ain.digitalyili.com diff --git a/.env.production b/.env.production deleted file mode 100644 index 9e37b5c..0000000 --- a/.env.production +++ /dev/null @@ -1,2 +0,0 @@ -VITE_APP_BASE_URL = 'https://xx.digitalyili.com' -VITE_APP_ENV = 'prod' diff --git a/.env.sit b/.env.sit deleted file mode 100644 index b62dff6..0000000 --- a/.env.sit +++ /dev/null @@ -1,2 +0,0 @@ -VITE_APP_BASE_URL = 'https://sit.xx.digitalyili.com' -VITE_APP_ENV = 'sit' diff --git a/.env.uat b/.env.uat deleted file mode 100644 index c4b9b8b..0000000 --- a/.env.uat +++ /dev/null @@ -1,2 +0,0 @@ -VITE_APP_BASE_URL = 'https://uat.xx.digitalyili.com' -VITE_APP_ENV = 'uat' diff --git a/auto-imports.d.ts b/auto-imports.d.ts index b0b0357..9d24007 100644 --- a/auto-imports.d.ts +++ b/auto-imports.d.ts @@ -5,4 +5,6 @@ // Generated by unplugin-auto-import // biome-ignore lint: disable export {} -declare global {} +declare global { + +} diff --git a/package-lock.json b/package-lock.json index 393a4ca..24957ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,12 +9,15 @@ "version": "0.0.0", "dependencies": { "@element-plus/icons-vue": "^2.3.1", + "axios": "^1.8.2", + "dotenv": "^16.4.7", "element-plus": "^2.7.8", "lodash": "^4.17.21", "pinia": "^2.1.7", "sortablejs": "^1.15.6", "uuid": "^11.1.0", "vant": "^4.9.17", + "vite-plugin-vue": "^0.0.1", "vue": "^3.4.29", "vue-router": "^4.3.3", "vuex": "^4.1.0" @@ -4782,6 +4785,11 @@ "resolved": "https://registry.npmmirror.com/async-validator/-/async-validator-4.2.5.tgz", "integrity": "sha512-7HhHjtERjqlNbZtqNqy2rckN/SpOOlmDliet+lP7k+eKZEjPk3DgyeU9lIXLdeLz0uBbbVp+9Qdow9wJWgwwfg==" }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmmirror.com/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, "node_modules/available-typed-arrays": { "version": "1.0.7", "resolved": "https://registry.npmmirror.com/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", @@ -4797,6 +4805,16 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/axios": { + "version": "1.8.2", + "resolved": "https://registry.npmmirror.com/axios/-/axios-1.8.2.tgz", + "integrity": "sha512-ls4GYBm5aig9vWx8AWDSGLpnpDQRtWAfrjU+EuytuODrFBkqesN2RkOQCBzrA1RQNHw1SmRMSDDDSwzNAYQ6Rg==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmmirror.com/balanced-match/-/balanced-match-1.0.2.tgz", @@ -4974,7 +4992,6 @@ }, "node_modules/call-bind-apply-helpers": { "version": "1.0.2", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -5100,6 +5117,17 @@ "integrity": "sha512-jeC1axXpnb0/2nn/Y1LPuLdgXBLH7aDcHu4KEKfqw3CUhX7ZpfBSlPKyqXE6btIgEzfWtrX3/tyBCaCvXvMkOw==", "dev": true }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmmirror.com/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmmirror.com/concat-map/-/concat-map-0.0.1.tgz", @@ -5311,6 +5339,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmmirror.com/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/detect-libc": { "version": "1.0.3", "resolved": "https://registry.npmmirror.com/detect-libc/-/detect-libc-1.0.3.tgz", @@ -5404,9 +5440,19 @@ "url": "https://github.com/fb55/domutils?sponsor=1" } }, + "node_modules/dotenv": { + "version": "16.4.7", + "resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-16.4.7.tgz", + "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", - "dev": true, "license": "MIT", "dependencies": { "call-bind-apply-helpers": "^1.0.1", @@ -5548,7 +5594,6 @@ }, "node_modules/es-define-property": { "version": "1.0.1", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -5556,7 +5601,6 @@ }, "node_modules/es-errors": { "version": "1.3.0", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -5591,7 +5635,6 @@ }, "node_modules/es-object-atoms": { "version": "1.1.1", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0" @@ -5602,7 +5645,6 @@ }, "node_modules/es-set-tostringtag": { "version": "2.1.0", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -6614,6 +6656,25 @@ "integrity": "sha512-GX+ysw4PBCz0PzosHDepZGANEuFCMLrnRTiEy9McGjmkCQYwRq4A/X786G/fjM/+OjsWSU1ZrY5qyARZmO/uwg==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-each": { "version": "0.3.5", "resolved": "https://registry.npmmirror.com/for-each/-/for-each-0.3.5.tgz", @@ -6629,6 +6690,20 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/form-data": { + "version": "4.0.2", + "resolved": "https://registry.npmmirror.com/form-data/-/form-data-4.0.2.tgz", + "integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmmirror.com/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -6652,7 +6727,6 @@ }, "node_modules/function-bind": { "version": "1.1.2", - "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" @@ -6697,7 +6771,6 @@ }, "node_modules/get-intrinsic": { "version": "1.3.0", - "dev": true, "license": "MIT", "dependencies": { "call-bind-apply-helpers": "^1.0.2", @@ -6720,7 +6793,6 @@ }, "node_modules/get-proto": { "version": "1.0.1", - "dev": true, "license": "MIT", "dependencies": { "dunder-proto": "^1.0.1", @@ -6914,7 +6986,6 @@ }, "node_modules/gopd": { "version": "1.2.0", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -6978,7 +7049,6 @@ }, "node_modules/has-symbols": { "version": "1.1.0", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -6989,7 +7059,6 @@ }, "node_modules/has-tostringtag": { "version": "1.0.2", - "dev": true, "license": "MIT", "dependencies": { "has-symbols": "^1.0.3" @@ -7003,7 +7072,6 @@ }, "node_modules/hasown": { "version": "2.0.2", - "dev": true, "license": "MIT", "dependencies": { "function-bind": "^1.1.2" @@ -7826,7 +7894,6 @@ }, "node_modules/math-intrinsics": { "version": "1.1.0", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -7908,6 +7975,25 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmmirror.com/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/minimatch": { "version": "9.0.3", "resolved": "https://registry.npmmirror.com/minimatch/-/minimatch-9.0.3.tgz", @@ -8662,6 +8748,11 @@ "react-is": "^16.13.1" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmmirror.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmmirror.com/punycode/-/punycode-2.3.1.tgz", @@ -10450,6 +10541,12 @@ } } }, + "node_modules/vite-plugin-vue": { + "version": "0.0.1", + "resolved": "https://registry.npmmirror.com/vite-plugin-vue/-/vite-plugin-vue-0.0.1.tgz", + "integrity": "sha512-PhAy+v+t6W3JAeqFxf6w/hGyURZ2qvrJMS/HTeCPLnfllz+O5wNP49TcAb4MROeif93kKIOigtDFJowaLuU+0w==", + "deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info." + }, "node_modules/vscode-uri": { "version": "3.1.0", "resolved": "https://registry.npmmirror.com/vscode-uri/-/vscode-uri-3.1.0.tgz", diff --git a/package.json b/package.json index bb5aa8a..a2c9510 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "type": "module", "scripts": { - "dev": "vite", + "dev": "vite --mode development", "build": "run-p type-check \"build-only {@}\" --", "preview": "vite preview", "build-only": "vite build", @@ -14,12 +14,15 @@ }, "dependencies": { "@element-plus/icons-vue": "^2.3.1", + "axios": "^1.8.2", + "dotenv": "^16.4.7", "element-plus": "^2.7.8", "lodash": "^4.17.21", "pinia": "^2.1.7", "sortablejs": "^1.15.6", "uuid": "^11.1.0", "vant": "^4.9.17", + "vite-plugin-vue": "^0.0.1", "vue": "^3.4.29", "vue-router": "^4.3.3", "vuex": "^4.1.0" diff --git a/src/api/home/index.js b/src/api/home/index.js new file mode 100644 index 0000000..a63a33b --- /dev/null +++ b/src/api/home/index.js @@ -0,0 +1,9 @@ +import request from '@/utils/request.js'; + +export function getQuestionList(params) { + return request({ + url: '/console/template/list_shortcut', + method: 'get', + params + }); +} diff --git a/src/components/YLPicker.vue b/src/components/YLPicker.vue index a172ec1..1e98e52 100644 --- a/src/components/YLPicker.vue +++ b/src/components/YLPicker.vue @@ -167,8 +167,8 @@ const getMaxDateLimit = computed(() => { props.format ); const tempStr = '0000-12-31 23:59:59'; - const result = - props.maxDate.length !== 0 && thisMax.length > props.maxDate.length + const result + = props.maxDate.length !== 0 && thisMax.length > props.maxDate.length ? thisMax.slice(0, props.maxDate.length) + tempStr.slice(props.maxDate.length) : thisMax; return result.slice(0, props.format.length); @@ -191,8 +191,8 @@ function onChange({ selectedValues, columnIndex }) { renderMinuteColumns, renderSecondColumns ]; - updateColumns[columnIndex] && - updateColumns[columnIndex](changeValue, getMinDateLimit.value, getMaxDateLimit.value, false); + updateColumns[columnIndex] + && updateColumns[columnIndex](changeValue, getMinDateLimit.value, getMaxDateLimit.value, false); } // 渲染全部列 diff --git a/src/config.js b/src/config.js new file mode 100644 index 0000000..f3fc324 --- /dev/null +++ b/src/config.js @@ -0,0 +1,12 @@ +// src/config.js +export default { + proxyUrl: import.meta.env.VITE_APP_BASEURL, + proxyUrlDelivery: import.meta.env.VITE_APP_DELIVERY_BASEURL, + proxyUrlMessageCenter: import.meta.env.VITE_APP_MESSAGE_CENTER, + baseOss: import.meta.env.VITE_APP_BASEOSS, + loginUrl: import.meta.env.VITE_APP_LOGIN, + socketUrl: import.meta.env.VITE_APP_SOCKETURL, + jsonpUrl: import.meta.env.VITE_APP_JSONPURL, + jqrUrl: import.meta.env.VITE_APP_YQRURL, + currentMode: import.meta.env.VITE_APP_CURRENTMODE +}; diff --git a/src/utils/request.js b/src/utils/request.js new file mode 100644 index 0000000..93bd32c --- /dev/null +++ b/src/utils/request.js @@ -0,0 +1,94 @@ +import axios from 'axios'; + +// import router from '@/router/index'; +// import { A_COMMON_CLEAR_TOKEN } from '@/stores/constance/constance.common.js'; + +import * as config from '@/config.js'; + +console.log(config.default); +// import {proxyUrl} from config.default +// + +const NODE_ENV = import.meta.env.VITE_APP_ENV; +const baseURL = NODE_ENV === 'production' ? config.default.proxyUrl : '/backend-api'; + +// axios.defaults.withCredentials = true; + +// create an axios instance +const service = axios.create({ + baseURL: `${baseURL}`, // url = base url + request url + // withCredentials: true, // send cookies when cross-domain requests + timeout: 30000 // request timeout +}); + +// request interceptor +service.interceptors.request.use( + (config) => { + if (!config.headers) { + config.headers.Accept = 'application/json'; + } + config.headers.Authorization = `${localStorage.getItem('plantToken')}`; + if (!config.headers.remoteIp) { + config.baseURL += '/api'; + } + // config.headers.remoteIp = localStorage.getItem('plantIp') || '127.0.0.1'; + // if (store.state.common.token) { + // config.headers['Login-Type'] = 'pc'; + // config.headers.Authorization = `Bearer ${store.state.common.token}`; + // } + return config; + }, + (error) => Promise.reject(error) +); + +// response interceptor +service.interceptors.response.use( + (response) => { + if ( + response.status === 200 || + response.status === 201 || + response.status === 202 || + response.status === 204 + ) { + if (response.config.method === 'put') { + // message.success('保存中...'); + } + return Promise.resolve(response); + } + // return Promise.reject(/* new Error(response.message || 'Error') */); + } + // (error) => { + // // for debug + // if (error.response.status === 401) { + // const query = router.currentRoute.value.query; + // //关闭已弹出的所有弹框,防止弹框重叠 + // // Modal.destroyAll(); + // store.dispatch(A_COMMON_CLEAR_TOKEN); + // window.parent.postMessage( + // { + // code: '301', + // params: {} + // }, + // '*' + // ); + // store.commit('common/M_COMMON_SET_TOKEN_UNAUTHORIZED', false); + // } else if (error.response.status === 403) { + // router.push({ + // path: '/error/403' + // }); + // } else if (error.response.status === 404) { + // router.push({ + // path: '/error/404' + // }); + // } else if (error.response.status === 500) { + // router.push({ + // path: '/error/500' + // }); + // } else { + // // message.error(error.response.data?.message || '服务器错误'); + // } + // return Promise.reject(error.response); + // } +); + +export default service; diff --git a/src/views/Home/components/CreateSurvey/Index.vue b/src/views/Home/components/CreateSurvey/Index.vue index e7027fa..a31b9c1 100644 --- a/src/views/Home/components/CreateSurvey/Index.vue +++ b/src/views/Home/components/CreateSurvey/Index.vue @@ -1,5 +1,10 @@