未登录的情况下,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)
provide(AddToToken, addTo)
onUnmounted(() => {
store.type = 1
})
// onUnmounted(() => {
// store.type = 1
// })
return () => (
<div
class={clsx(

View File

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

View File

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

View File

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

View File

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