mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-student.git
synced 2025-12-22 01:06:48 +08:00
30 lines
958 B
JavaScript
30 lines
958 B
JavaScript
import {watch, ref} from "vue";
|
|
import {boeRequest} from "@/api/request";
|
|
import {BASE, GET_USER_LIST} from "@/api/ThirdApi";
|
|
|
|
const BASE_AVATAR = import.meta.env.DEV ? `${BASE}/upload` : ''
|
|
|
|
export function useImage(src) {
|
|
return new URL(`../assets/image/${src}`, import.meta.url).href
|
|
}
|
|
|
|
export function setCookie(name, value, perpetual) {
|
|
const d = new Date()
|
|
d.setDate(perpetual * 24 * 60 * 60 * 1000)
|
|
document.cookie = `${name}=${value};expires=${d.toGMTString()};path=/`
|
|
}
|
|
|
|
export function getCookie(name) {
|
|
return document.cookie?.split(";").find(e => e.includes(name)).replace(`${name}=`, '') || ''
|
|
}
|
|
|
|
export function useUserInfo(id) {
|
|
const userInfo = ref({})
|
|
watch(id, () => {
|
|
id.value && boeRequest(GET_USER_LIST, {id: id.value}).then(res => {
|
|
userInfo.value = res.result.userInfoList[0]
|
|
userInfo.value.avatar = BASE_AVATAR + userInfo.value.avatar
|
|
})
|
|
})
|
|
return userInfo
|
|
} |