feat 代码精简, 开发OpenId相关获取功能

This commit is contained in:
DaxPay
2024-09-24 19:59:53 +08:00
parent 2ba1318212
commit d49572f94c
22 changed files with 113 additions and 357 deletions

View File

@@ -2,26 +2,16 @@
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_PREFIX = /
VITE_GLOB_API_URL_PREFIX=/server

View File

@@ -1,26 +1,17 @@
# 网站根目录 和 接口 (api) 前缀 这个是嵌入式模式
#VITE_PUBLIC_PATH = /h5
#VITE_GLOB_API_URL_PREFIX = /
# 网站根目录(与PC部署在一起, 所以根目录不可以为 /) 和 接口 (server) 前缀 这个是独立部署模式
# 独立部署模式
VITE_PUBLIC_PATH = /h5
VITE_GLOB_API_URL_PREFIX=
# API 接口前缀
VITE_GLOB_API_URL_PREFIX = /api
# 嵌入式模式 与网关部署在一起, 和 接口 (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
# 如果你需要多种形式,你可以用','来分隔
# 是否启用gzip压缩或brotli压缩, 可选: gzip | brotli | none, 如果你需要多种形式,你可以用','来分隔
VITE_BUILD_COMPRESS='none'
# 使用压缩时是否删除原始文件默认为false

View File

@@ -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"
}
}
}

View File

@@ -1,60 +0,0 @@
import { http } from '@/utils/http/axios'
import type { Result } from '#/axios'
export interface BasicResponseModel<T = any> {
code: number
message: string
result: T
}
/**
* @description: 用户登录
*/
export function login(params: any) {
return http.request<Result<string>>(
{
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,
},
)
}

View File

@@ -9,8 +9,6 @@ export function useGlobSetting(): Readonly<GlobConfig> {
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<GlobConfig> {
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<GlobConfig>
}

View File

@@ -24,3 +24,29 @@ export const ErrorPageRoute: RouteRecordRaw = {
},
],
}
/**
* 主页面
*/
export const routeModuleList: Array<RouteRecordRaw> = [
{
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'),
},
],
},
]

View File

@@ -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,
},
},
{

30
src/router/daxpay.ts Normal file
View File

@@ -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: '微信信息获取',
},
},
],
}

View File

@@ -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,

View File

@@ -1,28 +0,0 @@
import type { RouteRecordRaw } from 'vue-router'
const Layout = () => import('@/layout/index.vue')
const routeModuleList: Array<RouteRecordRaw> = [
{
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

View File

@@ -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'],
},
}

View File

@@ -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<UserInfo>
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)
}

View File

@@ -1,3 +1,2 @@
export const ACCESS_TOKEN = 'ACCESS-TOKEN' // 用户token
export const CURRENT_USER = 'CURRENT-USER' // 当前用户信息
export const DESIGN_SETTING = 'DESIGN-SETTING' // 当前用户主题信息

View File

@@ -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,
}
}

View File

@@ -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<T = any>(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<T>({
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

View File

@@ -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<Result>, 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: 响应错误处理
*/

View File

@@ -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

View File

@@ -0,0 +1,17 @@
<template>
<div>
</div>
</template>
<script setup lang="ts">
import { useRoute } from 'vue-router'
const route = useRoute()
const {appId, channel, queryCode, aliAppId} = route.params
console.log(appId, channel)
</script>
<style scoped lang="less">
</style>

View File

@@ -0,0 +1,13 @@
<script setup lang="ts">
</script>
<template>
const {appId, channel,queryCode} = route.params
console.log(appId, channel)
</template>
<style scoped lang="less">
</style>

View File

@@ -2,18 +2,18 @@
<div> 跳转中... </div>
</template>
<script setup lang="ts" name="DispatchRouter">
<script setup lang="ts">
// 获取路由参数
import { useRouter } from 'vue-router'
import { onMounted, unref } from 'vue'
import { onMounted } from 'vue'
import { getRouterByKey } from './Dispatch.api'
import router from '@/router'
const { currentRoute } = useRouter()
const { query } = unref(currentRoute)
const { params } = unref(currentRoute)
onMounted(() => {
const key = query.key as string
const key = params.key as string
getRouterByKey(key).then(({ data }) => {
console.log(data)
router.push({

8
types/config.d.ts vendored
View File

@@ -4,8 +4,6 @@ export interface GlobConfig {
apiUrl: string
shortName: string
urlPrefix?: string
uploadUrl?: string
imgUrl?: string
}
export interface GlobEnvConfig {
@@ -17,10 +15,6 @@ export interface GlobEnvConfig {
VITE_GLOB_API_URL: string
// 接口前缀
VITE_GLOB_API_URL_PREFIX?: string
// Project abbreviation
//项目简称
VITE_GLOB_APP_SHORT_NAME: string
// 图片上传地址
VITE_GLOB_UPLOAD_URL?: string
// 图片前缀地址
VITE_GLOB_IMG_URL?: string
}

1
types/global.d.ts vendored
View File

@@ -61,7 +61,6 @@ declare global {
VITE_GLOB_APP_TITLE: string
VITE_GLOB_APP_SHORT_NAME: string
VITE_DROP_CONSOLE: boolean
VITE_GLOB_IMG_URL: string
VITE_PROXY: [string, string][]
VITE_BUILD_COMPRESS: 'gzip' | 'brotli' | 'none'
VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE: boolean