chat-drawer.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <view class="drawer-content">
  3. <!--右抽屉-->
  4. <tui-drawer mode="right" :visible="rightDrawer" @close="closeDrawer">
  5. <view class="drawer-container clearfix" scroll-y :style="{
  6. paddingTop: CustomBar + StatusBar/2 + 'px',
  7. paddingBottom: isIphoneX ? '180rpx' : '146rpx'
  8. }">
  9. <scroll-view class="tui-drawer-scroll" scroll-y :style="{ height: drawerH + 'px' }">
  10. <view class="cm_ai_container_records">
  11. <view class="cm_ai_records_btn">
  12. <view class="records_btn" :class="disabled ? 'disabled' : 'show'"
  13. @click="handleCreatedChat">
  14. <text class="iconfont icon-jiahao"></text>
  15. <text>新建对话</text>
  16. </view>
  17. </view>
  18. <view class="cm_ai_records_list">
  19. <view class="cm_ai_records_item" v-for="(chat, index) in chatHistory" :key="index"
  20. @click="handleChatDetail(chat.id)">
  21. <text class="content" v-text="chat.firstQuestion"></text>
  22. <text class="time" v-text="chat.addTime"></text>
  23. </view>
  24. </view>
  25. </view>
  26. </scroll-view>
  27. <view class="drawer-input btn" :style="{ paddingBottom: isIphoneX ? '68rpx' : '34rpx' }">
  28. <view class="drawer-btn clear" @click="closeDrawer">
  29. <text class="iconfont icon-iconfontguanbi"></text>
  30. </view>
  31. </view>
  32. </view>
  33. </tui-drawer>
  34. </view>
  35. </template>
  36. <script>
  37. import { mapState, mapMutations } from 'vuex'
  38. export default {
  39. name: 'rightDrawer',
  40. props: {
  41. rightDrawer: {
  42. type: Boolean,
  43. default: false
  44. },
  45. probeIndex: {
  46. type: Number
  47. }
  48. },
  49. data() {
  50. return {
  51. CustomBar: this.CustomBar, // 顶部导航栏高度
  52. StatusBar: this.StatusBar,
  53. isIphoneX: this.$store.state.isIphoneX,
  54. height: 0,
  55. drawerH: 0, // 抽屉内部scrollview高度
  56. chatHistory: [],
  57. chatHistoryParams: {
  58. userId: '',
  59. pageNum: 1,
  60. pageSize: 10
  61. },
  62. }
  63. },
  64. created() {
  65. this.setScrollHeight()
  66. this.userNewChatHistory()
  67. },
  68. computed: {
  69. disabled() {
  70. return !this.probeIndex
  71. }
  72. },
  73. methods: {
  74. async userNewChatHistory() {
  75. //获取组员协销列表
  76. try {
  77. const userInfo = await this.$api.getStorage()
  78. this.chatHistoryParams.userId = userInfo.userId
  79. const res = await this.UserService.userNewChatHistory(this.chatHistoryParams)
  80. this.chatHistory = res.data
  81. } catch (e) {
  82. console.log('=========>获取AI记录异常')
  83. }
  84. },
  85. //新建对话
  86. handleCreatedChat(){
  87. this.$emit('chat-news')
  88. this.$parent.rightDrawer = false
  89. },
  90. // 查看记录
  91. handleChatDetail(chatId) {
  92. this.$emit('chat-detail', chatId)
  93. this.$parent.rightDrawer = false
  94. },
  95. closeDrawer() {
  96. this.$parent.rightDrawer = false
  97. },
  98. setScrollHeight() {
  99. let obj = {}
  100. const { windowHeight, pixelRatio } = wx.getSystemInfoSync()
  101. uni.getSystemInfo({
  102. success: res => {
  103. this.height = obj.top ? obj.top + obj.height + 8 : res.statusBarHeight + 44
  104. this.drawerH = res.windowHeight - uni.upx2px(180) - this.height
  105. }
  106. })
  107. this.windowHeight = windowHeight - 1
  108. this.scrollHeight = windowHeight - 1
  109. }
  110. }
  111. }
  112. </script>
  113. <style lang="scss">
  114. /*screen*/
  115. .drawer-container {
  116. width: 580rpx;
  117. height: 100%;
  118. padding: 80rpx 0;
  119. overflow: hidden;
  120. box-sizing: border-box;
  121. background-image: linear-gradient(180deg, #f0edf7 .03%, #ebeaf5 32.19%, #e8e8f3 68.86%, #e4eaf7 99.12%);
  122. .cm_ai_container_records {
  123. width: 100%;
  124. height: 100%;
  125. display: flex;
  126. flex-direction: column;
  127. box-sizing: border-box;
  128. padding: 0 40rpx;
  129. flex: 0 0 auto;
  130. .cm_ai_records_btn {
  131. padding: 0 50rpx;
  132. margin-bottom: 12px;
  133. box-sizing: border-box;
  134. display: flex;
  135. justify-content: center;
  136. .records_btn {
  137. width: 100%;
  138. height: 80rpx;
  139. line-height: 80rpx;
  140. flex-shrink: 0;
  141. box-sizing: border-box;
  142. background-color: rgba(255, 91, 0, 0.05);
  143. text-align: center;
  144. border-radius: 16rpx;
  145. display: flex;
  146. justify-content: center;
  147. color: #ff5b00 !important;
  148. opacity: 1;
  149. &.disabled {
  150. opacity: 0.7;
  151. }
  152. &.show:hover {
  153. background-color: rgba(255, 91, 0, 0.1);
  154. }
  155. }
  156. }
  157. .cm_ai_records_list {
  158. flex: 1;
  159. display: flex;
  160. flex-direction: column;
  161. overflow: hidden;
  162. .cm_ai_records_item {
  163. display: flex;
  164. align-items: flex-start;
  165. height: 88rpx;
  166. box-sizing: border-box;
  167. flex-direction: row;
  168. justify-content: space-between;
  169. padding: 0 24rpx;
  170. border-radius: 16rpx;
  171. background-color: rgba(255,255,255,0.2);
  172. margin: 10rpx 0;
  173. .content {
  174. width: 200rpx;
  175. font-size: 30rpx;
  176. font-weight: 500;
  177. line-height: 88rpx;
  178. color: #50525c;
  179. display: -webkit-box;
  180. text-overflow: ellipsis;
  181. overflow: hidden;
  182. word-break: break-all;
  183. -webkit-line-clamp: 1;
  184. -webkit-box-orient: vertical;
  185. }
  186. .time {
  187. font-size: 24rpx;
  188. font-weight: 400;
  189. line-height: 88rpx;
  190. color: #848691;
  191. }
  192. }
  193. }
  194. }
  195. .drawer-input {
  196. width: 100%;
  197. float: left;
  198. box-sizing: border-box;
  199. padding: 24rpx 50rpx 0 50rpx;
  200. border: 1px solid rgba(0, 0, 0, 0.2);
  201. border-radius: 4rpx;
  202. position: relative;
  203. &.btn {
  204. border: none;
  205. display: flex;
  206. position: fixed;
  207. left: 0;
  208. bottom: 0;
  209. }
  210. .drawer-btn {
  211. width: 84rpx;
  212. height: 84rpx;
  213. border-radius: 42rpx;
  214. line-height: 84rpx;
  215. text-align: center;
  216. margin: 0 auto;
  217. background-color: rgba(255,255,255,0.4);
  218. .icon-iconfontguanbi{
  219. font-size: $font-size-48;
  220. color: #999999;
  221. }
  222. }
  223. }
  224. }
  225. </style>