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