diff --git a/src/App.vue b/src/App.vue index 14ef6389..a0699b92 100644 --- a/src/App.vue +++ b/src/App.vue @@ -12,10 +12,12 @@ import { useRoute } from "vue-router"; import { DictId } from "@/types/types.ts"; import { APP_VERSION, CAN_REQUEST, LOCAL_FILE_KEY, SAVE_DICT_KEY, SAVE_SETTING_KEY } from "@/config/env.ts"; import { syncSetting } from "@/apis"; +import {useAuthStore} from "@/stores/auth.ts"; const store = useBaseStore() const runtimeStore = useRuntimeStore() const settingStore = useSettingStore() +const authStore = useAuthStore() const {setTheme} = useTheme() let lastAudioFileIdList = [] @@ -60,6 +62,8 @@ async function init() { await store.init() await settingStore.init() store.load = true + await authStore.init() + setTheme(settingStore.theme) if (!settingStore.first) { @@ -78,19 +82,19 @@ watch(() => route.path, (to, from) => { return transitionName = '' // console.log('watch', to, from) // //footer下面的5个按钮,对跳不要用动画 - let noAnimation = [ - '/pc/practice', - '/pc/dict', - '/mobile', - '/' - ] - if (noAnimation.indexOf(from) !== -1 && noAnimation.indexOf(to) !== -1) { - return transitionName = '' - } - - const toDepth = routes.findIndex(v => v.path === to) - const fromDepth = routes.findIndex(v => v.path === from) - transitionName = toDepth > fromDepth ? 'go' : 'back' + // let noAnimation = [ + // '/pc/practice', + // '/pc/dict', + // '/mobile', + // '/' + // ] + // if (noAnimation.indexOf(from) !== -1 && noAnimation.indexOf(to) !== -1) { + // return transitionName = '' + // } + // + // const toDepth = routes.findIndex(v => v.path === to) + // const fromDepth = routes.findIndex(v => v.path === from) + // transitionName = toDepth > fromDepth ? 'go' : 'back' // console.log('transitionName', transitionName, toDepth, fromDepth) }) diff --git a/src/apis/user.ts b/src/apis/user.ts index bdad11dd..d93de337 100644 --- a/src/apis/user.ts +++ b/src/apis/user.ts @@ -1,4 +1,5 @@ import http from '@/utils/http.ts' +import {CodeType} from "@/types/types.ts"; // 用户登录接口 export interface LoginParams { @@ -22,11 +23,9 @@ export interface LoginResponse { // 用户注册接口 export interface RegisterParams { - email?: string - phone: string + account: string password: string code: string - nickname?: string } export interface RegisterResponse { @@ -42,15 +41,13 @@ export interface RegisterResponse { // 发送验证码接口 export interface SendCodeParams { - email?: string - phone: string - type: 'login' | 'register' | 'reset_password' + val: string + type: CodeType } // 重置密码接口 export interface ResetPasswordParams { - email?: string - phone: string + account: string code: string newPassword: string } @@ -61,24 +58,7 @@ export interface WechatLoginParams { state?: string } -// API 函数定义 export function loginApi(params: LoginParams) { - // 暂时直接返回成功响应,等待后端接入 - // return Promise.resolve({ - // success: true, - // code: 200, - // msg: '登录成功', - // data: { - // token: 'mock_token_' + Date.now(), - // user: { - // id: '1', - // account: params.account ?? 'account', - // phone: params.phone ?? 'phone', - // nickname: '测试用户', - // avatar: '' - // } - // } - // }) return http('user/login', params, null, 'post') } @@ -98,10 +78,6 @@ export function wechatLogin(params: WechatLoginParams) { return http('user/wechatLogin', params, null, 'post') } -export function logoutApi() { - return http('user/logout', null, null, 'post') -} - export function refreshToken() { return http<{ token: string }>('user/refreshToken', null, null, 'post') } diff --git a/src/components/base/form/FormItem.vue b/src/components/base/form/FormItem.vue index 8f6ba091..5f80f747 100644 --- a/src/components/base/form/FormItem.vue +++ b/src/components/base/form/FormItem.vue @@ -19,9 +19,13 @@ const myRules = $computed(() => { }) // 校验函数 -const validate = (rules) => { +const validate = (rules, isBlur = false) => { error = '' const val = formModel.value[props.prop] + //为空并且是非主动触发检验的情况下,不检验 + if (isBlur && val.trim() === '') { + return true + } for (const rule of rules) { if (rule.required && (!val || !val.toString().trim())) { error = rule.message @@ -55,7 +59,7 @@ const validate = (rules) => { // 自动触发 blur 校验 function handleBlur() { const blurRules = myRules.filter((r) => r.trigger === 'blur') - if (blurRules.length) validate(blurRules) + if (blurRules.length) validate(blurRules, true) } function handChange() { diff --git a/src/config/env.ts b/src/config/env.ts index 33442a67..6409b952 100644 --- a/src/config/env.ts +++ b/src/config/env.ts @@ -1,7 +1,4 @@ -import { useBaseStore } from "@/stores/base.ts"; - export const GITHUB = 'https://github.com/zyronon/TypeWords' -export const ProjectName = 'Type Words' export const Host = '2study.top' export const Origin = `https://${Host}` export const APP_NAME = 'Type Words' @@ -18,9 +15,20 @@ const map = { export const ENV = Object.assign(map['DEV'], common) // export const IS_OFFICIAL = import.meta.env.DEV // export let IS_LOGIN = true -export const IS_OFFICIAL = false -export let IS_LOGIN = false -export const CAN_REQUEST = IS_LOGIN && IS_OFFICIAL +export let IS_OFFICIAL = true +export let IS_LOGIN = (!!localStorage.getItem('token')) || false +export let CAN_REQUEST = IS_LOGIN && IS_OFFICIAL + +export let AppEnv = { + TOKEN: localStorage.getItem('token') ?? '', + IS_OFFICIAL: true, + IS_LOGIN: false, + CAN_REQUEST: false +} + +AppEnv.IS_LOGIN = !!AppEnv.TOKEN +AppEnv.CAN_REQUEST = AppEnv.IS_LOGIN && AppEnv.IS_OFFICIAL + export const RESOURCE_PATH = ENV.API + 'static' export const DICT_LIST = { @@ -58,6 +66,7 @@ export const EXPORT_DATA_KEY = { version: 4 } export const LOCAL_FILE_KEY = 'typing-word-files' + export const PracticeSaveWordKey = { key: 'PracticeSaveWord', version: 1 diff --git a/src/main.ts b/src/main.ts index c1d66867..80ec4535 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,14 +1,13 @@ -import { createApp } from 'vue' +import {createApp} from 'vue' import './assets/css/style.scss' import 'virtual:uno.css'; import App from './App.vue' -import { createPinia } from "pinia" +import {createPinia} from "pinia" import router from "@/router.ts"; import VueVirtualScroller from 'vue-virtual-scroller' import 'vue-virtual-scroller/dist/vue-virtual-scroller.css' import './types/global.d.ts' import loadingDirective from './directives/loading.tsx' -import { useAuthStore } from './stores/auth.ts' const pinia = createPinia() @@ -22,12 +21,7 @@ app.directive('opacity', (el, binding) => { el.style.opacity = binding.value ? 1 : 0 }) app.directive('loading', loadingDirective) - -// 初始化认证状态 -const authStore = useAuthStore() -authStore.initAuth().then(() => { - app.mount('#app') -}) +app.mount('#app') // 注册Service Worker(pwa支持) if ('serviceWorker' in navigator) { diff --git a/src/pages/setting/Setting.vue b/src/pages/setting/Setting.vue index 510d050a..dcc2c1c6 100644 --- a/src/pages/setting/Setting.vue +++ b/src/pages/setting/Setting.vue @@ -1,17 +1,17 @@ + + \ No newline at end of file diff --git a/src/pages/user/index.vue b/src/pages/user/index.vue deleted file mode 100644 index 352cc0aa..00000000 --- a/src/pages/user/index.vue +++ /dev/null @@ -1,408 +0,0 @@ - - - - - diff --git a/src/pages/user/login.vue b/src/pages/user/login.vue index 4c5f2cb6..59a922f2 100644 --- a/src/pages/user/login.vue +++ b/src/pages/user/login.vue @@ -1,18 +1,20 @@