index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. <el-col :span="1.5">
  56. <el-button
  57. type="warning"
  58. icon="el-icon-download"
  59. size="mini"
  60. @click="handleExport"
  61. v-hasPermi="['fastGpt:fastgptEventLogTotal:export']"
  62. >导出</el-button>
  63. </el-col>
  64. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  65. </el-row>
  66. <el-table border v-loading="loading" :data="fastgptEventLogTotalList" :row-class-name="() => 'fixed-bottom-row'"
  67. @selection-change="handleSelectionChange" :max-height="600">
  68. <el-table-column type="selection" width="55" align="center" />
  69. <el-table-column label="角色名称" align="center" prop="roleName" />
  70. <el-table-column label="时间" align="center" prop="statTime" />
  71. <el-table-column
  72. v-for="dict in sortedTypeOptions"
  73. :key="dict.dictValue"
  74. :label="dict.dictLabel"
  75. align="center">
  76. <template slot-scope="scope">
  77. <span>{{ scope.row.typeCountMap ? scope.row.typeCountMap[dict.dictValue] : '' }}</span>
  78. <span v-if="dict.dictValue !== '11'"
  79. :style="{ fontSize: '12px', marginLeft: '5px',
  80. color: getPercentageColor((scope.row.typeCountMap[dict.dictValue] / scope.row.typeCountMap[2]) * 100) }">
  81. ({{ ((scope.row.typeCountMap[dict.dictValue] / scope.row.typeCountMap[2]) * 100).toFixed(2) }}%)
  82. </span>
  83. </template>
  84. </el-table-column>
  85. <!-- 新增金额列 -->
  86. <el-table-column label="金额" align="center">
  87. <template slot-scope="scope">
  88. <span>{{ scope.row.typeCountMap && scope.row.typeCountMap['11'] ? (scope.row.typeCountMap['11'] / 100000).toFixed(4) : '0.0000' }}</span>
  89. </template>
  90. </el-table-column>
  91. </el-table>
  92. <pagination
  93. v-show="total>0"
  94. :total="total"
  95. :page.sync="queryParams.pageNum"
  96. :limit.sync="queryParams.pageSize"
  97. @pagination="getList"
  98. />
  99. </div>
  100. </template>
  101. <script>
  102. import { listFastgptEventLogTotal, getFastgptEventLogTotal, delFastgptEventLogTotal, addFastgptEventLogTotal, updateFastgptEventLogTotal, exportFastgptEventLogTotal, getFastGptRoleAppKeyList} from "@/api/fastGpt/fastgptEventLogTotal";
  103. import SelectTree from "@/components/TreeSelect/index.vue";
  104. import {getDeptData} from "@/api/system/employeeStats";
  105. import TreeSelect from '@riophae/vue-treeselect'
  106. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  107. export default {
  108. name: "FastgptEventLogTotal",
  109. components: {SelectTree,TreeSelect},
  110. data() {
  111. return {
  112. createTime:null,
  113. // 遮罩层
  114. loading: true,
  115. // 导出遮罩层
  116. exportLoading: false,
  117. selectedCompanyList: [],
  118. deptList: [],
  119. companyUserList: [],
  120. selectedAppKey: null,
  121. selectedAppKeyLabel: '',
  122. appKeyOptions: [],
  123. // 选中数组
  124. ids: [],
  125. // 非单个禁用
  126. single: true,
  127. // 非多个禁用
  128. multiple: true,
  129. // 显示搜索条件
  130. showSearch: true,
  131. // 总条数
  132. total: 0,
  133. // ai事件埋点统计表格数据
  134. fastgptEventLogTotalList: [],
  135. // 弹出层标题
  136. title: "",
  137. // 是否显示弹出层
  138. open: false,
  139. typeCountMap: null,
  140. // 日志类型字典
  141. typeOptions: [],
  142. // 查询参数
  143. queryParams: {
  144. pageNum: 1,
  145. pageSize: 10,
  146. roleId: null,
  147. count: null,
  148. type: null,
  149. companyId: null,
  150. companyUserId: null,
  151. qwUserId: null,
  152. typeCountMap: null,
  153. beginTime:null,
  154. endTime:null,
  155. appKey:null,
  156. },
  157. // 表单参数
  158. form: {},
  159. // 表单校验
  160. rules: {
  161. }
  162. };
  163. },
  164. created() {
  165. this.getList();
  166. this.getDicts("sys_fastgpt_event_log_type").then(response => {
  167. this.typeOptions = response.data;
  168. });
  169. getDeptData().then(response => {
  170. this.deptList = response.data;
  171. });
  172. getFastGptRoleAppKeyList().then(res => {
  173. this.appKeyOptions = res.data.map(item => ({
  174. id: `p_${item.roleId}`,
  175. label: item.roleName,
  176. children: (item.roleList || []).map(child => ({
  177. id: `c_${child.roleId}`,
  178. label: child.roleName,
  179. parentId: `p_${item.roleId}`, // 记录父节点 ID
  180. parentLabel: item.roleName, // 记录父节点 label
  181. disabled: true
  182. }))
  183. }));
  184. });
  185. },
  186. // 在 data() 中添加一个新的计算属性或方法来处理排序后的 typeOptions
  187. computed: {
  188. sortedTypeOptions() {
  189. if (!this.typeOptions || this.typeOptions.length === 0) return [];
  190. // 将 dictValue 为 '11' 的选项过滤出来并放到最后
  191. const normalOptions = this.typeOptions.filter(option => option.dictValue !== '11');
  192. const lastOption = this.typeOptions.find(option => option.dictValue === '11');
  193. if (lastOption) {
  194. return [...normalOptions, lastOption];
  195. }
  196. return normalOptions;
  197. }
  198. },
  199. methods: {
  200. /** 查询ai事件埋点统计列表 */
  201. getList() {
  202. this.loading = true;
  203. if(this.selectedCompanyList != null && this.selectedCompanyList.length > 0) {
  204. this.queryParams.userIds = this.selectedCompanyList;
  205. }else {
  206. this.queryParams.userIds = [];
  207. }
  208. listFastgptEventLogTotal(this.queryParams).then(response => {
  209. console.log(response)
  210. this.fastgptEventLogTotalList = response.data.list;
  211. this.total = response.data.total;
  212. this.loading = false;
  213. });
  214. },
  215. normalizer(node) {
  216. return {
  217. id: node.id,
  218. label: node.label,
  219. children: node.children,
  220. disabled: node.disabled
  221. }
  222. },
  223. handleAppKeyChange(value) {
  224. const node = this.findNodeById(this.appKeyOptions, value);
  225. if (!node) {
  226. this.selectedAppKeyLabel = '';
  227. return;
  228. }
  229. // 如果是子节点,则找父节点 label
  230. if (node.parentLabel) {
  231. this.queryParams.appKey = node.parentLabel;
  232. this.selectedAppKeyLabel = node.parentLabel;
  233. this.selectedAppKey = this.selectedAppKeyLabel;
  234. } else {
  235. this.queryParams.appKey = node.label;
  236. this.selectedAppKeyLabel = node.label;
  237. this.selectedAppKey = this.selectedAppKeyLabel;
  238. }
  239. },
  240. findNodeById(nodes, id) {
  241. for (const node of nodes) {
  242. if (node.id === id) return node;
  243. if (node.children) {
  244. const found = this.findNodeById(node.children, id);
  245. if (found) return found;
  246. }
  247. }
  248. return null;
  249. },
  250. changeTime(){
  251. console.log(this.createTime);
  252. if(this.createTime!=null){
  253. this.queryParams.beginTime=this.createTime[0];
  254. this.queryParams.endTime=this.createTime[1];
  255. }else{
  256. this.queryParams.beginTime=null;
  257. this.queryParams.endTime=null;
  258. }
  259. console.log(this.queryParams.beginTime);
  260. console.log(this.queryParams.endTime);
  261. },
  262. // 取消按钮
  263. cancel() {
  264. this.open = false;
  265. this.reset();
  266. },
  267. handleMultiChange(e){
  268. },
  269. handleCompanyUserId(val){
  270. if(val == null || val === '') {
  271. this.queryParams.companyUserId = null;
  272. this.queryParams.userIds = [];
  273. }
  274. console.log(val);
  275. },
  276. // 表单重置
  277. reset() {
  278. this.form = {
  279. id: null,
  280. roleId: null,
  281. count: null,
  282. type: null,
  283. companyId: null,
  284. companyUserId: null,
  285. qwUserId: null,
  286. statTime: null
  287. };
  288. this.resetForm("form");
  289. },
  290. getPercentageColor(percentage) {
  291. // HSL模式从黄色(60度)渐变到红色(0度)
  292. const percent = Math.min(100, Math.max(0, parseFloat(percentage)));
  293. // 调整色相范围:从深黄色(40°)渐变到红色(0°)
  294. const hue = 40 - 40 * (percent / 100); // 初始 hue=40(深黄),终点 hue=0(红)
  295. // 提高饱和度(100%),亮度保持 50%(鲜艳但不刺眼)
  296. return `hsl(${hue}, 100%, 50%)`;
  297. },
  298. /** 搜索按钮操作 */
  299. handleQuery() {
  300. this.queryParams.pageNum = 1;
  301. console.log(this.selectedAppKey)
  302. if(this.selectedAppKey === null || typeof this.selectedAppKey === 'undefined'){
  303. this.queryParams.appKey = null;
  304. }
  305. this.getList();
  306. },
  307. /** 重置按钮操作 */
  308. resetQuery() {
  309. this.selectedAppKey = null;
  310. this.selectedAppKeyLabel = '';
  311. this.selectedCompanyList = [];
  312. this.queryParams.appKey = null;
  313. this.resetForm("queryForm");
  314. this.handleQuery();
  315. },
  316. // 多选框选中数据
  317. handleSelectionChange(selection) {
  318. this.ids = selection.map(item => item.id)
  319. this.single = selection.length!==1
  320. this.multiple = !selection.length
  321. },
  322. /** 导出按钮操作 */
  323. handleExport() {
  324. const queryParams = this.queryParams;
  325. if(this.selectedCompanyList != null && this.selectedCompanyList.length > 0) {
  326. this.queryParams.userIds = this.selectedCompanyList;
  327. }else {
  328. this.queryParams.userIds = [];
  329. }
  330. this.$confirm('是否确认导出所有ai事件埋点统计数据项?', "警告", {
  331. confirmButtonText: "确定",
  332. cancelButtonText: "取消",
  333. type: "warning"
  334. }).then(() => {
  335. this.exportLoading = true;
  336. return exportFastgptEventLogTotal(queryParams);
  337. }).then(response => {
  338. this.download(response.msg);
  339. this.exportLoading = false;
  340. }).catch(() => {});
  341. }
  342. }
  343. };
  344. </script>