index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
  4. <el-form-item label="用户昵称" prop="nickName">
  5. <el-input
  6. v-model="queryParams.nickName"
  7. placeholder="请输入用户昵称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="客服角色" prop="roleId">
  14. <el-select v-model="queryParams.roleId" placeholder="请选择客服角色" clearable size="small">
  15. <el-option
  16. v-for="item in roles"
  17. :key="item.roleId"
  18. :label="item.roleName"
  19. :value="item.roleId"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="消息类型" prop="msgType">
  24. <el-select v-model="queryParams.msgType" placeholder="请选择类型" clearable size="small">
  25. <el-option
  26. v-for="item in typeOptions"
  27. :key="item.dictValue"
  28. :label="item.dictLabel"
  29. :value="item.dictValue"
  30. />
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item label="发送时间" prop="createTime">
  34. <el-date-picker
  35. style="width:220px"
  36. clearable size="small"
  37. v-model="dateRange"
  38. type="daterange"
  39. value-format="yyyy-MM-dd"
  40. start-placeholder="开始日期"
  41. end-placeholder="结束日期">
  42. </el-date-picker>
  43. </el-form-item>
  44. <el-form-item>
  45. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  46. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  47. </el-form-item>
  48. </el-form>
  49. <el-row :gutter="10" class="mb8">
  50. <el-col :span="1.5">
  51. <el-button
  52. type="warning"
  53. plain
  54. icon="el-icon-download"
  55. size="mini"
  56. :loading="exportLoading"
  57. @click="handleExport"
  58. v-hasPermi="['chat:chatMsg:export']"
  59. >导出</el-button>
  60. </el-col>
  61. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  62. </el-row>
  63. <el-table border v-loading="loading" :data="chatMsgList" @selection-change="handleSelectionChange">
  64. <el-table-column type="selection" width="55" align="center" />
  65. <el-table-column label="ID" align="center" prop="msgId" />
  66. <el-table-column label="用户" align="center" prop="nickname" />
  67. <el-table-column label="头像" width="150" align="center">
  68. <template slot-scope="scope">
  69. <img :src="scope.row.avatar" style="height: 80px">
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="AI客服" align="center" prop="roleName" />
  73. <el-table-column show-overflow-tooltip label="消息内容" align="center" prop="content" />
  74. <el-table-column label="消息类型" align="center" prop="msgType">
  75. <template slot-scope="scope">
  76. <el-tag prop="type" v-for="(item, index) in typeOptions" v-if="scope.row.msgType==item.dictValue">{{item.dictLabel}}</el-tag>
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="发送方式" align="center" prop="sendType">
  80. <template slot-scope="scope">
  81. <el-tag prop="type" v-for="(item, index) in sendTypeOptions" v-if="scope.row.sendType==item.dictValue">{{item.dictLabel}}</el-tag>
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="发送时间" align="center" prop="createTime" />
  85. <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  86. <template slot-scope="scope">
  87. <el-button
  88. size="mini"
  89. type="text"
  90. @click="handledetails(scope.row)"
  91. v-hasPermi="['chat:chatMsg:query']"
  92. >查看</el-button>
  93. </template>
  94. </el-table-column> -->
  95. </el-table>
  96. <pagination
  97. v-show="total>0"
  98. :total="total"
  99. :page.sync="queryParams.pageNum"
  100. :limit.sync="queryParams.pageSize"
  101. @pagination="getList"
  102. />
  103. <!-- 添加或修改聊天消息记录对话框 -->
  104. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  105. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  106. <el-form-item label="消息ID" prop="chatId">
  107. <el-input v-model="form.chatId" placeholder="请输入消息ID" />
  108. </el-form-item>
  109. <el-form-item label="消息内容">
  110. <editor v-model="form.content" :min-height="192"/>
  111. </el-form-item>
  112. <el-form-item label="消息类型 1文本" prop="msgType">
  113. <el-select v-model="form.msgType" placeholder="请选择消息类型 1文本">
  114. <el-option label="请选择字典生成" value="" />
  115. </el-select>
  116. </el-form-item>
  117. <el-form-item label="发送类型 1用户发送 2客服发送" prop="sendType">
  118. <el-select v-model="form.sendType" placeholder="请选择发送类型 1用户发送 2客服发送">
  119. <el-option label="请选择字典生成" value="" />
  120. </el-select>
  121. </el-form-item>
  122. <el-form-item label="公司ID" prop="companyId">
  123. <el-input v-model="form.companyId" placeholder="请输入公司ID" />
  124. </el-form-item>
  125. <el-form-item label="角色ID" prop="roleId">
  126. <el-input v-model="form.roleId" placeholder="请输入角色ID" />
  127. </el-form-item>
  128. <el-form-item label="销售ID" prop="companyUserId">
  129. <el-input v-model="form.companyUserId" placeholder="请输入销售ID" />
  130. </el-form-item>
  131. <el-form-item label="消息JSON" prop="msgJson">
  132. <el-input v-model="form.msgJson" type="textarea" placeholder="请输入内容" />
  133. </el-form-item>
  134. </el-form>
  135. <div slot="footer" class="dialog-footer">
  136. <el-button type="primary" @click="submitForm">确 定</el-button>
  137. <el-button @click="cancel">取 消</el-button>
  138. </div>
  139. </el-dialog>
  140. <!-- <el-drawer
  141. :with-header="false"
  142. size="75%"
  143. :title="show.title" :visible.sync="show.open">
  144. <chatMsgDetails ref="Details" />
  145. </el-drawer> -->
  146. </div>
  147. </template>
  148. <script>
  149. import { listChatMsg, getChatMsg, delChatMsg, addChatMsg, updateChatMsg, exportChatMsg } from "@/api/chat/chatMsg";
  150. import { getAllRoleList } from "@/api/chat/chatRole";
  151. import chatMsgDetails from '../components/chatMsgDetails.vue';
  152. export default {
  153. name: "ChatMsg",
  154. components: {chatMsgDetails },
  155. data() {
  156. return {
  157. show:{
  158. title:"聊天详情",
  159. open:false,
  160. },
  161. roles:[],
  162. dateRange:[],
  163. typeOptions:[],
  164. sendTypeOptions:[],
  165. // 遮罩层
  166. loading: true,
  167. // 导出遮罩层
  168. exportLoading: false,
  169. // 选中数组
  170. ids: [],
  171. // 非单个禁用
  172. single: true,
  173. // 非多个禁用
  174. multiple: true,
  175. // 显示搜索条件
  176. showSearch: true,
  177. // 总条数
  178. total: 0,
  179. // 聊天消息记录表格数据
  180. chatMsgList: [],
  181. // 弹出层标题
  182. title: "",
  183. // 是否显示弹出层
  184. open: false,
  185. // 查询参数
  186. queryParams: {
  187. pageNum: 1,
  188. pageSize: 10,
  189. chatId: null,
  190. content: null,
  191. msgType: null,
  192. sendType: null,
  193. companyId: null,
  194. roleId: null,
  195. companyUserId: null,
  196. msgJson: null
  197. },
  198. // 表单参数
  199. form: {},
  200. // 表单校验
  201. rules: {
  202. }
  203. };
  204. },
  205. created() {
  206. this.getDicts("chat_msg_type").then((response) => {
  207. this.typeOptions = response.data;
  208. });
  209. this.getDicts("chat_msg_send_type").then((response) => {
  210. this.sendTypeOptions = response.data;
  211. });
  212. getAllRoleList().then(response => {
  213. this.roles = response.data;
  214. });
  215. this.getList();
  216. },
  217. methods: {
  218. handleShow(){
  219. },
  220. /** 查询聊天消息记录列表 */
  221. getList() {
  222. this.loading = true;
  223. listChatMsg(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  224. this.chatMsgList = response.rows;
  225. this.total = response.total;
  226. this.loading = false;
  227. });
  228. },
  229. handledetails(row){
  230. this.show.open=true;
  231. setTimeout(() => {
  232. this.$refs.Details.getDetails(row.msgId);
  233. }, 1);
  234. },
  235. // 取消按钮
  236. cancel() {
  237. this.open = false;
  238. this.reset();
  239. },
  240. // 表单重置
  241. reset() {
  242. this.form = {
  243. msgId: null,
  244. chatId: null,
  245. content: null,
  246. msgType: null,
  247. sendType: null,
  248. companyId: null,
  249. roleId: null,
  250. companyUserId: null,
  251. createTime: null,
  252. msgJson: null
  253. };
  254. this.resetForm("form");
  255. },
  256. /** 搜索按钮操作 */
  257. handleQuery() {
  258. this.queryParams.pageNum = 1;
  259. this.getList();
  260. },
  261. /** 重置按钮操作 */
  262. resetQuery() {
  263. this.resetForm("queryForm");
  264. this.dateRange=null
  265. this.handleQuery();
  266. },
  267. // 多选框选中数据
  268. handleSelectionChange(selection) {
  269. this.ids = selection.map(item => item.msgId)
  270. this.single = selection.length!==1
  271. this.multiple = !selection.length
  272. },
  273. /** 新增按钮操作 */
  274. handleAdd() {
  275. this.reset();
  276. this.open = true;
  277. this.title = "添加聊天消息记录";
  278. },
  279. /** 修改按钮操作 */
  280. handleUpdate(row) {
  281. this.reset();
  282. const msgId = row.msgId || this.ids
  283. getChatMsg(msgId).then(response => {
  284. this.form = response.data;
  285. this.open = true;
  286. this.title = "修改聊天消息记录";
  287. });
  288. },
  289. /** 提交按钮 */
  290. submitForm() {
  291. this.$refs["form"].validate(valid => {
  292. if (valid) {
  293. if (this.form.msgId != null) {
  294. updateChatMsg(this.form).then(response => {
  295. this.msgSuccess("修改成功");
  296. this.open = false;
  297. this.getList();
  298. });
  299. } else {
  300. addChatMsg(this.form).then(response => {
  301. this.msgSuccess("新增成功");
  302. this.open = false;
  303. this.getList();
  304. });
  305. }
  306. }
  307. });
  308. },
  309. /** 删除按钮操作 */
  310. handleDelete(row) {
  311. const msgIds = row.msgId || this.ids;
  312. this.$confirm('是否确认删除聊天消息记录编号为"' + msgIds + '"的数据项?', "警告", {
  313. confirmButtonText: "确定",
  314. cancelButtonText: "取消",
  315. type: "warning"
  316. }).then(function() {
  317. return delChatMsg(msgIds);
  318. }).then(() => {
  319. this.getList();
  320. this.msgSuccess("删除成功");
  321. }).catch(() => {});
  322. },
  323. /** 导出按钮操作 */
  324. handleExport() {
  325. const queryParams = this.queryParams;
  326. this.$confirm('是否确认导出所有聊天消息记录数据项?', "警告", {
  327. confirmButtonText: "确定",
  328. cancelButtonText: "取消",
  329. type: "warning"
  330. }).then(() => {
  331. this.exportLoading = true;
  332. return exportChatMsg(queryParams);
  333. }).then(response => {
  334. this.download(response.msg);
  335. this.exportLoading = false;
  336. }).catch(() => {});
  337. }
  338. }
  339. };
  340. </script>
  341. <style lang="css">
  342. .el-tooltip__popper{
  343. max-width:40%
  344. }
  345. </style>