From 8e4ab7acddbdb84fd755acf7e75cf471f50cba60 Mon Sep 17 00:00:00 2001 From: houzhongjian <houzhongyi@126.com> Date: 星期四, 31 十月 2024 10:16:47 +0800 Subject: [PATCH] 优化部分页面及配置 --- src/router/modules/remaining.ts | 43 +++++ src/api/system/dict/dict.type.ts | 17 + src/api/system/menu/index.ts | 28 ++- types/env.d.ts | 3 src/views/Login/Login.vue | 4 .env | 30 ++- src/layout/components/Logo/src/Logo.vue | 6 src/views/Home/Index.vue | 83 ++++++++++ src/permission.ts | 1 src/api/system/dict/dict.data.ts | 14 + vite.config.ts | 3 src/views/Login/components/LoginForm.vue | 150 ++++++++++++------ .env.dev | 4 src/api/system/app/index.ts | 14 + src/utils/auth.ts | 4 index.html | 2 src/config/axios/config.ts | 5 package.json | 4 src/router/index.ts | 4 src/api/login/index.ts | 24 ++ src/api/login/types.ts | 9 + src/api/demo/index.ts | 14 22 files changed, 346 insertions(+), 120 deletions(-) diff --git a/.env b/.env index 9aa9294..d07bba3 100644 --- a/.env +++ b/.env @@ -8,16 +8,19 @@ VITE_OPEN=false # 请求路径 -VITE_BASE_URL='http://172.16.8.100:48080' +VITE_BASE_URL='http://localhost:8088' + +# 平台路径 +VITE_PLAT_URL='http://localhost:48080' # 接口地址 VITE_API_URL=/admin-api +# 平台接口地址 +VITE_PLAT_API_URL=/admin-api + # 租户开关 VITE_APP_TENANT_ENABLE=true - -# 验证码的开关 -VITE_APP_CAPTCHA_ENABLE=false # 文档地址的开关 VITE_APP_DOCALERT_ENABLE=true @@ -27,11 +30,16 @@ VITE_APP_DEFAULT_LOGIN_USERNAME = admin VITE_APP_DEFAULT_LOGIN_PASSWORD = admin123 +VITE_TENANT_ID=172 + ## 平台授权URL -#VITE_AUTH2_LOGIN_URL='http://localhost:48080/admin-api/system/oauth2/token' -# -## 平台授权AUTH2 clientId -#VITE_AUTH2_CLIENT_ID='shasteel' -# -## 平台授权AUTH2 clientSecret -#VITE_AUTH2_CLIENT_SECRET='iailab2019' +VITE_AUTH2_LOGIN_URL='http://localhost:48080/admin-api/system/oauth2/token' + +# 平台授权AUTH2 clientId +VITE_AUTH2_CLIENT_ID='shasteel' + +# 平台授权AUTH2 clientSecret +VITE_AUTH2_CLIENT_SECRET='iailab2019' + +# 验证码的开关 +VITE_APP_CAPTCHA_ENABLE=false diff --git a/.env.dev b/.env.dev index f6dd790..f344be0 100644 --- a/.env.dev +++ b/.env.dev @@ -1,5 +1,5 @@ # 开发环境:本地只启动前端项目,依赖开发环境(后端、APP) -NODE_ENV=production +NODE_ENV=development VITE_DEV=true @@ -19,7 +19,7 @@ VITE_SOURCEMAP=true # 打包路径 -VITE_BASE_PATH=/ +VITE_BASE_PATH=/energy # 输出路径 VITE_OUT_DIR=dist diff --git a/index.html b/index.html index 7652be0..948786e 100644 --- a/index.html +++ b/index.html @@ -108,7 +108,7 @@ <div class="app-loading-wrap"> <div class="app-loading-title"> <img src="/logo.gif" class="app-loading-logo" alt="Logo" /> - <div class="app-loading-title">沙钢智慧能源平台</div> + <div class="app-loading-title">沙钢智慧能源系统</div> </div> <div class="app-loading-item"> <div class="app-loading-outter"></div> diff --git a/package.json b/package.json index 23cf8d1..b6183b8 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "dev-server": "vite --mode dev", "ts:check": "vue-tsc --noEmit", "build:local": "node --max_old_space_size=8192 ./node_modules/vite/bin/vite.js build", - "build:dev": "node --max_old_space_size=8192 ./node_modules/vite/bin/vite.js build --mode dev", - "build:test": "node --max_old_space_size=8192 ./node_modules/vite/bin/vite.js build --mode test", + "build:dev": "node --max_old_space_size=4096 ./node_modules/vite/bin/vite.js build --mode dev", + "build:test": "node --max_old_space_size=4096 ./node_modules/vite/bin/vite.js build --mode test", "build:stage": "node --max_old_space_size=8192 ./node_modules/vite/bin/vite.js build --mode stage", "build:prod": "node --max_old_space_size=8192 ./node_modules/vite/bin/vite.js build --mode prod", "serve:dev": "vite preview --mode dev", diff --git a/src/api/demo/index.ts b/src/api/demo/index.ts index 39038db..11990a8 100644 --- a/src/api/demo/index.ts +++ b/src/api/demo/index.ts @@ -13,35 +13,35 @@ // 查询列表 export const getDemoPage = (params: PageParam) => { - return request.get({ url: 'http://localhost:8088/admin-api/shasteel/demo/page', params }) + return request.get({ url: '/shasteel/demo/page', params }) } // 获得 export const getDemo = (id: number) => { - return request.get({ url: 'http://localhost:8088/admin-api/shasteel/demo/get?id=' + id }) + return request.get({ url: '/shasteel/demo/get?id=' + id }) } // 查询应用列表 export const getDemoList = () => { - return request.get({ url: 'http://localhost:8088/admin-api/shasteel/demo/list' }) + return request.get({ url: '/shasteel/demo/list' }) } // 新增 export const createDemo = (data: DemoVO) => { - return request.post({ url: 'http://localhost:8088/admin-api/shasteel/demo/create', data }) + return request.post({ url: '/shasteel/demo/create', data }) } // 修改 export const updateDemo = (data: DemoVO) => { - return request.put({ url: 'http://localhost:8088/admin-api/shasteel/demo/update', data }) + return request.put({ url: '/shasteel/demo/update', data }) } // 删除 export const deleteDemo = (id: number) => { - return request.delete({ url: 'http://localhost:8088/admin-api/shasteel/demo/delete?id=' + id }) + return request.delete({ url: '/shasteel/demo/delete?id=' + id }) } // 导出 export const exportDemo = (params: DemoVO) => { - return request.download({ url: 'http://localhost:8088/admin-api/shasteel/demo/export-excel', params }) + return request.download({ url: '/shasteel/demo/export-excel', params }) } diff --git a/src/api/login/index.ts b/src/api/login/index.ts index c354be2..bc3b924 100644 --- a/src/api/login/index.ts +++ b/src/api/login/index.ts @@ -1,5 +1,8 @@ import request from '@/config/axios' -import type { UserLoginVO } from './types' +import {Oauth2TokenVO, UserLoginVO} from './types' +import { config } from '@/config/axios/config' + +const { plat_url} = config export interface SmsCodeVO { mobile: string @@ -13,31 +16,38 @@ // 登录 export const login = (data: UserLoginVO) => { - return request.post({ url: '/system/auth/login', data }) + return request.post({ url: plat_url + '/system/auth/login', data }) +} + +// 密码授权登录 +export const oauth2Login = (data: Oauth2TokenVO) => { + return request.post({ url: plat_url + '/system/oauth2/token?' // 客户端 + + "client_id=" + data.clientId + + "&client_secret=" + data.clientSecret, data }) } // 使用租户名,获得租户编号 export const getTenantIdByName = (name: string) => { - return request.get({ url: '/system/tenant/get-id-by-name?name=' + name }) + return request.get({ url: plat_url + '/system/tenant/get-id-by-name?name=' + name }) } // 登出 export const loginOut = () => { - return request.post({ url: '/system/auth/logout' }) + return request.post({ url: plat_url + '/system/auth/logout' }) } // 获取用户权限信息 export const getInfo = () => { - return request.get({ url: '/system/auth/get-permission-info' }) + return request.get({ url: plat_url + '/system/auth/get-permission-info' }) } // 获取验证图片以及 token export const getCode = (data) => { - return request.postOriginal({ url: 'captcha/get', data }) + return request.postOriginal({ url: plat_url + '/system/captcha/get', data }) } // 滑动或者点选验证 export const reqCheck = (data) => { - return request.postOriginal({ url: 'captcha/check', data }) + return request.postOriginal({ url: plat_url + '/system/captcha/check', data }) } diff --git a/src/api/login/types.ts b/src/api/login/types.ts index b8c0a3d..5c9d8f5 100644 --- a/src/api/login/types.ts +++ b/src/api/login/types.ts @@ -6,6 +6,15 @@ socialState?: string } +export type Oauth2TokenVO = { + clientId: string + clientSecret: string + grantType: string + username: string + password: string + scope: string +} + export type TokenType = { id: number // 编号 accessToken: string // 访问令牌 diff --git a/src/api/system/app/index.ts b/src/api/system/app/index.ts index 6c518a5..5c83498 100644 --- a/src/api/system/app/index.ts +++ b/src/api/system/app/index.ts @@ -1,5 +1,9 @@ import request from '@/config/axios' +import { config } from '@/config/axios/config' + +const { plat_url} = config + export interface AppVO { id: number appCode: string @@ -29,14 +33,14 @@ return request.get({ url: '/system/app/get?id=' + id }) } -// 查询应用列表 +// 查询所拥有应用列表 export const getAppList = () => { - return request.get({ url: '/system/app/list' }) + return request.get({ url: plat_url + '/system/auth/get-app-permission' }) } -// 查询应用列表 -export const getAppMenuList = () => { - return request.get({ url: '/system/app-menu/list' }) +// 查询所拥有应用菜单列表 +export const getAppMenuList = (id) => { + return request.get({ url: plat_url + '/system/auth/get-app-menu-permission?id=' + id }) } // 新增 diff --git a/src/api/system/dict/dict.data.ts b/src/api/system/dict/dict.data.ts index 41f62ab..d0cfd8f 100644 --- a/src/api/system/dict/dict.data.ts +++ b/src/api/system/dict/dict.data.ts @@ -1,4 +1,6 @@ import request from '@/config/axios' +import {config} from "@/config/axios/config"; +const { plat_url } = config export type DictDataVO = { id: number | undefined @@ -15,32 +17,32 @@ // 查询字典数据(精简)列表 export const getSimpleDictDataList = () => { - return request.get({ url: 'http://172.16.8.100:48080/admin-api/system/dict-data/simple-list' }) + return request.get({ url: plat_url + '/system/dict-data/simple-list' }) } // 查询字典数据列表 export const getDictDataPage = (params: PageParam) => { - return request.get({ url: 'http://172.16.8.100:48080/admin-api/system/dict-data/page', params }) + return request.get({ url: plat_url + '/system/dict-data/page', params }) } // 查询字典数据详情 export const getDictData = (id: number) => { - return request.get({ url: 'http://172.16.8.100:48080/admin-api/system/dict-data/get?id=' + id }) + return request.get({ url: plat_url + '/system/dict-data/get?id=' + id }) } // 新增字典数据 export const createDictData = (data: DictDataVO) => { - return request.post({ url: 'http://172.16.8.100:48080/admin-api/system/dict-data/create', data }) + return request.post({ url: plat_url + '/system/dict-data/create', data }) } // 修改字典数据 export const updateDictData = (data: DictDataVO) => { - return request.put({ url: 'http://172.16.8.100:48080/admin-api/system/dict-data/update', data }) + return request.put({ url: plat_url + '/system/dict-data/update', data }) } // 删除字典数据 export const deleteDictData = (id: number) => { - return request.delete({ url: 'http://172.16.8.100:48080/admin-api/system/dict-data/delete?id=' + id }) + return request.delete({ url: plat_url + '/system/dict-data/delete?id=' + id }) } // 导出字典类型数据 diff --git a/src/api/system/dict/dict.type.ts b/src/api/system/dict/dict.type.ts index eaa5fb6..9bd3a27 100644 --- a/src/api/system/dict/dict.type.ts +++ b/src/api/system/dict/dict.type.ts @@ -1,5 +1,8 @@ import request from '@/config/axios' +import {config} from "@/config/axios/config"; +const { plat_url } = config + export type DictTypeVO = { id: number | undefined name: string @@ -11,34 +14,34 @@ // 查询字典(精简)列表 export const getSimpleDictTypeList = () => { - return request.get({ url: '/system/dict-type/list-all-simple' }) + return request.get({ url: plat_url + '/system/dict-type/list-all-simple' }) } // 查询字典列表 export const getDictTypePage = (params: PageParam) => { - return request.get({ url: '/system/dict-type/page', params }) + return request.get({ url: plat_url + '/system/dict-type/page', params }) } // 查询字典详情 export const getDictType = (id: number) => { - return request.get({ url: '/system/dict-type/get?id=' + id }) + return request.get({ url: plat_url + '/system/dict-type/get?id=' + id }) } // 新增字典 export const createDictType = (data: DictTypeVO) => { - return request.post({ url: '/system/dict-type/create', data }) + return request.post({ url: plat_url + '/system/dict-type/create', data }) } // 修改字典 export const updateDictType = (data: DictTypeVO) => { - return request.put({ url: '/system/dict-type/update', data }) + return request.put({ url: plat_url + '/system/dict-type/update', data }) } // 删除字典 export const deleteDictType = (id: number) => { - return request.delete({ url: '/system/dict-type/delete?id=' + id }) + return request.delete({ url: plat_url + '/system/dict-type/delete?id=' + id }) } // 导出字典类型 export const exportDictType = (params) => { - return request.download({ url: '/system/dict-type/export', params }) + return request.download({ url: plat_url + '/system/dict-type/export', params }) } diff --git a/src/api/system/menu/index.ts b/src/api/system/menu/index.ts index f8bc112..145d553 100644 --- a/src/api/system/menu/index.ts +++ b/src/api/system/menu/index.ts @@ -1,5 +1,9 @@ import request from '@/config/axios' +import { config } from '@/config/axios/config' + +const { plat_url} = config + export interface MenuVO { id: number name: string @@ -20,60 +24,60 @@ // 查询菜单(精简)列表 export const getSimpleMenusList = () => { - return request.get({ url: '/system/menu/simple-list' }) + return request.get({ url: plat_url + '/system/menu/simple-list' }) } // 查询应用菜单(精简)列表 export const getSimpleAppMenusList = () => { - return request.get({ url: '/system/menu/simple-app-menus' }) + return request.get({ url: plat_url + '/system/menu/simple-app-menus' }) } // 查询菜单列表 export const getMenuList = (params) => { - return request.get({ url: '/system/menu/list', params }) + return request.get({ url: plat_url + '/system/menu/list', params }) } // 查询应用菜单列表 export const getAppMenuList = (params) => { - return request.get({ url: '/system/menu/app-menu-list', params }) + return request.get({ url: plat_url + '/system/menu/app-menu-list', params }) } // 获取菜单详情 export const getMenu = (id: number) => { - return request.get({ url: '/system/menu/get?id=' + id }) + return request.get({ url: plat_url + '/system/menu/get?id=' + id }) } // 获取应用菜单详情 export const getAppMenu = (id: number) => { - return request.get({ url: '/system/menu/getAppMenu?id=' + id }) + return request.get({ url: plat_url + '/system/menu/getAppMenu?id=' + id }) } // 新增菜单 export const createMenu = (data: MenuVO) => { - return request.post({ url: '/system/menu/create', data }) + return request.post({ url: plat_url + '/system/menu/create', data }) } // 新增应用菜单 export const createAppMenu = (data: MenuVO) => { - return request.post({ url: '/system/menu/createAppMenu', data }) + return request.post({ url: plat_url + '/system/menu/createAppMenu', data }) } // 修改菜单 export const updateMenu = (data: MenuVO) => { - return request.put({ url: '/system/menu/update', data }) + return request.put({ url: plat_url + '/system/menu/update', data }) } // 修改应用菜单 export const updateAppMenu = (data: MenuVO) => { - return request.put({ url: '/system/menu/updateAppMenu', data }) + return request.put({ url: plat_url + '/system/menu/updateAppMenu', data }) } // 删除菜单 export const deleteMenu = (id: number) => { - return request.delete({ url: '/system/menu/delete?id=' + id }) + return request.delete({ url: plat_url + '/system/menu/delete?id=' + id }) } // 删除应用菜单 export const deleteAppMenu = (id: number) => { - return request.delete({ url: '/system/menu/deleteAppMenu?id=' + id }) + return request.delete({ url: plat_url + '/system/menu/deleteAppMenu?id=' + id }) } diff --git a/src/config/axios/config.ts b/src/config/axios/config.ts index 8116508..45a8908 100644 --- a/src/config/axios/config.ts +++ b/src/config/axios/config.ts @@ -1,5 +1,6 @@ const config: { base_url: string + plat_url: string result_code: number | string default_headers: AxiosHeaders request_timeout: number @@ -9,6 +10,10 @@ */ base_url: import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL, /** + * 平台请求基础路径 + */ + plat_url: import.meta.env.VITE_PLAT_URL + import.meta.env.VITE_PLAT_API_URL, + /** * 接口成功返回状态码 */ result_code: 200, diff --git a/src/layout/components/Logo/src/Logo.vue b/src/layout/components/Logo/src/Logo.vue index d241130..554f4b9 100644 --- a/src/layout/components/Logo/src/Logo.vue +++ b/src/layout/components/Logo/src/Logo.vue @@ -19,6 +19,10 @@ const collapse = computed(() => appStore.getCollapse) +const homePath = ref('/index') + +homePath.value = '/index' + onMounted(() => { if (unref(collapse)) show.value = false }) @@ -64,7 +68,7 @@ layout !== 'classic' ? `${prefixCls}__Top` : '', 'flex !h-[var(--logo-height)] items-center cursor-pointer pl-8px relative decoration-none overflow-hidden' ]" - to="/" + :to="homePath" > <img class="h-[calc(var(--logo-height)-10px)] w-[calc(var(--logo-height)-10px)]" diff --git a/src/permission.ts b/src/permission.ts index 11c8d00..cbdff32 100644 --- a/src/permission.ts +++ b/src/permission.ts @@ -48,6 +48,7 @@ // 路由不重定向白名单 const whiteList = [ '/login', + '/callback', '/social-login', '/auth-redirect', '/bind', diff --git a/src/router/index.ts b/src/router/index.ts index 8c047ca..ab2d0a5 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -5,14 +5,14 @@ // 创建路由实例 const router = createRouter({ - history: createWebHistory("/"), // createWebHashHistory URL带#,createWebHistory URL不带# + history: createWebHistory("/energy"), // createWebHashHistory URL带#,createWebHistory URL不带# strict: true, routes: remainingRouter as RouteRecordRaw[], scrollBehavior: () => ({ left: 0, top: 0 }) }) export const resetRouter = (): void => { - const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root'] + const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root', 'Callback'] router.getRoutes().forEach((route) => { const { name } = route if (name && !resetWhiteNameList.includes(name as string)) { diff --git a/src/router/modules/remaining.ts b/src/router/modules/remaining.ts index 4ab5e37..a8ae008 100644 --- a/src/router/modules/remaining.ts +++ b/src/router/modules/remaining.ts @@ -51,6 +51,15 @@ } }, { + path: '/callback', + component: () => import('@/views/Login/Callback.vue'), + name: 'Callback', + meta: { + hidden: true, + noTagsView: true + } + }, + { path: '/home2', component: () => import('@/views/Home/Index2.vue'), name: 'Home2', @@ -82,6 +91,40 @@ ] }, { + path: '/user', + component: Layout, + name: 'UserInfo', + meta: { + hidden: true + }, + children: [ + { + path: 'profile', + component: () => import('@/views/Profile/Index.vue'), + name: 'Profile', + meta: { + canTo: true, + hidden: true, + noTagsView: false, + icon: 'ep:user', + title: t('common.profile') + } + }, + { + path: 'notify-message', + component: () => import('@/views/system/notify/my/index.vue'), + name: 'MyNotifyMessage', + meta: { + canTo: true, + hidden: true, + noTagsView: false, + icon: 'ep:message', + title: '我的站内信' + } + } + ] + }, + { path: '/login', component: () => import('@/views/Login/Login.vue'), name: 'Login', diff --git a/src/utils/auth.ts b/src/utils/auth.ts index d836500..0b20e53 100644 --- a/src/utils/auth.ts +++ b/src/utils/auth.ts @@ -1,11 +1,12 @@ import { useCache, CACHE_KEY } from '@/hooks/web/useCache' -import { TokenType } from '@/api/login/types' +import {TokenType} from '@/api/login/types' import { decrypt, encrypt } from '@/utils/jsencrypt' const { wsCache } = useCache() const AccessTokenKey = 'ACCESS_TOKEN' const RefreshTokenKey = 'REFRESH_TOKEN' +const TenantId = 'tenantId' // 获取token export const getAccessToken = () => { @@ -22,6 +23,7 @@ export const setToken = (token: TokenType) => { wsCache.set(RefreshTokenKey, token.refreshToken) wsCache.set(AccessTokenKey, token.accessToken) + wsCache.set(TenantId, import.meta.env.VITE_TENANT_ID) } // 删除token diff --git a/src/views/Home/Index.vue b/src/views/Home/Index.vue index b824385..340a7da 100644 --- a/src/views/Home/Index.vue +++ b/src/views/Home/Index.vue @@ -1,12 +1,89 @@ <template> - <div> - <h1>这里是应用首页</h1> - </div> + <div> + <h1>这里是主页</h1> + </div> +<!-- <div>--> +<!-- <h1>应用列表</h1>--> +<!-- </div>--> +<!-- <el-skeleton :loading="loading" animated>--> +<!-- <div id="app" v-for="(item, index) in appList" :key="`dynamics-${index}`">--> +<!-- <div class="card" @click="gotoApp(item)">--> +<!-- <img :src="item.icon" style="width: 100px; height: 100px" />--> +<!-- <div>--> +<!-- {{item.appName}}--> +<!-- </div>--> +<!-- </div>--> +<!-- </div>--> +<!-- </el-skeleton>--> + </template> <script lang="ts" setup> + +import * as AppApi from '@/api/system/app' +import {Apps} from "@/views/Home/types"; +import {CACHE_KEY, useCache} from "@/hooks/web/useCache"; defineOptions({ name: 'Home' }) +const { wsCache } = useCache() + +const loading = ref(true) + +// let appList = reactive<Apps[]>([]) +// +// const getAppList = async () => { +// const data = await AppApi.getAppList() +// appList = Object.assign(appList, data) +// } +// +// const getAppMenuList = async (id) => { +// const data = await AppApi.getAppMenuList(id) +// let userInfo = wsCache.get(CACHE_KEY.USER) +// let routers = wsCache.get(CACHE_KEY.ROLE_ROUTERS) +// console.log(userInfo) +// console.log(routers) +// userInfo.menus = data +// wsCache.set(CACHE_KEY.USER, userInfo) +// wsCache.set(CACHE_KEY.ROLE_ROUTERS, data) +// window.location.href = '/energy/index' +// } +// +// const getAllApi = async () => { +// await Promise.all([ +// getAppList() +// ]) +// loading.value = false +// } +// +// // getAllApi() +// +// // 进入应用 +// const gotoApp = async (item) => { +// let id = item.id +// getAppMenuList(id) +// } </script> + +<style lang="scss" scoped> +#app{ + width: 300px; + height: 200px; + display: inline-block; + background: transparent; +} +.card{ + border: thin dashed gainsboro; + width: 150px; + height: 100px; + padding: 30px; + text-align: center; + justify-content: center; + font-size: 15px; + font-weight: bolder; + color: blue; + background: aliceblue; + border-radius: 10px; +} +</style> diff --git a/src/views/Login/Login.vue b/src/views/Login/Login.vue index 66556a9..7ad46ba 100644 --- a/src/views/Login/Login.vue +++ b/src/views/Login/Login.vue @@ -53,7 +53,7 @@ <!-- 注册 --> <!--<RegisterForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />--> <!-- 三方登录 --> - <!--<SSOLoginVue class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />--> +<!-- <SSOLoginVue class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />--> </div> </Transition> </div> @@ -68,7 +68,7 @@ import { ThemeSwitch } from '@/layout/components/ThemeSwitch' import { LocaleDropdown } from '@/layout/components/LocaleDropdown' -import { LoginForm, QrCodeForm} from './components' +import { LoginForm, QrCodeForm } from './components' defineOptions({ name: 'Login' }) diff --git a/src/views/Login/components/LoginForm.vue b/src/views/Login/components/LoginForm.vue index f3df729..54faac0 100644 --- a/src/views/Login/components/LoginForm.vue +++ b/src/views/Login/components/LoginForm.vue @@ -64,14 +64,35 @@ /> </el-form-item> </el-col> -<!-- <Verify--> -<!-- ref="verify"--> -<!-- :captchaType="captchaType"--> -<!-- :imgSize="{ width: '400px', height: '200px' }"--> -<!-- mode="pop"--> -<!-- @success="handleLogin"--> -<!-- />--> + <Verify + ref="verify" + :captchaType="captchaType" + :imgSize="{ width: '400px', height: '200px' }" + mode="pop" + @success="handleLogin" + /> </el-row> + +<!-- <!– 统一身份登录–>--> +<!-- <el-divider content-position="center">统一身份登录</el-divider>--> +<!-- <el-col :span="24" style="padding-right: 10px; padding-left: 10px">--> +<!-- <el-form-item>--> +<!-- <el-row :gutter="10" justify="space-between" style="width: 100%">--> +<!-- <el-col :span="8">--> +<!-- <el-button type="primary" style="width: 100%;"--> +<!-- @click="ssoPasswordLogin">--> +<!-- {{ ssoLoginPasswordTitle }}--> +<!-- </el-button>--> +<!-- </el-col>--> +<!-- <el-col :span="8">--> +<!-- <el-button type="primary" style="width: 100%;"--> +<!-- @click="ssoCodeLogin">--> +<!-- {{ ssoLoginCodeTitle }}--> +<!-- </el-button>--> +<!-- </el-col>--> +<!-- </el-row>--> +<!-- </el-form-item>--> +<!-- </el-col>--> </el-form> </template> <script lang="ts" setup> @@ -84,6 +105,7 @@ import * as authUtil from '@/utils/auth' import * as LoginApi from '@/api/login' import { LoginStateEnum, useFormValid, useLoginState } from './useLogin' +// import axios from "axios"; defineOptions({ name: 'LoginForm' }) @@ -96,7 +118,10 @@ const { currentRoute, push } = useRouter() const redirect = ref<string>('') const loginLoading = ref(false) +// const ssoLoginPasswordTitle = ref('账号密码模式') +// const ssoLoginCodeTitle = ref('授权码模式') const verify = ref() +const captchaType = ref('blockPuzzle') // blockPuzzle 滑块 clickWord 点击文字 const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN) @@ -112,15 +137,35 @@ password: import.meta.env.VITE_APP_DEFAULT_LOGIN_PASSWORD || '', scope: 'user.read user.write', grantType: 'password', + captchaVerification: '', rememberMe: true // 默认记录我。如果不需要,可手动修改 } }) + +// const ssoLoginData = reactive({ +// loginParam: { +// username: '', +// password: '', +// token: '' +// } +// }) +// +// const oauth2Token = reactive({ +// oauthParam: { +// clientId: 'shasteel', +// clientSecret: 'shasteel111111111111111', +// grantType: 'password', +// username: '', +// password: '', +// scope: '' +// } +// }) // 获取验证码 const getCode = async () => { // 情况一,未开启:则直接登录 if (loginData.captchaEnable === 'false') { - await handleLogin() + await handleLogin({}) } else { // 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录 // 弹出验证码 @@ -143,13 +188,14 @@ const loading = ref() // ElLoading.service 返回的实例 // 登录 -const handleLogin = async () => { +const handleLogin = async (params) => { loginLoading.value = true try { const data = await validForm() if (!data) { return } + loginData.loginForm.captchaVerification = params.captchaVerification const res = await LoginApi.login(loginData.loginForm) if (!res) { return @@ -166,7 +212,7 @@ } authUtil.setToken(res) if (!redirect.value) { - redirect.value = '/' + redirect.value = '/index' } // 判断是否为SSO登录 if (redirect.value.indexOf('sso') !== -1) { @@ -180,41 +226,52 @@ } } -// 自动登录 -// const autoLogin = async (appid, username) => { -// console.log(appid) -// console.log(username) -// loginLoading.value = true -// try { -// const res = await LoginApi.auth2Login(loginData.loginForm) -// if (!res) { -// return +// const ssoPasswordLogin = () => { +// // 发起请求 +// axios({ +// url: "http://localhost:48080/admin-api/system/oauth2/token?" +// // 客户端 +// + "client_id=" + oauth2Token.oauthParam.clientId +// + "&client_secret=" + oauth2Token.oauthParam.clientSecret +// // 密码模式的参数 +// + "&grant_type=" + oauth2Token.oauthParam.grantType +// + "&username=" + loginData.loginForm.username +// + "&password=" + loginData.loginForm.password +// + '&scope=user.read user.write', +// method: 'POST', +// headers: { +// 'tenant-id': '172', // 多租户编号,写死 // } -// loading.value = ElLoading.service({ -// lock: true, -// text: '正在加载系统中...', -// background: 'rgba(0, 0, 0, 0.7)' -// }) -// if (loginData.loginForm.rememberMe) { -// authUtil.setLoginForm(loginData.loginForm) +// }).then((result) => { +// const res = result.data +// if (res.code !== 0) { +// alert('授权失败,原因:' + res.msg) +// return; +// } +// const auth_token = res.data.access_token +// // 设置token +// authUtil.setToken(res.data) +// // 提示登录成功 +// alert('授权成功!校验系统用户及权限'); +// ssoLoginData.loginParam.token = auth_token +// if (!!redirect.value) { +// location.href = decodeURIComponent(redirect.value); // } else { -// authUtil.removeLoginForm() +// push({ path: '/index' }) // } -// authUtil.setToken(res) -// if (!redirect.value) { -// redirect.value = '/' -// } -// console.log(permissionStore) -// // 判断是否为SSO登录 -// if (redirect.value.indexOf('sso') !== -1) { -// window.location.href = window.location.href.replace('/login?redirect=', '') -// } else { -// push({ path: redirect.value }) -// } -// } finally { -// loginLoading.value = false -// loading.value.close() -// } +// }).catch((e) => { +// ElMessage.error('授权失败:' + e.message); +// }); +// } + +// const ssoCodeLogin = () => { +// alert('暂未开通'); +// // const clientId = 'shasteel'; +// // const redirectUri = encodeURIComponent('http://127.0.0.1:9000/callback'); +// // const responseType = 'code'; // 1)授权码模式,对应 code;2)简化模式,对应 token +// // window.location.href = 'http://localhost/sso?client_id=' + clientId +// // + '&redirect_uri=' + redirectUri +// // + '&response_type=' + responseType; // } watch( @@ -228,15 +285,6 @@ ) onMounted(() => { getLoginFormCache() - let params = new URLSearchParams(window.location.search); - console.log(params) - let appid = params.get('appid'); - let username = params.get('username'); - console.log(appid) - console.log(username) - // if(appid) { - // autoLogin(appid, username) - // } }) </script> diff --git a/types/env.d.ts b/types/env.d.ts index 30cf8c6..ce972f0 100644 --- a/types/env.d.ts +++ b/types/env.d.ts @@ -19,16 +19,19 @@ readonly VITE_APP_DEFAULT_LOGIN_PASSWORD: string readonly VITE_APP_DOCALERT_ENABLE: string readonly VITE_BASE_URL: string + readonly VITE_PLAT_URL: string readonly VITE_AUTH2_LOGIN_URL: string readonly VITE_AUTH2_CLIENT_ID: string readonly VITE_AUTH2_CLIENT_SECRET: string readonly VITE_UPLOAD_URL: string readonly VITE_API_URL: string + readonly VITE_PLAT_API_URL: string readonly VITE_BASE_PATH: string readonly VITE_DROP_DEBUGGER: string readonly VITE_DROP_CONSOLE: string readonly VITE_SOURCEMAP: string readonly VITE_OUT_DIR: string + readonly VITE_TENANT_ID: string } declare global { diff --git a/vite.config.ts b/vite.config.ts index ce2b1c2..8b68932 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -37,6 +37,9 @@ rewrite: (path) => path.replace(new RegExp(`^/admin-api`), ''), }, }, + hmr: { + overlay: false + } }, // 项目使用的vite插件。 单独提取到build/vite/plugin中管理 plugins: createVitePlugins(), -- Gitblit v1.9.3