Comment.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <!-- -->
  2. <template>
  3. <div class="aside-item right-item">
  4. <div class="comment-content" ref="slider" v-if="slideHeigt" :style="`height:${slideHeigt - 84}px;`">
  5. <div class="comment-header">
  6. <span>{{ $t('tag.comment') }}</span>
  7. </div>
  8. <div class="comment-msg">
  9. <div class="comment-item" v-for="(i, index) in commentList">
  10. <div class="avatar-box" :style="i.head ? `background-image:url(${i.head});` : `background-image:url(${emptyAvatar});`"></div>
  11. <div class="comment-box">
  12. <div class="view-box view-top">
  13. <span class="user-name">{{ i.nickName || $t('tag.unkownUser') }}</span>
  14. <i class="iconfont icon-del" v-if="i.userId == userId" @click="delComment({ commentId: i.commentId, index })"></i>
  15. </div>
  16. <div class="view-box view-middle">
  17. <span class="comment-text">{{ i.content }}</span>
  18. </div>
  19. <div class="view-box view-bottom">
  20. <span class="comment-time">{{ i.createTime }}</span>
  21. <span class="reply-btn" @click="handlerReply({ parentId: i.commentId, nickName: i.nickName }, index)">{{ $t('tag.reply') }}</span>
  22. </div>
  23. <div class="reply-content" v-if="i.children">
  24. <div class="reply-item" v-for="(j, j_index) in i.children">
  25. <div class="avatar-box" :style="j.head ? `background-image:url(${j.head});` : `background-image:url(${emptyAvatar});`"></div>
  26. <div class="reply-box">
  27. <div class="view-box view-top">
  28. <span class="user-name">{{ j.nickName || $t('tag.unkownUser') }}</span>
  29. <i class="iconfont icon-del" v-if="j.userId == userId" @click="delComment({ commentId: j.commentId, index: j_index, parentIndex: index })"></i>
  30. </div>
  31. <div class="view-box view-middle">
  32. <span class="reply-text"
  33. ><span v-if="j.replyId"
  34. >{{ $t('tag.reply') }}<span class="reply-tips">@{{ j.replyNickName || $t('tag.unkownUser') }}</span></span
  35. >
  36. {{ j.content }}</span
  37. >
  38. </div>
  39. <div class="view-box view-bottom">
  40. <span class="reply-time">{{ j.createTime }}</span>
  41. <span class="reply-btn" @click="handlerReply({ parentId: i.commentId, replyId: j.commentId, parentUserId: j.userId, nickName: j.nickName }, j_index)">{{
  42. $t('tag.reply')
  43. }}</span>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. <div class="empty-box" v-if="!commentList.length">
  52. <div class="pic"></div>
  53. <div>{{ $t('tag.noComment') }}</div>
  54. </div>
  55. </div>
  56. <div class="input-content">
  57. <div class="input-box"><input ref="input$" @input="handlerInput" v-model="inputText" :placeholder="placeholderText" type="text" /></div>
  58. <div class="send-btn" @click="hanlderSubmit">{{ $t('common.publish') }}</div>
  59. </div>
  60. </div>
  61. <Toast v-if="showTips" :type="tipsType" :content="showTips" :close="() => (showTips = null)" />
  62. <ui-confirm v-if="delComfirm" :title="$t('common.tips')" :noText="$t('common.cancel')" :okText="$t('common.confirm')" @ok="handlerDel" @no="handlerDel">
  63. <template #content>
  64. <div>{{ $t('tag.deletetCommentTips') }}</div>
  65. </template>
  66. </ui-confirm>
  67. </template>
  68. <script setup>
  69. import { ref, onMounted, onBeforeUnmount, computed, inject, nextTick, defineProps } from 'vue'
  70. import Toast from '@/components/dialog/Toast'
  71. import { http } from '@/utils/request'
  72. import avatar from '@/assets/img/avatar@2x.png'
  73. import UiConfirm from '@/components/dialog/Confirm.vue'
  74. import i18n from '@/i18n'
  75. const { t } = i18n.global
  76. const props = defineProps({
  77. slideHeigt: Number,
  78. })
  79. let canPut = true
  80. const delComfirm = ref(null)
  81. const emptyAvatar = ref(avatar)
  82. const notify = inject('notify')
  83. const emits = defineEmits(['action'])
  84. const input$ = ref(null)
  85. const inputText = ref('')
  86. const placeholderText = ref(t('tag.addComment'))
  87. const replyInfo = ref(null)
  88. const tipsType = ref('warn')
  89. const showTips = ref(null)
  90. const slider = ref(null)
  91. const handlerReply = (data, index) => {
  92. inputText.value = ''
  93. let name = data.nickName ? data.nickName : t('tag.unkownUser')
  94. placeholderText.value = '@' + name
  95. delete data.nickName
  96. replyInfo.value = data
  97. }
  98. const handlerInput = () => {
  99. // console.log(inputText.value.length)
  100. // if (replyInfo.value && inputText.value.length) {
  101. // // console.log(1)
  102. // }
  103. }
  104. let parentId = null
  105. let commentId = null
  106. const userId = ref(localStorage.getItem('userId') - 0)
  107. const commentList = ref([])
  108. const hanlderSubmit = () => {
  109. if (inputText.value == '') {
  110. tipsType.value = 'warn'
  111. showTips.value = t('tag.addCommentTips')
  112. return
  113. }
  114. let params = {
  115. markingId: notify.value.id,
  116. content: inputText.value,
  117. userId: userId.value,
  118. parentId: parentId,
  119. }
  120. if (replyInfo.value) {
  121. for (let key in replyInfo.value) {
  122. if (replyInfo.value[key]) {
  123. params[key] = replyInfo.value[key]
  124. }
  125. }
  126. }
  127. if (canPut) {
  128. canPut = false
  129. http.post(`smart-site/comment/reply`, params)
  130. .then(response => {
  131. if (response.success) {
  132. getAllComments()
  133. // if (replyInfo.value) {
  134. // } else {
  135. // // slider.value.
  136. // slider.value.scrollTo({
  137. // top: 0,
  138. // behavior: 'smooth',
  139. // })
  140. // }
  141. replyInfo.value = null
  142. inputText.value = ''
  143. placeholderText.value = t('tag.addComment')
  144. } else {
  145. tipsType.value = 'error'
  146. showTips.value = response.message
  147. }
  148. canPut = true
  149. })
  150. .catch(err => {
  151. canPut = true
  152. })
  153. }
  154. }
  155. const onClose = () => {
  156. if (window.kankan) {
  157. if (notify.value.__temp) {
  158. kankan.TagManager.remove(notify.value.sid)
  159. }
  160. } else {
  161. }
  162. notify.value = null
  163. }
  164. const getAllComments = () => {
  165. http.post(`smart-site/comment/tree/all`, { markingId: notify.value.id }).then(response => {
  166. if (response.success) {
  167. commentList.value = response.data
  168. } else {
  169. }
  170. })
  171. }
  172. const handlerDel = status => {
  173. if (status == 'ok') {
  174. http.post(`smart-site/comment/del`, { commentId: delComfirm.value.commentId }).then(response => {
  175. if (response.success) {
  176. // if (!delComfirm.value.parentIndex) {
  177. // commentList.value.splice(delComfirm.value.index, 1)
  178. // } else {
  179. // commentList.value[delComfirm.value.parentIndex].children.splice(delComfirm.value.index, 1)
  180. // }
  181. getAllComments()
  182. if (replyInfo.value?.parentId == delComfirm.value.commentId) {
  183. replyInfo.value = null
  184. inputText.value = ''
  185. placeholderText.value = t('tag.addComment')
  186. }
  187. tipsType.value = 'success'
  188. showTips.value = t('common.deleteSuccess')
  189. } else {
  190. tipsType.value = 'error'
  191. showTips.value = response.message
  192. }
  193. delComfirm.value = null
  194. })
  195. } else {
  196. delComfirm.value = null
  197. }
  198. }
  199. const delComment = data => {
  200. delComfirm.value = data
  201. }
  202. onMounted(() => {
  203. getAllComments()
  204. if (window.kankan) {
  205. window.kankan.TagManager.focusTag(notify.value.sid, {
  206. direction: 'left',
  207. attrs: {
  208. width: 0,
  209. // height: 400,
  210. },
  211. })
  212. } else if (window.laser) {
  213. window.laser.then(sdk => {
  214. let pos = notify.value.position
  215. sdk.scene.comeToTag(new THREE.Vector3(pos.x, pos.y, pos.z))
  216. })
  217. }
  218. nextTick(() => {
  219. input$.value.addEventListener('keydown', function (e) {
  220. if (e.keyCode == 8) {
  221. if (replyInfo.value && !inputText.value.length) {
  222. replyInfo.value = null
  223. placeholderText.value = t('tag.addComment')
  224. }
  225. }
  226. })
  227. })
  228. })
  229. onBeforeUnmount(() => {})
  230. </script>
  231. <style lang="scss" scoped>
  232. .aside-item {
  233. padding: 20px 0 20px 20px;
  234. box-sizing: border-box;
  235. line-height: 28px;
  236. flex: 1;
  237. &.right-item {
  238. position: relative;
  239. .input-content {
  240. width: 100%;
  241. height: 34px;
  242. margin: 20px 0;
  243. padding: 0 20px;
  244. position: absolute;
  245. bottom: 0;
  246. left: 0;
  247. display: flex;
  248. align-items: center;
  249. justify-content: space-between;
  250. .input-box {
  251. width: 226px;
  252. height: 34px;
  253. background: rgba(255, 255, 255, 0.1);
  254. border-radius: 4px;
  255. opacity: 1;
  256. border: 1px solid rgba(255, 255, 255, 0.2);
  257. input {
  258. line-height: 34px;
  259. padding: 0 10px;
  260. color: #fff;
  261. }
  262. }
  263. .send-btn {
  264. width: 60px;
  265. height: 34px;
  266. background: #0076f6;
  267. border-radius: 4px;
  268. opacity: 1;
  269. text-align: center;
  270. line-height: 34px;
  271. cursor: pointer;
  272. }
  273. }
  274. .empty-box {
  275. display: flex;
  276. align-items: center;
  277. justify-content: center;
  278. flex-flow: column;
  279. position: absolute;
  280. top: 50%;
  281. left: 50%;
  282. transform: translate(-50%, -50%);
  283. .pic {
  284. width: 134px;
  285. height: 134px;
  286. background: url('~@/assets/img/pic_bg.png') no-repeat;
  287. background-size: 100% 100%;
  288. }
  289. div {
  290. margin-top: 5px;
  291. color: #999;
  292. }
  293. }
  294. .comment-content {
  295. // height: calc(100% - 54px);
  296. overflow-y: auto;
  297. padding: 0 20px 0 0;
  298. position: relative;
  299. .comment-header {
  300. font-size: 16px;
  301. font-weight: bold;
  302. color: #999;
  303. }
  304. .comment-msg {
  305. .comment-item {
  306. display: flex;
  307. align-items: flex-start;
  308. justify-content: flex-start;
  309. margin-top: 14px;
  310. .avatar-box {
  311. width: 24px;
  312. height: 24px;
  313. border-radius: 50%;
  314. margin-right: 6px;
  315. background-size: 100% 100%;
  316. background-repeat: no-repeat;
  317. }
  318. .comment-box {
  319. flex: 1;
  320. > div.view-box {
  321. display: flex;
  322. align-items: center;
  323. justify-content: space-between;
  324. }
  325. .view-top {
  326. .user-name {
  327. font-size: 14px;
  328. color: #999;
  329. }
  330. .iconfont {
  331. color: #999;
  332. font-size: 1em;
  333. cursor: pointer;
  334. }
  335. }
  336. .view-middle {
  337. .comment-text {
  338. font-size: 14px;
  339. color: #fff;
  340. }
  341. }
  342. .view-bottom {
  343. font-size: 12px;
  344. .comment-time {
  345. color: #999;
  346. }
  347. .reply-btn {
  348. color: #0076f6;
  349. cursor: pointer;
  350. }
  351. }
  352. .reply-content {
  353. .reply-item {
  354. display: flex;
  355. align-items: flex-start;
  356. justify-content: flex-start;
  357. margin-top: 14px;
  358. width: 100%;
  359. .avatar-box {
  360. width: 24px;
  361. height: 24px;
  362. border-radius: 50%;
  363. margin-right: 6px;
  364. background-size: 100% 100%;
  365. background-repeat: no-repeat;
  366. }
  367. .reply-box {
  368. flex: 1;
  369. > div {
  370. display: flex;
  371. align-items: center;
  372. justify-content: space-between;
  373. }
  374. .view-top {
  375. .user-name {
  376. font-size: 14px;
  377. color: #999;
  378. }
  379. .iconfont {
  380. color: #999;
  381. font-size: 1em;
  382. cursor: pointer;
  383. }
  384. }
  385. .view-middle {
  386. .reply-text {
  387. font-size: 14px;
  388. color: #fff;
  389. .reply-tips {
  390. color: #0076f6;
  391. margin: 0 2px;
  392. }
  393. }
  394. }
  395. .view-bottom {
  396. font-size: 12px;
  397. .reply-time {
  398. color: #999;
  399. }
  400. .reply-btn {
  401. color: #0076f6;
  402. cursor: pointer;
  403. }
  404. }
  405. }
  406. }
  407. }
  408. }
  409. }
  410. }
  411. }
  412. }
  413. }
  414. </style>