From 6d044a3ea28d489f3be83b28647b529684228a49 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=B4=AB=E6=98=9F?= <1315228475@qq.com>
Date: Tue, 12 Nov 2024 15:36:07 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90xiaohong=20TODO?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pnpm-lock.yaml | 11 ++-
src/pages/login/components/Banner.vue | 21 +++---
src/pages/login/components/LoginForm.vue | 5 +-
src/pages/login/registerCode.vue | 5 +-
src/service/login/LoginAPI.ts | 9 ++-
src/service/role/RoleApi.ts | 4 +-
src/store/user.ts | 3 +-
src/types/auto-import.d.ts | 89 ++----------------------
src/utils/http.ts | 57 +++++++--------
9 files changed, 65 insertions(+), 139 deletions(-)
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index a24ac72..4c1df42 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -29,6 +29,9 @@ dependencies:
dayjs:
specifier: 1.11.10
version: 1.11.10
+ mockjs:
+ specifier: ^1.1.0
+ version: 1.1.0
pinia:
specifier: 2.0.36
version: 2.0.36(typescript@5.6.3)(vue@3.4.21)
@@ -5101,7 +5104,6 @@ packages:
/commander@12.1.0:
resolution: {integrity: sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==}
engines: {node: '>=18'}
- dev: true
/commander@2.20.3:
resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==}
@@ -8213,6 +8215,13 @@ packages:
pkg-types: 1.2.1
ufo: 1.5.4
+ /mockjs@1.1.0:
+ resolution: {integrity: sha512-eQsKcWzIaZzEZ07NuEyO4Nw65g0hdWAyurVol1IPl1gahRwY+svqzfgfey8U8dahLwG44d6/RwEzuK52rSa/JQ==}
+ hasBin: true
+ dependencies:
+ commander: 12.1.0
+ dev: false
+
/module-alias@2.2.3:
resolution: {integrity: sha512-23g5BFj4zdQL/b6tor7Ji+QY4pEfNH784BMslY9Qb0UnJWRAt+lQGLYmRaM0KDBwIG23ffEBELhZDP2rhi9f/Q==}
diff --git a/src/pages/login/components/Banner.vue b/src/pages/login/components/Banner.vue
index e2b5c31..12256e4 100644
--- a/src/pages/login/components/Banner.vue
+++ b/src/pages/login/components/Banner.vue
@@ -13,20 +13,22 @@
- {{ currentTenant.label || '请选择租户' }}
+ {{ currentTenant.name || '请选择租户' }}
@@ -48,7 +50,7 @@
defineProps({
tenantId: {
- type: [String, Number] // TODO @xiaohong:租户只有 number 类型。
+ type: Number
}
})
@@ -56,10 +58,9 @@
const loading = ref(false) // loading
const tenantList = ref([]) // 租户列表
- // TODO @xiaohong:id、name 哈。
- const currentTenant = ref<{ label: string; value: string }>({
- label: '',
- value: ''
+ const currentTenant = ref<{ name: string; id: string }>({
+ name: '',
+ id: ''
}) // 当前租户
/** 获取租户列表 */
@@ -77,9 +78,9 @@
/** 选择租户信息 */
function selectTenant({ selectedItems }) {
currentTenant.value = selectedItems
- emits('update:tenantId', selectedItems.value)
+ emits('update:tenantId', selectedItems.id)
// 缓存租户编号
- setTenantId(selectedItems.value)
+ setTenantId(selectedItems.id)
}
/** 初始化 */
diff --git a/src/pages/login/components/LoginForm.vue b/src/pages/login/components/LoginForm.vue
index ebce0fc..3e5937a 100644
--- a/src/pages/login/components/LoginForm.vue
+++ b/src/pages/login/components/LoginForm.vue
@@ -34,7 +34,7 @@
:block="true"
:round="false"
custom-class="mt-8"
- @click="handleLogin('userinfo')"
+ @click="handleLogin('password')"
>
登录
@@ -106,8 +106,7 @@
// 账号密码登录
const { afterLogin } = useUserStore()
- // TODO @xiaohong:userinfo 改成 password
- if (type === 'userinfo') {
+ if (type === 'password') {
try {
// 校验表单
const { valid } = await loginForm.value.validate()
diff --git a/src/pages/login/registerCode.vue b/src/pages/login/registerCode.vue
index 5db326a..065ccdf 100644
--- a/src/pages/login/registerCode.vue
+++ b/src/pages/login/registerCode.vue
@@ -63,13 +63,12 @@
async function getCode() {
try {
toast.loading('获取验证码......')
- // TODO @xiaohong:code 是不是没用。可以去掉哈?
- const code = await getCodeApi({
+ await getCodeApi({
phoneNo: phoneNo.value
})
// 倒计时
- loadTime.value = 60
+ loadTime.value = 5
codeDisabled.value = true
showKeyboard.value = true
timer.value = setInterval(getTime, 1000)
diff --git a/src/service/login/LoginAPI.ts b/src/service/login/LoginAPI.ts
index 79fed0e..3b303a2 100644
--- a/src/service/login/LoginAPI.ts
+++ b/src/service/login/LoginAPI.ts
@@ -1,15 +1,15 @@
import { http, httpGet, httpPost } from '@/utils/http'
+import Mock from 'mockjs'
/** 获取租户列表 */
-// TODO @xiaohong:字段调整下。返回 id = 租户 id(number 类型);name = 租户名字
export const getTenants = () => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(
Array.from({ length: 20 }, (_, index) => {
return {
- label: `租户${index}`,
- value: index + 1
+ name: `租户${index}`,
+ id: index + 1
}
})
)
@@ -17,12 +17,11 @@ export const getTenants = () => {
})
}
-// TODO @xiaohong:可以用 mockjs 哈。项目已经使用了
/** 获取验证码 */
export const getCode = (data: Recordable) => {
return new Promise((resolve) => {
setTimeout(() => {
- resolve(123456)
+ resolve(Mock.mock('@string("number", 6)'))
}, 2000)
})
}
diff --git a/src/service/role/RoleApi.ts b/src/service/role/RoleApi.ts
index a7f71de..cb1dc5d 100644
--- a/src/service/role/RoleApi.ts
+++ b/src/service/role/RoleApi.ts
@@ -17,7 +17,6 @@ export interface RoleVO {
const useMock = import.meta.env.VITE_USE_MOCK === 'true'
// 模拟数据类型是数组
const mockConfig = (type = 'array') => {
-
if (type === 'array') {
return {
'data|10': [
@@ -37,7 +36,7 @@ const mockConfig = (type = 'array') => {
}
} else {
return {
- 'data': {
+ data: {
id: 1,
name: '@name',
code: '@word',
@@ -51,7 +50,6 @@ const mockConfig = (type = 'array') => {
}
}
}
-
}
export const getList = (query: object) => {
if (useMock) {
diff --git a/src/store/user.ts b/src/store/user.ts
index dc9c296..11fe2e1 100644
--- a/src/store/user.ts
+++ b/src/store/user.ts
@@ -71,9 +71,8 @@ export const useUserStore = defineStore(
await setUserInfoAction()
// 跳转为登录前的页面(redirect)
- // TODO @xiaohong:貌似重定向不了
const fullPath = currRoute()
- uni.redirectTo({
+ uni.reLaunch({
url: fullPath.query.redirect || '/pages/work/index'
})
}
diff --git a/src/types/auto-import.d.ts b/src/types/auto-import.d.ts
index 255cb5b..b5c1bff 100644
--- a/src/types/auto-import.d.ts
+++ b/src/types/auto-import.d.ts
@@ -94,7 +94,7 @@ declare global {
// for type re-export
declare global {
// @ts-ignore
- export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue'
+ export type { Component, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue'
import('vue')
}
// for vue template auto import
@@ -156,6 +156,7 @@ declare module 'vue' {
readonly onUnload: UnwrapRef
readonly onUnmounted: UnwrapRef
readonly onUpdated: UnwrapRef
+ readonly onWatcherCleanup: UnwrapRef
readonly provide: UnwrapRef
readonly reactive: UnwrapRef
readonly readonly: UnwrapRef
@@ -173,91 +174,11 @@ declare module 'vue' {
readonly useAttrs: UnwrapRef
readonly useCssModule: UnwrapRef
readonly useCssVars: UnwrapRef
+ readonly useId: UnwrapRef
+ readonly useModel: UnwrapRef
readonly useRequest: UnwrapRef
readonly useSlots: UnwrapRef
- readonly useUpload: UnwrapRef
- readonly watch: UnwrapRef
- readonly watchEffect: UnwrapRef
- readonly watchPostEffect: UnwrapRef
- readonly watchSyncEffect: UnwrapRef
- }
-}
-declare module '@vue/runtime-core' {
- interface GlobalComponents {}
- interface ComponentCustomProperties {
- readonly EffectScope: UnwrapRef
- readonly computed: UnwrapRef
- readonly createApp: UnwrapRef
- readonly customRef: UnwrapRef
- readonly defineAsyncComponent: UnwrapRef
- readonly defineComponent: UnwrapRef
- readonly effectScope: UnwrapRef
- readonly getCurrentInstance: UnwrapRef
- readonly getCurrentScope: UnwrapRef
- readonly h: UnwrapRef
- readonly inject: UnwrapRef
- readonly isProxy: UnwrapRef
- readonly isReactive: UnwrapRef
- readonly isReadonly: UnwrapRef
- readonly isRef: UnwrapRef
- readonly markRaw: UnwrapRef
- readonly nextTick: UnwrapRef
- readonly onActivated: UnwrapRef
- readonly onAddToFavorites: UnwrapRef
- readonly onBackPress: UnwrapRef
- readonly onBeforeMount: UnwrapRef
- readonly onBeforeUnmount: UnwrapRef
- readonly onBeforeUpdate: UnwrapRef
- readonly onDeactivated: UnwrapRef
- readonly onError: UnwrapRef
- readonly onErrorCaptured: UnwrapRef
- readonly onHide: UnwrapRef
- readonly onLaunch: UnwrapRef
- readonly onLoad: UnwrapRef
- readonly onMounted: UnwrapRef
- readonly onNavigationBarButtonTap: UnwrapRef
- readonly onNavigationBarSearchInputChanged: UnwrapRef
- readonly onNavigationBarSearchInputClicked: UnwrapRef
- readonly onNavigationBarSearchInputConfirmed: UnwrapRef
- readonly onNavigationBarSearchInputFocusChanged: UnwrapRef
- readonly onPageNotFound: UnwrapRef
- readonly onPageScroll: UnwrapRef
- readonly onPullDownRefresh: UnwrapRef
- readonly onReachBottom: UnwrapRef
- readonly onReady: UnwrapRef
- readonly onRenderTracked: UnwrapRef
- readonly onRenderTriggered: UnwrapRef
- readonly onResize: UnwrapRef
- readonly onScopeDispose: UnwrapRef
- readonly onServerPrefetch: UnwrapRef
- readonly onShareAppMessage: UnwrapRef
- readonly onShareTimeline: UnwrapRef
- readonly onShow: UnwrapRef
- readonly onTabItemTap: UnwrapRef
- readonly onThemeChange: UnwrapRef
- readonly onUnhandledRejection: UnwrapRef
- readonly onUnload: UnwrapRef
- readonly onUnmounted: UnwrapRef
- readonly onUpdated: UnwrapRef
- readonly provide: UnwrapRef
- readonly reactive: UnwrapRef
- readonly readonly: UnwrapRef
- readonly ref: UnwrapRef
- readonly resolveComponent: UnwrapRef
- readonly shallowReactive: UnwrapRef
- readonly shallowReadonly: UnwrapRef
- readonly shallowRef: UnwrapRef
- readonly toRaw: UnwrapRef
- readonly toRef: UnwrapRef
- readonly toRefs: UnwrapRef
- readonly toValue: UnwrapRef
- readonly triggerRef: UnwrapRef
- readonly unref: UnwrapRef
- readonly useAttrs: UnwrapRef
- readonly useCssModule: UnwrapRef
- readonly useCssVars: UnwrapRef
- readonly useRequest: UnwrapRef
- readonly useSlots: UnwrapRef
+ readonly useTemplateRef: UnwrapRef
readonly useUpload: UnwrapRef
readonly watch: UnwrapRef
readonly watchEffect: UnwrapRef
diff --git a/src/utils/http.ts b/src/utils/http.ts
index e2e6fe3..cf8f664 100644
--- a/src/utils/http.ts
+++ b/src/utils/http.ts
@@ -43,16 +43,16 @@ export const http = (options: CustomRequestOptions) => {
// 1. 如果获取不到刷新令牌,则只能执行登出操作
if (!getRefreshToken()) {
- showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(
- (res: any) => {
- if (res.confirm) {
- // 清除缓存起来的用户信息
- userStore.LogOut().then((res) => {
- uni.reLaunch({ url: '/pages/login/index' })
- })
- }
- },
- )
+ showConfirm(
+ '登录状态已过期,您可以继续留在该页面,或者重新登录?'
+ ).then((res: any) => {
+ if (res.confirm) {
+ // 清除缓存起来的用户信息
+ userStore.LogOut().then((res) => {
+ uni.reLaunch({ url: '/pages/login/index' })
+ })
+ }
+ })
}
// 2. 刷新accesstoken
@@ -60,16 +60,16 @@ export const http = (options: CustomRequestOptions) => {
const refreshTokenRes: any = await refreshToken()
if (refreshTokenRes.data.code !== 0) {
// 如果获取不到refresh token,就直接跳转到登录页面
- showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(
- (res: any) => {
- if (res.confirm) {
- // 清除缓存起来的用户信息
- userStore.LogOut().then((res) => {
- uni.reLaunch({ url: '/pages/login/index' })
- })
- }
- },
- )
+ showConfirm(
+ '登录状态已过期,您可以继续留在该页面,或者重新登录?'
+ ).then((res: any) => {
+ if (res.confirm) {
+ // 清除缓存起来的用户信息
+ userStore.LogOut().then((res) => {
+ uni.reLaunch({ url: '/pages/login/index' })
+ })
+ }
+ })
const rejMsg = '无效的会话,或者会话已过期,请重新登录。'
reject(rejMsg)
}
@@ -125,10 +125,10 @@ export const http = (options: CustomRequestOptions) => {
fail(err) {
uni.showToast({
icon: 'none',
- title: '网络错误,换个网络试试',
+ title: '网络错误,换个网络试试'
})
reject(err)
- },
+ }
})
})
}
@@ -143,7 +143,7 @@ export const httpGet = (url: string, query?: Record) => {
return http({
url,
query,
- method: 'GET',
+ method: 'GET'
})
}
@@ -157,13 +157,13 @@ export const httpGet = (url: string, query?: Record) => {
export const httpPost = (
url: string,
data?: Record,
- query?: Record,
+ query?: Record
) => {
return http({
url,
query,
data,
- method: 'POST',
+ method: 'POST'
})
}
@@ -173,9 +173,10 @@ http.post = httpPost
const refreshToken = async () => {
return await uni.request({
method: 'POST',
- url: baseUrl + '/system/auth/refresh-token?refreshToken=' + getRefreshToken(),
+ url:
+ baseUrl + '/system/auth/refresh-token?refreshToken=' + getRefreshToken(),
header: {
- 'tenant-id': 1,
- },
+ 'tenant-id': 1
+ }
})
}
--
Gitee