From eac7c5321dca68e34db95995db2cabd29b9324da Mon Sep 17 00:00:00 2001 From: zhuguifei <zhuguifei@zhuguifeideiMac.local> Date: 星期五, 18 四月 2025 14:25:32 +0800 Subject: [PATCH] 网络请求配置,开发登录接口 --- eims-ui-mobile/src/store/access.ts | 79 ++++++++++++++++++++++++++ eims-ui-mobile/env/.env | 6 + eims-ui-mobile/src/service/login.d.ts | 7 ++ eims-ui-mobile/src/service/login.ts | 25 ++++++++ eims-ui-mobile/vite.config.ts | 1 eims-ui-mobile/src/env.d.ts | 1 eims-ui-mobile/src/components/fg-tabbar/fg-tabbar.vue | 2 eims-ui-mobile/pages.config.ts | 6 +- eims-ui-mobile/src/utils/http.ts | 11 +++ eims-ui-mobile/src/pages.json | 9 +- eims-ui-mobile/src/uni.scss | 2 eims-ui-mobile/src/store/index.ts | 1 eims-ui-mobile/src/interceptors/route.ts | 6 +- eims-ui-mobile/src/style/index.scss | 20 ++++++ 14 files changed, 160 insertions(+), 16 deletions(-) diff --git a/eims-ui-mobile/env/.env b/eims-ui-mobile/env/.env index 1d4b444..e404113 100644 --- a/eims-ui-mobile/env/.env +++ b/eims-ui-mobile/env/.env @@ -7,7 +7,7 @@ # h5閮ㄧ讲缃戠珯鐨刡ase锛岄厤缃埌 manifest.config.ts 閲岀殑 h5.router.base VITE_APP_PUBLIC_BASE=/ -VITE_SERVER_BASEURL = 'https://ukw0y1.laf.run' +VITE_SERVER_BASEURL = 'http://192.168.12.33:8080' VITE_UPLOAD_BASEURL = 'https://ukw0y1.laf.run/upload' # 鏈変簺鍚屽鍙兘闇�瑕佸湪寰俊灏忕▼搴忛噷闈㈡牴鎹� develop銆乼rial銆乺elease 鍒嗗埆璁剧疆涓婁紶鍦板潃锛屽弬鑰冧唬鐮佸涓嬨�� @@ -23,3 +23,7 @@ # h5鏄惁闇�瑕侀厤缃唬鐞� VITE_APP_PROXY=false VITE_APP_PROXY_PREFIX = '/api' + + +# 鍚庣鍙傛暟閰嶇疆 +VITE_APP_CLIENT_ID = '428a8310cd442757ae699df5d894f051' diff --git a/eims-ui-mobile/pages.config.ts b/eims-ui-mobile/pages.config.ts index 50eab64..c46f09f 100644 --- a/eims-ui-mobile/pages.config.ts +++ b/eims-ui-mobile/pages.config.ts @@ -4,8 +4,8 @@ globalStyle: { navigationStyle: 'default', navigationBarTitleText: '鍏板疂璁惧绠$悊', - navigationBarBackgroundColor: '#f8f8f8', - navigationBarTextStyle: 'black', + navigationBarBackgroundColor: '#4D80F0', + navigationBarTextStyle: 'white', backgroundColor: '#FFFFFF', }, easycom: { @@ -20,7 +20,7 @@ tabBar: { custom: true, color: '#999999', - selectedColor: '#007aff', + selectedColor: '#4D80F0', borderStyle: 'black', height: '50px', fontSize: '10px', diff --git a/eims-ui-mobile/src/components/fg-tabbar/fg-tabbar.vue b/eims-ui-mobile/src/components/fg-tabbar/fg-tabbar.vue index e8d12de..72675c5 100644 --- a/eims-ui-mobile/src/components/fg-tabbar/fg-tabbar.vue +++ b/eims-ui-mobile/src/components/fg-tabbar/fg-tabbar.vue @@ -6,7 +6,7 @@ safeAreaInsetBottom placeholder @change="selectTabBar" - active-color="#007aff" + active-color="#4D80F0" inactive-color="#7d7e80" > <block v-for="(item, idx) in tabbarList" :key="item.path"> diff --git a/eims-ui-mobile/src/env.d.ts b/eims-ui-mobile/src/env.d.ts index daea211..6d405bf 100644 --- a/eims-ui-mobile/src/env.d.ts +++ b/eims-ui-mobile/src/env.d.ts @@ -23,6 +23,7 @@ readonly VITE_UPLOAD_BASEURL: string /** 鏄惁娓呴櫎console */ readonly VITE_DELETE_CONSOLE: string + readonly VITE_APP_CLIENT_ID: string // 鏇村鐜鍙橀噺... } diff --git a/eims-ui-mobile/src/interceptors/route.ts b/eims-ui-mobile/src/interceptors/route.ts index ddd6c98..fe5bc2f 100644 --- a/eims-ui-mobile/src/interceptors/route.ts +++ b/eims-ui-mobile/src/interceptors/route.ts @@ -4,15 +4,15 @@ * 鍙互璁剧疆璺敱鐧藉悕鍗曪紝鎴栬�呴粦鍚嶅崟锛岀湅涓氬姟闇�瑕侀�夊摢涓�涓� * 鎴戣繖閲屽簲涓哄ぇ閮ㄥ垎閮藉彲浠ラ殢渚胯繘鍏ワ紝鎵�浠ヤ娇鐢ㄩ粦鍚嶅崟 */ -import { useUserStore } from '@/store' +import { useUserStore, useAccessStore } from '@/store' import { needLoginPages as _needLoginPages, getNeedLoginPages } from '@/utils' // TODO Check const loginRoute = '/pages/login/index' const isLogined = () => { - const userStore = useUserStore() - return userStore.isLogined + const accessStore = useAccessStore() + return accessStore.isLogined } const isDev = import.meta.env.DEV diff --git a/eims-ui-mobile/src/pages.json b/eims-ui-mobile/src/pages.json index d346a4b..fc6eadb 100644 --- a/eims-ui-mobile/src/pages.json +++ b/eims-ui-mobile/src/pages.json @@ -2,8 +2,8 @@ "globalStyle": { "navigationStyle": "default", "navigationBarTitleText": "鍏板疂璁惧绠$悊", - "navigationBarBackgroundColor": "#f8f8f8", - "navigationBarTextStyle": "black", + "navigationBarBackgroundColor": "#4D80F0", + "navigationBarTextStyle": "white", "backgroundColor": "#FFFFFF" }, "easycom": { @@ -16,7 +16,7 @@ "tabBar": { "custom": true, "color": "#999999", - "selectedColor": "#007aff", + "selectedColor": "#4D80F0", "borderStyle": "black", "height": "50px", "fontSize": "10px", @@ -60,7 +60,6 @@ "type": "home", "layout": "tabbar", "style": { - "navigationStyle": "custom", "navigationBarTitleText": "棣栭〉" } }, @@ -68,6 +67,7 @@ "path": "pages/equ/index", "type": "page", "layout": "tabbar", + "needLogin": true, "style": { "navigationBarTitleText": "鍏充簬" } @@ -77,7 +77,6 @@ "type": "page", "layout": "default", "style": { - "navigationStyle": "custom", "navigationBarTitleText": "鐧诲綍" } }, diff --git a/eims-ui-mobile/src/service/login.d.ts b/eims-ui-mobile/src/service/login.d.ts new file mode 100644 index 0000000..04cec7d --- /dev/null +++ b/eims-ui-mobile/src/service/login.d.ts @@ -0,0 +1,7 @@ +export interface LoginParams { + username: string; + password: string; + clientId?: string; + tenantId?: string; + grantType?: string; +} diff --git a/eims-ui-mobile/src/service/login.ts b/eims-ui-mobile/src/service/login.ts new file mode 100644 index 0000000..05a4c58 --- /dev/null +++ b/eims-ui-mobile/src/service/login.ts @@ -0,0 +1,25 @@ +import { http } from '@/utils/http' +import type { LoginParams } from './login.d' +const clientId = import.meta.env.VITE_APP_CLIENT_ID + +const DEFAULT_TENANT_ID = '000000' +const GRANT_TYPE = 'password' + +/** GET 璇锋眰 */ +export const getFooAPI = (name: string) => { + return http.get<LoginParams>('/foo', { name }) +} + +/** POST 璇锋眰 */ +export const login = (params: LoginParams) => { + const { username, password } = params + // 鏋勯�犳柊鐨勮姹傚弬鏁帮紝閬垮厤鐩存帴淇敼鍘熷瀵硅薄 + const requestData = { + username, + password, + clientId, + tenantId: DEFAULT_TENANT_ID, + grantType: GRANT_TYPE, + } + return http.post<any>('/auth/login', requestData) +} diff --git a/eims-ui-mobile/src/store/access.ts b/eims-ui-mobile/src/store/access.ts new file mode 100644 index 0000000..5b7e266 --- /dev/null +++ b/eims-ui-mobile/src/store/access.ts @@ -0,0 +1,79 @@ +import { defineStore } from 'pinia' +import { ref } from 'vue' + +type AccessToken = null | string +const initState = { + access_codes: [], + access_menus: [], + access_routes: [], + access_token: null, + is_access_checked: false, + login_expired: false, + refresh_token: null, +} + +interface AccessInfo { + /** + * 鏉冮檺鐮� + */ + access_codes: string[] + /** + * 鍙闂殑鑿滃崟鍒楄〃 + */ + access_menus: string[] + /** + * 鍙闂殑璺敱鍒楄〃 + */ + access_routes: string[] + /** + * 鐧诲綍 accessToken + */ + access_token: AccessToken + /** + * 鏄惁宸茬粡妫�鏌ヨ繃鏉冮檺 + */ + is_access_checked: boolean + /** + * 鐧诲綍鏄惁杩囨湡 + */ + login_expired: boolean + /** + * 鐧诲綍 accessToken + */ + refresh_token: AccessToken +} + +export const useAccessStore = defineStore( + 'access', + () => { + const accessInfo = ref<AccessInfo>({ ...initState }) + + const setAccessInfo = (val: AccessInfo) => { + accessInfo.value = val + } + const setAccessToken = (val: AccessToken) => { + accessInfo.value.access_token = val + } + + const clearAccessInfo = () => { + accessInfo.value = { ...initState } + } + // 涓�鑸病鏈塺eset闇�姹傦紝涓嶉渶瑕佺殑鍙互鍒犻櫎 + const reset = () => { + accessInfo.value = { ...initState } + } + const isLogined = computed(() => !!accessInfo.value.access_token) + + return { + accessInfo, + setAccessInfo, + setAccessToken, + clearAccessInfo, + isLogined, + reset, + } + }, + { + persist: true, + }, +) diff --git a/eims-ui-mobile/src/store/index.ts b/eims-ui-mobile/src/store/index.ts index 74b1b2f..7eca81f 100644 --- a/eims-ui-mobile/src/store/index.ts +++ b/eims-ui-mobile/src/store/index.ts @@ -15,3 +15,4 @@ // 妯″潡缁熶竴瀵煎嚭 export * from './user' +export * from './access' diff --git a/eims-ui-mobile/src/style/index.scss b/eims-ui-mobile/src/style/index.scss index 86184d9..feed87c 100644 --- a/eims-ui-mobile/src/style/index.scss +++ b/eims-ui-mobile/src/style/index.scss @@ -16,3 +16,23 @@ // 淇敼鎸夐挳鑳屾櫙鑹� // --wot-button-primary-bg-color: green; } + +// base鏂囧瓧棰滆壊 +.text-color-base { + color: $uni-text-color; +} +.text-color-gray { + color: $uni-text-color-grey; +} + +// 鍥炬爣棰滆壊 +.icon-color-base { + color: $uni-color-primary; +} + +.bg-base { + background: $uni-bg-color-grey; +} + + + diff --git a/eims-ui-mobile/src/uni.scss b/eims-ui-mobile/src/uni.scss index 21b9e5f..0607edc 100644 --- a/eims-ui-mobile/src/uni.scss +++ b/eims-ui-mobile/src/uni.scss @@ -16,7 +16,7 @@ /* 棰滆壊鍙橀噺 */ /* 琛屼负鐩稿叧棰滆壊 */ -$uni-color-primary: #007aff; +$uni-color-primary: #4D80F0; $uni-color-success: #4cd964; $uni-color-warning: #f0ad4e; $uni-color-error: #dd524d; diff --git a/eims-ui-mobile/src/utils/http.ts b/eims-ui-mobile/src/utils/http.ts index 4e3f38c..246cc7e 100644 --- a/eims-ui-mobile/src/utils/http.ts +++ b/eims-ui-mobile/src/utils/http.ts @@ -14,11 +14,18 @@ // 鐘舵�佺爜 2xx锛屽弬鑰� axios 鐨勮璁� if (res.statusCode >= 200 && res.statusCode < 300) { // 2.1 鎻愬彇鏍稿績鏁版嵁 res.data - resolve(res.data as IResData<T>) + if ((res.data as IResData<T>).code === 200) { + resolve((res.data as IResData<T>).data as IResData<T>) + } else { + uni.showToast({ + icon: 'none', + title: (res.data as IResData<T>).msg || '璇锋眰閿欒', + }) + } } else if (res.statusCode === 401) { // 401閿欒 -> 娓呯悊鐢ㄦ埛淇℃伅锛岃烦杞埌鐧诲綍椤� // userStore.clearUserInfo() - // uni.navigateTo({ url: '/pages/login/login' }) + uni.navigateTo({ url: '/pages/login/index' }) reject(res) } else { // 鍏朵粬閿欒 -> 鏍规嵁鍚庣閿欒淇℃伅杞绘彁绀� diff --git a/eims-ui-mobile/vite.config.ts b/eims-ui-mobile/vite.config.ts index f0fec23..0f44391 100644 --- a/eims-ui-mobile/vite.config.ts +++ b/eims-ui-mobile/vite.config.ts @@ -43,6 +43,7 @@ VITE_SHOW_SOURCEMAP, VITE_APP_PROXY, VITE_APP_PROXY_PREFIX, + VITE_APP_CLIENT_ID, } = env console.log('鐜鍙橀噺 env -> ', env) -- Gitblit v1.9.3