import { computed, defineComponent, inject, onMounted, reactive, ref, watch } from 'vue' import useLayoutStore from '../useLayoutStore' import { Button, Form, Input, InputGroup } from 'ant-design-vue' import { OhVueIcon, addIcons } from 'oh-vue-icons' import { MdUpload, MdImage, MdCheck } from 'oh-vue-icons/icons' import useLink from '../../utils/useLink' import { CheckOutlined } from '@ant-design/icons-vue' import { v4 as uuid } from 'uuid' import type { Block } from '../layout.types' import { ColorPicker } from 'vue3-colorpicker' import 'vue3-colorpicker/style.css' import { globalToast } from '@/main' import UploadAndCut from '@/utils/UploadAndCut' import { AddToToken } from './AdderPage' import DefaultImg from '/tab/icons/bgGameCloud.png' import useAdderPageStore, { type EditBlockItemType } from './useAdderPageStore' import useRouterStore from '@/useRouterStore' addIcons(MdUpload, MdImage, MdCheck) const TypeSelector = defineComponent({ props: { value: { type: Number, default: 0 }, icon: { type: String, default: '' }, text: { type: String, default: '' }, color: { type: String, default: '' }, background: { type: String, default: '' }, name: { type: String, default: '' } }, emits: { 'update:value': (() => true) as (val: number) => boolean, 'update:icon': (() => true) as (val: string) => boolean }, setup(props, ctx) { const layout = useLayoutStore() return () => (
{ ctx.emit('update:value', 0) }} > {!props.icon && } {props.value === 0 && (
)}
默认
{ ctx.emit('update:value', 1) }} > {props.text ? props.text.substring(0, 2) : props.name.substring(0, 2).toLocaleUpperCase() || 'A'} {props.value === 1 && (
)}
文字
{/* { ctx.emit('update:icon', e) }} > */} { ctx.emit('update:icon', e) }} >
自定义
) } }) export default defineComponent(() => { const layout = useLayoutStore() const form = reactive({ link: '', name: '', text: '', background: 'rgb(247,169,78)', color: 'rgb(255,255,255)', icon: '', type: 0 // 0 默认,1 文字 } as EditBlockItemType) const isGame = computed(() => layout.state.current === 0) const debounced = ref('') const store = useAdderPageStore() onMounted(() => { if (store.editBlockItem !== null) { form.link = store.editBlockItem.link form.name = store.editBlockItem.name form.icon = store.editBlockItem.icon form.text = store.editBlockItem.text form.background = store.editBlockItem.background form.color = store.editBlockItem.color form.type = store.editBlockItem.type } }) watch( () => form.link, (val, _, onCleanup) => { const it = setTimeout(() => { debounced.value = val }, 500) onCleanup(() => { clearTimeout(it) }) } ) const info = useLink(debounced) watch(info, (val) => { if (val.name) form.name = val.name if (val.icon) form.icon = val.icon }) const addTo = inject(AddToToken) return () => (
{form.type === 1 && ( <>
)}
) })