navbar.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. dateArr.forEach(i => {
  81. arr[i.date.substr(0, 10)] = arr[i.date.substr(0, 10)] || []
  82. arr[i.date.substr(0, 10)].push(i)
  83. })
  84. for (let key in arr) {
  85. let obj = {}
  86. obj.date = key
  87. obj.children = arr[key]
  88. this.list.unshift(obj)
  89. }
  90. },
  91. getHidden() {
  92. uni.setStorageSync("barActive", this.barActive = this.barActive ? false : true)
  93. },
  94. getNewChat() {
  95. this.active = -1
  96. msgList().then(res => {
  97. if (res.code === 20000) {
  98. this.$emit('click', res.data)
  99. }
  100. })
  101. },
  102. getHistory(e) {
  103. this.active = e
  104. this.$emit('history', this.list[e])
  105. this.getDetail()
  106. },
  107. // 删除历史记录
  108. getDelete(item, index) {
  109. this.list.splice(index, 1)
  110. let storage = this.$squni.getStorageSync('chatHistory').filter(i => i.date.substr(0, 10) !== item.date)
  111. this.$squni.setStorageSync('chatHistory', storage)
  112. this.$emit('delete')
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="scss" scoped>
  118. .nav {
  119. background-color: #202123;
  120. transition: width 0.2s;
  121. }
  122. .history-list{
  123. height: calc(100% - 130px);
  124. overflow-y: auto;
  125. }
  126. </style>