mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-student.git
synced 2025-12-11 20:06:49 +08:00
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
import {watch, ref} from "vue";
|
|
import {boeRequest} from "@/api/request";
|
|
import {BASE, GET_USER_LIST} from "@/api/ThirdApi";
|
|
|
|
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 delCookie(name){
|
|
setCookie(name, "", -1)
|
|
}
|
|
|
|
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 = userInfo.value.avatar?userInfo.value.avatar.includes('upload')?userInfo.value.avatar:'/upload'+userInfo.value.avatar:'/800e23f7-b58c-4192-820d-0c6a2b7544cc.png'
|
|
})
|
|
})
|
|
return userInfo
|
|
}
|
|
|
|
export function IsPhone() {
|
|
return /mobile/i.test(navigator.userAgent);
|
|
} |