sceneInGroupInEditor.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <div
  3. class="scene-item"
  4. :class="isConfirmingDeletion ? '' : 'not-confirming-deletion'"
  5. @dragstart="onDragStart"
  6. draggable="true"
  7. >
  8. <img
  9. :src="sceneInfo.icon + ossImagePreviewUrlSuffix()"
  10. alt=""
  11. class="scene-image"
  12. draggable="false"
  13. >
  14. <div class="right">
  15. <span v-if="!isRenaming" class="scene-title" v-title="sceneInfo.sceneTitle">{{sceneInfo.sceneTitle}}</span>
  16. <input
  17. v-if="isRenaming"
  18. class="scene-title-input"
  19. v-model.trim="newName"
  20. ref="input-for-rename"
  21. maxlength="50"
  22. placeholder="输入名字"
  23. @blur="onInputNewNameComplete"
  24. @keydown.enter="onInputEnter"
  25. />
  26. <div class="right-bottom">
  27. <span class="scene-type">{{translateSceneType(sceneInfo.type)}}</span>
  28. <div class="icons">
  29. <i class="iconfont icon-editor_list_edit icon-edit" v-tooltip="'重命名'"
  30. @click="onRequestForRename"
  31. >
  32. </i>
  33. <i class="iconfont icon-editor_list_delete icon-delete" v-tooltip="'删除'"
  34. @click="onRequestForDelete"
  35. >
  36. </i>
  37. </div>
  38. </div>
  39. </div>
  40. <div class="deletion-confirm-wrap">
  41. <div class="deletion-confirm" :class="isConfirmingDeletion ? 'show' : 'hide'"
  42. v-clickoutside="onRequestForCancelDelete"
  43. @click="onConfirmDelete"
  44. >
  45. 删除
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. import { ossImagePreviewUrlSuffix } from '@/utils/other.js'
  52. export default {
  53. name: 'SceneInGroupInEditor',
  54. components: {
  55. },
  56. props: {
  57. sceneInfo: {
  58. type: Object,
  59. require: true,
  60. },
  61. },
  62. data() {
  63. return {
  64. isRenaming: false,
  65. newName: '',
  66. isConfirmingDeletion: false,
  67. }
  68. },
  69. methods: {
  70. onDragStart(e) {
  71. e.dataTransfer.setData("application/target-type", `scene`)
  72. e.dataTransfer.setData("application/target-id", this.sceneInfo.id)
  73. e.dataTransfer.setDragImage(e.target.children[0], -10, -18)
  74. },
  75. ossImagePreviewUrlSuffix,
  76. translateSceneType(type) {
  77. if (type === 'pano') {
  78. return '全景'
  79. } else {
  80. return '三维'
  81. }
  82. },
  83. onRequestForRename() {
  84. this.isRenaming = true
  85. this.newName = this.sceneInfo.sceneTitle
  86. this.$nextTick(() => {
  87. this.$refs['input-for-rename'].focus()
  88. })
  89. },
  90. onInputNewNameComplete() {
  91. this.isRenaming = false
  92. this.$emit('rename', this.sceneInfo.id, this.newName)
  93. this.newName = ''
  94. },
  95. onInputEnter() {
  96. this.isRenaming = false // 会导致input blur,进而触发onInputNewNameComplete
  97. },
  98. onRequestForDelete() {
  99. this.isConfirmingDeletion = true
  100. },
  101. onRequestForCancelDelete() {
  102. this.isConfirmingDeletion = false
  103. },
  104. onConfirmDelete() {
  105. this.$emit('delete', this.sceneInfo.id)
  106. this.isConfirmingDeletion = false
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="less" scoped>
  112. .scene-item {
  113. position: relative;
  114. margin-left: -12px;
  115. margin-right: -10px;
  116. padding-right: 10px;
  117. padding-top: 10px;
  118. padding-bottom: 10px;
  119. display: flex;
  120. border-radius: 4px;
  121. &:hover {
  122. background: #313131;
  123. }
  124. &.not-confirming-deletion:hover {
  125. .icons {
  126. display: block !important;
  127. }
  128. }
  129. .scene-image {
  130. flex: 0 0 auto;
  131. width: 64px;
  132. height: 64px;
  133. background: #B0B0B0;
  134. border-radius: 2px;
  135. object-fit: cover;
  136. }
  137. .right {
  138. margin-left: 10px;
  139. width: 0px;
  140. flex: 1 1 auto;
  141. display: flex;
  142. flex-direction: column;
  143. justify-content: space-between;
  144. .scene-title {
  145. word-break: break-all;
  146. display: -webkit-box;
  147. -webkit-box-orient: vertical;
  148. -webkit-line-clamp: 2;
  149. overflow: hidden;
  150. font-size: 14px;
  151. color: rgba(255, 255, 255, 0.6);
  152. }
  153. .scene-title-input {
  154. height: 30px;
  155. background: #1A1B1D;
  156. border-radius: 2px;
  157. border: 1px solid #404040;
  158. color: #fff;
  159. font-size: 14px;
  160. padding: 0 10px 0 16px;
  161. &:focus {
  162. border-color: #0076F6;
  163. }
  164. }
  165. .right-bottom {
  166. display: flex;
  167. justify-content: space-between;
  168. align-items: flex-end;
  169. .scene-type {
  170. color: #0076F6;
  171. line-height: 16px;
  172. }
  173. .icons {
  174. display: none;
  175. i {
  176. font-size: 16px;
  177. cursor: pointer;
  178. color: rgba(255, 255, 255, 0.6);
  179. }
  180. .icon-edit {
  181. &:hover {
  182. color: #0076F6;
  183. }
  184. }
  185. .icon-delete {
  186. margin-left: 11px;
  187. &:hover {
  188. color: #fa5555;
  189. }
  190. }
  191. }
  192. }
  193. }
  194. .deletion-confirm-wrap {
  195. position: absolute;
  196. top: 0;
  197. bottom: 0;
  198. right: 0;
  199. width: 44px;
  200. overflow: hidden;
  201. pointer-events: none;
  202. border-top-right-radius: 4px;
  203. border-bottom-right-radius: 4px;
  204. > .deletion-confirm {
  205. position: absolute;
  206. top: 0;
  207. bottom: 0;
  208. width: 100%;
  209. background: #FA5555;
  210. transition: right 0.3s;
  211. cursor: pointer;
  212. text-align: center;
  213. font-size: 12px;
  214. color: #fff;
  215. pointer-events: auto;
  216. &::after {
  217. content: '';
  218. height: 100%;
  219. vertical-align: middle;
  220. display: inline-block;
  221. }
  222. &.show {
  223. right: 0;
  224. }
  225. &.hide {
  226. right: -44px;
  227. }
  228. }
  229. }
  230. }
  231. </style>