From 744c02798afea06a55cc43c6b4bf1c0998903329 Mon Sep 17 00:00:00 2001 From: expdsn <18111002318@163.com> Date: Thu, 12 Sep 2024 17:59:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=BD=91=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/layout/adder/AdderPage.tsx | 5 +- src/layout/adder/AdderPageBack.tsx | 2 +- src/layout/adder/CustomAdder.tsx | 195 ++++++++++++++++++++--------- src/layout/adder/useLink.ts | 34 +++++ src/utils/ImageUploader.tsx | 2 +- 6 files changed, 179 insertions(+), 60 deletions(-) create mode 100644 src/layout/adder/useLink.ts diff --git a/package.json b/package.json index 2d75726..b976c75 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@fingerprintjs/fingerprintjs": "^4.4.3", "ali-oss": "^6.21.0", "ant-design-vue": "4.x", + "clsx": "^2.1.1", "dayjs": "^1.11.13", "localforage": "^1.10.0", "lunar-typescript": "^1.7.5", diff --git a/src/layout/adder/AdderPage.tsx b/src/layout/adder/AdderPage.tsx index 785ab50..62b8520 100644 --- a/src/layout/adder/AdderPage.tsx +++ b/src/layout/adder/AdderPage.tsx @@ -4,6 +4,7 @@ import useLayoutStore from '../useLayoutStore' import { OhVueIcon, addIcons } from 'oh-vue-icons' import { MdKeyboardcommandkey, FaCompass, FaPencilRuler } from 'oh-vue-icons/icons' import CustomAdder from './CustomAdder' +import clsx from 'clsx' addIcons(MdKeyboardcommandkey, FaCompass, FaPencilRuler) const ItemButton = defineComponent({ @@ -53,7 +54,7 @@ export default defineComponent(() => { const isGame = computed(() => layout.state.current === 0) const type = ref(1) return () => ( -
+
{isGame.value && }
{
e.stopPropagation()} > diff --git a/src/layout/adder/AdderPageBack.tsx b/src/layout/adder/AdderPageBack.tsx index 85991d1..ccfa832 100644 --- a/src/layout/adder/AdderPageBack.tsx +++ b/src/layout/adder/AdderPageBack.tsx @@ -10,7 +10,7 @@ export default defineComponent(() => () => ( > (
-
- {!props.icon && } -
-
- +
{ + ctx.emit('update:value', 0) }} > - {props.text ? props.text.substring(0, 2) : 'A'} - + {!props.icon && } + {props.value === 0 && ( +
+ +
+ )} +
+ 默认
-
- +
+
{ + ctx.emit('update:value', 1) + }} + > + + {props.text ? props.text.substring(0, 2) : 'A'} + + {props.value === 1 && ( +
+ +
+ )} +
+ 文字 +
+
+
+ { + ctx.emit('update:icon', e) + }} + > +
+ 自定义
) @@ -81,7 +122,6 @@ export default defineComponent({ }, setup(props, ctx) { const layout = useLayoutStore() - const isGame = computed(() => layout.state.current === 0) const form = reactive({ link: '', name: '', @@ -91,45 +131,88 @@ export default defineComponent({ icon: '', type: 0 // 0 默认,1 文字 }) + const isGame = computed(() => layout.state.current === 0) + const debounced = ref('') + watch( + () => form.link, + (val, _, onCleanup) => { + const it = setTimeout(() => { + debounced.value = val + }, 500) + onCleanup(() => { + clearTimeout(it) + }) + } + ) + + const info = useLink(debounced) + console.log(info); + + watch(info, (val) => { + console.log(val); + + if (val.name) form.name = val.name + if (val.icon) form.icon = val.icon + + }) return () => (
- -
- - - - - - - - - - - - - -
-
+
+
+ 地址 + + 获取地址 +
+
+ 名称 + +
+
+ 图标 + +
+
+ + +
+
) } diff --git a/src/layout/adder/useLink.ts b/src/layout/adder/useLink.ts new file mode 100644 index 0000000..ee39fcd --- /dev/null +++ b/src/layout/adder/useLink.ts @@ -0,0 +1,34 @@ +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) { + const info = reactive({ + background: '', + desc: '', + icon: '', + link: '', + name: '' + }) + watch( + url, + (val) => { + if (!val) return + const tag = val.match(/(?<=http(s?):\/\/)[^/]*/g)?.[0] || val + console.log(tag); + + request('GET', `/api/app/pic/info/${tag}`).then((res) => { + Object.assign(info, res) + }) + }, + { immediate: true } + ) + return info +} diff --git a/src/utils/ImageUploader.tsx b/src/utils/ImageUploader.tsx index bcb519d..721c0e5 100644 --- a/src/utils/ImageUploader.tsx +++ b/src/utils/ImageUploader.tsx @@ -89,7 +89,7 @@ export default defineComponent({ )}
-
支持上传 .png, .jpeg, .jpg, .svg
{' '} + {/*
支持上传 .png, .jpeg, .jpg, .svg
{' '} */}
)