Skip to content

Commit b4fed46

Browse files
Update ResourceSetting.vue
1 parent ba5f4f6 commit b4fed46

1 file changed

Lines changed: 156 additions & 3 deletions

File tree

Lines changed: 156 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,158 @@
11
<template>
2-
<div>Setting</div>
2+
<plugin-setting v-if="isShow" :fixed-name="PLUGIN_NAME.Resource" :align="align" :title="state.title">
3+
<template #header>
4+
<button-group>
5+
<tiny-button type="primary" @click="saveResourceSetting">保存</tiny-button>
6+
<svg-button name="close" @click="cancelResourceSetting"></svg-button>
7+
</button-group>
8+
</template>
9+
10+
<template #content>
11+
<div class="resource-setting-content">
12+
<tiny-collapse v-model="state.activeName" class="resource-setting-collapse">
13+
<tiny-collapse-item title="基本设置" name="general">
14+
<tiny-form
15+
ref="generalForm"
16+
:model="state.data"
17+
:rules="rules"
18+
label-width="80px"
19+
label-position="left"
20+
class="general-config-form"
21+
>
22+
<tiny-form-item prop="name" label="分组名称">
23+
<tiny-input v-model="state.data.name"></tiny-input>
24+
</tiny-form-item>
25+
<tiny-form-item prop="description" label="分组描述">
26+
<tiny-input type="textarea" v-model="state.data.description"></tiny-input>
27+
</tiny-form-item>
28+
</tiny-form>
29+
</tiny-collapse-item>
30+
</tiny-collapse>
31+
</div>
32+
</template>
33+
</plugin-setting>
334
</template>
4-
<script setup></script>
5-
<style lang="less" scoped></style>
35+
<script>
36+
import { ref, reactive, computed } from 'vue'
37+
import { Button, Collapse, CollapseItem, Form, FormItem, Input } from '@opentiny/vue'
38+
import { useLayout, useNotify, getMetaApi, META_SERVICE } from '@opentiny/tiny-engine-meta-register'
39+
import { PluginSetting, ButtonGroup, SvgButton } from '@opentiny/tiny-engine-common'
40+
import { createResourceGroup, updateResourceGroup } from './js/http'
41+
42+
const isShow = ref(false)
43+
44+
const state = reactive({
45+
title: '分组设置',
46+
activeName: 'general',
47+
data: {
48+
name: '',
49+
description: ''
50+
}
51+
})
52+
53+
export const openResourceSettingPanel = (data) => {
54+
if (data) {
55+
state.data = { ...data }
56+
console.log(state.data)
57+
}
58+
isShow.value = true
59+
}
60+
61+
export const closeResourceSettingPanel = () => {
62+
isShow.value = false
63+
}
64+
65+
export default {
66+
components: {
67+
PluginSetting,
68+
SvgButton,
69+
TinyButton: Button,
70+
TinyCollapse: Collapse,
71+
TinyCollapseItem: CollapseItem,
72+
TinyFormItem: FormItem,
73+
TinyForm: Form,
74+
TinyInput: Input,
75+
ButtonGroup
76+
},
77+
props: {},
78+
emits: ['create-group'],
79+
setup(props, { emit }) {
80+
const { PLUGIN_NAME, getPluginByLayout } = useLayout()
81+
const align = computed(() => getPluginByLayout(PLUGIN_NAME.Resource))
82+
83+
const generalForm = ref()
84+
85+
const rules = reactive({
86+
name: [{ required: true, message: '必填', trigger: 'blur' }]
87+
})
88+
const saveResourceSetting = () => {
89+
generalForm.value.validate((valid) => {
90+
if (state.data.id) {
91+
updateResourceGroup(state.data.id, { name: state.data.name, description: state.data.description })
92+
.then((res) => {
93+
emit('create-group')
94+
closeResourceSettingPanel()
95+
useNotify({ message: '修改资源分组成功', type: 'success' })
96+
})
97+
.catch((err) => {
98+
useNotify({ message: err, type: 'error' })
99+
})
100+
} else {
101+
createResourceGroup(state.data)
102+
.then((res) => {
103+
emit('create-group')
104+
closeResourceSettingPanel()
105+
useNotify({ message: '添加资源分组成功', type: 'success' })
106+
})
107+
.catch((err) => {
108+
useNotify({ message: err, type: 'error' })
109+
})
110+
}
111+
})
112+
}
113+
114+
const cancelResourceSetting = () => {
115+
closeResourceSettingPanel()
116+
}
117+
118+
return {
119+
PLUGIN_NAME,
120+
align,
121+
isShow,
122+
generalForm,
123+
state,
124+
rules,
125+
saveResourceSetting,
126+
cancelResourceSetting
127+
}
128+
}
129+
}
130+
</script>
131+
<style lang="less" scoped>
132+
.resource-plugin-setting {
133+
:deep(.plugin-setting-content) {
134+
padding: 0 0 16px 0;
135+
}
136+
137+
:deep(.tiny-collapse) {
138+
border-bottom: 0;
139+
}
140+
}
141+
.resource-setting-collapse {
142+
:deep(.tiny-collapse-item__header) {
143+
&,
144+
&.is-active {
145+
&::before {
146+
border: none;
147+
}
148+
}
149+
150+
.svg-icon {
151+
margin-right: 6px;
152+
}
153+
}
154+
:deep(.tiny-collapse-item__content) {
155+
padding: 0 12px 12px;
156+
}
157+
}
158+
</style>

0 commit comments

Comments
 (0)