index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. <el-select v-model="queryParams.companyId" placeholder="请选择所属公司" filterable size="small">
  6. <el-option v-for="(option, index) in companyList" :key="index" :value="option.dictValue" :label="option.dictLabel"></el-option>
  7. </el-select>
  8. </el-form-item>
  9. <el-form-item label="创建时间" prop="createTime">
  10. <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>
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  14. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  15. </el-form-item>
  16. </el-form>
  17. <el-row :gutter="10" class="mb8">
  18. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  19. </el-row>
  20. <el-table border v-loading="loading" :data="fastGptPushTokenTotalList" :row-class-name="() => 'fixed-bottom-row'"
  21. @selection-change="handleSelectionChange" :max-height="600">
  22. <el-table-column type="selection" width="55" align="center" />
  23. <el-table-column label="公司名称" align="center" prop="companyName" />
  24. <el-table-column label="token消耗" align="center" prop="count" />
  25. <el-table-column label="时间" align="center" prop="statTime" />
  26. </el-table>
  27. <pagination
  28. v-show="total>0"
  29. :total="total"
  30. :page.sync="queryParams.pageNum"
  31. :limit.sync="queryParams.pageSize"
  32. @pagination="getList"
  33. />
  34. </div>
  35. </template>
  36. <script>
  37. import { listFastgptEventLogTotal, exportFastgptEventLogTotal, getFastGptRoleAppKeyList} from "@/api/fastGpt/fastgptEventLogTotal";
  38. import { getFastGptPushTokenTotal} from "@/api/fastGpt/fastgptPushTokenTotal";
  39. import SelectTree from "@/components/TreeSelect/index.vue";
  40. import {getDeptData} from "@/api/system/employeeStats";
  41. import TreeSelect from '@riophae/vue-treeselect'
  42. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  43. import {allList} from "@/api/company/company";
  44. export default {
  45. name: "FastgptEventLogTotal",
  46. components: {SelectTree,TreeSelect},
  47. data() {
  48. return {
  49. createTime:null,
  50. // 遮罩层
  51. loading: true,
  52. // 导出遮罩层
  53. exportLoading: false,
  54. selectedCompanyList: [],
  55. companyList:[],
  56. deptList: [],
  57. companyUserList: [],
  58. selectedAppKey: null,
  59. selectedAppKeyLabel: '',
  60. appKeyOptions: [],
  61. // 选中数组
  62. ids: [],
  63. // 非单个禁用
  64. single: true,
  65. // 非多个禁用
  66. multiple: true,
  67. // 显示搜索条件
  68. showSearch: true,
  69. // 总条数
  70. total: 0,
  71. // token统计表格数据
  72. fastGptPushTokenTotalList: [],
  73. // 弹出层标题
  74. title: "",
  75. // 是否显示弹出层
  76. open: false,
  77. typeCountMap: null,
  78. // 日志类型字典
  79. typeOptions: [],
  80. // 查询参数
  81. queryParams: {
  82. pageNum: 1,
  83. pageSize: 10,
  84. roleId: null,
  85. count: null,
  86. type: null,
  87. companyId: null,
  88. companyUserId: null,
  89. qwUserId: null,
  90. typeCountMap: null,
  91. beginTime:null,
  92. endTime:null,
  93. appKey:null,
  94. },
  95. // 表单参数
  96. form: {},
  97. // 表单校验
  98. rules: {
  99. }
  100. };
  101. },
  102. created() {
  103. this.getList();
  104. this.getAllCompany();
  105. },
  106. methods: {
  107. getAllCompany() {
  108. allList().then(response => {
  109. this.companyList = response.rows;
  110. this.companyList.push({dictLabel: "无",
  111. dictValue: "0"})
  112. });
  113. },
  114. /** 查询ai事件埋点统计列表 */
  115. getList() {
  116. this.loading = true;
  117. getFastGptPushTokenTotal(this.queryParams).then(response => {
  118. console.log(response)
  119. this.fastGptPushTokenTotalList = response.rows;
  120. this.total = response.total;
  121. this.loading = false;
  122. });
  123. },
  124. normalizer(node) {
  125. return {
  126. id: node.id,
  127. label: node.label,
  128. children: node.children,
  129. disabled: node.disabled
  130. }
  131. },
  132. handleAppKeyChange(value) {
  133. const node = this.findNodeById(this.appKeyOptions, value);
  134. if (!node) {
  135. this.selectedAppKeyLabel = '';
  136. return;
  137. }
  138. // 如果是子节点,则找父节点 label
  139. if (node.parentLabel) {
  140. this.queryParams.appKey = node.parentLabel;
  141. this.selectedAppKeyLabel = node.parentLabel;
  142. this.selectedAppKey = this.selectedAppKeyLabel;
  143. } else {
  144. this.queryParams.appKey = node.label;
  145. this.selectedAppKeyLabel = node.label;
  146. this.selectedAppKey = this.selectedAppKeyLabel;
  147. }
  148. },
  149. findNodeById(nodes, id) {
  150. for (const node of nodes) {
  151. if (node.id === id) return node;
  152. if (node.children) {
  153. const found = this.findNodeById(node.children, id);
  154. if (found) return found;
  155. }
  156. }
  157. return null;
  158. },
  159. changeTime(){
  160. console.log(this.createTime);
  161. if(this.createTime!=null){
  162. this.queryParams.beginTime=this.createTime[0];
  163. this.queryParams.endTime=this.createTime[1];
  164. }else{
  165. this.queryParams.beginTime=null;
  166. this.queryParams.endTime=null;
  167. }
  168. console.log(this.queryParams.beginTime);
  169. console.log(this.queryParams.endTime);
  170. },
  171. // 取消按钮
  172. cancel() {
  173. this.open = false;
  174. this.reset();
  175. },
  176. // 表单重置
  177. reset() {
  178. this.form = {
  179. id: null,
  180. roleId: null,
  181. count: null,
  182. type: null,
  183. companyId: null,
  184. companyUserId: null,
  185. qwUserId: null,
  186. statTime: null
  187. };
  188. this.resetForm("form");
  189. },
  190. getPercentageColor(percentage) {
  191. // HSL模式从黄色(60度)渐变到红色(0度)
  192. const percent = Math.min(100, Math.max(0, parseFloat(percentage)));
  193. // 调整色相范围:从深黄色(40°)渐变到红色(0°)
  194. const hue = 40 - 40 * (percent / 100); // 初始 hue=40(深黄),终点 hue=0(红)
  195. // 提高饱和度(100%),亮度保持 50%(鲜艳但不刺眼)
  196. return `hsl(${hue}, 100%, 50%)`;
  197. },
  198. /** 搜索按钮操作 */
  199. handleQuery() {
  200. this.queryParams.pageNum = 1;
  201. console.log(this.selectedAppKey)
  202. if(this.selectedAppKey === null || typeof this.selectedAppKey === 'undefined'){
  203. this.queryParams.appKey = null;
  204. }
  205. this.getList();
  206. },
  207. /** 重置按钮操作 */
  208. resetQuery() {
  209. this.selectedAppKey = null;
  210. this.selectedAppKeyLabel = '';
  211. this.selectedCompanyList = [];
  212. this.queryParams.appKey = null;
  213. this.resetForm("queryForm");
  214. this.handleQuery();
  215. },
  216. // 多选框选中数据
  217. handleSelectionChange(selection) {
  218. this.ids = selection.map(item => item.id)
  219. this.single = selection.length!==1
  220. this.multiple = !selection.length
  221. },
  222. /** 导出按钮操作 */
  223. handleExport() {
  224. const queryParams = this.queryParams;
  225. if(this.selectedCompanyList != null && this.selectedCompanyList.length > 0) {
  226. this.queryParams.userIds = this.selectedCompanyList;
  227. }else {
  228. this.queryParams.userIds = [];
  229. }
  230. this.$confirm('是否确认导出所有ai事件埋点统计数据项?', "警告", {
  231. confirmButtonText: "确定",
  232. cancelButtonText: "取消",
  233. type: "warning"
  234. }).then(() => {
  235. this.exportLoading = true;
  236. return exportFastgptEventLogTotal(queryParams);
  237. }).then(response => {
  238. this.download(response.msg);
  239. this.exportLoading = false;
  240. }).catch(() => {});
  241. }
  242. }
  243. };
  244. </script>