Comment.vue 18 KB

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