index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <div class="intelligentQA">
  3. <div class="history">
  4. <div class="historyTitle">历史记录</div>
  5. <div class="historyContent">
  6. <div v-for="item in historyData" :key="item.id" class="historyItem">
  7. <span style="float: left"> {{ item.question }}</span>
  8. <i class="el-icon-more historyMore" @click="historyDetail(item.id)"></i>
  9. </div>
  10. </div>
  11. </div>
  12. <div class="chat">
  13. <!-- <div class="header">Header</div> -->
  14. <div ref="main" class="main">
  15. <div class="chatLine">
  16. <div v-for="(item, index) in chatInfo" :key="index">
  17. <div class="chatRow chatQ" v-if="item.question">
  18. <div class="questionContent">{{ item.question }}</div>
  19. </div>
  20. <div class="chatRow" v-if="item.answer">
  21. <div class="answerData">
  22. <div class="answer">{{ item.answer }}</div>
  23. <!-- <div class="graph"></div> -->
  24. <graphECharts v-if="item.graph" :graphData="item.graph" class="charts"></graphECharts>
  25. <i v-if="item.answer" class="el-icon-more more" @click="handleMore(item)"></i>
  26. </div>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. <div class="footer">
  32. <div class="footerContent">
  33. <textarea v-model="questionInput" :style="{ height: `${currentHeight}px`, overflowY: isScrollable ? 'auto' : 'hidden' }" placeholder="请输入您的问题..." @keydown="handleKeydown"> </textarea>
  34. <i class="el-icon-s-promotion icon" @click="sendQuestion"></i>
  35. </div>
  36. </div>
  37. </div>
  38. <div class="statistics">
  39. <div class="statisticsTitle">统计列表</div>
  40. </div>
  41. <el-dialog title="更多" :visible.sync="dialogVisible" width="1500px" :before-close="handleClose">
  42. <div class="dialogContent">
  43. <div class="contentLeft">
  44. <div>
  45. <div class="moreAnswer">{{ moreData.answer }}</div>
  46. <graphECharts :graphData="moreData.graph"></graphECharts>
  47. </div>
  48. </div>
  49. <div class="contentRight">
  50. <div>
  51. <div class="source">
  52. <el-link :href="`${fileInfo.url}`" style="color: #209cc1" :underline="false" target="_blank">
  53. <el-tooltip class="item" effect="dark" content="点击可下载" placement="top">
  54. <span> 来源:《{{ moreData.file_name }}{{ moreData.fileName }}》</span>
  55. </el-tooltip>
  56. </el-link>
  57. </div>
  58. <div class="fileContent">
  59. <div v-if="fileInfo.fileSuffix == '.docx' || fileInfo.fileSuffix == '.doc'">
  60. <VueOfficeDocx style="width: 100%; height: calc(100vh - 400px)" :src="fileInfo.url" />
  61. </div>
  62. <div v-if="fileInfo.fileSuffix == '.pdf'">
  63. <VueOfficePdf style="width: 100%; height: calc(100vh - 400px)" :src="fileInfo.url" />
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. <!-- <span slot="footer" class="dialog-footer">
  70. <el-button @click="dialogVisible = false">取 消</el-button>
  71. <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  72. </span> -->
  73. </el-dialog>
  74. </div>
  75. </template>
  76. <script>
  77. import store from '@/store'
  78. import { handlerAsk, getQAHistoryList, getQAHistoryDetail } from '@/api/als/intelligentQA'
  79. import graphECharts from '@/views/als/components/Charts/graph.vue'
  80. import axios from 'axios'
  81. import { getListByIdsApi } from '@/api/als/oss'
  82. //引入VueOfficeDocx组件
  83. import VueOfficeDocx from '@vue-office/docx'
  84. import VueOfficePdf from '@vue-office/pdf'
  85. import '@vue-office/docx/lib/index.css'
  86. export default {
  87. name: 'IntelligentQA',
  88. components: { graphECharts, VueOfficeDocx, VueOfficePdf },
  89. data() {
  90. return {
  91. dialogVisible: false,
  92. chatInfo: [],
  93. questionInput: '', //202310150010
  94. currentHeight: 'auto',
  95. lastScrollHeight: 0,
  96. isScrollable: false,
  97. moreData: {
  98. user_id: '',
  99. answer: '',
  100. file_name: '',
  101. ossID: '',
  102. graph: {}
  103. },
  104. historyData: [],
  105. fileInfo: {}
  106. }
  107. },
  108. mounted() {
  109. this.getHistory()
  110. this.adjustHeight()
  111. },
  112. watch: {},
  113. created() {},
  114. methods: {
  115. adjustHeight() {
  116. const textarea = this.$el.querySelector('textarea')
  117. this.currentHeight = 'auto'
  118. if (textarea.scrollHeight < this.lastScrollHeight) {
  119. this.lastScrollHeight = this.lastScrollHeight - 16
  120. }
  121. this.$nextTick(() => {
  122. this.currentHeight = Math.min(this.lastScrollHeight, 200)
  123. this.lastScrollHeight = textarea.scrollHeight
  124. if (textarea.scrollHeight >= 200) {
  125. this.isScrollable = true
  126. } else {
  127. this.isScrollable = false
  128. }
  129. })
  130. },
  131. async getHistory() {
  132. try {
  133. const {
  134. data: { list, total }
  135. } = await getQAHistoryList()
  136. this.historyData = list
  137. // console.log('this.historyData', this.historyData)
  138. } catch (error) {}
  139. },
  140. handleKeydown(event) {
  141. if (event.key === 'Enter') {
  142. if (event.ctrlKey) {
  143. // 按下了 Ctrl+Enter,则插入换行符
  144. this.questionInput += '\n'
  145. this.adjustHeight()
  146. } else {
  147. // 只是按下了 Enter,阻止默认行为并发送消息
  148. event.preventDefault()
  149. this.sendQuestion()
  150. }
  151. }
  152. if (event.key === 'Backspace') {
  153. if (this.questionInput) {
  154. this.adjustHeight()
  155. } else {
  156. this.currentHeight = '50'
  157. }
  158. }
  159. },
  160. async sendQuestion() {
  161. const sendInput = {
  162. question: this.questionInput,
  163. userId: String(store.state.user.userInfo.user.userId)
  164. }
  165. try {
  166. if (this.questionInput.trim() === '') {
  167. return
  168. }
  169. this.chatInfo.push(sendInput, {
  170. answer: '正在解析您的问题,请稍后......'
  171. })
  172. this.questionInput = ''
  173. // const { code, data } = await handlerAsk(sendInput)
  174. const { code, data } = {
  175. code: 200,
  176. msg: '',
  177. data: {
  178. user_id: 'user',
  179. answer: '解决办法为:更换电池或遥控器',
  180. file_name: '排故手册',
  181. // ossID: '225825878820585472',//pdf
  182. ossID: '225840762526433280', //word
  183. graph: {
  184. data: [
  185. { name: '202310150010', category: 'HMC' },
  186. { name: '电视', category: '成品' },
  187. { name: '电视遥控器失灵', category: '故障描述' },
  188. { name: '家用电器', category: '系统' },
  189. { name: '更换电池或遥控器', category: '维修策略' }
  190. ],
  191. links: [
  192. { source: '202310150010', target: '电视', value: '成品' },
  193. { source: '202310150010', target: '电视遥控器失灵', value: '故障描述' },
  194. { source: '202310150010', target: '家用电器', value: '系统' },
  195. { source: '202310150010', target: '更换电池或遥控器', value: '维修策略' }
  196. ]
  197. }
  198. }
  199. }
  200. if (code == 200) {
  201. // const newData = this.handleData(JSON.parse(data))
  202. const newData = this.handleData(data)
  203. this.chatInfo.pop()
  204. this.chatInfo.push(newData)
  205. }
  206. // 等处理过返回数据后,调用使视图保持在最底部
  207. let main = this.$refs.main
  208. setTimeout(() => {
  209. main.scrollTop = main.scrollHeight
  210. }, 0)
  211. } catch (error) {}
  212. },
  213. handleData(data) {
  214. // const graphData = eval('(' + data.graph + ')')
  215. // data.graph = graphData
  216. const categories = []
  217. data.graph.data.forEach((node) => {
  218. const flag = categories.find((item) => {
  219. return item.name === node.category
  220. })
  221. if (!flag) {
  222. categories.push({ name: node.category })
  223. }
  224. })
  225. data.graph.categories = categories
  226. return data
  227. },
  228. handleMore(data) {
  229. this.getListById(data.ossID)
  230. this.moreData = data
  231. this.dialogVisible = true
  232. },
  233. async getListById(id) {
  234. const { data } = await getListByIdsApi(id)
  235. this.fileInfo = data[0]
  236. },
  237. handleClose() {
  238. this.dialogVisible = false
  239. },
  240. async historyDetail(id) {
  241. try {
  242. const { data } = await getQAHistoryDetail(id)
  243. const newData = this.handleData(data)
  244. this.chatInfo = []
  245. this.chatInfo.push(newData)
  246. } catch (error) {}
  247. }
  248. // const { code, data } = {
  249. // code: 200,
  250. // msg: '',
  251. // data: {
  252. // user_id: 'user',
  253. // answer: '解决办法为:更换电池或遥控器',
  254. // file_name: '排故手册',
  255. // ossID: 2,
  256. // graph: {
  257. // data: [
  258. // { name: '202310150010', category: 'HMC' },
  259. // { name: '电视', category: '成品' },
  260. // { name: '电视遥控器失灵', category: '故障描述' },
  261. // { name: '家用电器', category: '系统' },
  262. // { name: '更换电池或遥控器', category: '维修策略' }
  263. // ],
  264. // links: [
  265. // { source: '202310150010', target: '电视', value: '成品' },
  266. // { source: '202310150010', target: '电视遥控器失灵', value: '故障描述' },
  267. // { source: '202310150010', target: '家用电器', value: '系统' },
  268. // { source: '202310150010', target: '更换电池或遥控器', value: '维修策略' }
  269. // ]
  270. // }
  271. // }
  272. // }
  273. }
  274. }
  275. </script>
  276. <style lang="scss">
  277. @import './index.scss';
  278. </style>