未登录的情况下,profile接口每次刷新报错

This commit is contained in:
expdsn 2024-11-15 19:03:00 +08:00
parent 0c188cc40b
commit eca34957a2
5 changed files with 182 additions and 147 deletions

View File

@ -83,9 +83,9 @@ export default defineComponent(() => {
const addTo = ref(layout.state.currentPage) const addTo = ref(layout.state.currentPage)
provide(AddToToken, addTo) provide(AddToToken, addTo)
onUnmounted(() => { // onUnmounted(() => {
store.type = 1 // store.type = 1
}) // })
return () => ( return () => (
<div <div
class={clsx( class={clsx(

View File

@ -5,6 +5,8 @@ import { EditOutlined, DeleteOutlined, PlusOutlined } from '@ant-design/icons-vu
import asyncLoader from '@/utils/asyncLoader' import asyncLoader from '@/utils/asyncLoader'
import ThemeProvider from '@/utils/ThemeProvider' import ThemeProvider from '@/utils/ThemeProvider'
import { globalToast } from '@/main' import { globalToast } from '@/main'
import useUserStore from '@/user/useUserStore'
import useRouterStore from '@/useRouterStore'
const SearchAdder = asyncLoader(() => import('./SearchAdder')) const SearchAdder = asyncLoader(() => import('./SearchAdder'))
const SearchItem = defineComponent({ const SearchItem = defineComponent({
props: { props: {
@ -157,7 +159,12 @@ export default defineComponent(() => {
block block
icon={<PlusOutlined />} icon={<PlusOutlined />}
onClick={() => { onClick={() => {
if (useUserStore().isLogin) {
showAdder.value = null showAdder.value = null
} else {
globalToast.warning('请先登录')
useRouterStore().go('global-login')
}
}} }}
> >

View File

@ -79,6 +79,9 @@ export default defineStore('user', () => {
localStorage.setItem('token', val) localStorage.setItem('token', val)
if (!val) return if (!val) return
if (!isLogin.value) {
return
}
const res = await request<UserInfo>('GET', '/api/profile') const res = await request<UserInfo>('GET', '/api/profile')
Object.assign(profile, res) Object.assign(profile, res)
}, },

View File

@ -5,6 +5,8 @@ import upload from './upload'
import 'viewerjs/dist/viewer.css' import 'viewerjs/dist/viewer.css'
import { api as showViewer } from 'v-viewer' import { api as showViewer } from 'v-viewer'
import { globalToast } from '@/main' import { globalToast } from '@/main'
import useUserStore from '@/user/useUserStore'
import useRouterStore from '@/useRouterStore'
addIcons(MdUpload, FaEye) addIcons(MdUpload, FaEye)
@ -33,6 +35,7 @@ export default defineComponent({
}, },
setup(props, ctx) { setup(props, ctx) {
let input: HTMLInputElement | null = null let input: HTMLInputElement | null = null
return () => ( return () => (
<div> <div>
<input <input
@ -62,7 +65,12 @@ export default defineComponent({
backgroundImage: `url('${props.value}')` backgroundImage: `url('${props.value}')`
}} }}
onClick={() => { onClick={() => {
if (useUserStore().isLogin) {
input?.click() input?.click()
} else {
globalToast.warning('请先登录')
useRouterStore().go('global-login')
}
}} }}
> >
{props.value ? ( {props.value ? (

View File

@ -3,14 +3,16 @@ import { defineComponent, ref, watch } from 'vue'
import { VueCropper } from 'vue-cropper' import { VueCropper } from 'vue-cropper'
import 'vue-cropper/dist/index.css' import 'vue-cropper/dist/index.css'
import upload from './upload' import upload from './upload'
import { v4 as uuid } from "uuid" import { v4 as uuid } from 'uuid'
import { MdCroprotateRound, BiPlusLg } from "oh-vue-icons/icons"; import { MdCroprotateRound, BiPlusLg } from 'oh-vue-icons/icons'
import { OhVueIcon, addIcons, } from 'oh-vue-icons' import { OhVueIcon, addIcons } from 'oh-vue-icons'
import NativeColorPicker from './NativeColorPicker' import NativeColorPicker from './NativeColorPicker'
import useUserStore from '@/user/useUserStore'
import { globalToast } from '@/main'
import useRouterStore from '@/useRouterStore'
addIcons(MdCroprotateRound, BiPlusLg) addIcons(MdCroprotateRound, BiPlusLg)
export default defineComponent({ export default defineComponent({
emits: { emits: {
'update:value': (() => true) as (val: string) => boolean 'update:value': (() => true) as (val: string) => boolean
}, },
@ -73,18 +75,20 @@ export default defineComponent({
<> <>
<Modal <Modal
open={showCutModel.value} open={showCutModel.value}
onCancel={() => showCutModel.value = false} onCancel={() => (showCutModel.value = false)}
onOk={() => { onOk={() => {
cropper.value.getCropBlob((blob: any) => { cropper.value.getCropBlob((blob: any) => {
handleFinish(blob) handleFinish(blob)
}) })
}} }}
> >
<div class="w-full flex flex-col items-center gap-y-2"> <div class="w-full flex flex-col items-center gap-y-2">
<div class="w-[250px] h-[250px]" style={{ <div
backgroundColor: fillColor.value || 'transparent', class="w-[250px] h-[250px]"
}}> style={{
backgroundColor: fillColor.value || 'transparent'
}}
>
<VueCropper <VueCropper
ref={cropper} ref={cropper}
autoCropWidth="250px" autoCropWidth="250px"
@ -94,7 +98,6 @@ export default defineComponent({
img={originFile.value} img={originFile.value}
autoCrop={true} autoCrop={true}
fillColor={fillColor.value} fillColor={fillColor.value}
/> />
</div> </div>
<div class="flex justify-between w-[250px]"> <div class="flex justify-between w-[250px]">
@ -102,12 +105,13 @@ export default defineComponent({
class="text-[10px] w-8 h-8 cursor-pointer" class="text-[10px] w-8 h-8 cursor-pointer"
onClick={() => ($refs.cropper as any).rotateRight()} onClick={() => ($refs.cropper as any).rotateRight()}
/> */} /> */}
<span class="flex items-center cursor-pointer" <span
class="flex items-center cursor-pointer"
onClick={() => { onClick={() => {
cropper.value.rotateRight() cropper.value.rotateRight()
}}> }}
>
<OhVueIcon name="md-croprotate-round" scale={1} fill="#707070"></OhVueIcon> <OhVueIcon name="md-croprotate-round" scale={1} fill="#707070"></OhVueIcon>
</span> </span>
<span class="flex items-center gap-x-1"> <span class="flex items-center gap-x-1">
<svg <svg
@ -136,7 +140,11 @@ export default defineComponent({
</svg> </svg>
</span> </span>
</div> </div>
<NativeColorPicker value={fillColor.value} onUpdate:value={e => fillColor.value = e} transparent={true} /> <NativeColorPicker
value={fillColor.value}
onUpdate:value={(e) => (fillColor.value = e)}
transparent={true}
/>
{/* {props.colorList && ( {/* {props.colorList && (
<div class="w-[250px] flex justify-center"> <div class="w-[250px] flex justify-center">
<NativeColorPicker <NativeColorPicker
@ -147,23 +155,32 @@ export default defineComponent({
/> />
</div> </div>
)} */} )} */}
</div> </div>
</Modal> </Modal>
<div class="w-full h-full bg-white flex items-center justify-center" <div
class="w-full h-full bg-white flex items-center justify-center"
onClick={() => { onClick={() => {
if (useUserStore().isLogin) {
inputRef.value?.click?.() inputRef.value?.click?.()
} else {
globalToast.warning('请先登录')
useRouterStore().go('global-login')
// useAdderPageStore().type = 2
}
}} }}
> >
<OhVueIcon name={BiPlusLg.name} fill='#666666' scale={2}></OhVueIcon> <OhVueIcon name={BiPlusLg.name} fill="#666666" scale={2}></OhVueIcon>
</div> </div>
<input <input
ref={inputRef} ref={inputRef}
style={{ style={{
display: 'none' display: 'none'
}} accept=".jpg,.jpeg,.png,.svg" type="file" onChange={handleFile} /> }}
accept=".jpg,.jpeg,.png,.svg"
type="file"
onChange={handleFile}
/>
</> </>
) )
} }
}) })