index.vue
6.6 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<template>
<div v-if="cardData" class="go-items-list-card">
<n-card hoverable size="small">
<div class="list-content">
<!-- 顶部按钮 -->
<div class="list-content-top">
<mac-os-control-btn
class="top-btn"
:hidden="['remove']"
@close="deleteHandle"
@resize="handleLoadThreeModel"
></mac-os-control-btn>
</div>
<!-- 中间 -->
<div class="list-content-img">
<LoadThreeModelImage v-if="showThreeModel" :threeModelPath="cardData.threeModelFilePath" />
<n-image
object-fit="contain"
height="180"
preview-disabled
v-else
:src="requireUrl('ThreeModelDefault.svg')"
:fallback-src="requireErrorImg()"
></n-image>
</div>
</div>
<template #action>
<div class="go-flex-items-center list-footer" justify="space-between">
<n-text @click="handleFocus">
<n-button v-show="!focus" secondary size="tiny">
<span class="title">
{{ cardData.name || cardData.id }}
</span>
</n-button>
</n-text>
<n-input
v-show="focus"
ref="inputInstRef"
size="small"
type="text"
maxlength="16"
show-count
v-model:value.trim="title"
@keyup.enter="handleBlur"
@blur="handleBlur"
></n-input>
<!-- 工具 -->
<div class="go-flex-items-center list-footer-ri">
<n-space>
<n-text>
<n-badge
class="go-animation-twinkle"
dot
:color="cardData.state === 1 ? '#34c749' : '#fcbc40'"
></n-badge>
{{ cardData.state === 1 ? $t('project.release') : $t('project.unreleased') }}
</n-text>
<template v-for="item in fnBtnList" :key="item.key">
<template v-if="item.key === 'select'">
<n-dropdown
trigger="hover"
placement="bottom"
:options="selectOptions"
:show-arrow="true"
@select="handleSelect"
>
<n-button size="small">
<template #icon>
<component :is="item.icon"></component>
</template>
</n-button>
</n-dropdown>
</template>
<n-tooltip v-else placement="bottom" trigger="hover">
<template #trigger>
<n-button size="small" @click="handleSelect(item.key)">
<template #icon>
<component :is="item.icon"></component>
</template>
</n-button>
</template>
<component :is="item.label"></component>
</n-tooltip>
</template>
</n-space>
</div>
<!-- end -->
</div>
</template>
</n-card>
</div>
</template>
<script setup lang="ts">
import { reactive, ref, PropType, nextTick } from 'vue'
import { renderIcon, renderLang, requireErrorImg } from '@/utils'
import { icon } from '@/plugins'
import { MacOsControlBtn } from '@/components/Tips/MacOsControlBtn'
import { ChartType } from '../..'
import { updateThreeJsModel } from '@/api/external/contentSave/content'
import LoadThreeModelImage from '../LoadThreeModelImage.vue'
const { EllipsisHorizontalCircleSharpIcon, TrashIcon, HammerIcon, SendIcon } = icon.ionicons5
const emit = defineEmits(['delete', 'resize', 'edit', 'release', 'inputUpdateCard'])
const props = defineProps({
cardData: Object as PropType<ChartType>
})
const focus = ref<boolean>(false)
const inputInstRef = ref(null)
const title = ref<string>('')
const showThreeModel = ref(false)
const handleLoadThreeModel = () => (showThreeModel.value = true)
// 处理url获取
const requireUrl = (name: string) => {
return new URL(`../../../../../assets/images/${name}`, import.meta.url).href
}
const fnBtnList = reactive([
{
label: renderLang('global.r_edit'),
key: 'edit',
icon: renderIcon(HammerIcon)
},
{
label: renderLang('global.r_more'),
key: 'select',
icon: renderIcon(EllipsisHorizontalCircleSharpIcon)
}
])
const selectOptions = ref([
{
label: props.cardData?.state ? renderLang('global.r_unpublish') : renderLang('global.r_publish'),
key: 'release',
icon: renderIcon(SendIcon)
},
{
label: renderLang('global.r_delete'),
key: 'delete',
icon: renderIcon(TrashIcon)
}
])
const handleSelect = (key: string) => {
switch (key) {
case 'delete':
deleteHandle()
break
case 'release':
releaseHandle()
break
case 'edit':
editHandle()
break
}
}
// 删除处理
const deleteHandle = () => {
emit('delete', props.cardData)
}
// 编辑处理
const editHandle = () => {
emit('edit', props.cardData)
}
// 发布处理
const releaseHandle = () => {
emit('release', props.cardData)
}
// // 放大处理
// const resizeHandle = () => {
// emit('resize', props.cardData)
// }
const handleFocus = () => {
focus.value = true
nextTick(() => {
inputInstRef.value && (inputInstRef.value as any).focus()
})
}
const handleBlur = async () => {
focus.value = false
if (!title.value) return
await updateThreeJsModel({
id: props.cardData?.id as string,
name: title.value
})
emit('inputUpdateCard')
window['$message'].success(window['$t']('common.operationSuccessText'))
}
</script>
<style lang="scss" scoped>
$contentHeight: 180px;
@include go('items-list-card') {
position: relative;
border-radius: $--border-radius-base;
border: 1px solid rgba(0, 0, 0, 0);
@extend .go-transition;
&:hover {
@include hover-border-color('hover-border-color');
}
.list-content {
margin-top: 20px;
margin-bottom: 5px;
cursor: pointer;
border-radius: $--border-radius-base;
@include background-image('background-point');
@extend .go-point-bg;
&-top {
position: absolute;
top: 10px;
left: 10px;
height: 22px;
}
&-img {
height: $contentHeight;
@extend .go-flex-center;
@extend .go-border-radius;
@include deep() {
img {
@extend .go-border-radius;
}
}
}
}
.list-footer {
flex-wrap: nowrap;
justify-content: space-between;
line-height: 30px;
&-ri {
justify-content: flex-end;
min-width: 180px;
}
}
}
</style>