navbar.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <view class="h100 relative">
  3. <view class="nav h100 relative" :style="{width: barActive ? '520rpx': '0px'}">
  4. <view class="fff flex p-10" :style="{visibility: barActive ? 'visible' : 'hidden'}">
  5. <view class="border-info w100 radius p-10 mr-10 flex item-center hover space-nowrap cursor-pointer"
  6. @click="getNewChat">
  7. + New Chat
  8. </view>
  9. <view class="border-info radius p-10 flex item-center hover cursor-pointer" @click="getHidden">
  10. <uni-icons type="bars" size="24" :color="barActive ? '#FFF' : '#000'" />
  11. </view>
  12. </view>
  13. <view class="history-list fff p-10" :style="{visibility: barActive ? 'visible' : 'hidden'}">
  14. <view style="padding: 0 15px 10px; color: #8E8EA0;">History</view>
  15. <view :class="['w100 radius p-15 hover cursor-pointer flex item-center content-between',
  16. index == active ? 'background-color-active' : '' ]" v-for="(item, index) in list" :key="index"
  17. @click="getHistory(index)">
  18. <view>
  19. {{ item.date }}
  20. </view>
  21. <uni-icons v-if="index == active" type="trash" color="#FFF" @click="getDelete(item, index)" />
  22. </view>
  23. </view>
  24. <view class="p-5 absolute b0 w100" style="border-top1px solid #FFF3"
  25. :style="{visibility: barActive ? 'visible' : 'hidden'}">
  26. <view class="flex item-center p-10 gap radius">
  27. <img src="@/static/logo-100.png" width="30" height="30" />
  28. <view class="space-nowrap overflow-ellipsis overflow-hidden grow fff">
  29. {{ usernameSimple || '尚未登录' }}
  30. <view class="fff">
  31. <text>每日免费剩余额度</text>
  32. <text>{{ chatAsset.dfn || 0 }}次</text>
  33. </view>
  34. </view>
  35. <!-- <uni-icons type="more-filled" size="24" color="#FFF" @click="getInfo" /> -->
  36. </view>
  37. </view>
  38. </view>
  39. <view class="cursor-pointer radius p-10 flex item-center hover z-index" style="left: 10px; top: 10px;"
  40. :style="{display: barActive ? 'none' : 'block', 'position': barActive ? 'relative' : 'absolute'}"
  41. @click="getHidden">
  42. <uni-icons type="bars" size="24" :color="barActive ? '#FFF' : '#000'" />
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import {
  48. msgList
  49. } from '@/api/chat.js'
  50. import {
  51. mapGetters
  52. } from 'vuex'
  53. export default {
  54. props: {
  55. chatAsset: {
  56. type: Object,
  57. default: () => {}
  58. }
  59. },
  60. data() {
  61. return {
  62. barActive: uni.getStorageSync("barActive") !== '' ? uni.getStorageSync("barActive") : true,
  63. list: [],
  64. active: -1,
  65. }
  66. },
  67. computed: {
  68. ...mapGetters([
  69. 'usernameSimple'
  70. ])
  71. },
  72. mounted() {
  73. this.getDetail()
  74. },
  75. methods: {
  76. getDetail() {
  77. this.list = []
  78. const dateArr = this.$squni.getStorageSync('chatHistory')
  79. let arr = []
  80. if (dateArr.length > 0) {
  81. dateArr.forEach(i => {
  82. arr[i.date.substr(0, 10)] = arr[i.date.substr(0, 10)] || []
  83. arr[i.date.substr(0, 10)].push(i)
  84. })
  85. for (let key in arr) {
  86. let obj = {}
  87. obj.date = key
  88. obj.children = arr[key]
  89. this.list.unshift(obj)
  90. }
  91. }
  92. },
  93. getHidden() {
  94. uni.setStorageSync("barActive", this.barActive = this.barActive ? false : true)
  95. },
  96. getNewChat() {
  97. this.active = -1
  98. msgList().then(res => {
  99. if (res.code === 20000) {
  100. this.$emit('click', res.data)
  101. }
  102. })
  103. },
  104. getHistory(e) {
  105. this.active = e
  106. this.$emit('history', this.list[e])
  107. this.getDetail()
  108. },
  109. // 删除历史记录
  110. getDelete(item, index) {
  111. this.list.splice(index, 1)
  112. let storage = this.$squni.getStorageSync('chatHistory').filter(i => i.date.substr(0, 10) !== item.date)
  113. this.$squni.setStorageSync('chatHistory', storage)
  114. this.$emit('delete')
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. .nav {
  121. background-color: #202123;
  122. transition: width 0.2s;
  123. }
  124. .history-list {
  125. height: calc(100% - 130px);
  126. overflow-y: auto;
  127. }
  128. </style>