forked from opentiny/tiny-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataSourceList.vue
More file actions
203 lines (182 loc) · 4.99 KB
/
Copy pathDataSourceList.vue
File metadata and controls
203 lines (182 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<template>
<div class="data-source-list lowcode-scrollbar">
<ul>
<li v-for="key in filteredKey" :key="key" :class="['data-source-list-item', { selected: key === selectedKey }]">
<div class="item-head">
<div class="item-head-left">
<svg-icon name="plugin-icon-var" class="item-head-left-icon"></svg-icon>
<span class="protocal"> {{ stateScope === STATE.CURRENT_STATE ? 'state.' : 'stores.' }}</span>
<span class="name">{{ key }}</span>
</div>
<div class="item-head-right">
<svg-button name="to-edit" :hoverBgColor="false" @click="openPanel(OPTION_TYPE.UPDATE, key)"></svg-button>
<svg-button name="copy" :hoverBgColor="false" @click="openPanel(OPTION_TYPE.COPY, key)"></svg-button>
<svg-button name="delete" :hoverBgColor="false" @click="confirmClick(key)"></svg-button>
</div>
</div>
</li>
</ul>
<search-empty :isShow="!filteredKey.length" />
</div>
</template>
<script lang="tsx">
import { computed } from 'vue'
import { useModal, useResource } from '@opentiny/tiny-engine-meta-register'
import { findExpressionInAppSchema } from '@opentiny/tiny-engine-common/js/ast'
import { constants } from '@opentiny/tiny-engine-utils'
import { SvgButton, SearchEmpty } from '@opentiny/tiny-engine-common'
import { STATE, OPTION_TYPE } from './js/constants'
const { COMPONENT_NAME } = constants
export default {
components: {
SvgButton,
SearchEmpty
},
props: {
modelValue: {
type: Object,
default: () => ({})
},
query: {
type: String,
default: ''
},
stateScope: {
type: String
},
selectedKey: {
type: String
}
},
emits: ['openPanel', 'remove', 'removeStore'],
setup(props, { emit }) {
const filteredKey = computed(() => props.modelValue.filter((key) => key.includes(props.query)))
const openPanel = (flag, key) => {
emit('openPanel', flag, key)
}
const removeConfirm = (key) => {
useModal().confirm({
title: '提示',
message: `您确定要删除 ${key} 吗?`,
exec: () => emit('remove', key)
})
}
const removeStoreConfirm = (key) => {
const appPages = useResource().appSchemaState.pageTree.filter(
(page) => page.componentName === COMPONENT_NAME.Page && page?.meta?.group !== 'publicPages'
)
const expression = `stores.${key}`
const expresstionPages = findExpressionInAppSchema(appPages, expression)
if (expresstionPages.length > 0) {
useModal().message({
title: '提示',
message: (
<div>
不允许删除,因为检查到 {expression} 在以下页面中被引用:
{expresstionPages.map((pagaName) => (
<div key={pagaName}>{pagaName}</div>
))}
</div>
)
})
} else {
useModal().confirm({
title: '提示',
message: `您确定要删除 ${key} 吗?`,
exec: () => emit('removeStore', key)
})
}
}
const confirmClick = (key) => {
if (props.stateScope === STATE.CURRENT_STATE) {
removeConfirm(key)
} else {
removeStoreConfirm(key)
}
}
return {
filteredKey,
confirmClick,
openPanel,
STATE,
OPTION_TYPE
}
}
}
</script>
<style lang="less" scoped>
.data-source-list {
padding-top: 12px;
border-top: 1px solid var(--te-state-common-border-color-divider);
overflow-y: scroll;
.data-source-list-item {
&.selected,
&:hover {
background: var(--te-state-common-bg-color-hover);
.item-head-right {
display: flex;
justify-content: flex-end;
width: 30%;
}
}
}
.item-head {
height: 24px;
padding: 0 10px;
color: var(--te-state-data-list-text-color);
display: flex;
justify-content: space-between;
align-items: center;
.item-head-left {
display: flex;
align-items: center;
width: 70%;
.tiny-svg {
margin-right: 4px;
cursor: pointer;
transition: 0.3s;
color: var(--te-state-data-list-left-icon-color);
flex-shrink: 0;
&.is-expand {
transform: rotate(90deg);
}
}
.protocal {
margin-right: 4px;
font-size: 12px;
flex-shrink: 0;
}
.remote {
color: #3ac295;
}
.name {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.item-head-left-icon {
color: var(--te-state-data-list-left-icon-color);
margin-right: 8px;
}
}
.item-head-right {
display: none;
}
}
.item-content {
padding: 0 8px;
transition: 0.3s;
}
.content-item {
p span {
&:first-child {
font-size: 14;
color: var(--te-state-common-label-text-color);
}
&:last-child {
color: var(--te-state-common-text-color);
}
}
}
}
</style>