diff --git a/src/layout/adder/CustomAdder.tsx b/src/layout/adder/CustomAdder.tsx
index 368c284..568bda5 100644
--- a/src/layout/adder/CustomAdder.tsx
+++ b/src/layout/adder/CustomAdder.tsx
@@ -1,4 +1,4 @@
-import { computed, defineComponent, inject, reactive, ref, watch } from 'vue'
+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'
@@ -12,7 +12,9 @@ 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({
@@ -47,6 +49,7 @@ const TypeSelector = defineComponent({
'update:icon': (() => true) as (val: string) => boolean
},
setup(props, ctx) {
+ const layout = useLayoutStore()
return () => (
@@ -60,7 +63,7 @@ const TypeSelector = defineComponent({
ctx.emit('update:value', 0)
}}
>
- {!props.icon &&
}
+ {!props.icon &&
}
{props.value === 0 && (
*/}
- {
+ {
ctx.emit('update:icon', e)
-
- }}>
+ }}
+ >
自定义
@@ -134,9 +138,21 @@ export default defineComponent(() => {
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) => {
@@ -234,21 +250,38 @@ export default defineComponent(() => {
globalToast.error('文字图标请至少填写文字或者名称')
return
}
- const id = uuid()
- const data: Block = {
- id,
- link: form.link,
- name: '',
- icon: form.type === 0 ? form.icon || info.icon : '',
- background: form.type === 0 ? '' : form.background,
- color: form.type === 0 ? '' : form.color,
- w: 1,
- h: 1,
- text:
- form.type === 0 ? '' : form.text || form.name.substring(0, 2).toLocaleUpperCase(),
- label: form.name
+ if (!form.link) {
+ globalToast.warning('请输入网站链接')
+ return
+ }
+ if (!form.name) {
+ globalToast.warning('请输入网站名称')
+ return
+ }
+ if (store.editBlockItem !== null) {
+ console.log(123)
+ layout.changeBlock(form, store.editBlockItem.id)
+ useRouterStore().back()
+ store.editBlockItem = null
+ } else {
+ const id = uuid()
+ const data: Block = {
+ id,
+ link: form.link,
+ name: '',
+ icon: form.type === 0 ? form.icon || info.icon : '',
+ background: form.type === 0 ? '' : form.background,
+ color: form.type === 0 ? '' : form.color,
+ w: 1,
+ h: 1,
+ text:
+ form.type === 0
+ ? ''
+ : form.text || form.name.substring(0, 2).toLocaleUpperCase(),
+ label: form.name
+ }
+ layout.addBlock(data, addTo?.value)
}
- layout.addBlock(data, addTo?.value)
}}
>
确定
diff --git a/src/layout/adder/useAdderPageStore.tsx b/src/layout/adder/useAdderPageStore.tsx
index d422df1..78a90b6 100644
--- a/src/layout/adder/useAdderPageStore.tsx
+++ b/src/layout/adder/useAdderPageStore.tsx
@@ -17,6 +17,16 @@ export interface HotAppCategoryType {
name: string
ordinal: number
}
+export type EditBlockItemType = {
+ id: string
+ link: string
+ name: string
+ text: string
+ background: string
+ color: string
+ icon: string
+ type: number // 0 默认,1 文字
+}
export default defineStore('adderPage', () => {
const type = ref(1)
const selectType = ref('')
@@ -26,6 +36,7 @@ export default defineStore('adderPage', () => {
const isSearch = ref(false)
const widgetSearchWords = ref('')
const gameSearch = ref('')
+ const editBlockItem = ref
(null)
request('GET', '/api/app/hotAppTypes').then((res) => {
categoryList.value = res.map((el) => ({
id: el.id,
@@ -78,6 +89,7 @@ export default defineStore('adderPage', () => {
selectType,
search,
isSearch,
- gameSearch
+ gameSearch,
+ editBlockItem
}
})
diff --git a/src/layout/useLayoutStore.ts b/src/layout/useLayoutStore.ts
index 766b523..752c2a4 100644
--- a/src/layout/useLayoutStore.ts
+++ b/src/layout/useLayoutStore.ts
@@ -8,6 +8,7 @@ import jump from '@/utils/jump'
import useSettingsStore from '@/settings/useSettingsStore'
import useUserStore from '@/user/useUserStore'
import request from '@/utils/request'
+import type { EditBlockItemType } from './adder/useAdderPageStore'
const defaultLayout: Layout = {
content: [
@@ -78,6 +79,21 @@ export default defineStore('layout', () => {
pageList.push(block)
globalToast.success('添加成功')
}
+ const changeBlock = (item: EditBlockItemType, target: string) => {
+ const idx = currentPage.value.list.findIndex((el) => el.id === target)
+ if (idx < 0) return
+ currentPage.value.list.splice(idx, 1, {
+ ...currentPage.value.list[idx],
+ label: item.name,
+ color: item.color,
+ text: item.text,
+ link: item.link,
+ background: item.background,
+ icon: item.type === 0 ? item.icon : '',
+
+ })
+
+ }
const openDir = ref('')
// 文件夹只有一个时,将当前界面的文件夹替换为图标
const checkDir = (id: string) => {
@@ -172,6 +188,7 @@ export default defineStore('layout', () => {
checkDir,
getLabel,
changeBackground,
- resetAll
+ resetAll,
+ changeBlock
}
})