Skip to content

Commit bc51eb7

Browse files
Update Main.vue
1 parent 18f0395 commit bc51eb7

1 file changed

Lines changed: 173 additions & 3 deletions

File tree

Lines changed: 173 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,175 @@
11
<template>
2-
<div>Main</div>
2+
<div class="plugin-resource">
3+
<plugin-panel
4+
:title="title"
5+
:fixed-name="PLUGIN_NAME.Resource"
6+
:fixedPanels="fixedPanels"
7+
@close="pluginPanelClosed"
8+
:docsContent="docsContent"
9+
:isShowDocsIcon="true"
10+
>
11+
<template #header>
12+
<svg-button
13+
class="add-collection-icon"
14+
name="add-collection"
15+
placement="bottom"
16+
tips="新建分组"
17+
@click="openCategoryForm"
18+
></svg-button>
19+
</template>
20+
<template #content>
21+
<div class="resouce-list">
22+
<div
23+
v-for="item in resourceList"
24+
:class="['resource-item', { 'active-item': item.active }]"
25+
@click="openResourceList(item)"
26+
>
27+
<span>
28+
<svg-icon name="plugin-icon-data"></svg-icon>
29+
<span>{{ item.name }}</span>
30+
</span>
31+
<svg-icon name="setting" class="item-setting" @click.stop="openCategoryForm(item)"></svg-icon>
32+
</div>
33+
</div>
34+
<search-empty :isShow="!resourceList?.length" />
35+
</template>
36+
</plugin-panel>
37+
<resource-setting @create-group="createCategory"></resource-setting>
38+
<resource-list></resource-list>
39+
</div>
340
</template>
4-
<script setup></script>
5-
<style lang="less" scoped></style>
41+
<script>
42+
import { ref, reactive, provide, onMounted } from 'vue'
43+
import { useLayout, getMetaApi, META_SERVICE } from '@opentiny/tiny-engine-meta-register'
44+
import { PluginPanel, SvgButton, SearchEmpty } from '@opentiny/tiny-engine-common'
45+
import ResourceSetting, { openResourceSettingPanel, closeResourceSettingPanel } from './ResourceSetting.vue'
46+
import ResourceList, { openResourceListPanel, closeResourceListPanel } from './ResourceList.vue'
47+
import { fetchResourceGroupByAppId } from './js/http'
48+
export default {
49+
components: {
50+
PluginPanel,
51+
SvgButton,
52+
SearchEmpty,
53+
ResourceSetting,
54+
ResourceList
55+
},
56+
props: {
57+
title: {
58+
type: String,
59+
default: '资源管理'
60+
},
61+
fixedPanels: {
62+
type: Array
63+
}
64+
},
65+
emits: ['close'],
66+
setup(props, { emit }) {
67+
const { PLUGIN_NAME } = useLayout()
68+
const docsContent = '在这里新增图片资源,包括上传图片和使用uri。'
69+
70+
const panelState = reactive({
71+
emitEvent: emit
72+
})
73+
74+
provide('panelState', panelState)
75+
76+
const resourceList = ref([])
77+
78+
const pluginPanelClosed = () => {
79+
closeResourceListPanel()
80+
closeResourceSettingPanel()
81+
emit('close')
82+
}
83+
84+
const openCategoryForm = (data) => {
85+
if (data) {
86+
setItemActive(data)
87+
openResourceSettingPanel(data)
88+
} else {
89+
openResourceSettingPanel()
90+
}
91+
closeResourceListPanel()
92+
}
93+
94+
const getCategoryList = () => {
95+
fetchResourceGroupByAppId().then(res => {
96+
resourceList.value = res
97+
})
98+
}
99+
100+
const setItemActive = (data) => {
101+
resourceList.value.forEach((item) => {
102+
if (data.id === item.id) {
103+
item.active = true
104+
} else {
105+
item.active = false
106+
}
107+
})
108+
}
109+
110+
const createCategory = () => {
111+
getCategoryList()
112+
}
113+
114+
const updateCategory = (data) => {
115+
resourceList.value = data
116+
}
117+
118+
const openResourceList = (data) => {
119+
setItemActive(data)
120+
openResourceListPanel(data)
121+
closeResourceSettingPanel()
122+
}
123+
124+
onMounted(() => {
125+
getCategoryList()
126+
})
127+
128+
return {
129+
PLUGIN_NAME,
130+
docsContent,
131+
resourceList,
132+
pluginPanelClosed,
133+
openCategoryForm,
134+
openResourceList,
135+
createCategory,
136+
updateCategory
137+
}
138+
}
139+
}
140+
</script>
141+
<style lang="less" scoped>
142+
.resouce-list {
143+
margin: 8px 0;
144+
145+
.resource-item {
146+
padding: 0 16px;
147+
height: 32px;
148+
line-height: 32px;
149+
display: flex;
150+
justify-content: space-between;
151+
align-items: center;
152+
cursor: pointer;
153+
.item-setting {
154+
display: none;
155+
}
156+
.svg-icon {
157+
color: #808080;
158+
margin-right: 4px;
159+
}
160+
&:hover {
161+
background-color: #f5f5f5;
162+
.item-setting {
163+
display: inline;
164+
}
165+
}
166+
}
167+
.active-item {
168+
font-weight: 600;
169+
background-color: #f5f5f5;
170+
}
171+
}
172+
.plugin-resource {
173+
width: 100%;
174+
}
175+
</style>

0 commit comments

Comments
 (0)