Skip to content

Commit a089417

Browse files
committed
feat(resources): add resource manager plugin
1 parent fc6f956 commit a089417

7 files changed

Lines changed: 94 additions & 71 deletions

File tree

packages/configurator/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import SwitchConfigurator from './switch-configurator/SwitchConfigurator.vue'
2929
import TableColumnsConfigurator from './table-columns-configurator/TableColumnsConfigurator.vue'
3030
import TabsGroupConfigurator from './tabs-group-configurator/TabsGroupConfigurator.vue'
3131
import VariableConfigurator from './variable-configurator/VariableConfigurator.vue'
32+
import SourceSelectConfigurator from './source-select-configurator/SourceSelectConfigurator.vue'
3233

3334
import { I18nInput, MetaCodeEditor } from '@opentiny/tiny-engine-common'
3435
import './styles/vars.less'
@@ -65,6 +66,7 @@ export {
6566
TableColumnsConfigurator,
6667
TabsGroupConfigurator,
6768
VariableConfigurator,
69+
SourceSelectConfigurator,
6870
MetaCodeEditor,
6971
I18nInput as I18nConfigurator,
7072
MetaCodeEditor as CodeConfigurator,

packages/configurator/src/source-select-configurator/SourceSelectConfigurator.vue

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
</div>
1818
<div class="source-content">
1919
<div class="source-filter">
20-
<tiny-select v-model="sourceCategory" :options="categoryOptions" placeholder="请选择分组" @change="categoryChange"> </tiny-select>
21-
<tiny-search
22-
class="search"
23-
v-model="searchWords"
24-
placeholder="按资源名称搜索"
25-
clearable
20+
<tiny-select
21+
v-model="sourceCategory"
22+
:options="categoryOptions"
23+
placeholder="请选择分组"
24+
@change="categoryChange"
2625
>
26+
</tiny-select>
27+
<tiny-search class="search" v-model="searchWords" placeholder="按资源名称搜索" clearable>
2728
<template #prefix>
2829
<tiny-icon-search />
2930
</template>
@@ -45,7 +46,12 @@
4546
<div class="source-list">
4647
<div v-for="(item, index) in sourceList" :key="item.id" class="source-item">
4748
<img :src="item.thumbnailUrl ?? item.resourceUrl" />
48-
<tiny-radio v-model="selectedSourceIndex" @change="selectSource(index)" :label="index" text=""></tiny-radio>
49+
<tiny-radio
50+
v-model="selectedSourceIndex"
51+
@change="selectSource(index)"
52+
:label="index"
53+
text=""
54+
></tiny-radio>
4955
<div class="source-name-wrap">
5056
<span :title="item.name">{{ item.name }}</span>
5157
</div>
@@ -68,12 +74,12 @@
6874
</div>
6975
</template>
7076
<script>
71-
import { ref, reactive, watch } from 'vue'
72-
import { Popover, Button, Input, Search, Select, Divider, RadioGroup, Radio } from '@opentiny/vue'
77+
import { ref, watch } from 'vue'
78+
import { Popover, Button, Input, Search, Select, Divider, Radio } from '@opentiny/vue'
7379
import { iconClose, iconSearch } from '@opentiny/vue-icon'
7480
import { SearchEmpty } from '@opentiny/tiny-engine-common'
7581
import { useNotify } from '@opentiny/tiny-engine-meta-register'
76-
import { fetchResourceListByGroupId, fetchResourceGroupByAppId } from './http'
82+
import { fetchResourceGroupByAppId } from './http'
7783
7884
const isShow = ref(false)
7985
@@ -94,7 +100,6 @@ export default {
94100
TinySelect: Select,
95101
TinyDivider: Divider,
96102
TinyRadio: Radio,
97-
TinyRadioGroup: RadioGroup,
98103
SearchEmpty,
99104
TinyIconClose: iconClose(),
100105
TinyIconSearch: iconSearch()
@@ -126,26 +131,28 @@ export default {
126131
const selectedSourceIndex = ref()
127132
128133
const getResourceData = () => {
129-
fetchResourceGroupByAppId().then((res) => {
130-
categoryData.value = res
131-
categoryOptions.value = res.map((item) => ({ label: item.name, value: item.id, resources: item.resources }))
132-
if (categoryOptions.value.length) {
133-
sourceCategory.value = categoryOptions.value[0].value
134-
sourceOriginList.value = categoryOptions.value[0].resources
135-
sourceList.value = categoryOptions.value[0].resources
136-
openPopover()
137-
}
138-
}).catch(error => {
139-
useNotify({
140-
type: 'error',
141-
message: error
134+
fetchResourceGroupByAppId()
135+
.then((res) => {
136+
categoryData.value = res
137+
categoryOptions.value = res.map((item) => ({ label: item.name, value: item.id, resources: item.resources }))
138+
if (categoryOptions.value.length) {
139+
sourceCategory.value = categoryOptions.value[0].value
140+
sourceOriginList.value = categoryOptions.value[0].resources
141+
sourceList.value = categoryOptions.value[0].resources
142+
openPopover()
143+
}
144+
})
145+
.catch((error) => {
146+
useNotify({
147+
type: 'error',
148+
message: error
149+
})
142150
})
143-
})
144151
}
145152
146153
const categoryChange = () => {
147-
sourceOriginList.value = categoryData.value.find(item => item.id === sourceCategory.value).resources
148-
sourceList.value = sourceOriginList.value.filter(item => item.name.includes(searchWords.value))
154+
sourceOriginList.value = categoryData.value.find((item) => item.id === sourceCategory.value).resources
155+
sourceList.value = sourceOriginList.value.filter((item) => item.name.includes(searchWords.value))
149156
}
150157
151158
const selectSource = (sourceIndex) => {
@@ -164,7 +171,7 @@ export default {
164171
watch(
165172
() => searchWords.value,
166173
() => {
167-
sourceList.value = sourceOriginList.value.filter(item => item.name.includes(searchWords.value))
174+
sourceList.value = sourceOriginList.value.filter((item) => item.name.includes(searchWords.value))
168175
}
169176
)
170177
@@ -286,7 +293,7 @@ export default {
286293
gap: 16px;
287294
288295
.empty-wrap {
289-
width: 100%
296+
width: 100%;
290297
}
291298
292299
.source-item {

packages/design-core/registry.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
Block,
4141
Datasource,
4242
Robot,
43+
Resource,
4344
Props,
4445
Events,
4546
Styles,
@@ -160,7 +161,8 @@ export default {
160161
__TINY_ENGINE_REMOVED_REGISTRY['engine.plugins.state'] === false ? null : State,
161162
__TINY_ENGINE_REMOVED_REGISTRY['engine.plugins.schema'] === false ? null : Schema,
162163
__TINY_ENGINE_REMOVED_REGISTRY['engine.plugins.editorhelp'] === false ? null : Help,
163-
__TINY_ENGINE_REMOVED_REGISTRY['engine.plugins.robot'] === false ? null : Robot
164+
__TINY_ENGINE_REMOVED_REGISTRY['engine.plugins.robot'] === false ? null : Robot,
165+
__TINY_ENGINE_REMOVED_REGISTRY['engine.plugins.resource'] === false ? null : Resource
164166
],
165167
settings: [
166168
__TINY_ENGINE_REMOVED_REGISTRY['engine.setting.props'] === false ? null : Props,

packages/plugins/resource/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
},
3838
"peerDependencies": {
3939
"@opentiny/vue": "^3.20.0",
40+
"@opentiny/vue-icon": "^3.20.0",
4041
"vue": "^3.4.15"
4142
}
4243
}

packages/plugins/resource/src/Main.vue

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<div class="resouce-list">
2222
<div
2323
v-for="item in resourceList"
24+
:key="item.id"
2425
:class="['resource-item', { 'active-item': item.active }]"
2526
@click="openResourceList(item)"
2627
>
@@ -40,7 +41,7 @@
4041
</template>
4142
<script>
4243
import { ref, reactive, provide, onMounted } from 'vue'
43-
import { useLayout, getMetaApi, META_SERVICE } from '@opentiny/tiny-engine-meta-register'
44+
import { useLayout, useNotify } from '@opentiny/tiny-engine-meta-register'
4445
import { PluginPanel, SvgButton, SearchEmpty } from '@opentiny/tiny-engine-common'
4546
import ResourceSetting, { openResourceSettingPanel, closeResourceSettingPanel } from './ResourceSetting.vue'
4647
import ResourceList, { openResourceListPanel, closeResourceListPanel } from './ResourceList.vue'
@@ -81,6 +82,16 @@ export default {
8182
emit('close')
8283
}
8384
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+
8495
const openCategoryForm = (data) => {
8596
if (data) {
8697
setItemActive(data)
@@ -92,19 +103,16 @@ export default {
92103
}
93104
94105
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-
})
106+
fetchResourceGroupByAppId()
107+
.then((res) => {
108+
resourceList.value = res
109+
})
110+
.catch((error) => {
111+
useNotify({
112+
type: 'error',
113+
message: error
114+
})
115+
})
108116
}
109117
110118
const createCategory = () => {

packages/plugins/resource/src/ResourceList.vue

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</div>
3030
</div>
3131
<div class="source-list-wrap">
32-
<div v-for="item in state.sourceList" class="source-list-item">
32+
<div v-for="item in state.sourceList" :key="item.id" class="source-list-item">
3333
<div class="source-image-wrap">
3434
<img :src="item.thumbnailUrl ?? item.resourceUrl" />
3535
<tiny-checkbox
@@ -78,6 +78,7 @@
7878
:multiple="true"
7979
:auto-upload="false"
8080
:show-file-list="false"
81+
action="#"
8182
@change="chooseFileChange"
8283
>
8384
<template #trigger>
@@ -205,9 +206,7 @@ export default {
205206
SearchEmpty,
206207
TinyIconPopup: iconPopup()
207208
},
208-
props: {},
209-
emits: ['close'],
210-
setup(props, { emit }) {
209+
setup() {
211210
const { PLUGIN_NAME, getPluginByLayout } = useLayout()
212211
const { toClipboard } = useClipboard()
213212
const { confirm } = useModal()
@@ -228,20 +227,23 @@ export default {
228227
const addSourceData = ref([])
229228
230229
const validRules = {
231-
name: [{ required: true, message: '资源名称必填' }, {
232-
type: 'string',
233-
validator: ({ row }, value) => {
234-
return new Promise((resolve, reject) => {
235-
if (!/^[a-zA-Z0-9_-]+\.(png|jpg|jpeg|svg)$/.test(value)) {
236-
reject(new Error('资源名成只能包含字母、数字、_和-等字符,且须以文件后缀名结尾'))
237-
} else if (addSourceData.value.find(item => item._RID !== row._RID && item.name === value)) {
238-
reject(new Error('已存在的资源名称'))
239-
} else {
240-
resolve()
241-
}
242-
})
230+
name: [
231+
{ required: true, message: '资源名称必填' },
232+
{
233+
type: 'string',
234+
validator: ({ row }, value) => {
235+
return new Promise((resolve, reject) => {
236+
if (!/^[a-zA-Z0-9_-]+\.(png|jpg|jpeg|svg)$/.test(value)) {
237+
reject(new Error('资源名成只能包含字母、数字、_和-等字符,且须以文件后缀名结尾'))
238+
} else if (addSourceData.value.find((item) => item._RID !== row._RID && item.name === value)) {
239+
reject(new Error('已存在的资源名称'))
240+
} else {
241+
resolve()
242+
}
243+
})
244+
}
243245
}
244-
}],
246+
],
245247
resourceUrl: {
246248
type: 'string',
247249
validator: ({ row }, value) => {
@@ -337,7 +339,7 @@ export default {
337339
})
338340
.filter((source) => source !== null)
339341
})
340-
.then((res) => {
342+
.then(() => {
341343
getSourceList()
342344
})
343345
.catch((error) => {
@@ -367,14 +369,14 @@ export default {
367369
description: state.group.description,
368370
resources: state.sourceList
369371
.map((source) => {
370-
if (selectedSources.value.find(item => item.id === source.id)) {
372+
if (selectedSources.value.find((item) => item.id === source.id)) {
371373
return null
372374
}
373375
return { id: source.id }
374376
})
375377
.filter((source) => source !== null)
376378
})
377-
.then((res) => {
379+
.then(() => {
378380
getSourceList()
379381
})
380382
.catch((error) => {
@@ -422,7 +424,6 @@ export default {
422424
423425
const submitSourceAdd = () => {
424426
addSourceGridRef.value.validate((valid) => {
425-
console.log(valid)
426427
if (!valid) {
427428
return
428429
}
@@ -436,7 +437,7 @@ export default {
436437
}
437438
})
438439
batchCreateResource(params)
439-
.then((res) => {
440+
.then(() => {
440441
getSourceList()
441442
enableUrlForm.value = false
442443
addSourceData.value = []
@@ -456,7 +457,7 @@ export default {
456457
457458
watch(
458459
() => state.group.id,
459-
(groupId) => {
460+
() => {
460461
getSourceList()
461462
}
462463
)

packages/plugins/resource/src/ResourceSetting.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<script>
3636
import { ref, reactive, computed } from 'vue'
3737
import { Button, Collapse, CollapseItem, Form, FormItem, Input } from '@opentiny/vue'
38-
import { useLayout, useNotify, getMetaApi, META_SERVICE } from '@opentiny/tiny-engine-meta-register'
38+
import { useLayout, useNotify } from '@opentiny/tiny-engine-meta-register'
3939
import { PluginSetting, ButtonGroup, SvgButton } from '@opentiny/tiny-engine-common'
4040
import { createResourceGroup, updateResourceGroup } from './js/http'
4141
@@ -53,7 +53,6 @@ const state = reactive({
5353
export const openResourceSettingPanel = (data) => {
5454
if (data) {
5555
state.data = { ...data }
56-
console.log(state.data)
5756
}
5857
isShow.value = true
5958
}
@@ -87,9 +86,12 @@ export default {
8786
})
8887
const saveResourceSetting = () => {
8988
generalForm.value.validate((valid) => {
89+
if (!valid) {
90+
return
91+
}
9092
if (state.data.id) {
9193
updateResourceGroup(state.data.id, { name: state.data.name, description: state.data.description })
92-
.then((res) => {
94+
.then(() => {
9395
emit('create-group')
9496
closeResourceSettingPanel()
9597
useNotify({ message: '修改资源分组成功', type: 'success' })
@@ -99,7 +101,7 @@ export default {
99101
})
100102
} else {
101103
createResourceGroup(state.data)
102-
.then((res) => {
104+
.then(() => {
103105
emit('create-group')
104106
closeResourceSettingPanel()
105107
useNotify({ message: '添加资源分组成功', type: 'success' })

0 commit comments

Comments
 (0)