33 lines
751 B
TypeScript
33 lines
751 B
TypeScript
import request from '@/utils/request'
|
|
import { reactive, watch, type Ref } from 'vue'
|
|
|
|
export interface LinkInfo {
|
|
background: string
|
|
desc: string
|
|
icon: string
|
|
link: string
|
|
name: string
|
|
}
|
|
|
|
export default function useLink(url: Ref<string>) {
|
|
const info = reactive<LinkInfo>({
|
|
background: '',
|
|
desc: '',
|
|
icon: 'https://oss.goosetab.com/000/user_upload/1/resource/120be9d6-1c68-41ba-b539-570c39ce2421.png',
|
|
link: '',
|
|
name: ''
|
|
})
|
|
watch(
|
|
url,
|
|
(val) => {
|
|
if (!val) return
|
|
const tag = val.match(/(?<=http(s?):\/\/)[^/]*/g)?.[0] || val
|
|
request<LinkInfo>('GET', `/api/app/pic/info/${tag}`).then((res) => {
|
|
Object.assign(info, res)
|
|
})
|
|
},
|
|
{ immediate: true }
|
|
)
|
|
return info
|
|
}
|