index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="公司名" prop="companyId">
  5. <select-tree
  6. v-model="selectedCompanyList"
  7. :raw-data="deptList"
  8. placeholder="请选择销售"
  9. :parentSelectable="true"
  10. :multiple="true"
  11. component-width="300px"
  12. :max-display-tags="3"
  13. :check-strictly="false"
  14. :return-leaf-only="false"
  15. @change="handleMultiChange"
  16. ></select-tree>
  17. </el-form-item>
  18. <el-form-item label="销售" prop="nickName" v-if="queryParams.companyId">
  19. <el-select v-model="queryParams.companyUserId" remote
  20. placeholder="请选择"
  21. filterable clearable
  22. style="width: 100%;"
  23. @keyup.enter.native="handleQuery"
  24. @change="handleCompanyUserId"
  25. >
  26. <el-option
  27. v-for="dict in companyUserList"
  28. :key="`${dict.nickName} - ${dict.userName}`"
  29. :label="`${dict.nickName} - ${dict.userName}`"
  30. :value="dict.userId">
  31. </el-option>
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item label="AppKey" prop="appKey">
  35. <div style="display: flex; align-items: center;">
  36. <tree-select
  37. v-model="selectedAppKey"
  38. :options="appKeyOptions"
  39. :normalizer="normalizer"
  40. :disable-branch-nodes="false"
  41. placeholder="请选择 AppKey" style="width: 300px;"
  42. @input="handleAppKeyChange"
  43. />
  44. </div>
  45. </el-form-item>
  46. <el-form-item label="创建时间" prop="createTime">
  47. <el-date-picker v-model="createTime" size="small" style="width: 220px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" @change="changeTime"></el-date-picker>
  48. </el-form-item>
  49. <el-form-item>
  50. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  51. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  52. </el-form-item>
  53. </el-form>
  54. <el-row :gutter="10" class="mb8">
  55. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  56. </el-row>
  57. <el-table border v-loading="loading" :data="fastgptEventLogTotalList" :row-class-name="() => 'fixed-bottom-row'"
  58. @selection-change="handleSelectionChange" :max-height="600">
  59. <el-table-column type="selection" width="55" align="center" />
  60. <el-table-column label="角色名称" align="center" prop="roleName" />
  61. <el-table-column label="时间" align="center" prop="statTime" />
  62. <el-table-column
  63. v-for="dict in typeOptions"
  64. :key="dict.dictValue"
  65. :label="dict.dictLabel"
  66. align="center">
  67. <template slot-scope="scope">
  68. <span>{{ scope.row.typeCountMap ? scope.row.typeCountMap[dict.dictValue] : '' }}</span>
  69. <span v-if="dict.dictValue !== '11'"
  70. :style="{ fontSize: '12px', marginLeft: '5px',
  71. color: getPercentageColor((scope.row.typeCountMap[dict.dictValue] / scope.row.typeCountMap[2]) * 100) }">
  72. ({{ ((scope.row.typeCountMap[dict.dictValue] / scope.row.typeCountMap[2]) * 100).toFixed(2) }}%)
  73. </span>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <pagination
  78. v-show="total>0"
  79. :total="total"
  80. :page.sync="queryParams.pageNum"
  81. :limit.sync="queryParams.pageSize"
  82. @pagination="getList"
  83. />
  84. </div>
  85. </template>
  86. <script>
  87. import { listFastgptEventLogTotal, getFastgptEventLogTotal, delFastgptEventLogTotal, addFastgptEventLogTotal, updateFastgptEventLogTotal, exportFastgptEventLogTotal, getFastGptRoleAppKeyList} from "@/api/fastGpt/fastgptEventLogTotal";
  88. import SelectTree from "@/components/TreeSelect/index.vue";
  89. import {getDeptData} from "@/api/system/employeeStats";
  90. import TreeSelect from '@riophae/vue-treeselect'
  91. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  92. export default {
  93. name: "FastgptEventLogTotal",
  94. components: {SelectTree,TreeSelect},
  95. data() {
  96. return {
  97. createTime:null,
  98. // 遮罩层
  99. loading: true,
  100. // 导出遮罩层
  101. exportLoading: false,
  102. selectedCompanyList: [],
  103. deptList: [],
  104. companyUserList: [],
  105. selectedAppKey: null,
  106. selectedAppKeyLabel: '',
  107. appKeyOptions: [],
  108. // 选中数组
  109. ids: [],
  110. // 非单个禁用
  111. single: true,
  112. // 非多个禁用
  113. multiple: true,
  114. // 显示搜索条件
  115. showSearch: true,
  116. // 总条数
  117. total: 0,
  118. // ai事件埋点统计表格数据
  119. fastgptEventLogTotalList: [],
  120. // 弹出层标题
  121. title: "",
  122. // 是否显示弹出层
  123. open: false,
  124. typeCountMap: null,
  125. // 日志类型字典
  126. typeOptions: [],
  127. // 查询参数
  128. queryParams: {
  129. pageNum: 1,
  130. pageSize: 10,
  131. roleId: null,
  132. count: null,
  133. type: null,
  134. companyId: null,
  135. companyUserId: null,
  136. qwUserId: null,
  137. typeCountMap: null,
  138. beginTime:null,
  139. endTime:null,
  140. appKey:null,
  141. },
  142. // 表单参数
  143. form: {},
  144. // 表单校验
  145. rules: {
  146. }
  147. };
  148. },
  149. created() {
  150. this.getList();
  151. this.getDicts("sys_fastgpt_event_log_type").then(response => {
  152. this.typeOptions = response.data;
  153. });
  154. getDeptData().then(response => {
  155. this.deptList = response.data;
  156. });
  157. getFastGptRoleAppKeyList().then(res => {
  158. this.appKeyOptions = res.data.map(item => ({
  159. id: `p_${item.roleId}`,
  160. label: item.roleName,
  161. children: (item.roleList || []).map(child => ({
  162. id: `c_${child.roleId}`,
  163. label: child.roleName,
  164. parentId: `p_${item.roleId}`, // 记录父节点 ID
  165. parentLabel: item.roleName, // 记录父节点 label
  166. disabled: true
  167. }))
  168. }));
  169. });
  170. },
  171. methods: {
  172. /** 查询ai事件埋点统计列表 */
  173. getList() {
  174. this.loading = true;
  175. if(this.selectedCompanyList != null && this.selectedCompanyList.length > 0) {
  176. this.queryParams.userIds = this.selectedCompanyList;
  177. }else {
  178. this.queryParams.userIds = [];
  179. }
  180. listFastgptEventLogTotal(this.queryParams).then(response => {
  181. console.log(response)
  182. this.fastgptEventLogTotalList = response.data.list;
  183. this.total = response.data.total;
  184. this.loading = false;
  185. });
  186. },
  187. normalizer(node) {
  188. return {
  189. id: node.id,
  190. label: node.label,
  191. children: node.children,
  192. disabled: node.disabled
  193. }
  194. },
  195. handleAppKeyChange(value) {
  196. const node = this.findNodeById(this.appKeyOptions, value);
  197. if (!node) {
  198. this.selectedAppKeyLabel = '';
  199. return;
  200. }
  201. // 如果是子节点,则找父节点 label
  202. if (node.parentLabel) {
  203. this.queryParams.appKey = node.parentLabel;
  204. this.selectedAppKeyLabel = node.parentLabel;
  205. this.selectedAppKey = this.selectedAppKeyLabel;
  206. } else {
  207. this.queryParams.appKey = node.label;
  208. this.selectedAppKeyLabel = node.label;
  209. this.selectedAppKey = this.selectedAppKeyLabel;
  210. }
  211. },
  212. findNodeById(nodes, id) {
  213. for (const node of nodes) {
  214. if (node.id === id) return node;
  215. if (node.children) {
  216. const found = this.findNodeById(node.children, id);
  217. if (found) return found;
  218. }
  219. }
  220. return null;
  221. },
  222. changeTime(){
  223. console.log(this.createTime);
  224. if(this.createTime!=null){
  225. this.queryParams.beginTime=this.createTime[0];
  226. this.queryParams.endTime=this.createTime[1];
  227. }else{
  228. this.queryParams.beginTime=null;
  229. this.queryParams.endTime=null;
  230. }
  231. console.log(this.queryParams.beginTime);
  232. console.log(this.queryParams.endTime);
  233. },
  234. // 取消按钮
  235. cancel() {
  236. this.open = false;
  237. this.reset();
  238. },
  239. handleMultiChange(e){
  240. },
  241. handleCompanyUserId(val){
  242. if(val == null || val === '') {
  243. this.queryParams.companyUserId = null;
  244. this.queryParams.userIds = [];
  245. }
  246. console.log(val);
  247. },
  248. // 表单重置
  249. reset() {
  250. this.form = {
  251. id: null,
  252. roleId: null,
  253. count: null,
  254. type: null,
  255. companyId: null,
  256. companyUserId: null,
  257. qwUserId: null,
  258. statTime: null
  259. };
  260. this.resetForm("form");
  261. },
  262. getPercentageColor(percentage) {
  263. // HSL模式从黄色(60度)渐变到红色(0度)
  264. const percent = Math.min(100, Math.max(0, parseFloat(percentage)));
  265. // 调整色相范围:从深黄色(40°)渐变到红色(0°)
  266. const hue = 40 - 40 * (percent / 100); // 初始 hue=40(深黄),终点 hue=0(红)
  267. // 提高饱和度(100%),亮度保持 50%(鲜艳但不刺眼)
  268. return `hsl(${hue}, 100%, 50%)`;
  269. },
  270. /** 搜索按钮操作 */
  271. handleQuery() {
  272. this.queryParams.pageNum = 1;
  273. console.log(this.selectedAppKey)
  274. if(this.selectedAppKey === null || typeof this.selectedAppKey === 'undefined'){
  275. this.queryParams.appKey = null;
  276. }
  277. this.getList();
  278. },
  279. /** 重置按钮操作 */
  280. resetQuery() {
  281. this.selectedAppKey = null;
  282. this.selectedAppKeyLabel = '';
  283. this.selectedCompanyList = [];
  284. this.queryParams.appKey = null;
  285. this.resetForm("queryForm");
  286. this.handleQuery();
  287. },
  288. // 多选框选中数据
  289. handleSelectionChange(selection) {
  290. this.ids = selection.map(item => item.id)
  291. this.single = selection.length!==1
  292. this.multiple = !selection.length
  293. },
  294. /** 导出按钮操作 */
  295. handleExport() {
  296. const queryParams = this.queryParams;
  297. if(this.selectedCompanyList != null && this.selectedCompanyList.length > 0) {
  298. this.queryParams.userIds = this.selectedCompanyList;
  299. }else {
  300. this.queryParams.userIds = [];
  301. }
  302. this.$confirm('是否确认导出所有ai事件埋点统计数据项?', "警告", {
  303. confirmButtonText: "确定",
  304. cancelButtonText: "取消",
  305. type: "warning"
  306. }).then(() => {
  307. this.exportLoading = true;
  308. return exportFastgptEventLogTotal(queryParams);
  309. }).then(response => {
  310. this.download(response.msg);
  311. this.exportLoading = false;
  312. }).catch(() => {});
  313. }
  314. }
  315. };
  316. </script>