index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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 sortedTypeOptions"
  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. // 在 data() 中添加一个新的计算属性或方法来处理排序后的 typeOptions
  172. computed: {
  173. sortedTypeOptions() {
  174. if (!this.typeOptions || this.typeOptions.length === 0) return [];
  175. // 将 dictValue 为 '11' 的选项过滤出来并放到最后
  176. const normalOptions = this.typeOptions.filter(option => option.dictValue !== '11');
  177. const lastOption = this.typeOptions.find(option => option.dictValue === '11');
  178. if (lastOption) {
  179. return [...normalOptions, lastOption];
  180. }
  181. return normalOptions;
  182. }
  183. },
  184. methods: {
  185. /** 查询ai事件埋点统计列表 */
  186. getList() {
  187. this.loading = true;
  188. if(this.selectedCompanyList != null && this.selectedCompanyList.length > 0) {
  189. this.queryParams.userIds = this.selectedCompanyList;
  190. }else {
  191. this.queryParams.userIds = [];
  192. }
  193. listFastgptEventLogTotal(this.queryParams).then(response => {
  194. console.log(response)
  195. this.fastgptEventLogTotalList = response.data.list;
  196. this.total = response.data.total;
  197. this.loading = false;
  198. });
  199. },
  200. normalizer(node) {
  201. return {
  202. id: node.id,
  203. label: node.label,
  204. children: node.children,
  205. disabled: node.disabled
  206. }
  207. },
  208. handleAppKeyChange(value) {
  209. const node = this.findNodeById(this.appKeyOptions, value);
  210. if (!node) {
  211. this.selectedAppKeyLabel = '';
  212. return;
  213. }
  214. // 如果是子节点,则找父节点 label
  215. if (node.parentLabel) {
  216. this.queryParams.appKey = node.parentLabel;
  217. this.selectedAppKeyLabel = node.parentLabel;
  218. this.selectedAppKey = this.selectedAppKeyLabel;
  219. } else {
  220. this.queryParams.appKey = node.label;
  221. this.selectedAppKeyLabel = node.label;
  222. this.selectedAppKey = this.selectedAppKeyLabel;
  223. }
  224. },
  225. findNodeById(nodes, id) {
  226. for (const node of nodes) {
  227. if (node.id === id) return node;
  228. if (node.children) {
  229. const found = this.findNodeById(node.children, id);
  230. if (found) return found;
  231. }
  232. }
  233. return null;
  234. },
  235. changeTime(){
  236. console.log(this.createTime);
  237. if(this.createTime!=null){
  238. this.queryParams.beginTime=this.createTime[0];
  239. this.queryParams.endTime=this.createTime[1];
  240. }else{
  241. this.queryParams.beginTime=null;
  242. this.queryParams.endTime=null;
  243. }
  244. console.log(this.queryParams.beginTime);
  245. console.log(this.queryParams.endTime);
  246. },
  247. // 取消按钮
  248. cancel() {
  249. this.open = false;
  250. this.reset();
  251. },
  252. handleMultiChange(e){
  253. },
  254. handleCompanyUserId(val){
  255. if(val == null || val === '') {
  256. this.queryParams.companyUserId = null;
  257. this.queryParams.userIds = [];
  258. }
  259. console.log(val);
  260. },
  261. // 表单重置
  262. reset() {
  263. this.form = {
  264. id: null,
  265. roleId: null,
  266. count: null,
  267. type: null,
  268. companyId: null,
  269. companyUserId: null,
  270. qwUserId: null,
  271. statTime: null
  272. };
  273. this.resetForm("form");
  274. },
  275. getPercentageColor(percentage) {
  276. // HSL模式从黄色(60度)渐变到红色(0度)
  277. const percent = Math.min(100, Math.max(0, parseFloat(percentage)));
  278. // 调整色相范围:从深黄色(40°)渐变到红色(0°)
  279. const hue = 40 - 40 * (percent / 100); // 初始 hue=40(深黄),终点 hue=0(红)
  280. // 提高饱和度(100%),亮度保持 50%(鲜艳但不刺眼)
  281. return `hsl(${hue}, 100%, 50%)`;
  282. },
  283. /** 搜索按钮操作 */
  284. handleQuery() {
  285. this.queryParams.pageNum = 1;
  286. console.log(this.selectedAppKey)
  287. if(this.selectedAppKey === null || typeof this.selectedAppKey === 'undefined'){
  288. this.queryParams.appKey = null;
  289. }
  290. this.getList();
  291. },
  292. /** 重置按钮操作 */
  293. resetQuery() {
  294. this.selectedAppKey = null;
  295. this.selectedAppKeyLabel = '';
  296. this.selectedCompanyList = [];
  297. this.queryParams.appKey = null;
  298. this.resetForm("queryForm");
  299. this.handleQuery();
  300. },
  301. // 多选框选中数据
  302. handleSelectionChange(selection) {
  303. this.ids = selection.map(item => item.id)
  304. this.single = selection.length!==1
  305. this.multiple = !selection.length
  306. },
  307. /** 导出按钮操作 */
  308. handleExport() {
  309. const queryParams = this.queryParams;
  310. if(this.selectedCompanyList != null && this.selectedCompanyList.length > 0) {
  311. this.queryParams.userIds = this.selectedCompanyList;
  312. }else {
  313. this.queryParams.userIds = [];
  314. }
  315. this.$confirm('是否确认导出所有ai事件埋点统计数据项?', "警告", {
  316. confirmButtonText: "确定",
  317. cancelButtonText: "取消",
  318. type: "warning"
  319. }).then(() => {
  320. this.exportLoading = true;
  321. return exportFastgptEventLogTotal(queryParams);
  322. }).then(response => {
  323. this.download(response.msg);
  324. this.exportLoading = false;
  325. }).catch(() => {});
  326. }
  327. }
  328. };
  329. </script>