Comment.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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. line-height: 34px;
  269. padding: 0 5px;
  270. color: #fff;
  271. }
  272. .maxlength {
  273. position: absolute;
  274. right: 0;
  275. top: 50%;
  276. transform: translateY(-50%);
  277. white-space: nowrap;
  278. margin-top: 2px;
  279. margin-right: 0px;
  280. color: #999;
  281. span {
  282. color: #0076f6;
  283. }
  284. }
  285. }
  286. .send-btn {
  287. width: 60px;
  288. height: 34px;
  289. background: #0076f6;
  290. border-radius: 4px;
  291. opacity: 1;
  292. text-align: center;
  293. line-height: 34px;
  294. cursor: pointer;
  295. }
  296. }
  297. .empty-box {
  298. display: flex;
  299. align-items: center;
  300. justify-content: center;
  301. flex-flow: column;
  302. position: absolute;
  303. top: 50%;
  304. left: 50%;
  305. transform: translate(-50%, -50%);
  306. .pic {
  307. width: 134px;
  308. height: 134px;
  309. background: url('~@/assets/img/pic_bg.png') no-repeat;
  310. background-size: 100% 100%;
  311. }
  312. div {
  313. margin-top: 5px;
  314. color: #999;
  315. }
  316. }
  317. .comment-content {
  318. // height: calc(100% - 54px);
  319. overflow-y: auto;
  320. padding: 0 20px 0 0;
  321. position: relative;
  322. .comment-header {
  323. font-size: 16px;
  324. font-weight: bold;
  325. color: #999;
  326. }
  327. .comment-msg {
  328. .comment-item {
  329. display: flex;
  330. align-items: flex-start;
  331. justify-content: flex-start;
  332. margin-top: 14px;
  333. .avatar-box {
  334. width: 24px;
  335. height: 24px;
  336. border-radius: 50%;
  337. margin-right: 6px;
  338. background-size: 100% 100%;
  339. background-repeat: no-repeat;
  340. }
  341. .comment-box {
  342. flex: 1;
  343. > div.view-box {
  344. display: flex;
  345. align-items: center;
  346. justify-content: space-between;
  347. }
  348. .view-top {
  349. .user-name {
  350. font-size: 14px;
  351. color: #999;
  352. }
  353. .iconfont {
  354. color: #999;
  355. font-size: 1em;
  356. cursor: pointer;
  357. }
  358. }
  359. .view-middle {
  360. .comment-text {
  361. word-break: break-all;
  362. font-size: 14px;
  363. color: #fff;
  364. }
  365. }
  366. .view-bottom {
  367. font-size: 12px;
  368. .comment-time {
  369. color: #999;
  370. }
  371. .reply-btn {
  372. color: #0076f6;
  373. cursor: pointer;
  374. }
  375. }
  376. .reply-content {
  377. .reply-item {
  378. display: flex;
  379. align-items: flex-start;
  380. justify-content: flex-start;
  381. margin-top: 14px;
  382. width: 100%;
  383. .avatar-box {
  384. width: 24px;
  385. height: 24px;
  386. border-radius: 50%;
  387. margin-right: 6px;
  388. background-size: 100% 100%;
  389. background-repeat: no-repeat;
  390. }
  391. .reply-box {
  392. flex: 1;
  393. > div {
  394. display: flex;
  395. align-items: center;
  396. justify-content: space-between;
  397. }
  398. .view-top {
  399. .user-name {
  400. font-size: 14px;
  401. color: #999;
  402. }
  403. .iconfont {
  404. color: #999;
  405. font-size: 1em;
  406. cursor: pointer;
  407. }
  408. }
  409. .view-middle {
  410. .reply-text {
  411. font-size: 14px;
  412. color: #fff;
  413. word-break: break-all;
  414. .reply-tips {
  415. color: #0076f6;
  416. margin: 0 2px;
  417. }
  418. }
  419. }
  420. .view-bottom {
  421. font-size: 12px;
  422. .reply-time {
  423. color: #999;
  424. }
  425. .reply-btn {
  426. color: #0076f6;
  427. cursor: pointer;
  428. }
  429. }
  430. }
  431. }
  432. }
  433. }
  434. }
  435. }
  436. }
  437. }
  438. }
  439. </style>