index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <transition name="slide-right" mode="in-out">
  3. <div class="files" v-if="showFiles">
  4. <div class="info">
  5. <button @click="onAdd">添加标注</button>
  6. <div>
  7. 已添加的标注(<span>{{ tags.length }}</span
  8. >)
  9. </div>
  10. </div>
  11. <div class="list">
  12. <ul>
  13. <li v-for="tag in tags" @click="onClick(tag)" :class="{ active: notify?.sid == tag.sid }">
  14. <div class="title"><i></i>{{ tag.title }}</div>
  15. <div class="more" @click.stop="onShowMore(tag)">
  16. <i class="iconfont icon-more"></i>
  17. <div v-if="showMoreSid == tag.id" v-click-outside="onOutside">
  18. <div @click.stop="onMoreHandler('modify', tag)">编辑</div>
  19. <div @click.stop="onMoreHandler('delete', tag)">删除</div>
  20. </div>
  21. </div>
  22. </li>
  23. </ul>
  24. </div>
  25. <div class="exit">
  26. <button type="button" @click="emits('exit')">退出</button>
  27. </div>
  28. </div>
  29. </transition>
  30. <transition name="slide-up" mode="in-out">
  31. <div class="toolbar" v-if="showToolbar">
  32. <button type="button" @click="onAddCancel">取消</button>
  33. <button type="submit" @click="onAddConfirm">确定</button>
  34. </div>
  35. </transition>
  36. </template>
  37. <script setup>
  38. import { ref, inject, watchEffect } from 'vue'
  39. import { http } from '@/utils/request'
  40. let editTag = null
  41. let tempTag = null
  42. const props = defineProps(['show'])
  43. const emits = defineEmits(['add', 'exit'])
  44. const showFiles = ref(false)
  45. const showToolbar = ref(false)
  46. const showMoreSid = ref('')
  47. const tags = inject('tags')
  48. const notify = inject('notify')
  49. const isEdit = inject('isEdit')
  50. const onClick = tag => {
  51. notify.value = tag //{ event: 'focus', sid: props.tag.sid, tag: props.tag }
  52. }
  53. const onAdd = () => {
  54. if (window.kankan) {
  55. window.kankan.TagManager.editor.then(editor => {
  56. editor.enter()
  57. showFiles.value = false
  58. showToolbar.value = true
  59. })
  60. } else {
  61. window.laser.then(sdk => {
  62. sdk.addMouseDownEvent(e => {
  63. if (showToolbar.value == false) {
  64. return
  65. }
  66. if (e.button == 2) {
  67. const info3d = sdk.scene.getPointByScreen({ x: e.clientX, y: e.clientY })
  68. const info2d = sdk.scene.getScreenByPoint(info3d.position)
  69. if (editTag) {
  70. tempTag = {}
  71. tempTag.x = editTag.x
  72. tempTag.y = editTag.y
  73. tempTag.visible = editTag.visible
  74. tempTag.position = new THREE.Vector3(editTag.position.x, editTag.position.y, editTag.position.z)
  75. editTag.x = info2d.pos.x
  76. editTag.y = info2d.pos.y
  77. editTag.visible = info2d.trueSide
  78. editTag.position = info3d.position
  79. } else {
  80. const tag = {
  81. panoId: '0',
  82. createTime: 1658223413176,
  83. icon: 'R7PTZK233714.png',
  84. x: info2d.pos.x,
  85. y: info2d.pos.y,
  86. position: info3d.position,
  87. media: { link: [{ src: 'https://test.4dkankan.com/#/scene' }] },
  88. type: 'link',
  89. title: '链接热点',
  90. content: '',
  91. sid: Date.now().toString(),
  92. visible: info2d.trueSide,
  93. __temp: true,
  94. }
  95. let index = tags.value.findIndex(item => item.__temp == true)
  96. if (index != -1) {
  97. tags.value.splice(index, 1)
  98. }
  99. tags.value.push(tag)
  100. }
  101. }
  102. })
  103. })
  104. showFiles.value = false
  105. showToolbar.value = true
  106. }
  107. }
  108. const onAddCancel = () => {
  109. showFiles.value = true
  110. showToolbar.value = false
  111. if (window.kankan) {
  112. if (isEdit.value) {
  113. kankan.TagManager.edit.exit()
  114. } else {
  115. kankan.TagManager.editor.then(editor => editor.exit())
  116. }
  117. } else {
  118. let index = tags.value.findIndex(item => item.__temp == true)
  119. if (index != -1) {
  120. tags.value.splice(index, 1)
  121. }
  122. }
  123. if (tempTag) {
  124. let tag = tags.value.find(item => item.sid == editTag.sid)
  125. tag.x = tempTag.x
  126. tag.y = tempTag.y
  127. tag.visible = tempTag.visible
  128. tag.position = tempTag.position
  129. }
  130. editTag = null
  131. tempTag = null
  132. isEdit.value = false
  133. }
  134. const onAddConfirm = () => {
  135. showFiles.value = true
  136. showToolbar.value = false
  137. if (window.kankan) {
  138. const tag = kankan.TagManager.edit.confirm()
  139. console.log(tag)
  140. if (tag) {
  141. if (!isEdit.value) {
  142. tag.icon = ''
  143. tag.__temp = true
  144. tags.value.push(tag)
  145. }
  146. notify.value = tag
  147. }
  148. // kankan.TagManager.editor.then(editor => {
  149. // var tag = editor.confirm()
  150. // if (tag) {
  151. // tag.icon = ''
  152. // tag.__temp = true
  153. // tags.value.push(tag)
  154. // notify.value = tag
  155. // isEdit.value = true
  156. // }
  157. // })
  158. } else {
  159. let tag = tags.value.find(item => item.__temp == true)
  160. if (tag) {
  161. delete tag.__temp
  162. }
  163. }
  164. editTag = null
  165. tempTag = null
  166. }
  167. const onOutside = () => {
  168. if (showMoreSid.value) {
  169. showMoreSid.value = ''
  170. }
  171. }
  172. const onShowMore = tag => {
  173. showMoreSid.value = tag.id
  174. }
  175. const onMoreHandler = (type, tag) => {
  176. if (type == 'modify') {
  177. editTag = tags.value.find(item => item.sid == tag.sid)
  178. showFiles.value = false
  179. showToolbar.value = true
  180. isEdit.value = true
  181. // window.kankan.TagManager.editor.then(editor => {
  182. // editor.enter()
  183. // })
  184. window.kankan.TagManager.focusBeforeModify(editTag.sid)
  185. } else if (type == 'delete') {
  186. http.post(`smart-site/marking/del`, {
  187. markingId: tag.id,
  188. }).then(response => {
  189. if (response.success) {
  190. let index = tags.value.findIndex(item => item.sid == tag.sid)
  191. if (index != -1) {
  192. tags.value.splice(index, 1)
  193. }
  194. }
  195. })
  196. }
  197. showMoreSid.value = ''
  198. }
  199. const onTagFocus = tag => {
  200. //tid.
  201. }
  202. watchEffect(() => {
  203. showFiles.value = props.show
  204. })
  205. </script>
  206. <style lang="scss" scoped>
  207. button {
  208. width: 100px;
  209. height: 34px;
  210. border: none;
  211. outline: none;
  212. border-radius: 4px;
  213. font-size: 14px;
  214. background: transparent;
  215. transition: all 0.3s ease;
  216. border: solid 1px rgb(0, 118, 246);
  217. color: rgb(0, 118, 246);
  218. margin: 0;
  219. padding: 0;
  220. &[type='submit'] {
  221. background: rgb(0, 118, 246);
  222. color: #fff;
  223. }
  224. }
  225. .files {
  226. display: flex;
  227. flex-direction: column;
  228. position: absolute;
  229. padding: 10px 0;
  230. top: 57px;
  231. right: 0;
  232. bottom: 0;
  233. width: 240px;
  234. background: rgba(27, 27, 28, 0.8);
  235. z-index: 1000;
  236. .info {
  237. padding: 10px;
  238. div {
  239. font-size: 16px;
  240. font-weight: bold;
  241. color: #999999;
  242. margin-top: 20px;
  243. padding-top: 20px;
  244. border-top: solid 1px rgba(255, 255, 255, 0.16);
  245. span {
  246. color: rgb(0, 118, 246);
  247. font-weight: normal;
  248. }
  249. }
  250. button {
  251. width: 100%;
  252. border: 1px solid rgba(255, 255, 255, 0.4);
  253. color: rgba(255, 255, 255, 0.4);
  254. &:hover {
  255. border-color: #fff;
  256. color: #fff;
  257. }
  258. }
  259. }
  260. .list {
  261. flex: 1;
  262. }
  263. .exit {
  264. padding: 0 10px;
  265. button {
  266. width: 100%;
  267. border: 1px solid rgba(255, 255, 255, 0.4);
  268. color: rgba(255, 255, 255, 0.4);
  269. &:hover {
  270. border-color: #fff;
  271. color: #fff;
  272. }
  273. }
  274. }
  275. .add {
  276. padding-bottom: 20px;
  277. border-bottom: solid 1px rgba(255, 255, 255, 0.16);
  278. button {
  279. width: 100%;
  280. border: 1px solid rgba(255, 255, 255, 0.4);
  281. color: rgba(255, 255, 255, 0.4);
  282. &:hover {
  283. border-color: #fff;
  284. color: #fff;
  285. }
  286. }
  287. }
  288. }
  289. .toolbar {
  290. position: absolute;
  291. bottom: 0;
  292. left: 0;
  293. right: 0;
  294. height: 60px;
  295. display: flex;
  296. align-items: center;
  297. justify-content: center;
  298. flex: 1;
  299. background-color: rgba(27, 27, 28, 0.8);
  300. pointer-events: all;
  301. z-index: 1000;
  302. transition: all 0.3s ease;
  303. button {
  304. width: 160px;
  305. margin: 0 10px;
  306. }
  307. }
  308. li {
  309. cursor: pointer;
  310. height: 44px;
  311. padding: 10px;
  312. list-style: none;
  313. display: flex;
  314. align-items: center;
  315. justify-content: space-between;
  316. font-size: 14px;
  317. &.active {
  318. background-color: rgba(0, 118, 246, 0.1);
  319. }
  320. .title {
  321. }
  322. .more {
  323. position: relative;
  324. cursor: pointer;
  325. width: 30px;
  326. height: 30px;
  327. display: flex;
  328. align-items: center;
  329. justify-content: center;
  330. &.active {
  331. > div {
  332. display: block;
  333. }
  334. }
  335. i {
  336. font-size: 14px;
  337. }
  338. > div {
  339. min-width: 82px;
  340. background: #222121;
  341. border-radius: 4px;
  342. border: 1px solid #000;
  343. backdrop-filter: blur(4px);
  344. position: absolute;
  345. right: 6px;
  346. top: 26px;
  347. z-index: 100;
  348. div {
  349. text-align: center;
  350. height: 32px;
  351. line-height: 32px;
  352. &:hover {
  353. background-color: rgb(0, 118, 246, 0.1);
  354. }
  355. }
  356. }
  357. }
  358. &:hover {
  359. background-color: rgb(0, 118, 246, 0.1);
  360. }
  361. }
  362. .slide-right-enter-active,
  363. .slide-right-leave-active {
  364. will-change: transform;
  365. transition: all 0.2s ease-in-out;
  366. }
  367. .slide-right-enter-from {
  368. opacity: 0;
  369. transform: translate3d(100%, 0, 0);
  370. }
  371. .slide-right-enter {
  372. opacity: 1;
  373. transform: translate3d(-100%, 0, 0);
  374. }
  375. .slide-right-leave-active {
  376. opacity: 0;
  377. transform: translate3d(100%, 0, 0);
  378. }
  379. .slide-up-enter-active,
  380. .slide-up-leave-active {
  381. will-change: transform;
  382. transition: all 0.2s ease-in-out;
  383. }
  384. .slide-up-enter-from {
  385. opacity: 0;
  386. transform: translate3d(0, 100%, 0);
  387. }
  388. .slide-up-enter {
  389. opacity: 1;
  390. transform: translate3d(0, -100%, 0);
  391. }
  392. .slide-up-leave-active {
  393. opacity: 0;
  394. transform: translate3d(0, 100%, 0);
  395. }
  396. </style>