From d49572f94c06894acf4efb1b7300f1505d0e8a19 Mon Sep 17 00:00:00 2001 From: DaxPay Date: Tue, 24 Sep 2024 19:59:53 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E4=BB=A3=E7=A0=81=E7=B2=BE=E7=AE=80,=20?= =?UTF-8?q?=E5=BC=80=E5=8F=91OpenId=E7=9B=B8=E5=85=B3=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 18 +-- .env.production | 31 ++--- package.json | 9 -- src/api/system/user.ts | 60 --------- src/hooks/setting/index.ts | 4 - src/router/base.ts | 26 ++++ src/router/business.ts | 4 +- src/router/daxpay.ts | 30 +++++ src/router/index.ts | 5 +- src/router/modules.ts | 28 ----- src/settings/componentSetting.ts | 15 --- src/store/modules/user.ts | 115 ------------------ src/store/mutation-types.ts | 1 - src/utils/env.ts | 6 - src/utils/http/axios/Axios.ts | 41 +------ src/utils/http/axios/index.ts | 17 +-- src/utils/http/axios/types.ts | 13 -- .../channel/alipay/AlipayAuthCallback.vue | 17 +++ .../channel/wechat/WechatAuthCallback.vue | 13 ++ src/views/system/dispatch/DispatchRouter.vue | 8 +- types/config.d.ts | 8 +- types/global.d.ts | 1 - 22 files changed, 113 insertions(+), 357 deletions(-) delete mode 100644 src/api/system/user.ts create mode 100644 src/router/daxpay.ts delete mode 100644 src/router/modules.ts delete mode 100644 src/settings/componentSetting.ts delete mode 100644 src/store/modules/user.ts create mode 100644 src/views/daxpay/channel/alipay/AlipayAuthCallback.vue create mode 100644 src/views/daxpay/channel/wechat/WechatAuthCallback.vue diff --git a/.env.development b/.env.development index 50268d6..4aab0f5 100644 --- a/.env.development +++ b/.env.development @@ -1,27 +1,17 @@ # 端口号 -VITE_PORT = 9100 +VITE_PORT=9100 # 网站根目录 -VITE_PUBLIC_PATH = /h5 - -# 是否删除console -VITE_DROP_CONSOLE = true +VITE_PUBLIC_PATH=/ # 跨域代理,可以配置多个,请注意不要换行 VITE_PROXY=[["/server","http://localhost:9000"]] # API 接口地址 -# 如果没有跨域问题,直接在这里配置即可 -VITE_GLOB_API_URL = - -# 图片上传地址 -VITE_GLOB_UPLOAD_URL = - -# 图片前缀地址 -VITE_GLOB_IMG_URL = +VITE_GLOB_API_URL= # 接口前缀 -VITE_GLOB_API_URL_PREFIX = / +VITE_GLOB_API_URL_PREFIX=/server diff --git a/.env.production b/.env.production index b04cb05..254f0da 100644 --- a/.env.production +++ b/.env.production @@ -1,27 +1,18 @@ -# 网站根目录 和 接口 (api) 前缀 这个是嵌入式模式 -#VITE_PUBLIC_PATH = /h5 -#VITE_GLOB_API_URL_PREFIX = / +# 独立部署模式 +VITE_PUBLIC_PATH = /h5 +# API 接口前缀 +VITE_GLOB_API_URL_PREFIX = /api -# 网站根目录(与PC部署在一起, 所以根目录不可以为 /) 和 接口 (server) 前缀 这个是独立部署模式 -VITE_PUBLIC_PATH=/h5 -VITE_GLOB_API_URL_PREFIX= +# 嵌入式模式 与网关部署在一起, 和 接口 (server) 前缀 这个是 +#VITE_PUBLIC_PATH=/h5 +## API 接口前缀 +#VITE_GLOB_API_URL_PREFIX= # 是否删除console VITE_DROP_CONSOLE=true -# API -VITE_GLOB_API_URL= - -# 图片上传地址 -VITE_GLOB_UPLOAD_URL= - -# 图片前缀地址 -VITE_GLOB_IMG_URL = - -# 是否启用gzip压缩或brotli压缩 -# 可选: gzip | brotli | none -# 如果你需要多种形式,你可以用','来分隔 -VITE_BUILD_COMPRESS = 'none' +# 是否启用gzip压缩或brotli压缩, 可选: gzip | brotli | none, 如果你需要多种形式,你可以用','来分隔 +VITE_BUILD_COMPRESS='none' # 使用压缩时是否删除原始文件,默认为false -VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE = false +VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE=false diff --git a/package.json b/package.json index 736748c..9c8e8ca 100644 --- a/package.json +++ b/package.json @@ -83,16 +83,7 @@ "vite-plugin-svg-icons": "^2.0.1", "vue-tsc": "^1.8.27" }, - "simple-git-hooks": { - "pre-commit": "pnpm lint-staged", - "commit-msg": "npx --no-install commitlint --edit $1" - }, "lint-staged": { "*": "eslint --fix" - }, - "config": { - "commitizen": { - "path": "node_modules/cz-git" - } } } diff --git a/src/api/system/user.ts b/src/api/system/user.ts deleted file mode 100644 index 54e3226..0000000 --- a/src/api/system/user.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { http } from '@/utils/http/axios' -import type { Result } from '#/axios' - -export interface BasicResponseModel { - code: number - message: string - result: T -} - -/** - * @description: 用户登录 - */ -export function login(params: any) { - return http.request>( - { - url: '/token/login', - method: 'POST', - params, - }, - { - isTransformResponse: false, - }, - ) -} - -/** - * @description: 获取用户信息 - */ -export function getUserInfo() { - return http.request({ - url: '/getUserInfo', - method: 'get', - }) -} - -/** - * @description: 用户登出 - */ -export function doLogout() { - return http.request({ - url: '/token/logout', - method: 'POST', - }) -} - -/** - * @description: 用户修改密码 - */ -export function changePassword(params: any, uid: any) { - return http.request( - { - url: `/user/u${uid}/changepw`, - method: 'POST', - params, - }, - { - isTransformResponse: false, - }, - ) -} diff --git a/src/hooks/setting/index.ts b/src/hooks/setting/index.ts index 8f73fed..7cc6e3e 100644 --- a/src/hooks/setting/index.ts +++ b/src/hooks/setting/index.ts @@ -9,8 +9,6 @@ export function useGlobSetting(): Readonly { VITE_GLOB_API_URL, VITE_GLOB_APP_SHORT_NAME, VITE_GLOB_API_URL_PREFIX, - VITE_GLOB_UPLOAD_URL, - VITE_GLOB_IMG_URL, } = getAppEnvConfig() if (!/[a-z_]*/i.test(VITE_GLOB_APP_SHORT_NAME)) { @@ -26,8 +24,6 @@ export function useGlobSetting(): Readonly { apiUrl: VITE_GLOB_API_URL, shortName: VITE_GLOB_APP_SHORT_NAME, urlPrefix: VITE_GLOB_API_URL_PREFIX, - uploadUrl: VITE_GLOB_UPLOAD_URL, - imgUrl: VITE_GLOB_IMG_URL, } return glob as Readonly } diff --git a/src/router/base.ts b/src/router/base.ts index 5db6a28..0346edc 100644 --- a/src/router/base.ts +++ b/src/router/base.ts @@ -24,3 +24,29 @@ export const ErrorPageRoute: RouteRecordRaw = { }, ], } + +/** + * 主页面 + */ +export const routeModuleList: Array = [ + { + path: '/dashboard', + name: 'Dashboard', + redirect: '/dashboard/index', + component: Layout, + meta: { + title: '主控台', + icon: 'wap-home', + }, + children: [ + { + path: 'index', + name: 'DashboardPage', + meta: { + keepAlive: false, + }, + component: () => import('@/views/dashboard/index.vue'), + }, + ], + }, +] diff --git a/src/router/business.ts b/src/router/business.ts index fb460fa..62c52bb 100644 --- a/src/router/business.ts +++ b/src/router/business.ts @@ -13,13 +13,11 @@ export const BusinessRoute: RouteRecordRaw = { component: Layout, children: [ { - path: '/t', + path: '/t/:key', name: 'DispatchRouter', component: () => import('@/views/system/dispatch/DispatchRouter.vue'), meta: { title: '中转页', - ignoreAuth: true, - hiddenTabbar: true, }, }, { diff --git a/src/router/daxpay.ts b/src/router/daxpay.ts new file mode 100644 index 0000000..3cde541 --- /dev/null +++ b/src/router/daxpay.ts @@ -0,0 +1,30 @@ +import type { RouteRecordRaw } from 'vue-router' + +const Layout = () => import('@/layout/index.vue') + +/** + * 支付模块路由 + */ +export const DaxPayRoute: RouteRecordRaw = { + path: '/daxpay', + name: 'daxpay', + component: Layout, + children: [ + { + path: '/alipay/auth/:appId/:channel/:queryCode/:aliAppId', + name: 'AlipayAuth', + component: () => import('@/views/daxpay/channel/alipay/AlipayAuthCallback.vue'), + meta: { + title: '支付宝信息获取', + }, + }, + { + path: '/wechat/auth/:appId/:channel/:queryCode', + name: 'WechatAuth', + component: () => import('@/views/daxpay/channel/wechat/WechatAuthCallback.vue'), + meta: { + title: '微信信息获取', + }, + }, + ], +} diff --git a/src/router/index.ts b/src/router/index.ts index b223abf..21b9439 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -2,16 +2,17 @@ import type { App } from 'vue' import type { RouteRecordRaw } from 'vue-router' import { createRouter, createWebHashHistory } from 'vue-router' import { createRouterGuards } from './router-guards' -import routeModuleList from './modules' -import { ErrorPageRoute } from '@/router/base' +import { ErrorPageRoute, routeModuleList } from '@/router/base' import { useRouteStoreWidthOut } from '@/store/modules/route' // 菜单 import { BusinessRoute } from '@/router/business' import { DemoRoute } from '@/router/demo' +import { DaxPayRoute } from '@/router/daxpay' // 普通路由 export const constantRouter: RouteRecordRaw[] = [ + DaxPayRoute, DemoRoute, ErrorPageRoute, BusinessRoute, diff --git a/src/router/modules.ts b/src/router/modules.ts deleted file mode 100644 index 3b9715b..0000000 --- a/src/router/modules.ts +++ /dev/null @@ -1,28 +0,0 @@ -import type { RouteRecordRaw } from 'vue-router' - -const Layout = () => import('@/layout/index.vue') - -const routeModuleList: Array = [ - { - path: '/dashboard', - name: 'Dashboard', - redirect: '/dashboard/index', - component: Layout, - meta: { - title: '主控台', - icon: 'wap-home', - }, - children: [ - { - path: 'index', - name: 'DashboardPage', - meta: { - keepAlive: false, - }, - component: () => import('@/views/dashboard/index.vue'), - }, - ], - }, -] - -export default routeModuleList diff --git a/src/settings/componentSetting.ts b/src/settings/componentSetting.ts deleted file mode 100644 index 8e3d802..0000000 --- a/src/settings/componentSetting.ts +++ /dev/null @@ -1,15 +0,0 @@ -export default { - upload: { - // 考虑接口规范不同 - apiSetting: { - // 集合字段名 - infoField: 'result', - // 图片地址字段名 - imgField: 'imagePath', - }, - // 最大上传图片大小 - maxSize: 1, - // 图片上传类型 - fileType: ['image/png', 'image/jpg', 'image/jpeg', 'image/gif', 'image/svg+xml'], - }, -} diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts deleted file mode 100644 index b2599f1..0000000 --- a/src/store/modules/user.ts +++ /dev/null @@ -1,115 +0,0 @@ -import { defineStore } from 'pinia' -import { createStorage } from '@/utils/Storage' -import { store } from '@/store' -import { ACCESS_TOKEN, CURRENT_USER } from '@/store/mutation-types' -import { ResultEnum } from '@/enums/httpEnum' -import { doLogout, getUserInfo, login } from '@/api/system/user' -import { PageEnum } from '@/enums/pageEnum' -import router from '@/router' - -const Storage = createStorage({ storage: localStorage }) - -interface UserInfo { - userId: string | number - username: string - realname: string - nickname: string - avatar: string - cover: string - gender: number - phone: string - sign?: string - industry?: number -} - -interface IUserState { - token?: string - userInfo: Nullable - lastUpdateTime: number -} - -interface LoginParams { - username: string - password: string -} - -export const useUserStore = defineStore({ - id: 'app-user', - state: (): IUserState => ({ - userInfo: null, - token: undefined, - lastUpdateTime: 0, - }), - getters: { - getUserInfo(): UserInfo { - return this.userInfo || Storage.get(CURRENT_USER, '') || {} - }, - getToken(): string { - return this.token || Storage.get(ACCESS_TOKEN, '') - }, - getLastUpdateTime(): number { - return this.lastUpdateTime - }, - }, - actions: { - setToken(token: string | undefined) { - this.token = token || '' - Storage.set(ACCESS_TOKEN, token) - }, - setUserInfo(info: UserInfo | null) { - this.userInfo = info - this.lastUpdateTime = new Date().getTime() - Storage.set(CURRENT_USER, info) - }, - - async Login(params: LoginParams) { - try { - const response = await login(params) - const { result, code } = response - if (code === ResultEnum.SUCCESS) { - // save token - this.setToken(result.token) - } - return Promise.resolve(response) - } - catch (error) { - return Promise.reject(error) - } - }, - - async GetUserInfo() { - return new Promise((resolve, reject) => { - getUserInfo() - .then((res) => { - this.setUserInfo(res) - resolve(res) - }) - .catch((error) => { - reject(error) - }) - }) - }, - - async Logout() { - if (this.getToken) { - try { - await doLogout() - } - catch { - console.error('注销Token失败') - } - } - this.setToken(undefined) - this.setUserInfo(null) - Storage.remove(ACCESS_TOKEN) - Storage.remove(CURRENT_USER) - router.push(PageEnum.BASE_LOGIN) - location.reload() - }, - }, -}) - -// Need to be used outside the setup -export function useUserStoreWidthOut() { - return useUserStore(store) -} diff --git a/src/store/mutation-types.ts b/src/store/mutation-types.ts index 82949ff..6fe75de 100644 --- a/src/store/mutation-types.ts +++ b/src/store/mutation-types.ts @@ -1,3 +1,2 @@ export const ACCESS_TOKEN = 'ACCESS-TOKEN' // 用户token export const CURRENT_USER = 'CURRENT-USER' // 当前用户信息 -export const DESIGN_SETTING = 'DESIGN-SETTING' // 当前用户主题信息 diff --git a/src/utils/env.ts b/src/utils/env.ts index 77ef030..2ac8d89 100644 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -28,9 +28,6 @@ export function getAppEnvConfig() { VITE_GLOB_API_URL, VITE_GLOB_APP_SHORT_NAME, VITE_GLOB_API_URL_PREFIX, - VITE_GLOB_UPLOAD_URL, - VITE_GLOB_PROD_MOCK, - VITE_GLOB_IMG_URL, } = ENV if (!/^[a-z_]*$/i.test(VITE_GLOB_APP_SHORT_NAME)) { @@ -45,9 +42,6 @@ export function getAppEnvConfig() { VITE_GLOB_API_URL, VITE_GLOB_APP_SHORT_NAME, VITE_GLOB_API_URL_PREFIX, - VITE_GLOB_UPLOAD_URL, - VITE_GLOB_PROD_MOCK, - VITE_GLOB_IMG_URL, } } diff --git a/src/utils/http/axios/Axios.ts b/src/utils/http/axios/Axios.ts index 12c3a81..790e430 100644 --- a/src/utils/http/axios/Axios.ts +++ b/src/utils/http/axios/Axios.ts @@ -4,7 +4,7 @@ import axios from 'axios' import qs from 'qs' import { cloneDeep } from 'lodash-es' import { AxiosCanceler } from './axiosCancel' -import type { CreateAxiosOptions, RequestOptions, UploadFileParams } from './types' +import type { CreateAxiosOptions, RequestOptions } from './types' import { isFunction } from '@/utils/is' import { ContentTypeEnum, RequestEnum } from '@/enums/httpEnum' @@ -108,45 +108,6 @@ export class VAxios { return transform } - /** - * @description: 文件上传 - */ - uploadFile(config: AxiosRequestConfig, params: UploadFileParams) { - const formData = new window.FormData() - const customFilename = params.name || 'file' - - if (params.filename) { - formData.append(customFilename, params.file, params.filename) - } - else { - formData.append(customFilename, params.file) - } - - if (params.data) { - Object.keys(params.data).forEach((key) => { - const value = params.data![key] - if (Array.isArray(value)) { - value.forEach((item) => { - formData.append(`${key}[]`, item) - }) - return - } - - formData.append(key, params.data![key]) - }) - } - - return this.axiosInstance.request({ - method: 'POST', - data: formData, - headers: { - 'Content-type': ContentTypeEnum.FORM_DATA, - 'ignoreCancelToken': true, - }, - ...config, - }) - } - // support form-data supportFormData(config: AxiosRequestConfig) { const headers = config.headers || this.options.headers diff --git a/src/utils/http/axios/index.ts b/src/utils/http/axios/index.ts index fdc1f1e..1a084b7 100644 --- a/src/utils/http/axios/index.ts +++ b/src/utils/http/axios/index.ts @@ -15,8 +15,6 @@ import { isString } from '@/utils/is/' import { deepMerge, isUrl } from '@/utils' import { setObjToUrlParams } from '@/utils/urlUtils' -import { useUserStoreWidthOut } from '@/store/modules/user' - import router from '@/router' import { storage } from '@/utils/Storage' import type { Result } from '#/axios' @@ -31,6 +29,8 @@ const transform: AxiosTransform = { /** * @description: 处理请求数据 */ + // eslint-disable-next-line ts/ban-ts-comment + // @ts-expect-error transformRequestData: (res: AxiosResponse, options: RequestOptions) => { const { isShowMessage = true, @@ -180,19 +180,6 @@ const transform: AxiosTransform = { return config }, - /** - * @description: 请求拦截器处理 - */ - requestInterceptors: (config, options) => { - // 请求之前处理config - const userStore = useUserStoreWidthOut() - const token = userStore.getToken - if (token) { - ;(config as Recordable).headers.Accesstoken = token - } - return config - }, - /** * @description: 响应错误处理 */ diff --git a/src/utils/http/axios/types.ts b/src/utils/http/axios/types.ts index bd2f985..7aa1b0a 100644 --- a/src/utils/http/axios/types.ts +++ b/src/utils/http/axios/types.ts @@ -7,19 +7,6 @@ export interface CreateAxiosOptions extends AxiosRequestConfig { authenticationScheme?: string } -// 上传文件 -export interface UploadFileParams { - // 其他参数 - data?: Recordable - // 文件参数接口字段名 - name?: string - // 文件 - file: File | Blob - // 文件名称 - filename?: string - [key: string]: any -} - export interface RequestOptions { // 请求参数拼接到url joinParamsToUrl?: boolean diff --git a/src/views/daxpay/channel/alipay/AlipayAuthCallback.vue b/src/views/daxpay/channel/alipay/AlipayAuthCallback.vue new file mode 100644 index 0000000..69da841 --- /dev/null +++ b/src/views/daxpay/channel/alipay/AlipayAuthCallback.vue @@ -0,0 +1,17 @@ + + + + + diff --git a/src/views/daxpay/channel/wechat/WechatAuthCallback.vue b/src/views/daxpay/channel/wechat/WechatAuthCallback.vue new file mode 100644 index 0000000..423a2b9 --- /dev/null +++ b/src/views/daxpay/channel/wechat/WechatAuthCallback.vue @@ -0,0 +1,13 @@ + + + + + diff --git a/src/views/system/dispatch/DispatchRouter.vue b/src/views/system/dispatch/DispatchRouter.vue index b30b213..2a627b7 100644 --- a/src/views/system/dispatch/DispatchRouter.vue +++ b/src/views/system/dispatch/DispatchRouter.vue @@ -2,18 +2,18 @@
跳转中...
-