mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-student.git
synced 2025-12-18 07:16:48 +08:00
init
This commit is contained in:
4
src/api/ThirdApi.js
Normal file
4
src/api/ThirdApi.js
Normal file
@@ -0,0 +1,4 @@
|
||||
export const BASE = 'https://u-pre.boe.com'
|
||||
export const GET_USER_LIST = `/userbasic/user/list post`
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import router from "@/router";
|
||||
import {reactive, ref, toRefs, watch} from "vue";
|
||||
import axios from 'axios';
|
||||
import {getCookie} from "@/api/utils";
|
||||
|
||||
export function usePage(_url, param) {
|
||||
|
||||
@@ -109,4 +110,39 @@ export async function request(_url, params) {
|
||||
console.log(e)
|
||||
// router.push({path: '/login'})
|
||||
})
|
||||
}
|
||||
|
||||
export async function boeRequest(_url, params) {
|
||||
const s = _url.split(' ')
|
||||
let url = s[0]
|
||||
const method = s[1]?.toLowerCase() || 'get'
|
||||
if (method === 'get') {
|
||||
let paramsArray = [];
|
||||
//拼接参数
|
||||
if (params) {
|
||||
Object.keys(params).forEach(key => paramsArray.push(key + '=' + params[key]))
|
||||
if (url.search(/\?/) === -1) {
|
||||
url += '?' + paramsArray.join('&')
|
||||
} else {
|
||||
url += '&' + paramsArray.join('&')
|
||||
}
|
||||
}
|
||||
}
|
||||
const body = method !== 'get' ? params || {} : {}
|
||||
return axios({
|
||||
url,
|
||||
method,
|
||||
headers: {
|
||||
token: getCookie('token'),
|
||||
...method !== 'get' ? {'Content-Type': 'application/json'} : {}
|
||||
},
|
||||
baseURL: '',
|
||||
...method !== 'get' ? {data: JSON.stringify(body)} : {}
|
||||
}).then(resp => resp.data).then(response => {
|
||||
return response
|
||||
}).catch(e => {
|
||||
console.log(2222)
|
||||
console.log(e)
|
||||
// router.push({path: '/login'})
|
||||
})
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
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
|
||||
}
|
||||
@@ -10,4 +14,14 @@ export function setCookie(name, value, perpetual) {
|
||||
|
||||
export function getCookie(name) {
|
||||
return document.cookie?.split(";").find(e => e.includes(name)).replace(`${name}=`, '') || ''
|
||||
}
|
||||
|
||||
export function useUserInfoAvatar(id) {
|
||||
const avatar = ref(import.meta.env.DEV ? `${BASE}/upload` : '')
|
||||
watch(id, () => {
|
||||
id.value && boeRequest(GET_USER_LIST, {id: id.value}).then(res => {
|
||||
avatar.value = avatar.value + res.result.userInfoList[0].avatar
|
||||
})
|
||||
})
|
||||
return avatar
|
||||
}
|
||||
Reference in New Issue
Block a user