pc.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <div id="emojiList" class="emoji-list pub-scroll-box">
  3. <p class="title" v-if="recentList.length">最近使用</p>
  4. <ul v-if="recentList.length">
  5. <li v-for="(item, key) in recentList"
  6. :key="key"
  7. v-html="item"
  8. @click="handleClick(item.names, $event)"></li>
  9. </ul>
  10. <div v-for="(arr, key) in emojiList" :key="key">
  11. <p class="title">{{key}}</p>
  12. <ul>
  13. <li v-for="(item, ind) in arr"
  14. :key="ind"
  15. v-html="item.surrogates"
  16. @click="handleClick(item.names, $event)"></li>
  17. </ul>
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. import { emojiList } from '@/util/emoji'
  23. export default {
  24. name: 'emojiList',
  25. data () {
  26. return {
  27. emojiList,
  28. recentList: []
  29. }
  30. },
  31. mounted () {
  32. this.recentList = JSON.parse(localStorage.getItem('recentEmoji')) || []
  33. },
  34. methods: {
  35. handleClick (name, event) {
  36. let val = event.target.innerHTML
  37. this.$emit('addEmoji', JSON.stringify(name))
  38. if (this.recentList.length > 11) {
  39. this.recentList.pop()
  40. }
  41. if (this.recentList.includes(val)) {
  42. let ind = this.recentList.indexOf(val)
  43. this.recentList.splice(ind, 1)
  44. }
  45. this.recentList.unshift(val)
  46. localStorage.setItem('recentEmoji', JSON.stringify(this.recentList))
  47. }
  48. }
  49. }
  50. </script>
  51. <style lang="scss" scoped>
  52. .emoji-list {
  53. position: absolute;
  54. border-radius: 4px;
  55. border: 1px solid #d6d6d6;
  56. left: 4px;
  57. height: 240px;
  58. top: -248px;
  59. overflow: auto;
  60. background-color: #ffffff;
  61. width: 488px;
  62. overflow: auto;
  63. .title{
  64. font-size: 12px;
  65. padding: 0 14px;
  66. height: 30px;
  67. line-height: 30px;
  68. color: #999999;
  69. }
  70. }
  71. .emoji-list * {
  72. -webkit-user-select: none;
  73. -moz-user-select: none;
  74. -ms-user-select: none;
  75. user-select: none;
  76. }
  77. .emoji-list li {
  78. font-size: 28px;
  79. border-radius: 4px;
  80. display: inline-block;
  81. padding: 6px;
  82. cursor: pointer;
  83. &:hover{
  84. background: #eeeeee;
  85. }
  86. }
  87. img.emoji {
  88. cursor: pointer;
  89. height: 1em;
  90. width: 1em;
  91. margin: 0 .05em 0 .1em;
  92. vertical-align: -0.1em;
  93. }
  94. </style>