index.vue 8.2 KB

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