index.vue 13 KB

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